From 9392ce259fec93c0a2060c0e490bc74d0c32431e Mon Sep 17 00:00:00 2001 From: twwu Date: Tue, 29 Apr 2025 15:44:32 +0800 Subject: [PATCH] feat: Refactor dataset components and update translations for new dataset creation options --- web/app/(commonLayout)/datasets/Container.tsx | 4 +- web/app/(commonLayout)/datasets/Datasets.tsx | 18 ++++---- .../datasets/NewDatasetCard.tsx | 42 ------------------- .../datasets/new-dataset-card/index.tsx | 37 ++++++++++++++++ .../datasets/new-dataset-card/link.tsx | 26 ++++++++++++ .../nodes/_base/components/next-step/add.tsx | 2 +- web/app/reset-password/check-code/page.tsx | 2 +- web/app/signin/check-code/page.tsx | 2 +- web/i18n/en-US/dataset.ts | 1 + web/i18n/zh-Hans/dataset.ts | 1 + 10 files changed, 78 insertions(+), 57 deletions(-) delete mode 100644 web/app/(commonLayout)/datasets/NewDatasetCard.tsx create mode 100644 web/app/(commonLayout)/datasets/new-dataset-card/index.tsx create mode 100644 web/app/(commonLayout)/datasets/new-dataset-card/link.tsx diff --git a/web/app/(commonLayout)/datasets/Container.tsx b/web/app/(commonLayout)/datasets/Container.tsx index 2a3efbea98..9d9c048403 100644 --- a/web/app/(commonLayout)/datasets/Container.tsx +++ b/web/app/(commonLayout)/datasets/Container.tsx @@ -43,9 +43,9 @@ const Container = () => { const options = useMemo(() => { return [ - { value: 'dataset', text: t('dataset.datasets'), Icon: RiBook2Line, count: 1 }, + { value: 'dataset', text: t('dataset.datasets'), Icon: RiBook2Line }, ...(currentWorkspace.role === 'dataset_operator' ? [] : [{ - value: 'api', text: t('dataset.datasetsApi'), Icon: RiTerminalBoxLine, count: 5, + value: 'api', text: t('dataset.datasetsApi'), Icon: RiTerminalBoxLine, }]), ] }, [currentWorkspace.role, t]) diff --git a/web/app/(commonLayout)/datasets/Datasets.tsx b/web/app/(commonLayout)/datasets/Datasets.tsx index 6383513e9e..dcc368bb85 100644 --- a/web/app/(commonLayout)/datasets/Datasets.tsx +++ b/web/app/(commonLayout)/datasets/Datasets.tsx @@ -1,10 +1,10 @@ 'use client' -import { useCallback, useEffect, useRef } from 'react' +import { useEffect, useMemo, useRef } from 'react' import useSWRInfinite from 'swr/infinite' import { debounce } from 'lodash-es' import { useTranslation } from 'react-i18next' -import NewDatasetCard from './NewDatasetCard' +import NewDatasetCard from './new-dataset-card' import DatasetCard from './DatasetCard' import type { DataSetListResponse, FetchDatasetsParams } from '@/models/datasets' import { fetchDatasets } from '@/service/datasets' @@ -48,6 +48,7 @@ const Datasets = ({ keywords, includeAll, }: Props) => { + const { t } = useTranslation() const { isCurrentWorkspaceEditor } = useAppContext() const { data, isLoading, setSize, mutate } = useSWRInfinite( (pageIndex: number, previousPageData: DataSetListResponse) => getKey(pageIndex, previousPageData, tags, keywords, includeAll), @@ -57,24 +58,21 @@ const Datasets = ({ const loadingStateRef = useRef(false) const anchorRef = useRef(null) - const { t } = useTranslation() - useEffect(() => { loadingStateRef.current = isLoading document.title = `${t('dataset.knowledge')} - Dify` }, [isLoading, t]) - const onScroll = useCallback( - debounce(() => { + const onScroll = useMemo(() => { + return debounce(() => { if (!loadingStateRef.current && containerRef.current && anchorRef.current) { const { scrollTop, clientHeight } = containerRef.current const anchorOffset = anchorRef.current.offsetTop if (anchorOffset - scrollTop - clientHeight < 100) setSize(size => size + 1) } - }, 50), - [setSize], - ) + }, 50) + }, [containerRef, setSize]) useEffect(() => { const currentContainer = containerRef.current @@ -83,7 +81,7 @@ const Datasets = ({ currentContainer?.removeEventListener('scroll', onScroll) onScroll.cancel() } - }, [onScroll]) + }, [onScroll, containerRef]) return (