Add tool duplication functionality and enhance ComponentsToolsPage
- Implement a new API endpoint for duplicating tools in the backend. - Add a duplicate_tool function in ComponentsToolsPage to handle tool duplication requests. - Update the UI to include a dropdown menu option for duplicating tools, improving user experience. - Refactor the remove function to accept a resource object instead of an ID for better clarity and maintainability.
This commit is contained in:
@@ -448,10 +448,11 @@ export function ComponentsModelsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(id: string) {
|
||||
setDeletingId(id);
|
||||
async function remove(resource: ModelResource) {
|
||||
if (!window.confirm(`确认删除模型“${resource.name}”?`)) return;
|
||||
setDeletingId(resource.id);
|
||||
try {
|
||||
await modelResourcesApi.remove(id);
|
||||
await modelResourcesApi.remove(resource.id);
|
||||
await load();
|
||||
} catch (error) {
|
||||
setLoadError(error instanceof Error ? error.message : "删除失败");
|
||||
@@ -663,7 +664,7 @@ export function ComponentsModelsPage() {
|
||||
disabled={deletingId === resource.id}
|
||||
onSelect={(event) => {
|
||||
event.preventDefault();
|
||||
void remove(resource.id);
|
||||
void remove(resource);
|
||||
}}
|
||||
>
|
||||
{deletingId === resource.id ? (
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
Copy,
|
||||
Loader2,
|
||||
MoreHorizontal,
|
||||
Pencil,
|
||||
@@ -243,6 +244,7 @@ export function ComponentsToolsPage() {
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [functionNameTouched, setFunctionNameTouched] = useState(false);
|
||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||
const [duplicatingId, setDuplicatingId] = useState<string | null>(null);
|
||||
|
||||
const loadTools = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -345,6 +347,18 @@ export function ComponentsToolsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function duplicateTool(id: string) {
|
||||
setDuplicatingId(id);
|
||||
try {
|
||||
await toolsApi.duplicate(id);
|
||||
await loadTools();
|
||||
} catch (duplicateError) {
|
||||
setError(duplicateError instanceof Error ? duplicateError.message : "复制失败");
|
||||
} finally {
|
||||
setDuplicatingId(null);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: DataListColumn<Tool>[] = [
|
||||
{
|
||||
key: "name",
|
||||
@@ -435,6 +449,21 @@ export function ComponentsToolsPage() {
|
||||
align="end"
|
||||
className="w-32 min-w-32 rounded-xl border border-hairline bg-popover p-1"
|
||||
>
|
||||
<DropdownMenuItem
|
||||
className="rounded-lg"
|
||||
disabled={duplicatingId === tool.id}
|
||||
onSelect={(event) => {
|
||||
event.preventDefault();
|
||||
void duplicateTool(tool.id);
|
||||
}}
|
||||
>
|
||||
{duplicatingId === tool.id ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Copy size={14} />
|
||||
)}
|
||||
复制
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
variant="destructive"
|
||||
className="rounded-lg"
|
||||
|
||||
Reference in New Issue
Block a user