From b7c546f2ad82157902c746ad233a48a5dbe5b22e Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 14 Feb 2025 16:24:49 +0800 Subject: [PATCH] feat: dataset metadata collection --- web/app/(commonLayout)/datasets/Container.tsx | 5 +- web/app/components/base/drawer/index.tsx | 2 +- .../metadata/dataset-metadata-drawer.tsx | 102 ++++++++++++------ 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/web/app/(commonLayout)/datasets/Container.tsx b/web/app/(commonLayout)/datasets/Container.tsx index a9e5e4a813..6212f147e8 100644 --- a/web/app/(commonLayout)/datasets/Container.tsx +++ b/web/app/(commonLayout)/datasets/Container.tsx @@ -85,6 +85,7 @@ const Container = () => { return router.replace('/apps') }, [currentWorkspace, router]) + const [isBuiltInEnabled, setIsBuiltInEnabled] = useState(false) const [userMetadata, setUserMetadata] = useState([ { id: '1', name: 'name1', type: DataType.string, valueLength: 1 }, { id: '2', name: 'name2', type: DataType.number, valueLength: 2 }, @@ -107,8 +108,8 @@ const Container = () => { { id: '2', name: 'name2', type: DataType.number, valueLength: 2 }, { id: '3', name: 'name3', type: DataType.time, valueLength: 3 }, ]} - isBuiltInEnabled={false} - onIsBuiltInEnabledChange={() => { }} + isBuiltInEnabled={isBuiltInEnabled} + onIsBuiltInEnabledChange={setIsBuiltInEnabled} onClose={() => { }} /> diff --git a/web/app/components/base/drawer/index.tsx b/web/app/components/base/drawer/index.tsx index 269cbce5a9..ec4bbbabeb 100644 --- a/web/app/components/base/drawer/index.tsx +++ b/web/app/components/base/drawer/index.tsx @@ -61,7 +61,7 @@ export default function Drawer({ {title} } {showClose && - + } diff --git a/web/app/components/datasets/metadata/dataset-metadata-drawer.tsx b/web/app/components/datasets/metadata/dataset-metadata-drawer.tsx index 91f2899486..04252e46e2 100644 --- a/web/app/components/datasets/metadata/dataset-metadata-drawer.tsx +++ b/web/app/components/datasets/metadata/dataset-metadata-drawer.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC } from 'react' -import React, { useCallback, useState } from 'react' +import React, { useCallback, useRef, useState } from 'react' import type { MetadataItemWithValueLength } from './types' import Drawer from '../../base/drawer' import Button from '@/app/components/base/button' @@ -15,6 +15,8 @@ import produce from 'immer' import Switch from '../../base/switch' import Tooltip from '../../base/tooltip' import CreateModal from '@/app/components/datasets/metadata/create-metadata-modal' +import { useBoolean, useHover } from 'ahooks' +import Confirm from '@/app/components/base/confirm' const i18nPrefix = 'dataset.metadata.datasetMetadata' @@ -29,12 +31,14 @@ type Props = { type ItemProps = { readonly?: boolean + disabled?: boolean payload: MetadataItemWithValueLength onRename?: () => void onDelete?: () => void } const Item: FC = ({ readonly, + disabled, payload, onRename, onDelete, @@ -45,25 +49,56 @@ const Item: FC = ({ onRename?.() }, [onRename]) + const deleteBtnRef = useRef(null) + const isDeleteHovering = useHover(deleteBtnRef) + const [isShowDeleteConfirm, { + setTrue: showDeleteConfirm, + setFalse: hideDeleteConfirm, + }] = useBoolean(false) const handleDelete = useCallback(() => { + hideDeleteConfirm() onDelete?.() - }, [onDelete]) + }, [hideDeleteConfirm, onDelete]) return (
-
- -
{payload.name}
-
-
- {payload.valueLength || 0} values -
-
- - +
+
+ +
{payload.name}
+
{payload.type}
+
+
+ {disabled ? 'Disabled' : `${payload.valueLength || 0} values`} +
+
+ +
+ +
+
+ {isShowDeleteConfirm && ( + + )}
) @@ -121,7 +156,7 @@ const DatasetMetadataDrawer: FC = ({ showClose title='Metadata' footer={null} - panelClassname='block !max-w-[420px] my-2 rounded-l-2xl' + panelClassname='px-4 block !max-w-[420px] my-2 rounded-l-2xl' >
You can manage all metadata in this knowledge here. Modifications will be synchronized to every document.
@@ -130,31 +165,36 @@ const DatasetMetadataDrawer: FC = ({ Add Metadata } hasBack onSave={handleAdd} /> - {userMetadata.map(payload => ( - - ))} +
+ {userMetadata.map(payload => ( + + ))} +
-
+
-
Built-in
+
Built-in
- {builtInMetadata.map(payload => ( - - ))} +
+ {builtInMetadata.map(payload => ( + + ))} +
{isShowRenameModal && (