+ {metadataParams.documentType && (
<>
-
{t('metadata.desc', { ns: 'datasetDocuments' })}
+
+ {metadataMap[metadataParams.documentType || 'book'].text}
+ {editStatus && (
+
+ ·
+
+ {t('operation.change', { ns: 'common' })}
+
+
+ )}
>
)}
-
- {!doc_type && !documentType && (
- <>
-
{t('metadata.docTypeSelectTitle', { ns: 'datasetDocuments' })}
- >
- )}
- {documentType && (
- <>
-
{t('metadata.docTypeChangeTitle', { ns: 'datasetDocuments' })}
-
{t('metadata.docTypeSelectWarning', { ns: 'datasetDocuments' })}
- >
- )}
-
- {CUSTOMIZABLE_DOC_TYPES.map((type, index) => {
- const currValue = tempDocType ?? documentType
- return (
-
-
-
- )
- })}
-
- {!doc_type && !documentType && (
-
- )}
- {documentType && (
-
-
-
-
- )}
-
- >
- )
- }
-
- // show metadata info and edit
- const renderFieldInfos = ({ mainField = 'book', canEdit }: { mainField?: metadataType | '', canEdit?: boolean }) => {
- if (!mainField)
- return null
- const fieldMap = metadataMap[mainField]?.subFieldsMap
- const sourceData = ['originInfo', 'technicalParameters'].includes(mainField) ? docDetail : metadataParams.metadata
-
- const getTargetMap = (field: string) => {
- if (field === 'language')
- return languageMap
- if (field === 'category' && mainField === 'book')
- return bookCategoryMap
-
- if (field === 'document_type') {
- if (mainField === 'personal_document')
- return personalDocCategoryMap
- if (mainField === 'business_document')
- return businessDocCategoryMap
- }
- return {} as any
- }
-
- const getTargetValue = (field: string) => {
- const val = get(sourceData, field, '')
- if (!val && val !== 0)
- return '-'
- if (fieldMap[field]?.inputType === 'select')
- return getTargetMap(field)[val]
- if (fieldMap[field]?.render)
- return fieldMap[field]?.render?.(val, field === 'hit_count' ? get(sourceData, 'segment_count', 0) as number : undefined)
- return val
- }
-
- return (
-
- {Object.keys(fieldMap).map((field) => {
- return (
- {
- setMetadataParams(pre => ({ ...pre, metadata: { ...pre.metadata, [field]: val } }))
- }}
- selectOptions={map2Options(getTargetMap(field))}
- />
- )
- })}
)
}
- const enabledEdit = () => {
- setEditStatus(true)
- }
+ const renderHeaderActions = () => {
+ if (!editStatus) {
+ return (
+
+ )
+ }
- const onCancel = () => {
- setMetadataParams({ documentType: doc_type || '', metadata: { ...docDetail?.doc_metadata } })
- setEditStatus(!doc_type)
- if (!doc_type)
- setShowDocTypes(true)
- }
+ if (showDocTypes)
+ return null
- const onSave = async () => {
- setSaveLoading(true)
- const [e] = await asyncRunSafe
(modifyDocMetadata({
- datasetId,
- documentId,
- body: {
- doc_type: metadataParams.documentType || doc_type || '',
- doc_metadata: metadataParams.metadata,
- },
- }) as Promise)
- if (!e)
- notify({ type: 'success', message: t('actionMsg.modifiedSuccessfully', { ns: 'common' }) })
- else
- notify({ type: 'error', message: t('actionMsg.modifiedUnsuccessfully', { ns: 'common' }) })
- onUpdate?.()
- setEditStatus(false)
- setSaveLoading(false)
+ return (
+
+
+
+
+ )
}
return (
@@ -353,68 +126,47 @@ const Metadata: FC = ({ docDetail, loading, onUpdate }) => {
<>
{t('metadata.title', { ns: 'datasetDocuments' })}
- {!editStatus
- ? (
-
- )
- : showDocTypes
- ? null
- : (
-
-
-
-
- )}
+ {renderHeaderActions()}
- {/* show selected doc type and changing entry */}
- {!editStatus
- ? (
-
-
- {metadataMap[doc_type || 'book'].text}
-
- )
- : showDocTypes
- ? null
- : (
-
- {metadataParams.documentType && (
- <>
-
- {metadataMap[metadataParams.documentType || 'book'].text}
- {editStatus && (
-
- ·
-
{ setShowDocTypes(true) }}
- className="cursor-pointer hover:text-text-accent"
- >
- {t('operation.change', { ns: 'common' })}
-
-
- )}
- >
- )}
-
- )}
+ {renderDocTypeDisplay()}
{(!doc_type && showDocTypes) ? null : }
- {showDocTypes ? renderSelectDocType() : renderFieldInfos({ mainField: metadataParams.documentType, canEdit: editStatus })}
- {/* show fixed fields */}
+ {showDocTypes
+ ? (
+
+ )
+ : (
+
+ )}
- {renderFieldInfos({ mainField: 'originInfo', canEdit: false })}
+
{metadataMap.technicalParameters.text}
- {renderFieldInfos({ mainField: 'technicalParameters', canEdit: false })}
+
>
)}
diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json
index e23515ffe2..2223094e35 100644
--- a/web/eslint-suppressions.json
+++ b/web/eslint-suppressions.json
@@ -1784,12 +1784,9 @@
"count": 1
}
},
- "app/components/datasets/documents/detail/metadata/index.tsx": {
+ "app/components/datasets/documents/detail/metadata/hooks/use-metadata-editor.ts": {
"react-hooks-extra/no-direct-set-state-in-use-effect": {
"count": 4
- },
- "ts/no-explicit-any": {
- "count": 2
}
},
"app/components/datasets/documents/detail/new-segment.tsx": {