extract listpane

This commit is contained in:
Ashwin Bhat
2024-10-08 16:20:50 -07:00
parent 4f26b5a51c
commit 019777bd93
4 changed files with 93 additions and 90 deletions

View File

@@ -0,0 +1,43 @@
import { Button } from "./ui/button";
type ListPaneProps<T> = {
items: T[];
listItems: () => void;
setSelectedItem: (item: T) => void;
renderItem: (item: T) => React.ReactNode;
title: string;
buttonText: string;
};
const ListPane = <T extends object>({
items,
listItems,
setSelectedItem,
renderItem,
title,
buttonText,
}: ListPaneProps<T>) => (
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200">
<h3 className="font-semibold">{title}</h3>
</div>
<div className="p-4">
<Button variant="outline" className="w-full mb-4" onClick={listItems}>
{buttonText}
</Button>
<div className="space-y-2">
{items.map((item, index) => (
<div
key={index}
className="flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
onClick={() => setSelectedItem(item)}
>
{renderItem(item)}
</div>
))}
</div>
</div>
</div>
);
export default ListPane;

View File

@@ -6,6 +6,7 @@ import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { useState } from "react";
import { Label } from "@/components/ui/label";
import ListPane from "./ListPane";
export type Prompt = {
name: string;
@@ -48,34 +49,22 @@ const PromptsTab = ({
return (
<TabsContent value="prompts" className="grid grid-cols-2 gap-4">
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200">
<h3 className="font-semibold">Prompts</h3>
</div>
<div className="p-4">
<Button
variant="outline"
className="w-full mb-4"
onClick={listPrompts}
>
List Prompts
</Button>
<div className="space-y-2">
{prompts.map((prompt) => (
<div
key={prompt.name}
className="flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
onClick={() => {
setSelectedPrompt(prompt);
setPromptArgs({});
}}
>
<span className="flex-1">{prompt.name}</span>
</div>
))}
</div>
</div>
</div>
<ListPane
items={prompts}
listItems={listPrompts}
setSelectedItem={(prompt) => {
setSelectedPrompt(prompt);
setPromptArgs({});
}}
renderItem={(prompt) => (
<>
<span className="flex-1">{prompt.name}</span>
<span className="text-sm text-gray-500">{prompt.description}</span>
</>
)}
title="Prompts"
buttonText="List Prompts"
/>
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200">

View File

@@ -1,13 +1,8 @@
import {
FileText,
PlayCircle,
ChevronRight,
AlertCircle,
RefreshCw,
} from "lucide-react";
import { FileText, ChevronRight, AlertCircle, RefreshCw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { TabsContent } from "@/components/ui/tabs";
import ListPane from "./ListPane";
export type Resource = {
uri: string;
@@ -31,37 +26,23 @@ const ResourcesTab = ({
error: string | null;
}) => (
<TabsContent value="resources" className="grid grid-cols-2 gap-4">
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200">
<h3 className="font-semibold">Resources</h3>
</div>
<div className="p-4">
<Button
variant="outline"
className="w-full mb-4"
onClick={listResources}
>
<PlayCircle className="w-4 h-4 mr-2" />
List Resources
</Button>
<div className="space-y-2">
{resources.map((resource, index) => (
<div
key={index}
className="flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
onClick={() => {
setSelectedResource(resource);
readResource(resource.uri);
}}
>
<FileText className="w-4 h-4 mr-2 text-gray-500" />
<span className="flex-1">{resource.uri}</span>
<ChevronRight className="w-4 h-4 text-gray-400" />
</div>
))}
</div>
</div>
</div>
<ListPane
items={resources}
listItems={listResources}
setSelectedItem={(resource) => {
setSelectedResource(resource);
readResource(resource.uri);
}}
renderItem={(resource) => (
<>
<FileText className="w-4 h-4 mr-2 text-gray-500" />
<span className="flex-1">{resource.uri}</span>
<ChevronRight className="w-4 h-4 text-gray-400" />
</>
)}
title="Resources"
buttonText="List Resources"
/>
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200 flex justify-between items-center">

View File

@@ -5,6 +5,7 @@ import { Send, AlertCircle } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { useState } from "react";
import { Label } from "@/components/ui/label";
import ListPane from "./ListPane";
export type Tool = {
name: string;
@@ -36,30 +37,19 @@ const ToolsTab = ({
return (
<TabsContent value="tools" className="grid grid-cols-2 gap-4">
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200">
<h3 className="font-semibold">Tools</h3>
</div>
<div className="p-4">
<Button variant="outline" className="w-full mb-4" onClick={listTools}>
List Tools
</Button>
<div className="space-y-2">
{tools.map((tool, index) => (
<div
key={index}
className="flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
onClick={() => setSelectedTool(tool)}
>
<span className="flex-1">{tool.name}</span>
<span className="text-sm text-gray-500">
{tool.description}
</span>
</div>
))}
</div>
</div>
</div>
<ListPane
items={tools}
listItems={listTools}
setSelectedItem={setSelectedTool}
renderItem={(tool) => (
<>
<span className="flex-1">{tool.name}</span>
<span className="text-sm text-gray-500">{tool.description}</span>
</>
)}
title="Tools"
buttonText="List Tools"
/>
<div className="bg-white rounded-lg shadow">
<div className="p-4 border-b border-gray-200">