瀏覽代碼

知识库

CzRger 4 月之前
父節點
當前提交
8ba27bf31d

+ 27 - 1
web/app/(commonLayout)/datasets/Container.tsx

@@ -29,6 +29,8 @@ import { useTabSearchParams } from '@/hooks/use-tab-searchparams'
 import { useStore as useTagStore } from '@/app/components/base/tag-management/store'
 import { useAppContext } from '@/context/app-context'
 import { useExternalApiPanel } from '@/context/external-api-panel-context'
+import { SimpleSelect } from '@/app/components/base/select'
+import { fetchTypes } from '@/service/common'
 
 const Container = () => {
   const { t } = useTranslation()
@@ -81,6 +83,20 @@ const Container = () => {
       return router.replace('/apps')
   }, [currentWorkspace, router])
 
+  const [type, setType] = useState<any>()
+  const [searchType, setSearchType] = useState('')
+  const { run: handleTypeUpdate } = useDebounceFn(() => {
+    setSearchType(type)
+  }, { wait: 500 })
+  const [optionsType, setOptionsType] = useState<any>([])
+  useEffect(() => {
+    fetchTypes({
+      url: '/workspaces/123123',
+      params: {},
+    }).then((res: any) => {
+      setOptionsType(res.data.map((v: any) => ({ name: v.name, value: v.id })) || [])
+    })
+  }, [])
   return (
     <div ref={containerRef} className='scroll-container relative flex grow flex-col overflow-y-auto bg-background-body'>
       <div className='sticky top-0 z-10 flex flex-wrap justify-between gap-y-2 bg-background-body px-12 pb-2 pt-4 leading-[56px]'>
@@ -91,6 +107,16 @@ const Container = () => {
         />
         {activeTab === 'dataset' && (
           <div className='flex items-center justify-center gap-2'>
+            <SimpleSelect
+              className="w-[200px]"
+              defaultValue={type}
+              onSelect={(i) => {
+                setType(i.value)
+                handleTypeUpdate()
+              }}
+              items={optionsType}
+              allowSearch={false}
+            />
             {isCurrentWorkspaceOwner && <CheckboxWithLabel
               isChecked={includeAll}
               onChange={toggleIncludeAll}
@@ -122,7 +148,7 @@ const Container = () => {
       </div>
       {activeTab === 'dataset' && (
         <>
-          <Datasets containerRef={containerRef} tags={tagIDs} keywords={searchKeywords} includeAll={includeAll} />
+          <Datasets containerRef={containerRef} tags={tagIDs} keywords={searchKeywords} includeAll={includeAll} type={searchType} optionsType={optionsType} />
           <DatasetFooter />
           {showTagManagementModal && (
             <TagManagementModal type='knowledge' show={showTagManagementModal} />

+ 5 - 1
web/app/(commonLayout)/datasets/DatasetCard.tsx

@@ -23,12 +23,14 @@ import { useAppContext } from '@/context/app-context'
 
 export type DatasetCardProps = {
   dataset: DataSet
-  onSuccess?: () => void
+  onSuccess?: () => void,
+  optionsType: any[]
 }
 
 const DatasetCard = ({
   dataset,
   onSuccess,
+  optionsType,
 }: DatasetCardProps) => {
   const { t } = useTranslation()
   const { notify } = useContext(ToastContext)
@@ -37,6 +39,7 @@ const DatasetCard = ({
 
   const { isCurrentWorkspaceDatasetOperator } = useAppContext()
   const [tags, setTags] = useState<Tag[]>(dataset.tags)
+  const [type, setType] = useState<any>(dataset.type)
 
   const [showRenameModal, setShowRenameModal] = useState(false)
   const [showConfirmDelete, setShowConfirmDelete] = useState(false)
@@ -159,6 +162,7 @@ const DatasetCard = ({
               </div>
             </div>
           </div>
+          <div>{optionsType.filter((v: any) => v.value === type)[0]?.name}</div>
         </div>
         <div
           className={cn(

+ 10 - 3
web/app/(commonLayout)/datasets/Datasets.tsx

@@ -16,6 +16,7 @@ const getKey = (
   tags: string[],
   keyword: string,
   includeAll: boolean,
+  type: string,
 ) => {
   if (!pageIndex || previousPageData.has_more) {
     const params: FetchDatasetsParams = {
@@ -30,6 +31,8 @@ const getKey = (
       params.params.tag_ids = tags
     if (keyword)
       params.params.keyword = keyword
+    if (type)
+      params.params.type = type
     return params
   }
   return null
@@ -39,7 +42,9 @@ type Props = {
   containerRef: React.RefObject<HTMLDivElement>
   tags: string[]
   keywords: string
-  includeAll: boolean
+  includeAll: boolean,
+  type: string,
+  optionsType: any[]
 }
 
 const Datasets = ({
@@ -47,10 +52,12 @@ const Datasets = ({
   tags,
   keywords,
   includeAll,
+  type,
+  optionsType,
 }: Props) => {
   const { isCurrentWorkspaceEditor } = useAppContext()
   const { data, isLoading, setSize, mutate } = useSWRInfinite(
-    (pageIndex: number, previousPageData: DataSetListResponse) => getKey(pageIndex, previousPageData, tags, keywords, includeAll),
+    (pageIndex: number, previousPageData: DataSetListResponse) => getKey(pageIndex, previousPageData, tags, keywords, includeAll, type),
     fetchDatasets,
     { revalidateFirstPage: false, revalidateAll: true },
   )
@@ -89,7 +96,7 @@ const Datasets = ({
     <nav className='grid shrink-0 grow grid-cols-1 content-start gap-4 px-12 pt-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'>
       { isCurrentWorkspaceEditor && <NewDatasetCard ref={anchorRef} /> }
       {data?.map(({ data: datasets }) => datasets.map(dataset => (
-        <DatasetCard key={dataset.id} dataset={dataset} onSuccess={mutate} />),
+        <DatasetCard key={dataset.id} dataset={dataset} onSuccess={mutate} optionsType={optionsType}/>),
       ))}
     </nav>
   )

+ 1 - 1
web/i18n/zh-Hans/app.ts

@@ -33,7 +33,7 @@ const translation = {
   roadmap: '产品路线图',
   newApp: {
     learnMore: '了解更多',
-    startFromBlank: '创建空白应用',
+    startFromBlank: '创建机器人',
     startFromTemplate: '从应用模版创建',
     captionAppType: '想要哪种应用类型?',
     foundResult: '{{count}} 个结果',

+ 1 - 1
web/i18n/zh-Hans/common.ts

@@ -138,7 +138,7 @@ const translation = {
   menus: {
     status: 'beta',
     explore: '探索',
-    apps: '工作室',
+    apps: '机器人管理',
     plugins: '插件',
     exploreMarketplace: '探索 Marketplace',
     pluginsTips: '集成第三方插件或创建与 ChatGPT 兼容的 AI 插件。',

+ 1 - 1
web/i18n/zh-Hant/common.ts

@@ -132,7 +132,7 @@ const translation = {
   menus: {
     status: 'beta',
     explore: '探索',
-    apps: '工作室',
+    apps: '機器人管理',
     plugins: '外掛',
     pluginsTips: '整合第三方外掛或建立與 ChatGPT 相容的 AI 外掛。',
     datasets: '知識庫',

+ 2 - 1
web/models/datasets.ts

@@ -156,7 +156,8 @@ export type FetchDatasetsParams = {
     tag_ids?: string[]
     limit?: number
     include_all?: boolean
-    keyword?: string
+    keyword?: string,
+    type?: string,
   }
 }