diff --git a/web/app/components/datasets/metadata/edit-metadat-batch/add-row.tsx b/web/app/components/datasets/metadata/edit-metadat-batch/add-row.tsx new file mode 100644 index 0000000000..83c054dd82 --- /dev/null +++ b/web/app/components/datasets/metadata/edit-metadat-batch/add-row.tsx @@ -0,0 +1,45 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import type { MetadataItemWithEdit } from '../types' +import cn from '@/utils/classnames' +import Label from './label' +import InputCombined from './input-combined' +import { RiIndeterminateCircleLine } from '@remixicon/react' + +type Props = { + className?: string + payload: MetadataItemWithEdit + onChange: (value: any) => void + onRemove: () => void +} + +const AddRow: FC = ({ + className, + payload, + onChange, + onRemove, +}) => { + return ( +
+
+ ) +} + +export default React.memo(AddRow) diff --git a/web/app/components/datasets/metadata/edit-metadat-batch/edit-row.tsx b/web/app/components/datasets/metadata/edit-metadat-batch/edit-row.tsx index 9a592fb755..5e962dd0ec 100644 --- a/web/app/components/datasets/metadata/edit-metadat-batch/edit-row.tsx +++ b/web/app/components/datasets/metadata/edit-metadat-batch/edit-row.tsx @@ -2,7 +2,6 @@ import type { FC } from 'react' import React from 'react' import { type MetadataItemWithEdit, UpdateType } from '../types' -import Input from '../../create/website/base/input' import Label from './label' import { RiDeleteBinLine } from '@remixicon/react' import cn from '@/utils/classnames' @@ -16,23 +15,6 @@ type Props = { onRemove: (id: string) => void } -const labelClassName = '' - -export const AddedMetadataItem: FC = ({ - payload, - onChange, -}) => { - return ( -
-
{payload.name}
- onChange({ ...payload, value: v as string }) - } /> -
- ) -} - const EditMetadatabatchItem: FC = ({ payload, onChange, diff --git a/web/app/components/datasets/metadata/edit-metadat-batch/input-combined.tsx b/web/app/components/datasets/metadata/edit-metadat-batch/input-combined.tsx index 6342f6a4a1..a152eabd3d 100644 --- a/web/app/components/datasets/metadata/edit-metadat-batch/input-combined.tsx +++ b/web/app/components/datasets/metadata/edit-metadat-batch/input-combined.tsx @@ -23,14 +23,13 @@ const InputCombined: FC = ({ if (type === DataType.number) { return ( -
+
diff --git a/web/app/components/datasets/metadata/edit-metadat-batch/label.tsx b/web/app/components/datasets/metadata/edit-metadat-batch/label.tsx index d48a4dbc72..4a582d08fc 100644 --- a/web/app/components/datasets/metadata/edit-metadat-batch/label.tsx +++ b/web/app/components/datasets/metadata/edit-metadat-batch/label.tsx @@ -4,7 +4,7 @@ import React from 'react' import cn from '@/utils/classnames' type Props = { - isDeleted: boolean, + isDeleted?: boolean, className?: string, text: string } diff --git a/web/app/components/datasets/metadata/edit-metadat-batch/modal.tsx b/web/app/components/datasets/metadata/edit-metadat-batch/modal.tsx index 719ca2b76e..bf51ab3b42 100644 --- a/web/app/components/datasets/metadata/edit-metadat-batch/modal.tsx +++ b/web/app/components/datasets/metadata/edit-metadat-batch/modal.tsx @@ -2,12 +2,16 @@ 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-row' +import { DataType, type MetadataItemWithEdit } from '../types' +import EditMetadataBatchItem from './edit-row' +import AddedMetadataItem from './add-row' import Button from '../../../base/button' import { useTranslation } from 'react-i18next' import Checkbox from '../../../base/checkbox' import Tooltip from '../../../base/tooltip' +import SelectMetadataModal from '../select-metadata-modal' +import { RiAddLine } from '@remixicon/react' +import Divider from '@/app/components/base/divider' type Props = { documentNum: number @@ -33,14 +37,24 @@ const EditMetadataBatchModal: FC = ({ setTempleList(newTempleList) }, [templeList]) - const [addedList, setAddedList] = useState([]) + const testAddedList: MetadataItemWithEdit[] = [ + { + id: '1', name: 'name1', type: DataType.string, value: 'aaa', + }, + { + id: '2.1', name: 'num v', type: DataType.number, value: 10, + }, + ] + const [addedList, setAddedList] = useState(testAddedList) 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) + const handleAddedItemRemove = useCallback((removeIndex: number) => { + return () => { + const newAddedList = addedList.filter((i, index) => index !== removeIndex) + setAddedList(newAddedList) + } }, [addedList]) const [isApplyToAllSelectDocument, setIsApplyToAllSelectDocument] = useState(false) @@ -68,16 +82,32 @@ const EditMetadataBatchModal: FC = ({ /> ))}
- -
- {addedList.map(item => ( - +
+
New metadata
+ +
+
+ {addedList.map((item, i) => ( + + ))} +
+
+ + +
Add metadata
+ + } + onSave={data => setAddedList([...addedList, data])} /> - ))} +
diff --git a/web/app/components/datasets/metadata/select-metadata-modal.tsx b/web/app/components/datasets/metadata/select-metadata-modal.tsx index ba82ba36f2..b85a1c4eb0 100644 --- a/web/app/components/datasets/metadata/select-metadata-modal.tsx +++ b/web/app/components/datasets/metadata/select-metadata-modal.tsx @@ -49,6 +49,7 @@ const SelectMetadataModal: FC = ({ > setOpen(!open)} + className='block' > {trigger} diff --git a/web/app/components/datasets/metadata/types.ts b/web/app/components/datasets/metadata/types.ts index 346686a7dc..1b4cb06704 100644 --- a/web/app/components/datasets/metadata/types.ts +++ b/web/app/components/datasets/metadata/types.ts @@ -18,7 +18,7 @@ export enum UpdateType { delete = 'delete', } export type MetadataItemWithEdit = MetadataItem & { - value: string + value: string | number isMultipleValue?: boolean isUpdated?: boolean updateType?: UpdateType