-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: improve tool catalog UX (#1045)
- Display only bundle tools initially (when available) and require user action to display granular tool items
- Loading branch information
1 parent
f03c070
commit a689d22
Showing
6 changed files
with
155 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { useState } from "react"; | ||
|
||
import { ToolCategory } from "~/lib/service/api/toolreferenceService"; | ||
import { cn } from "~/lib/utils"; | ||
|
||
import { ToolItem } from "~/components/tools/ToolItem"; | ||
import { CommandGroup } from "~/components/ui/command"; | ||
|
||
export function ToolCatalogGroup({ | ||
category, | ||
tools, | ||
selectedTools, | ||
onUpdateTools, | ||
}: { | ||
category: string; | ||
tools: ToolCategory; | ||
selectedTools: string[]; | ||
onUpdateTools: (tools: string[]) => void; | ||
}) { | ||
const handleSelect = (toolId: string) => { | ||
if (selectedTools.includes(toolId)) { | ||
onUpdateTools(selectedTools.filter((tool) => tool !== toolId)); | ||
} | ||
|
||
const newTools = selectedTools | ||
.filter((tool) => tool !== tools.bundleTool?.id) | ||
.concat(toolId); | ||
|
||
onUpdateTools(newTools); | ||
}; | ||
|
||
const handleSelectBundle = (bundleToolId: string) => { | ||
if (selectedTools.includes(bundleToolId)) { | ||
onUpdateTools( | ||
selectedTools.filter((tool) => tool !== bundleToolId) | ||
); | ||
return; | ||
} | ||
|
||
const toolsToRemove = new Set(tools.tools.map((tool) => tool.id)); | ||
|
||
const newTools = [ | ||
...selectedTools.filter((tool) => !toolsToRemove.has(tool)), | ||
bundleToolId, | ||
]; | ||
|
||
onUpdateTools(newTools); | ||
}; | ||
|
||
const [expanded, setExpanded] = useState(() => { | ||
const set = new Set(tools.tools.map((tool) => tool.id)); | ||
return selectedTools.some((tool) => set.has(tool)); | ||
}); | ||
|
||
return ( | ||
<CommandGroup | ||
key={category} | ||
className={cn({ | ||
"has-[.group-heading:hover]:bg-accent": !!tools.bundleTool, | ||
})} | ||
heading={!tools.bundleTool ? category : undefined} | ||
> | ||
{tools.bundleTool && ( | ||
<ToolItem | ||
tool={tools.bundleTool} | ||
isSelected={selectedTools.includes(tools.bundleTool.id)} | ||
isBundleSelected={false} | ||
onSelect={() => handleSelectBundle(tools.bundleTool!.id)} | ||
expanded={expanded} | ||
onExpand={setExpanded} | ||
isBundle | ||
/> | ||
)} | ||
|
||
{(expanded || !tools.bundleTool) && | ||
tools.tools.map((categoryTool) => ( | ||
<ToolItem | ||
key={categoryTool.id} | ||
tool={categoryTool} | ||
isSelected={selectedTools.includes(categoryTool.id)} | ||
isBundleSelected={ | ||
tools.bundleTool | ||
? selectedTools.includes(tools.bundleTool.id) | ||
: false | ||
} | ||
onSelect={() => handleSelect(categoryTool.id)} | ||
/> | ||
))} | ||
</CommandGroup> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters