Skip to content

Commit d3cdb45

Browse files
committed
Add enum parameter support in ToolsTab component and corresponding tests
1 parent b7ef160 commit d3cdb45

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

.worktrees/pr-716

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 897d9f07bc23e3c196c5943cf9ad2f9bbba9e3a1

.worktrees/pr-727

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 4a7ae16ffdbc4aa489baf7e298f1041f115b8da7

.worktrees/pr-739

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 06f2098ae56d7507eda113d53406d713a5e718dd

.worktrees/pr-751

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 6f727b6662594651b57d1d633377485a750781b5

.worktrees/pr-789

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 1207834b7eccd56692fd071de8be5d5f8a9f1492

client/src/components/ToolsTab.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { Input } from "@/components/ui/input";
55
import { Label } from "@/components/ui/label";
66
import { TabsContent } from "@/components/ui/tabs";
77
import { Textarea } from "@/components/ui/textarea";
8+
import {
9+
Select,
10+
SelectContent,
11+
SelectItem,
12+
SelectTrigger,
13+
SelectValue,
14+
} from "@/components/ui/select";
815
import DynamicJsonForm, { DynamicJsonFormRef } from "./DynamicJsonForm";
916
import type { JsonValue, JsonSchemaType } from "@/utils/jsonUtils";
1017
import {
@@ -180,6 +187,42 @@ const ToolsTab = ({
180187
{prop.description || "Toggle this option"}
181188
</label>
182189
</div>
190+
) : prop.type === "string" && prop.enum ? (
191+
<Select
192+
value={
193+
params[key] === undefined
194+
? ""
195+
: String(params[key])
196+
}
197+
onValueChange={(value) => {
198+
if (value === "") {
199+
setParams({
200+
...params,
201+
[key]: undefined,
202+
});
203+
} else {
204+
setParams({
205+
...params,
206+
[key]: value,
207+
});
208+
}
209+
}}
210+
>
211+
<SelectTrigger id={key} className="mt-1">
212+
<SelectValue
213+
placeholder={
214+
prop.description || "Select an option"
215+
}
216+
/>
217+
</SelectTrigger>
218+
<SelectContent>
219+
{prop.enum.map((option) => (
220+
<SelectItem key={option} value={option}>
221+
{option}
222+
</SelectItem>
223+
))}
224+
</SelectContent>
225+
</Select>
183226
) : prop.type === "string" ? (
184227
<Textarea
185228
id={key}

client/src/components/__tests__/ToolsTab.test.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,64 @@ describe("ToolsTab", () => {
638638
});
639639
});
640640

641+
describe("Enum Parameters", () => {
642+
const toolWithEnumParam: Tool = {
643+
name: "enumTool",
644+
description: "Tool with enum parameter",
645+
inputSchema: {
646+
type: "object" as const,
647+
properties: {
648+
format: {
649+
type: "string" as const,
650+
enum: ["json", "xml", "csv", "yaml"],
651+
description: "Output format",
652+
},
653+
},
654+
},
655+
};
656+
657+
beforeEach(() => {
658+
// Mock scrollIntoView for Radix UI Select
659+
Element.prototype.scrollIntoView = jest.fn();
660+
});
661+
662+
it("should render enum parameter as dropdown", () => {
663+
renderToolsTab({
664+
tools: [toolWithEnumParam],
665+
selectedTool: toolWithEnumParam,
666+
});
667+
668+
// Should render a select button instead of textarea
669+
const selectTrigger = screen.getByRole("combobox", { name: /format/i });
670+
expect(selectTrigger).toBeInTheDocument();
671+
});
672+
673+
it("should render non-enum string parameter as textarea", () => {
674+
const toolWithStringParam: Tool = {
675+
name: "stringTool",
676+
description: "Tool with regular string parameter",
677+
inputSchema: {
678+
type: "object" as const,
679+
properties: {
680+
text: {
681+
type: "string" as const,
682+
description: "Some text input",
683+
},
684+
},
685+
},
686+
};
687+
688+
renderToolsTab({
689+
tools: [toolWithStringParam],
690+
selectedTool: toolWithStringParam,
691+
});
692+
693+
// Should render textarea, not select
694+
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
695+
expect(screen.getByRole("textbox")).toBeInTheDocument();
696+
});
697+
});
698+
641699
describe("JSON Validation Integration", () => {
642700
const toolWithJsonParams: Tool = {
643701
name: "jsonTool",

0 commit comments

Comments
 (0)