Implementation:Infiniflow Ragflow MetadataManageValuesHook
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Knowledge_Base |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Complex state management hook with validation for managing metadata field names, value types, and value lists within the metadata modal.
Description
The useManageValues hook manages the full lifecycle of a metadata editing session. It maintains synchronized dual state -- metaData (canonical) and tempValues (transient per-input) -- to avoid closure issues. It validates field names against existsKeys for duplicate detection using MetadataDeleteMap for context-appropriate error messages. The hook supports add, update, delete, and blur-sync operations for individual values, a deferred save pattern (shouldSave flag with setTimeout), and a nested delete confirmation dialog state machine. It returns 13 handler functions and state objects consumed by the metadata modal UI.
Usage
Used exclusively by the metadata management modal component to orchestrate field/value CRUD operations with inline validation and deletion confirmations.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: web/src/pages/dataset/components/metedata/hooks/use-manage-values-modal.ts
- Lines: 1-296
Signature
export const useManageValues = (props: IManageValuesProps) => {
// Returns:
return {
metaData, handleClearValues, tempValues, valueError,
deleteDialogContent, handleChange, handleValueChange,
handleValueBlur, handleDelete, handleAddValue,
showDeleteModal, handleSave, handleHideModal,
};
};
Import
import { useManageValues } from '../hooks/use-manage-values-modal';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data | IMetaDataTableData | Yes | Initial metadata row data |
| isAddValueMode | boolean | Yes | Whether the modal is in add-value mode |
| hideModal | function | Yes | Callback to close the modal |
| onSave | function | Yes | Persist metadata callback |
| addUpdateValue | function | Yes | Update single value callback |
| addDeleteValue | function | Yes | Delete single value callback |
| existsKeys | string[] | Yes | Existing field names for duplicate validation |
| type | MetadataType | Yes | Current metadata editing mode |
Outputs
| Name | Type | Description |
|---|---|---|
| metaData | IMetaDataTableData | Current metadata state |
| valueError | Record<string, string> | Validation error messages for field and values |
| tempValues | string[] | Transient input values before blur-sync |
| handleSave | function | Trigger save with deferred execution |
Usage Examples
const { metaData, handleChange, handleSave, valueError } = useManageValues({
data: currentRow,
isAddValueMode: true,
hideModal,
onSave: persistMetadata,
addUpdateValue,
addDeleteValue,
existsKeys: existingFieldNames,
type: MetadataType.Manage,
});