From b265ff25b9a338a4aaf7b9790814faaf97139f19 Mon Sep 17 00:00:00 2001 From: Jagger <634750802@qq.com> Date: Wed, 27 Nov 2024 23:08:12 +0800 Subject: [PATCH] ui(frontend): refine admin ui --- .../app/(main)/(admin)/chat-engines/page.tsx | 2 + .../(main)/(admin)/embedding-models/page.tsx | 6 +++ .../app/src/app/(main)/(admin)/llms/page.tsx | 6 +++ .../(main)/(admin)/reranker-models/page.tsx | 6 +++ .../app/src/components/admin-page-heading.tsx | 27 ++++++------- .../chat-engine/chat-engines-table.tsx | 2 - .../components/dangerous-action-button.tsx | 6 +-- .../embedding-models/EmbeddingModelsTable.tsx | 12 ------ .../src/components/form/control-widget.tsx | 38 ++++++++++--------- .../knowledge-base/knowledge-base-card.tsx | 13 ++----- frontend/app/src/components/llm/LLMsTable.tsx | 12 ------ .../reranker/RerankerModelsTable.tsx | 12 ------ .../components/secondary-navigator-list.tsx | 1 + 13 files changed, 62 insertions(+), 81 deletions(-) diff --git a/frontend/app/src/app/(main)/(admin)/chat-engines/page.tsx b/frontend/app/src/app/(main)/(admin)/chat-engines/page.tsx index 5f84e4fd..ec72dfc7 100644 --- a/frontend/app/src/app/(main)/(admin)/chat-engines/page.tsx +++ b/frontend/app/src/app/(main)/(admin)/chat-engines/page.tsx @@ -1,5 +1,6 @@ import { AdminPageHeading } from '@/components/admin-page-heading'; import { ChatEnginesTable } from '@/components/chat-engine/chat-engines-table'; +import { NextLink } from '@/components/nextjs/NextLink'; export default function ChatEnginesPage () { return ( @@ -9,6 +10,7 @@ export default function ChatEnginesPage () { { title: 'Chat Engines', docsUrl: '/docs/chat-engine' }, ]} /> + New Chat Engine ); diff --git a/frontend/app/src/app/(main)/(admin)/embedding-models/page.tsx b/frontend/app/src/app/(main)/(admin)/embedding-models/page.tsx index 6792ee2e..944b415f 100644 --- a/frontend/app/src/app/(main)/(admin)/embedding-models/page.tsx +++ b/frontend/app/src/app/(main)/(admin)/embedding-models/page.tsx @@ -2,6 +2,8 @@ import { AdminPageHeading } from '@/components/admin-page-heading'; import { EmbeddingModelsTable } from '@/components/embedding-models/EmbeddingModelsTable'; +import { NextLink } from '@/components/nextjs/NextLink'; +import { PlusIcon } from 'lucide-react'; export default function EmbeddingModelPage () { @@ -13,6 +15,10 @@ export default function EmbeddingModelPage () { { title: 'Embedding Models', docsUrl: '/docs/embedding-model' }, ]} /> + + + New Embedding Model + ); diff --git a/frontend/app/src/app/(main)/(admin)/llms/page.tsx b/frontend/app/src/app/(main)/(admin)/llms/page.tsx index dc69e7aa..13e3ccab 100644 --- a/frontend/app/src/app/(main)/(admin)/llms/page.tsx +++ b/frontend/app/src/app/(main)/(admin)/llms/page.tsx @@ -1,5 +1,7 @@ import { AdminPageHeading } from '@/components/admin-page-heading'; import { LLMsTable } from '@/components/llm/LLMsTable'; +import { NextLink } from '@/components/nextjs/NextLink'; +import { PlusIcon } from 'lucide-react'; export default function Page () { return ( @@ -10,6 +12,10 @@ export default function Page () { { title: 'LLMs', docsUrl: '/docs/llm' }, ]} /> + + + New LLM + ); diff --git a/frontend/app/src/app/(main)/(admin)/reranker-models/page.tsx b/frontend/app/src/app/(main)/(admin)/reranker-models/page.tsx index 478d7d9d..31e116ee 100644 --- a/frontend/app/src/app/(main)/(admin)/reranker-models/page.tsx +++ b/frontend/app/src/app/(main)/(admin)/reranker-models/page.tsx @@ -1,5 +1,7 @@ import { AdminPageHeading } from '@/components/admin-page-heading'; +import { NextLink } from '@/components/nextjs/NextLink'; import RerankerModelsTable from '@/components/reranker/RerankerModelsTable'; +import { PlusIcon } from 'lucide-react'; export default function Page () { return ( @@ -10,6 +12,10 @@ export default function Page () { { title: 'Reranker Models', docsUrl: '/docs/reranker-model' }, ]} /> + + + New Reranker Model + ); diff --git a/frontend/app/src/components/admin-page-heading.tsx b/frontend/app/src/components/admin-page-heading.tsx index 3247cc85..fc04cf38 100644 --- a/frontend/app/src/components/admin-page-heading.tsx +++ b/frontend/app/src/components/admin-page-heading.tsx @@ -1,4 +1,7 @@ +'use client'; + import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from '@/components/ui/breadcrumb'; +import { useSettingContext } from '@/components/website-setting-provider'; import { HelpCircleIcon } from 'lucide-react'; import Link from 'next/link'; import { Fragment, type ReactNode } from 'react'; @@ -10,22 +13,24 @@ export interface BreadcrumbItem { } export interface TableHeadingProps { - /** - * @deprecated - */ - title?: ReactNode; breadcrumbs?: BreadcrumbItem[]; } -export function AdminPageHeading ({ title, breadcrumbs }: TableHeadingProps) { +export function AdminPageHeading ({ breadcrumbs }: TableHeadingProps) { + const { title: siteTitle } = useSettingContext(); return ( -
+
{breadcrumbs && ( + + + {siteTitle} + + {breadcrumbs.map((item, index) => ( - {index > 0 && } + {item.url ? {item.title} @@ -33,7 +38,7 @@ export function AdminPageHeading ({ title, breadcrumbs }: TableHeadingProps) { ? {item.title} : {item.title}} {item.docsUrl - ? + ? : undefined} @@ -41,10 +46,6 @@ export function AdminPageHeading ({ title, breadcrumbs }: TableHeadingProps) { )} -
- {title &&

{title}

} -
- ) - ; + ); } diff --git a/frontend/app/src/components/chat-engine/chat-engines-table.tsx b/frontend/app/src/components/chat-engine/chat-engines-table.tsx index 0f106924..e0f80e11 100644 --- a/frontend/app/src/components/chat-engine/chat-engines-table.tsx +++ b/frontend/app/src/components/chat-engine/chat-engines-table.tsx @@ -7,7 +7,6 @@ import { datetime } from '@/components/cells/datetime'; import { link } from '@/components/cells/link'; import { mono } from '@/components/cells/mono'; import { DataTableRemote } from '@/components/data-table-remote'; -import { NextLink } from '@/components/nextjs/NextLink'; import type { ColumnDef } from '@tanstack/react-table'; import { createColumnHelper } from '@tanstack/table-core'; import { CopyIcon, TrashIcon } from 'lucide-react'; @@ -59,7 +58,6 @@ const columns = [ export function ChatEnginesTable () { return ( New Chat Engine} columns={columns} apiKey="api.chat-engines.list" api={listChatEngines} diff --git a/frontend/app/src/components/dangerous-action-button.tsx b/frontend/app/src/components/dangerous-action-button.tsx index f5f46db2..d2a92cfd 100644 --- a/frontend/app/src/components/dangerous-action-button.tsx +++ b/frontend/app/src/components/dangerous-action-button.tsx @@ -1,6 +1,6 @@ import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; -import { Button, type ButtonProps } from '@/components/ui/button'; +import { Button, type ButtonProps, buttonVariants } from '@/components/ui/button'; import { getErrorMessage } from '@/lib/errors'; import { cn } from '@/lib/utils'; import { AlertTriangleIcon, Loader2Icon } from 'lucide-react'; @@ -50,8 +50,8 @@ export const DangerousActionButton = forwardRef{getErrorMessage(error)} } - Cancel - + Cancel + {acting && } Continue diff --git a/frontend/app/src/components/embedding-models/EmbeddingModelsTable.tsx b/frontend/app/src/components/embedding-models/EmbeddingModelsTable.tsx index 747f8efc..c51c43eb 100644 --- a/frontend/app/src/components/embedding-models/EmbeddingModelsTable.tsx +++ b/frontend/app/src/components/embedding-models/EmbeddingModelsTable.tsx @@ -2,27 +2,15 @@ import { type EmbeddingModel, listEmbeddingModels } from '@/api/embedding-models'; import { mono } from '@/components/cells/mono'; -import { DataTableHeading } from '@/components/data-table-heading'; import { DataTableRemote } from '@/components/data-table-remote'; import { Badge } from '@/components/ui/badge'; -import { buttonVariants } from '@/components/ui/button'; import type { ColumnDef } from '@tanstack/react-table'; import { createColumnHelper } from '@tanstack/table-core'; -import { PlusIcon } from 'lucide-react'; import Link from 'next/link'; export function EmbeddingModelsTable () { return ( - - - - New - - - )} columns={columns} apiKey="api.embedding-models.list" api={listEmbeddingModels} diff --git a/frontend/app/src/components/form/control-widget.tsx b/frontend/app/src/components/form/control-widget.tsx index e0d7ad67..4f7b2586 100644 --- a/frontend/app/src/components/form/control-widget.tsx +++ b/frontend/app/src/components/form/control-widget.tsx @@ -171,25 +171,10 @@ export const FormCombobox = forwardRef(({ config, placeh ? : config.error ? - : } + : config.clearable !== false && current != null && !disabled + ? onChange?.(null)} /> + : } - - - - {(config.clearable !== false && current != null && !disabled) && } - - - Clear select - - -
@@ -236,3 +221,20 @@ export const FormCombobox = forwardRef(({ config, placeh }); FormCombobox.displayName = 'FormCombobox'; + +function FormComboboxClearButton ({ onClick }: { onClick?: () => void }) { + return ( + + + + + + + Clear select + + + + ); +} diff --git a/frontend/app/src/components/knowledge-base/knowledge-base-card.tsx b/frontend/app/src/components/knowledge-base/knowledge-base-card.tsx index a0c14995..9c9aa6aa 100644 --- a/frontend/app/src/components/knowledge-base/knowledge-base-card.tsx +++ b/frontend/app/src/components/knowledge-base/knowledge-base-card.tsx @@ -1,5 +1,6 @@ import { deleteKnowledgeBase, type KnowledgeBaseSummary } from '@/api/knowledge-base'; import { DangerousActionButton } from '@/components/dangerous-action-button'; +import { mutateKnowledgeBases } from '@/components/knowledge-base/hooks'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader } from '@/components/ui/card'; @@ -10,7 +11,6 @@ import { cn } from '@/lib/utils'; import { AlertTriangleIcon, Book, Ellipsis } from 'lucide-react'; import { useRouter } from 'next/navigation'; import { ReactNode, startTransition, useState } from 'react'; -import { mutate } from 'swr'; export function KnowledgeBaseCard ({ knowledgeBase, children }: { knowledgeBase: KnowledgeBaseSummary, children?: ReactNode }) { const router = useRouter(); @@ -31,12 +31,7 @@ export function KnowledgeBaseCard ({ knowledgeBase, children }: { knowledgeBase: const handleDelete = async () => { await deleteKnowledgeBase(knowledgeBase.id); - await mutate(key => { - if (typeof key === 'string') { - return key.startsWith('api.knowledge-bases.list?'); - } - return false; - }); + await mutateKnowledgeBases(); setDropdownOpen(false); }; @@ -74,12 +69,12 @@ export function KnowledgeBaseCard ({ knowledgeBase, children }: { knowledgeBase: - event.stopPropagation()}> + event.stopPropagation()}> Settings event.preventDefault()} > Delete diff --git a/frontend/app/src/components/llm/LLMsTable.tsx b/frontend/app/src/components/llm/LLMsTable.tsx index 67f916d6..5aee5ea5 100644 --- a/frontend/app/src/components/llm/LLMsTable.tsx +++ b/frontend/app/src/components/llm/LLMsTable.tsx @@ -1,27 +1,15 @@ 'use client'; import { listLlms, type LLM } from '@/api/llms'; -import { DataTableHeading } from '@/components/data-table-heading'; import { DataTableRemote } from '@/components/data-table-remote'; import { Badge } from '@/components/ui/badge'; -import { buttonVariants } from '@/components/ui/button'; import type { ColumnDef } from '@tanstack/react-table'; import { createColumnHelper } from '@tanstack/table-core'; -import { PlusIcon } from 'lucide-react'; import Link from 'next/link'; export function LLMsTable () { return ( - - - - New - - - )} columns={columns} apiKey="api.llms.list" api={listLlms} diff --git a/frontend/app/src/components/reranker/RerankerModelsTable.tsx b/frontend/app/src/components/reranker/RerankerModelsTable.tsx index 57e0bd77..3d8a23b5 100644 --- a/frontend/app/src/components/reranker/RerankerModelsTable.tsx +++ b/frontend/app/src/components/reranker/RerankerModelsTable.tsx @@ -1,27 +1,15 @@ 'use client'; import { listRerankers, type Reranker } from '@/api/rerankers'; -import { DataTableHeading } from '@/components/data-table-heading'; import { DataTableRemote } from '@/components/data-table-remote'; import { Badge } from '@/components/ui/badge'; -import { buttonVariants } from '@/components/ui/button'; import type { ColumnDef } from '@tanstack/react-table'; import { createColumnHelper } from '@tanstack/table-core'; -import { PlusIcon } from 'lucide-react'; import Link from 'next/link'; export default function RerankerModelsTable () { return ( - - - - New - - - )} columns={columns} apiKey="api.rerankers.list" api={listRerankers} diff --git a/frontend/app/src/components/secondary-navigator-list.tsx b/frontend/app/src/components/secondary-navigator-list.tsx index 6afe7ccf..bf108f66 100644 --- a/frontend/app/src/components/secondary-navigator-list.tsx +++ b/frontend/app/src/components/secondary-navigator-list.tsx @@ -87,6 +87,7 @@ export const SecondaryNavigatorMain = forwardRef );