From 7692476097d1780f621a3e740545f413c6480072 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 14 Feb 2025 17:58:19 +0800 Subject: [PATCH] feat: edit modal struct --- web/app/(commonLayout)/datasets/Container.tsx | 20 +++- .../metadata/edit-metadata-batch-item.tsx | 45 ++++++++ .../metadata/edit-metadata-batch-modal.tsx | 100 ++++++++++++++++++ web/app/components/datasets/metadata/types.ts | 7 ++ 4 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 web/app/components/datasets/metadata/edit-metadata-batch-item.tsx create mode 100644 web/app/components/datasets/metadata/edit-metadata-batch-modal.tsx diff --git a/web/app/(commonLayout)/datasets/Container.tsx b/web/app/(commonLayout)/datasets/Container.tsx index 6212f147e8..96f1045ab0 100644 --- a/web/app/(commonLayout)/datasets/Container.tsx +++ b/web/app/(commonLayout)/datasets/Container.tsx @@ -22,8 +22,8 @@ import { ApiConnectionMod } from '@/app/components/base/icons/src/vender/solid/d import CheckboxWithLabel from '@/app/components/datasets/create/website/base/checkbox-with-label' import CreateModal from '@/app/components/datasets/metadata/create-metadata-modal' import SelectMetadataModal from '@/app/components/datasets/metadata/select-metadata-modal' -import DatasetMetadataDrawer from '@/app/components/datasets/metadata/dataset-metadata-drawer' - +// import DatasetMetadataDrawer from '@/app/components/datasets/metadata/dataset-metadata-drawer' +import EditMetadataBatchModal from '@/app/components/datasets/metadata/edit-metadata-batch-modal' // Services import { fetchDatasetApiBaseUrl } from '@/service/datasets' @@ -100,7 +100,7 @@ const Container = () => { - { isBuiltInEnabled={isBuiltInEnabled} onIsBuiltInEnabledChange={setIsBuiltInEnabled} onClose={() => { }} + /> */} + { }} + onChange={(list, newList, isApplyToAllSelectDocument) => { console.log(list, newList, isApplyToAllSelectDocument) }} + />
diff --git a/web/app/components/datasets/metadata/edit-metadata-batch-item.tsx b/web/app/components/datasets/metadata/edit-metadata-batch-item.tsx new file mode 100644 index 0000000000..9ac55cba05 --- /dev/null +++ b/web/app/components/datasets/metadata/edit-metadata-batch-item.tsx @@ -0,0 +1,45 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import type { MetadataItemWithEdit } from './types' +import Input from '../create/website/base/input' + +type Props = { + payload: MetadataItemWithEdit + onChange: (payload: MetadataItemWithEdit) => void + onRemove: (id: string) => void +} + +const labelClassName = 'w-[136px] system-xs-medium text-text-tertiary' + +export const AddedMetadataItem: FC = ({ + payload, + onChange, +}) => { + return ( +
+
{payload.name}
+ onChange({ ...payload, value: v as string }) + } /> +
+ ) +} + +const EditMetadatabatchItem: FC = ({ + payload, + onChange, + onRemove, +}) => { + return ( +
+
{payload.name}
+ onChange({ ...payload, value: v as string }) + } /> +
+ ) +} +export default React.memo(EditMetadatabatchItem) diff --git a/web/app/components/datasets/metadata/edit-metadata-batch-modal.tsx b/web/app/components/datasets/metadata/edit-metadata-batch-modal.tsx new file mode 100644 index 0000000000..ce385c8557 --- /dev/null +++ b/web/app/components/datasets/metadata/edit-metadata-batch-modal.tsx @@ -0,0 +1,100 @@ +'use client' +import type { FC } from 'react' +import React, { useCallback, useState } from 'react' +import Modal from '../../base/modal' +import type { MetadataItemWithEdit } from './types' +import EditMetadataBatchItem, { AddedMetadataItem } from './edit-metadata-batch-item' +import Button from '../../base/button' +import { useTranslation } from 'react-i18next' +import Checkbox from '../../base/checkbox' +import Tooltip from '../../base/tooltip' + +type Props = { + list: MetadataItemWithEdit[] + onChange: (list: MetadataItemWithEdit[], addedList: MetadataItemWithEdit[], isApplyToAllSelectDocument: boolean) => void + onHide: () => void +} + +const EditMetadataBatchModal: FC = ({ + list, + onChange, + onHide, +}) => { + const { t } = useTranslation() + const [templeList, setTempleList] = useState(list) + const handleTemplesChange = useCallback((payload: MetadataItemWithEdit) => { + const newTempleList = templeList.map(i => i.id === payload.id ? payload : i) + setTempleList(newTempleList) + }, [templeList]) + const handleTempleItemRemove = useCallback((id: string) => { + const newTempleList = templeList.filter(i => i.id !== id) + setTempleList(newTempleList) + }, [templeList]) + + const [addedList, setAddedList] = useState([]) + const handleAddedListChange = useCallback((payload: MetadataItemWithEdit) => { + const newAddedList = addedList.map(i => i.id === payload.id ? payload : i) + setAddedList(newAddedList) + }, [addedList]) + const handleAddedItemRemove = useCallback((id: string) => { + const newAddedList = addedList.filter(i => i.id !== id) + setAddedList(newAddedList) + }, [addedList]) + + const [isApplyToAllSelectDocument, setIsApplyToAllSelectDocument] = useState(false) + + const handleSave = useCallback(() => { + onChange(templeList, addedList, isApplyToAllSelectDocument) + }, [templeList, addedList, isApplyToAllSelectDocument, onChange]) + return ( + +
Editing 5 documents
+ {/* TODO handle list scroll. There is two list. */} +
+ {templeList.map(item => ( + + ))} +
+ +
+ {addedList.map(item => ( + + ))} +
+ +
+
+ setIsApplyToAllSelectDocument(!isApplyToAllSelectDocument)} /> +
Apply to all selected documents
+ Automatically create all the above edited and new metadata for all selected documents, otherwise editing metadata will only apply to documents with it.
+ } /> +
+
+ + +
+
+ + ) +} +export default React.memo(EditMetadataBatchModal) diff --git a/web/app/components/datasets/metadata/types.ts b/web/app/components/datasets/metadata/types.ts index ee44a1ce91..ee4d62b90a 100644 --- a/web/app/components/datasets/metadata/types.ts +++ b/web/app/components/datasets/metadata/types.ts @@ -13,3 +13,10 @@ export type MetadataItem = { export type MetadataItemWithValueLength = MetadataItem & { valueLength: number } + +export type MetadataItemWithEdit = MetadataItem & { + value: string + isMultipleValue?: boolean + isRemoved?: boolean + isUpdated?: boolean +}