From 55322642fe6ccc369d8084e75c148b3de72a298d Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 14:15:00 +0200 Subject: [PATCH 1/3] WIP - agenda field --- .../planning-editor-standalone/profile.ts | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/client/components/planning-editor-standalone/profile.ts b/client/components/planning-editor-standalone/profile.ts index 1b6b6c380..91f775b84 100644 --- a/client/components/planning-editor-standalone/profile.ts +++ b/client/components/planning-editor-standalone/profile.ts @@ -5,8 +5,11 @@ import { ICommonFieldConfig, IContentProfileV2, IDateTimeFieldConfig, + IDropdownConfigRemoteSource, IDropdownConfigVocabulary, IEditor3Config, + IRestApiResponse, + ITreeWithLookup, IVocabularyItem, } from 'superdesk-api'; import {superdeskApi} from '../../superdeskApi'; @@ -15,6 +18,8 @@ import { } from '../../planning-extension/src/authoring-react-fields/planning-attachments/interfaces'; import {getCustomVocabularyFields} from './field-adapters/custom-vocabularies'; import {getPlanningProfileFields} from './profile-fields'; +import {IAgenda} from 'interfaces'; +import {httpRequestJsonLocal} from 'superdesk-core/scripts/core/helpers/network'; function getTextFieldConfig(options: {id: string; label: string, required: boolean}): IAuthoringFieldV2 { const editor3ConfigWithoutFormatting: IEditor3Config = { @@ -172,7 +177,60 @@ export function getFieldDefinitions(): IFieldDefinitions { return field; }, - } + }, + { + fieldId: 'agendas', + getField: ({id, required}) => { + const fieldConfig: IDropdownConfigRemoteSource = { + source: 'remote-source', + searchOptions: (searchTerm, _language, callback) => { + httpRequestJsonLocal>({ + method: 'GET', + path: '/agenda', + urlParams: { + max_results: 200, + name: searchTerm, + }, + }).then((res) => { + const tree: ITreeWithLookup = { + nodes: res._items.map((item) => ({value: item})), + lookup: {}, + }; + + callback(tree); + }); + }, + getId: (option: IAgenda) => option._id, + getLabel: (option: IAgenda) => option.name, + multiple: true, + required: required, + width: 100, + }; + + const field: IAuthoringFieldV2 = { + id: id, + name: gettext('Agendas'), + fieldType: 'dropdown', + fieldConfig: fieldConfig, + }; + + return field; + }, + storageAdapter: { + storeValue: (item, operationalValue: Array) => { + const vocabulary = superdeskApi.entities.vocabulary.getAll().get('locators'); + const vocabularyItems = new Map( + vocabulary.items.map((item) => [item.qcode, item]), + ); + + return { + ...item, + place: operationalValue.map((qcode) => vocabularyItems.get(qcode)), + }; + }, + retrieveStoredValue: (item, fieldId) => item[fieldId].map(({qcode}) => qcode), + }, + }, ]; result.push( From 0437c7df7a57c1a023940b3845db4717acdcb46f Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 15:26:46 +0200 Subject: [PATCH 2/3] Agendas manual source, small fix --- .../fields/editor/CustomVocabularies.tsx | 3 +- .../planning-editor-standalone/profile.ts | 52 +++++-------------- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/client/components/fields/editor/CustomVocabularies.tsx b/client/components/fields/editor/CustomVocabularies.tsx index 0da3eb9a0..39ae1ba2d 100644 --- a/client/components/fields/editor/CustomVocabularies.tsx +++ b/client/components/fields/editor/CustomVocabularies.tsx @@ -6,7 +6,6 @@ import {superdeskApi} from '../../../superdeskApi'; import {IEditorFieldProps, IProfileSchemaTypeList} from '../../../interfaces'; import {Row} from '../../UI/Form'; import {getVocabularyItemFieldTranslated} from '../../../utils/vocabularies'; -import {arrayToTree} from 'superdesk-core/scripts/core/helpers/tree'; import {TreeSelect} from 'superdesk-ui-framework/react'; export interface ICustomVocabulariesProps extends IEditorFieldProps { @@ -61,7 +60,7 @@ class CustomVocabulariesComponent extends React.PureComponent { value={(item.subject ?? []).filter((x) => x.scheme === cv._id)} label={gettext(cv.display_name)} required={required ?? schema?.required} - getOptions={() => arrayToTree( + getOptions={() => superdeskApi.utilities.arrayToTree( cv.items.map((cvItem) => ({ ...cvItem, scheme: cv._id, diff --git a/client/components/planning-editor-standalone/profile.ts b/client/components/planning-editor-standalone/profile.ts index 91f775b84..52fc1d9b9 100644 --- a/client/components/planning-editor-standalone/profile.ts +++ b/client/components/planning-editor-standalone/profile.ts @@ -5,21 +5,18 @@ import { ICommonFieldConfig, IContentProfileV2, IDateTimeFieldConfig, - IDropdownConfigRemoteSource, + IDropdownConfigManualSource, IDropdownConfigVocabulary, IEditor3Config, - IRestApiResponse, - ITreeWithLookup, IVocabularyItem, } from 'superdesk-api'; -import {superdeskApi} from '../../superdeskApi'; +import {planningApi, superdeskApi} from '../../superdeskApi'; import { IAttachmentsFieldConfig, } from '../../planning-extension/src/authoring-react-fields/planning-attachments/interfaces'; import {getCustomVocabularyFields} from './field-adapters/custom-vocabularies'; import {getPlanningProfileFields} from './profile-fields'; import {IAgenda} from 'interfaces'; -import {httpRequestJsonLocal} from 'superdesk-core/scripts/core/helpers/network'; function getTextFieldConfig(options: {id: string; label: string, required: boolean}): IAuthoringFieldV2 { const editor3ConfigWithoutFormatting: IEditor3Config = { @@ -181,27 +178,16 @@ export function getFieldDefinitions(): IFieldDefinitions { { fieldId: 'agendas', getField: ({id, required}) => { - const fieldConfig: IDropdownConfigRemoteSource = { - source: 'remote-source', - searchOptions: (searchTerm, _language, callback) => { - httpRequestJsonLocal>({ - method: 'GET', - path: '/agenda', - urlParams: { - max_results: 200, - name: searchTerm, - }, - }).then((res) => { - const tree: ITreeWithLookup = { - nodes: res._items.map((item) => ({value: item})), - lookup: {}, - }; - - callback(tree); - }); - }, - getId: (option: IAgenda) => option._id, - getLabel: (option: IAgenda) => option.name, + const fieldConfig: IDropdownConfigManualSource = { + source: 'manual-entry', + options: ((planningApi.redux.store.getState().agenda.agendas ?? []) as Array) + .filter((item) => item.is_enabled) + .map((item) => ({ + id: item._id, + label: item.name, + })), + roundCorners: true, + type: 'text', multiple: true, required: required, width: 100, @@ -216,20 +202,6 @@ export function getFieldDefinitions(): IFieldDefinitions { return field; }, - storageAdapter: { - storeValue: (item, operationalValue: Array) => { - const vocabulary = superdeskApi.entities.vocabulary.getAll().get('locators'); - const vocabularyItems = new Map( - vocabulary.items.map((item) => [item.qcode, item]), - ); - - return { - ...item, - place: operationalValue.map((qcode) => vocabularyItems.get(qcode)), - }; - }, - retrieveStoredValue: (item, fieldId) => item[fieldId].map(({qcode}) => qcode), - }, }, ]; From 49b405c90346eca397d6687d793135870862617a Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 20:54:42 +0200 Subject: [PATCH 3/3] Remove width from config --- client/components/planning-editor-standalone/profile.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/components/planning-editor-standalone/profile.ts b/client/components/planning-editor-standalone/profile.ts index 52fc1d9b9..15595cbef 100644 --- a/client/components/planning-editor-standalone/profile.ts +++ b/client/components/planning-editor-standalone/profile.ts @@ -27,7 +27,6 @@ function getTextFieldConfig(options: {id: string; label: string, required: boole singleLine: true, disallowedCharacters: [], showStatistics: false, - width: 100, }; const field: IAuthoringFieldV2 = { @@ -190,7 +189,6 @@ export function getFieldDefinitions(): IFieldDefinitions { type: 'text', multiple: true, required: required, - width: 100, }; const field: IAuthoringFieldV2 = {