From 4025cd0b466c0b59efa720c1a95b24b4b2579902 Mon Sep 17 00:00:00 2001 From: twwu Date: Wed, 7 May 2025 11:30:13 +0800 Subject: [PATCH] feat: Refactor dataset pipeline creation components and add internationalization support --- .../[datasetId]/layout-main.tsx | 11 +-- .../create-from-dsl-modal/index.tsx | 1 - .../create-options/create-from-scratch.tsx | 79 ++++++++++++++----- .../create-options/index.tsx | 11 ++- .../datasets/create-from-pipeline/header.tsx | 5 +- .../list/built-in-pipeline-list.tsx | 62 ++++++++------- .../list/customized-list.tsx | 49 ++++++++---- .../create-from-pipeline/list/index.tsx | 18 +++-- .../list/template-card/edit-pipeline-info.tsx | 17 ++-- .../list/template-card/index.tsx | 15 ++-- .../datasets/list/dataset-card/index.tsx | 25 ++---- web/i18n/de-DE/dataset-pipeline.ts | 3 + web/i18n/en-US/dataset-pipeline.ts | 25 ++++++ web/i18n/es-ES/dataset-pipeline.ts | 3 + web/i18n/fa-IR/dataset-pipeline.ts | 3 + web/i18n/fr-FR/dataset-pipeline.ts | 3 + web/i18n/hi-IN/dataset-pipeline.ts | 3 + web/i18n/i18next-config.ts | 1 + web/i18n/it-IT/dataset-pipeline.ts | 3 + web/i18n/ja-JP/dataset-pipeline.ts | 3 + web/i18n/ko-KR/dataset-pipeline.ts | 3 + web/i18n/pl-PL/dataset-pipeline.ts | 3 + web/i18n/pt-BR/dataset-pipeline.ts | 3 + web/i18n/ro-RO/dataset-pipeline.ts | 3 + web/i18n/ru-RU/dataset-pipeline.ts | 3 + web/i18n/sl-SI/dataset-pipeline.ts | 3 + web/i18n/th-TH/dataset-pipeline.ts | 3 + web/i18n/tr-TR/dataset-pipeline.ts | 3 + web/i18n/uk-UA/dataset-pipeline.ts | 3 + web/i18n/vi-VN/dataset-pipeline.ts | 3 + web/i18n/zh-Hans/dataset-pipeline.ts | 25 ++++++ web/i18n/zh-Hant/dataset-pipeline.ts | 3 + web/models/datasets.ts | 61 ++++++++++++-- web/models/pipeline.ts | 36 +++++++++ web/service/knowledge/use-create-dataset.ts | 29 ++++++- web/service/use-pipeline.ts | 75 ++++++++++++++++++ 36 files changed, 473 insertions(+), 126 deletions(-) create mode 100644 web/i18n/de-DE/dataset-pipeline.ts create mode 100644 web/i18n/en-US/dataset-pipeline.ts create mode 100644 web/i18n/es-ES/dataset-pipeline.ts create mode 100644 web/i18n/fa-IR/dataset-pipeline.ts create mode 100644 web/i18n/fr-FR/dataset-pipeline.ts create mode 100644 web/i18n/hi-IN/dataset-pipeline.ts create mode 100644 web/i18n/it-IT/dataset-pipeline.ts create mode 100644 web/i18n/ja-JP/dataset-pipeline.ts create mode 100644 web/i18n/ko-KR/dataset-pipeline.ts create mode 100644 web/i18n/pl-PL/dataset-pipeline.ts create mode 100644 web/i18n/pt-BR/dataset-pipeline.ts create mode 100644 web/i18n/ro-RO/dataset-pipeline.ts create mode 100644 web/i18n/ru-RU/dataset-pipeline.ts create mode 100644 web/i18n/sl-SI/dataset-pipeline.ts create mode 100644 web/i18n/th-TH/dataset-pipeline.ts create mode 100644 web/i18n/tr-TR/dataset-pipeline.ts create mode 100644 web/i18n/uk-UA/dataset-pipeline.ts create mode 100644 web/i18n/vi-VN/dataset-pipeline.ts create mode 100644 web/i18n/zh-Hans/dataset-pipeline.ts create mode 100644 web/i18n/zh-Hant/dataset-pipeline.ts create mode 100644 web/models/pipeline.ts create mode 100644 web/service/use-pipeline.ts diff --git a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx index a88afc3adc..aeb96eab57 100644 --- a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx +++ b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout-main.tsx @@ -28,13 +28,12 @@ import DatasetDetailContext from '@/context/dataset-detail' import { DataSourceType } from '@/models/datasets' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useStore } from '@/app/components/app/store' -import { getLocaleOnClient } from '@/i18n' import { useAppContext } from '@/context/app-context' import Tooltip from '@/app/components/base/tooltip' import LinkedAppsPanel from '@/app/components/base/linked-apps-panel' import { PipelineFill, PipelineLine } from '@/app/components/base/icons/src/public/pipeline' import { Divider } from '@/app/components/base/icons/src/public/knowledge' -import { LanguagesSupported } from '@/i18n/language' +import { useGetDocLanguage } from '@/context/i18n' export type IAppDetailLayoutProps = { children: React.ReactNode @@ -54,8 +53,8 @@ const ExtraInfo = React.memo(({ documentCount, expand, }: IExtraInfoProps) => { - const locale = getLocaleOnClient() const { t } = useTranslation() + const docLanguage = useGetDocLanguage() const hasRelatedApps = relatedApps?.data && relatedApps?.data?.length > 0 const relatedAppsTotal = relatedApps?.data?.length || 0 @@ -122,11 +121,7 @@ const ExtraInfo = React.memo(({
{t('common.datasetMenus.emptyTip')}
diff --git a/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx b/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx index f3f417039d..214836b39f 100644 --- a/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx +++ b/web/app/components/datasets/create-from-pipeline/create-options/create-from-dsl-modal/index.tsx @@ -121,7 +121,6 @@ const CreateFromDSLModal = ({ message: t(status === DSLImportStatus.COMPLETED ? 'app.newApp.appCreated' : 'app.newApp.caution'), children: status === DSLImportStatus.COMPLETED_WITH_WARNINGS && t('app.newApp.appCreateDSLWarning'), }) - localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') if (app_id) await handleCheckPluginDependencies(app_id) getRedirection(isCurrentWorkspaceEditor, { id: app_id!, mode: app_mode }, push) diff --git a/web/app/components/datasets/create-from-pipeline/create-options/create-from-scratch.tsx b/web/app/components/datasets/create-from-pipeline/create-options/create-from-scratch.tsx index 15f1c3d2fd..f82b5c6370 100644 --- a/web/app/components/datasets/create-from-pipeline/create-options/create-from-scratch.tsx +++ b/web/app/components/datasets/create-from-pipeline/create-options/create-from-scratch.tsx @@ -1,3 +1,4 @@ +import React, { useCallback, useEffect, useRef, useState } from 'react' import AppIcon from '@/app/components/base/app-icon' import type { AppIconSelection } from '@/app/components/base/app-icon-picker' import AppIconPicker from '@/app/components/base/app-icon-picker' @@ -5,17 +6,19 @@ import Input from '@/app/components/base/input' import Textarea from '@/app/components/base/textarea' import type { AppIconType } from '@/types/app' import { RiCloseLine } from '@remixicon/react' -import React, { useCallback, useRef, useState } from 'react' import PermissionSelector from '../../settings/permission-selector' +import type { CreateDatasetReq } from '@/models/datasets' import { DatasetPermission } from '@/models/datasets' import { useMembers } from '@/service/use-common' import Button from '@/app/components/base/button' import { useTranslation } from 'react-i18next' import Toast from '@/app/components/base/toast' +import { useCreateDataset } from '@/service/knowledge/use-create-dataset' +import type { Member } from '@/models/common' type CreateFromScratchProps = { - onClose: () => void - onCreate: () => void + onClose?: () => void + onCreate?: () => void } const DEFAULT_APP_ICON: AppIconSelection = { @@ -36,8 +39,14 @@ const CreateFromScratch = ({ const [showAppIconPicker, setShowAppIconPicker] = useState(false) const [selectedMemberIDs, setSelectedMemberIDs] = useState([]) const previousAppIcon = useRef(DEFAULT_APP_ICON) + const [memberList, setMemberList] = useState([]) - const { data: memberList } = useMembers() + const { data: members } = useMembers() + + useEffect(() => { + if (members?.accounts) + setMemberList(members.accounts) + }, [members]) const handleAppNameChange = useCallback((event: React.ChangeEvent) => { const value = event.target.value @@ -68,6 +77,8 @@ const CreateFromScratch = ({ setPermission(value!) }, []) + const { mutateAsync: createEmptyDataset } = useCreateDataset() + const handleCreate = useCallback(() => { if (!name) { Toast.notify({ @@ -76,16 +87,38 @@ const CreateFromScratch = ({ }) return } - onCreate() - onClose() - }, [name, onCreate, onClose]) + const request: CreateDatasetReq = { + name, + description, + icon_info: { + icon_type: appIcon.type, + icon: appIcon.type === 'image' ? appIcon.fileId : appIcon.icon, + icon_background: appIcon.type === 'image' ? undefined : appIcon.background, + icon_url: appIcon.type === 'image' ? appIcon.url : undefined, + }, + permission, + } + // Handle permission + if (request.permission === DatasetPermission.partialMembers) { + const selectedMemberList = selectedMemberIDs.map((id) => { + return { + user_id: id, + role: memberList.find(member => member.id === id)?.role, + } + }) + request.partial_member_list = selectedMemberList + } + createEmptyDataset(request) + onCreate?.() + onClose?.() + }, [name, permission, appIcon, description, createEmptyDataset, memberList, selectedMemberIDs, onCreate, onClose]) return (
{/* Header */}
- Create Knowledge + {t('datasetPipeline.creation.createKnowledge')}