Skip to content

Commit

Permalink
enhance: organize tool catalog (#1075)
Browse files Browse the repository at this point in the history
- sort first by bundlable tool groups
- sort by alphabetical tool category name
  • Loading branch information
ryanhopperlowe authored Dec 30, 2024
1 parent 95281e5 commit 9674669
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions ui/admin/app/components/tools/ToolCatalog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AlertTriangleIcon, PlusIcon } from "lucide-react";
import { useMemo } from "react";
import useSWR from "swr";

import { ToolReferenceService } from "~/lib/service/api/toolreferenceService";
Expand Down Expand Up @@ -41,6 +42,19 @@ export function ToolCatalog({
{ fallbackData: {} }
);

const sortedCategories = useMemo(() => {
return Object.entries(toolCategories).sort(
([nameA, categoryA], [nameB, categoryB]): number => {
const aHasBundle = categoryA.bundleTool ? 1 : 0;
const bHasBundle = categoryB.bundleTool ? 1 : 0;

if (aHasBundle !== bHasBundle) return bHasBundle - aHasBundle;

return nameA.localeCompare(nameB);
}
);
}, [toolCategories]);

if (isLoading) return <LoadingSpinner />;

return (
Expand Down Expand Up @@ -68,17 +82,15 @@ export function ToolCatalog({
No results found.
</h1>{" "}
</CommandEmpty>
{Object.entries(toolCategories).map(
([category, categoryTools]) => (
<ToolCatalogGroup
key={category}
category={category}
tools={categoryTools}
selectedTools={tools}
onUpdateTools={onUpdateTools}
/>
)
)}
{sortedCategories.map(([category, categoryTools]) => (
<ToolCatalogGroup
key={category}
category={category}
tools={categoryTools}
selectedTools={tools}
onUpdateTools={onUpdateTools}
/>
))}
</CommandList>
</Command>
);
Expand Down

0 comments on commit 9674669

Please sign in to comment.