From 1101d6c80953ca3d8f5d32179c9ab616f50ced29 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 2 Oct 2024 12:45:42 +0300 Subject: [PATCH] Fix tree select item rendering --- .../fields/editor/CustomVocabularies.tsx | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/client/components/fields/editor/CustomVocabularies.tsx b/client/components/fields/editor/CustomVocabularies.tsx index e33c5bc1e..bc2e4b987 100644 --- a/client/components/fields/editor/CustomVocabularies.tsx +++ b/client/components/fields/editor/CustomVocabularies.tsx @@ -1,12 +1,13 @@ import * as React from 'react'; import {connect} from 'react-redux'; -import {ISubject, IVocabulary} from 'superdesk-api'; +import {IVocabulary} from 'superdesk-api'; import {superdeskApi} from '../../../superdeskApi'; import {IEditorFieldProps, IProfileSchemaTypeList} from '../../../interfaces'; import {Row} from '../../UI/Form'; -import {getVocabularyItemNameFromString} from '../../../utils/vocabularies'; -import {EditorFieldTreeSelect} from '../editor/base/treeSelect'; +import {getVocabularyItemFieldTranslated} from '../../../utils/vocabularies'; +import {arrayToTree} from 'superdesk-core/scripts/core/helpers/tree'; +import {TreeSelect} from 'superdesk-ui-framework/react'; interface IProps extends IEditorFieldProps { schema?: IProfileSchemaTypeList; @@ -33,6 +34,8 @@ class CustomVocabulariesComponent extends React.PureComponent { required, testId, language, + disabled, + invalid, } = this.props; const customVocabularies = vocabularies.filter((cv) => @@ -41,7 +44,7 @@ class CustomVocabulariesComponent extends React.PureComponent { return customVocabularies.map((cv) => { const cvFieldName = `custom_vocabularies.${cv._id}`; - const parentField = cv.schema_field || 'subject'; + const itemFieldName = cv.schema_field ?? 'subject'; return ( { id={`form-row-${cvFieldName}`} data-test-id={testId?.length ? `${testId}.${cv._id}` : cv._id} > - values.filter((value) => cv._id == null || value?.scheme === cv._id)} - item={item} - field={parentField} - label={gettext(cv.display_name)} - required={required || schema?.required} - allowMultiple={true} + cv.items.map((item: ISubject) => ({value: {...item, scheme: cv._id}}))} - getId={(item: ISubject) => item.qcode} - getLabel={(item: ISubject) => ( - getVocabularyItemNameFromString( - item.qcode, - cv.items, - 'qcode', - 'name', - language - ) + kind="synchronous" + allowMultiple={true} + value={item[itemFieldName] ?? []} + label={gettext(cv.display_name)} + required={required ?? schema?.required} + getOptions={() => arrayToTree( + cv.items, + ({qcode}) => qcode.toString(), + ({parent}) => parent?.toString(), + ).result} + getLabel={(item) => getVocabularyItemFieldTranslated( + item, + 'name', + language, )} - onChange={(field, value) => { - const otherCvValues = item[parentField] ?? []; - - const newValues = value.concat( - otherCvValues.filter((value) => value?.scheme != cv._id) - ); + getId={(item) => item.id} + invalid={errors?.length > 0 || invalid} + error={showErrors ? errors[itemFieldName] : undefined} + readOnly={disabled} + disabled={disabled} + onChange={(vals) => { + const filteredValues = vals.filter((value) => cv._id == null || value?.scheme === cv._id); - onChange(field, newValues); + onChange(itemFieldName, filteredValues); }} - errors={errors} + tabindex={0} + zIndex={1051} /> );