Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user tools to the top & toast on successful tool addition #839

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/admin/app/components/tools/CreateTool.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PlusCircle } from "lucide-react";
import { useCallback, useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import useSWR from "swr";

import { CreateToolReference, ToolReference } from "~/lib/model/toolReferences";
Expand Down Expand Up @@ -38,6 +39,9 @@ export function CreateTool({ onError, onSuccess }: CreateToolProps) {
if (loadedTool.error) {
onError(loadedTool.error);
} else {
toast.success(
`"${loadedTool.reference}" registered successfully.`
);
onSuccess();
}
},
Expand Down
51 changes: 35 additions & 16 deletions ui/admin/app/components/tools/toolGrid/ToolGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useCallback, useEffect, useState } from "react";

import { ToolCategoryMap } from "~/lib/service/api/toolreferenceService";
import { ToolReference } from "~/lib/model/toolReferences";
import {
ToolCategoryMap,
YourToolsToolCategory,
} from "~/lib/service/api/toolreferenceService";

import { TypographyP } from "~/components/Typography";
import { CategoryHeader } from "~/components/tools/toolGrid/CategoryHeader";
Expand Down Expand Up @@ -58,27 +62,42 @@ export function ToolGrid({ toolCategories, filter, onDelete }: ToolGridProps) {
return <TypographyP>No tools found...</TypographyP>;
}

const yourToolsCategory = filteredResults[YourToolsToolCategory];
return (
<div className="space-y-8 pb-16">
{yourToolsCategory &&
renderToolCategory(
YourToolsToolCategory,
yourToolsCategory.tools
)}
{Object.entries(filteredResults).map(
([category, { tools, bundleTool }]) => {
if (tools.length) {
return (
<div key={category} className="space-y-4">
<CategoryHeader
category={category}
description={bundleTool?.description || ""}
tools={tools}
/>
<CategoryTools
tools={tools}
onDelete={onDelete}
/>
</div>
);
}
if (category === YourToolsToolCategory) return null;
return renderToolCategory(
category,
tools,
bundleTool?.description
);
}
)}
</div>
);

function renderToolCategory(
category: string,
tools: ToolReference[],
description = ""
) {
if (!tools.length) return null;
return (
<div key={category} className="space-y-4">
<CategoryHeader
category={category}
description={description}
tools={tools}
/>
<CategoryTools tools={tools} onDelete={onDelete} />
</div>
);
}
}
6 changes: 5 additions & 1 deletion ui/admin/app/lib/service/api/toolreferenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type ToolCategory = {
bundleTool?: ToolReference;
tools: ToolReference[];
};
export const UncategorizedToolCategory = "Uncategorized";
export const YourToolsToolCategory = "Your Tools";
export type ToolCategoryMap = Record<string, ToolCategory>;
async function getToolReferencesCategoryMap(type?: ToolReferenceType) {
const res = await request<{ items: ToolReference[] }>({
Expand All @@ -35,7 +37,9 @@ async function getToolReferencesCategoryMap(type?: ToolReferenceType) {
const result: ToolCategoryMap = {};

for (const toolReference of toolReferences) {
const category = toolReference.metadata?.category || "Uncategorized";
const category = !toolReference.builtin
? YourToolsToolCategory
: toolReference.metadata?.category || UncategorizedToolCategory;

if (!result[category]) {
result[category] = {
Expand Down
13 changes: 12 additions & 1 deletion ui/admin/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { CircleCheckIcon } from "lucide-react";
import { SWRConfig } from "swr";

import { AuthProvider } from "~/components/auth/AuthContext";
Expand Down Expand Up @@ -48,7 +49,17 @@ export function Layout({ children }: { children: React.ReactNode }) {
</head>
<body>
{children}
<Toaster closeButton />
<Toaster
closeButton
icons={{
success: (
<CircleCheckIcon
className="text-success"
size={20}
/>
),
}}
/>
<ScrollRestoration />
<Scripts />
</body>
Expand Down