mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-06-30 02:57:38 +00:00
Enhance CommandMenu to prevent duplicate scripts across categories
This commit is contained in:
@ -139,9 +139,27 @@ export default function CommandMenu() {
|
||||
<CommandInput placeholder="Search for a script..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>{isLoading ? "Loading..." : "No scripts found."}</CommandEmpty>
|
||||
{links.map(category => (
|
||||
{(() => {
|
||||
// Track seen scripts globally to avoid duplicates across all categories
|
||||
const globalSeenScripts = new Set<string>();
|
||||
|
||||
return links.map((category) => {
|
||||
const uniqueScripts = category.scripts.filter((script) => {
|
||||
if (globalSeenScripts.has(script.slug)) {
|
||||
return false;
|
||||
}
|
||||
globalSeenScripts.add(script.slug);
|
||||
return true;
|
||||
});
|
||||
|
||||
// Only render category if it has unique scripts
|
||||
if (uniqueScripts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CommandGroup key={`category:${category.name}`} heading={category.name}>
|
||||
{category.scripts.map(script => (
|
||||
{uniqueScripts.map(script => (
|
||||
<CommandItem
|
||||
key={`script:${script.slug}`}
|
||||
value={`${script.slug}-${script.name}`}
|
||||
@ -166,7 +184,9 @@ export default function CommandMenu() {
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
))}
|
||||
);
|
||||
});
|
||||
})()}
|
||||
</CommandList>
|
||||
</CommandDialog>
|
||||
</>
|
||||
|
Reference in New Issue
Block a user