From 124fbbf31b486eedd337c5410896e72f6e987459 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 15:42:10 +0200 Subject: [PATCH 1/6] Refactor structure --- .../field-definitions/date-time-config.ts | 19 ++ .../field-definitions/index.ts | 97 +++++++++ .../field-definitions/interfaces.ts | 13 ++ .../field-definitions/place-field.ts | 37 ++++ .../field-definitions/text-field-config.ts | 26 +++ .../planning-editor-standalone/profile.ts | 188 +----------------- 6 files changed, 194 insertions(+), 186 deletions(-) create mode 100644 client/components/planning-editor-standalone/field-definitions/date-time-config.ts create mode 100644 client/components/planning-editor-standalone/field-definitions/index.ts create mode 100644 client/components/planning-editor-standalone/field-definitions/interfaces.ts create mode 100644 client/components/planning-editor-standalone/field-definitions/place-field.ts create mode 100644 client/components/planning-editor-standalone/field-definitions/text-field-config.ts diff --git a/client/components/planning-editor-standalone/field-definitions/date-time-config.ts b/client/components/planning-editor-standalone/field-definitions/date-time-config.ts new file mode 100644 index 000000000..03a170b5a --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/date-time-config.ts @@ -0,0 +1,19 @@ +import {IAuthoringFieldV2, IDateTimeFieldConfig} from 'superdesk-api'; + +export function getDateTimeField(options: {id: string; label: string, required: boolean}): IAuthoringFieldV2 { + const config: IDateTimeFieldConfig = { + allowSeconds: false, + }; + + const field: IAuthoringFieldV2 = { + id: options.id, + name: options.label, + fieldType: 'datetime', + fieldConfig: { + ...config, + required: options.required, + }, + }; + + return field; +} diff --git a/client/components/planning-editor-standalone/field-definitions/index.ts b/client/components/planning-editor-standalone/field-definitions/index.ts new file mode 100644 index 000000000..def4aac08 --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/index.ts @@ -0,0 +1,97 @@ +import { + IAttachmentsFieldConfig, +} from '../../../planning-extension/src/authoring-react-fields/planning-attachments/interfaces'; +import { + IAuthoringFieldV2, + ICommonFieldConfig, +} from 'superdesk-api'; +import {superdeskApi} from '../../../superdeskApi'; +import {getCustomVocabularyFields} from '../field-adapters/custom-vocabularies'; +import {getDateTimeField} from './date-time-config'; +import {IFieldDefinitions, IFieldDefinition} from './interfaces'; +import {getTextFieldConfig} from './text-field-config'; +import {getPlaceField} from './place-field'; + +export function getFieldDefinitions(): IFieldDefinitions { + const {gettext} = superdeskApi.localization; + const result: Array = [ + { + fieldId: 'ednote', + getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Ed Note'), required: required}), + }, + { + fieldId: 'internal_note', + getField: ({required, id}) => + getTextFieldConfig({id: id, label: gettext('Internal Note'), required: required}), + }, + { + fieldId: 'name', + getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Name'), required: required}), + }, + { + fieldId: 'slugline', + getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Slugline'), required: required}), + }, + { + fieldId: 'description_text', + getField: ({required, id}) => + getTextFieldConfig({id: id, label: gettext('Description'), required: required}), + }, + { + fieldId: 'headline', + getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Headline'), required: required}), + }, + { + fieldId: 'planning_date', + getField: ({required, id}) => + getDateTimeField({id: id, label: gettext('Planning date'), required: required}), + }, + { + fieldId: 'files', + getField: ({required, id}) => { + const fieldConfig: IAttachmentsFieldConfig = { + required, + }; + + const field: IAuthoringFieldV2 = { + id: id, + name: gettext('Attached files'), + fieldType: 'files', + fieldConfig: fieldConfig, + }; + + return field; + }, + }, + getPlaceField(gettext), + { + fieldId: 'coverages', + getField: ({id, required}) => { + const fieldConfig: ICommonFieldConfig = { + required, + }; + + const field: IAuthoringFieldV2 = { + id: id, + name: gettext('Coverages'), + fieldType: 'coverages', + fieldConfig: fieldConfig, + }; + + return field; + }, + } + ]; + + result.push( + ...getCustomVocabularyFields(), + ); + + const resultObj = result.reduce((acc, item) => { + acc[item.fieldId] = item; + + return acc; + }, {} as IFieldDefinitions); + + return resultObj; +} diff --git a/client/components/planning-editor-standalone/field-definitions/interfaces.ts b/client/components/planning-editor-standalone/field-definitions/interfaces.ts new file mode 100644 index 000000000..8921178fc --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/interfaces.ts @@ -0,0 +1,13 @@ +import {IAuthoringFieldV2} from 'superdesk-api'; + +export interface IFieldDefinition { + fieldId: string; + getField: (options: {required: boolean, id: string}) => IAuthoringFieldV2; + storageAdapter?: { + storeValue: (item: T, operationalValue: unknown) => T; // returns stored value + retrieveStoredValue: + (item: T, fieldId: string) => unknown; // returns operational value + }; +} + +export type IFieldDefinitions = {[fieldId: string]: IFieldDefinition}; diff --git a/client/components/planning-editor-standalone/field-definitions/place-field.ts b/client/components/planning-editor-standalone/field-definitions/place-field.ts new file mode 100644 index 000000000..17279189c --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/place-field.ts @@ -0,0 +1,37 @@ +import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; +import {superdeskApi} from '../../../superdeskApi'; + +export const getPlaceField = (gettext: (val: string) => string) => ({ + fieldId: 'place', + getField: ({id, required}) => { + const fieldConfig: IDropdownConfigVocabulary = { + source: 'vocabulary', + vocabularyId: 'locators', + multiple: true, + required: required, + }; + + const field: IAuthoringFieldV2 = { + id: id, + name: gettext('Place'), + 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), + }, +}); diff --git a/client/components/planning-editor-standalone/field-definitions/text-field-config.ts b/client/components/planning-editor-standalone/field-definitions/text-field-config.ts new file mode 100644 index 000000000..1c9b4caf0 --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/text-field-config.ts @@ -0,0 +1,26 @@ +import {IAuthoringFieldV2, IEditor3Config} from 'superdesk-api'; + +export function getTextFieldConfig(options: {id: string; label: string, required: boolean}): IAuthoringFieldV2 { + const editor3ConfigWithoutFormatting: IEditor3Config = { + editorFormat: [], + minLength: undefined, + maxLength: undefined, + cleanPastedHtml: false, + singleLine: true, + disallowedCharacters: [], + showStatistics: false, + width: 100, + }; + + const field: IAuthoringFieldV2 = { + id: options.id, + name: options.label, + fieldType: 'editor3', + fieldConfig: { + ...editor3ConfigWithoutFormatting, + required: options.required, + }, + }; + + return field; +} diff --git a/client/components/planning-editor-standalone/profile.ts b/client/components/planning-editor-standalone/profile.ts index 1b6b6c380..c73e127c3 100644 --- a/client/components/planning-editor-standalone/profile.ts +++ b/client/components/planning-editor-standalone/profile.ts @@ -1,192 +1,8 @@ import {OrderedMap} from 'immutable'; -import { - IAuthoringFieldV2, - ICommonFieldConfig, - IContentProfileV2, - IDateTimeFieldConfig, - IDropdownConfigVocabulary, - IEditor3Config, - IVocabularyItem, -} from 'superdesk-api'; -import {superdeskApi} from '../../superdeskApi'; -import { - IAttachmentsFieldConfig, -} from '../../planning-extension/src/authoring-react-fields/planning-attachments/interfaces'; -import {getCustomVocabularyFields} from './field-adapters/custom-vocabularies'; +import {IContentProfileV2} from 'superdesk-api'; import {getPlanningProfileFields} from './profile-fields'; - -function getTextFieldConfig(options: {id: string; label: string, required: boolean}): IAuthoringFieldV2 { - const editor3ConfigWithoutFormatting: IEditor3Config = { - editorFormat: [], - minLength: undefined, - maxLength: undefined, - cleanPastedHtml: false, - singleLine: true, - disallowedCharacters: [], - showStatistics: false, - width: 100, - }; - - const field: IAuthoringFieldV2 = { - id: options.id, - name: options.label, - fieldType: 'editor3', - fieldConfig: { - ...editor3ConfigWithoutFormatting, - required: options.required, - }, - }; - - return field; -} - -function getDateTimeField(options: {id: string; label: string, required: boolean}): IAuthoringFieldV2 { - const config: IDateTimeFieldConfig = { - allowSeconds: false, - }; - - const field: IAuthoringFieldV2 = { - id: options.id, - name: options.label, - fieldType: 'datetime', - fieldConfig: { - ...config, - required: options.required, - }, - }; - - return field; -} - -export interface IFieldDefinition { - fieldId: string; - getField: (options: {required: boolean, id: string}) => IAuthoringFieldV2; - storageAdapter?: { - storeValue: (item: T, operationalValue: unknown) => T; // returns stored value - retrieveStoredValue: - (item: T, fieldId: string) => unknown; // returns operational value - }; -} - -type IFieldDefinitions = {[fieldId: string]: IFieldDefinition}; - -export function getFieldDefinitions(): IFieldDefinitions { - const {gettext} = superdeskApi.localization; - const result: Array = [ - { - fieldId: 'ednote', - getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Ed Note'), required: required}), - }, - { - fieldId: 'internal_note', - getField: ({required, id}) => - getTextFieldConfig({id: id, label: gettext('Internal Note'), required: required}), - }, - { - fieldId: 'name', - getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Name'), required: required}), - }, - { - fieldId: 'slugline', - getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Slugline'), required: required}), - }, - { - fieldId: 'description_text', - getField: ({required, id}) => - getTextFieldConfig({id: id, label: gettext('Description'), required: required}), - }, - { - fieldId: 'headline', - getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Headline'), required: required}), - }, - { - fieldId: 'planning_date', - getField: ({required, id}) => - getDateTimeField({id: id, label: gettext('Planning date'), required: required}), - }, - { - fieldId: 'files', - getField: ({required, id}) => { - const fieldConfig: IAttachmentsFieldConfig = { - required, - }; - - const field: IAuthoringFieldV2 = { - id: id, - name: gettext('Attached files'), - fieldType: 'files', - fieldConfig: fieldConfig, - }; - - return field; - }, - }, - { - fieldId: 'place', - getField: ({id, required}) => { - const fieldConfig: IDropdownConfigVocabulary = { - source: 'vocabulary', - vocabularyId: 'locators', - multiple: true, - required: required, - }; - - const field: IAuthoringFieldV2 = { - id: id, - name: gettext('Place'), - 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), - }, - }, - { - fieldId: 'coverages', - getField: ({id, required}) => { - const fieldConfig: ICommonFieldConfig = { - required, - }; - - const field: IAuthoringFieldV2 = { - id: id, - name: gettext('Coverages'), - fieldType: 'coverages', - fieldConfig: fieldConfig, - }; - - return field; - }, - } - ]; - - result.push( - ...getCustomVocabularyFields(), - ); - - const resultObj = result.reduce((acc, item) => { - acc[item.fieldId] = item; - - return acc; - }, {} as IFieldDefinitions); - - return resultObj; -} +import {getFieldDefinitions} from './field-definitions/index'; export function getProfile() { const planningFieldIds = getPlanningProfileFields(); From a5b7c74c8d0905e05809f5a009fb8eae24498d01 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 15:59:22 +0200 Subject: [PATCH 2/6] Categories field implementation --- .../field-definitions/category-field.ts | 38 +++++++++++++++++++ .../field-definitions/index.ts | 6 ++- .../field-definitions/place-field.ts | 5 ++- .../profile-fields.ts | 8 +++- .../storage-adapter.ts | 2 +- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 client/components/planning-editor-standalone/field-definitions/category-field.ts diff --git a/client/components/planning-editor-standalone/field-definitions/category-field.ts b/client/components/planning-editor-standalone/field-definitions/category-field.ts new file mode 100644 index 000000000..5ad76bacf --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/category-field.ts @@ -0,0 +1,38 @@ +import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; +import {superdeskApi} from '../../../superdeskApi'; +import {IFieldGetter} from '.'; + +export const getCategoriesField: IFieldGetter = () => ({ + fieldId: 'anpa_category', + getField: ({id, required}) => { + const fieldConfig: IDropdownConfigVocabulary = { + source: 'vocabulary', + vocabularyId: 'categories', + multiple: true, + required: required, + }; + + const field: IAuthoringFieldV2 = { + id: id, + name: superdeskApi.localization.gettext('Categories'), + fieldType: 'dropdown', + fieldConfig: fieldConfig, + }; + + return field; + }, + storageAdapter: { + storeValue: (item, operationalValue: Array) => { + const vocabulary = superdeskApi.entities.vocabulary.getAll().get('categories'); + const vocabularyItems = new Map( + vocabulary.items.map((item) => [item.qcode, item]), + ); + + return { + ...item, + anpa_category: operationalValue.map((qcode) => vocabularyItems.get(qcode)), + }; + }, + retrieveStoredValue: (item, fieldId) => (item[fieldId] ?? []).map(({qcode}) => qcode), + }, +}); diff --git a/client/components/planning-editor-standalone/field-definitions/index.ts b/client/components/planning-editor-standalone/field-definitions/index.ts index def4aac08..d331b38ce 100644 --- a/client/components/planning-editor-standalone/field-definitions/index.ts +++ b/client/components/planning-editor-standalone/field-definitions/index.ts @@ -11,6 +11,9 @@ import {getDateTimeField} from './date-time-config'; import {IFieldDefinitions, IFieldDefinition} from './interfaces'; import {getTextFieldConfig} from './text-field-config'; import {getPlaceField} from './place-field'; +import {getCategoriesField} from './category-field'; + +export type IFieldGetter = () => IFieldDefinition; export function getFieldDefinitions(): IFieldDefinitions { const {gettext} = superdeskApi.localization; @@ -63,7 +66,8 @@ export function getFieldDefinitions(): IFieldDefinitions { return field; }, }, - getPlaceField(gettext), + getPlaceField(), + getCategoriesField(), { fieldId: 'coverages', getField: ({id, required}) => { diff --git a/client/components/planning-editor-standalone/field-definitions/place-field.ts b/client/components/planning-editor-standalone/field-definitions/place-field.ts index 17279189c..24b3c8037 100644 --- a/client/components/planning-editor-standalone/field-definitions/place-field.ts +++ b/client/components/planning-editor-standalone/field-definitions/place-field.ts @@ -1,7 +1,8 @@ import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; import {superdeskApi} from '../../../superdeskApi'; +import {IFieldGetter} from '.'; -export const getPlaceField = (gettext: (val: string) => string) => ({ +export const getPlaceField: IFieldGetter = () => ({ fieldId: 'place', getField: ({id, required}) => { const fieldConfig: IDropdownConfigVocabulary = { @@ -13,7 +14,7 @@ export const getPlaceField = (gettext: (val: string) => string) => ({ const field: IAuthoringFieldV2 = { id: id, - name: gettext('Place'), + name: superdeskApi.localization.gettext('Place'), fieldType: 'dropdown', fieldConfig: fieldConfig, }; diff --git a/client/components/planning-editor-standalone/profile-fields.ts b/client/components/planning-editor-standalone/profile-fields.ts index 8ba6b701b..dc26ead20 100644 --- a/client/components/planning-editor-standalone/profile-fields.ts +++ b/client/components/planning-editor-standalone/profile-fields.ts @@ -1,4 +1,3 @@ -import {flatMap} from 'lodash'; import {planningApi} from '../../superdeskApi'; import {getEditorFormGroupsFromProfile} from '../../utils/contentProfiles'; @@ -14,13 +13,18 @@ interface ICustomVocabularyField extends IBaseField<'custom_vocabulary'> { type IFieldConverted = IBaseField<'normal'> | ICustomVocabularyField; +const FIELDS_TO_FILTER = [ + 'associated_event', +]; + /** * A function that handles planning profile field types so they can be used in authoring react. */ export const getPlanningProfileFields = (): Array => { const planningProfile = planningApi.contentProfiles.get('planning'); const planningGroups = getEditorFormGroupsFromProfile(planningProfile); - const planningFieldIds = Object.values(planningGroups).flatMap((x) => x.fields); + const planningFieldIds = Object.values(planningGroups).flatMap((x) => x.fields) + .filter((x) => !FIELDS_TO_FILTER.includes(x)); const convertedFieldIds: Array = []; for (const fieldId of planningFieldIds) { diff --git a/client/components/planning-editor-standalone/storage-adapter.ts b/client/components/planning-editor-standalone/storage-adapter.ts index 663746422..e8118d10a 100644 --- a/client/components/planning-editor-standalone/storage-adapter.ts +++ b/client/components/planning-editor-standalone/storage-adapter.ts @@ -6,7 +6,7 @@ import { IStorageAdapter, } from 'superdesk-api'; import {superdeskApi} from '../../superdeskApi'; -import {getFieldDefinitions} from './profile'; +import {getFieldDefinitions} from './field-definitions/index'; export const storageAdapterPlanningItem: IStorageAdapter = { storeValue: (value, fieldId, item, config, fieldType) => { From ca97a80ae269a70d45c951d061b1cde78b4d2bfe Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 16:04:04 +0200 Subject: [PATCH 3/6] Revert "Categories field implementation" This reverts commit a5b7c74c8d0905e05809f5a009fb8eae24498d01. --- .../field-definitions/category-field.ts | 38 ------------------- .../field-definitions/index.ts | 6 +-- .../field-definitions/place-field.ts | 5 +-- .../profile-fields.ts | 8 +--- .../storage-adapter.ts | 2 +- 5 files changed, 6 insertions(+), 53 deletions(-) delete mode 100644 client/components/planning-editor-standalone/field-definitions/category-field.ts diff --git a/client/components/planning-editor-standalone/field-definitions/category-field.ts b/client/components/planning-editor-standalone/field-definitions/category-field.ts deleted file mode 100644 index 5ad76bacf..000000000 --- a/client/components/planning-editor-standalone/field-definitions/category-field.ts +++ /dev/null @@ -1,38 +0,0 @@ -import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; -import {superdeskApi} from '../../../superdeskApi'; -import {IFieldGetter} from '.'; - -export const getCategoriesField: IFieldGetter = () => ({ - fieldId: 'anpa_category', - getField: ({id, required}) => { - const fieldConfig: IDropdownConfigVocabulary = { - source: 'vocabulary', - vocabularyId: 'categories', - multiple: true, - required: required, - }; - - const field: IAuthoringFieldV2 = { - id: id, - name: superdeskApi.localization.gettext('Categories'), - fieldType: 'dropdown', - fieldConfig: fieldConfig, - }; - - return field; - }, - storageAdapter: { - storeValue: (item, operationalValue: Array) => { - const vocabulary = superdeskApi.entities.vocabulary.getAll().get('categories'); - const vocabularyItems = new Map( - vocabulary.items.map((item) => [item.qcode, item]), - ); - - return { - ...item, - anpa_category: operationalValue.map((qcode) => vocabularyItems.get(qcode)), - }; - }, - retrieveStoredValue: (item, fieldId) => (item[fieldId] ?? []).map(({qcode}) => qcode), - }, -}); diff --git a/client/components/planning-editor-standalone/field-definitions/index.ts b/client/components/planning-editor-standalone/field-definitions/index.ts index d331b38ce..def4aac08 100644 --- a/client/components/planning-editor-standalone/field-definitions/index.ts +++ b/client/components/planning-editor-standalone/field-definitions/index.ts @@ -11,9 +11,6 @@ import {getDateTimeField} from './date-time-config'; import {IFieldDefinitions, IFieldDefinition} from './interfaces'; import {getTextFieldConfig} from './text-field-config'; import {getPlaceField} from './place-field'; -import {getCategoriesField} from './category-field'; - -export type IFieldGetter = () => IFieldDefinition; export function getFieldDefinitions(): IFieldDefinitions { const {gettext} = superdeskApi.localization; @@ -66,8 +63,7 @@ export function getFieldDefinitions(): IFieldDefinitions { return field; }, }, - getPlaceField(), - getCategoriesField(), + getPlaceField(gettext), { fieldId: 'coverages', getField: ({id, required}) => { diff --git a/client/components/planning-editor-standalone/field-definitions/place-field.ts b/client/components/planning-editor-standalone/field-definitions/place-field.ts index 24b3c8037..17279189c 100644 --- a/client/components/planning-editor-standalone/field-definitions/place-field.ts +++ b/client/components/planning-editor-standalone/field-definitions/place-field.ts @@ -1,8 +1,7 @@ import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; import {superdeskApi} from '../../../superdeskApi'; -import {IFieldGetter} from '.'; -export const getPlaceField: IFieldGetter = () => ({ +export const getPlaceField = (gettext: (val: string) => string) => ({ fieldId: 'place', getField: ({id, required}) => { const fieldConfig: IDropdownConfigVocabulary = { @@ -14,7 +13,7 @@ export const getPlaceField: IFieldGetter = () => ({ const field: IAuthoringFieldV2 = { id: id, - name: superdeskApi.localization.gettext('Place'), + name: gettext('Place'), fieldType: 'dropdown', fieldConfig: fieldConfig, }; diff --git a/client/components/planning-editor-standalone/profile-fields.ts b/client/components/planning-editor-standalone/profile-fields.ts index dc26ead20..8ba6b701b 100644 --- a/client/components/planning-editor-standalone/profile-fields.ts +++ b/client/components/planning-editor-standalone/profile-fields.ts @@ -1,3 +1,4 @@ +import {flatMap} from 'lodash'; import {planningApi} from '../../superdeskApi'; import {getEditorFormGroupsFromProfile} from '../../utils/contentProfiles'; @@ -13,18 +14,13 @@ interface ICustomVocabularyField extends IBaseField<'custom_vocabulary'> { type IFieldConverted = IBaseField<'normal'> | ICustomVocabularyField; -const FIELDS_TO_FILTER = [ - 'associated_event', -]; - /** * A function that handles planning profile field types so they can be used in authoring react. */ export const getPlanningProfileFields = (): Array => { const planningProfile = planningApi.contentProfiles.get('planning'); const planningGroups = getEditorFormGroupsFromProfile(planningProfile); - const planningFieldIds = Object.values(planningGroups).flatMap((x) => x.fields) - .filter((x) => !FIELDS_TO_FILTER.includes(x)); + const planningFieldIds = Object.values(planningGroups).flatMap((x) => x.fields); const convertedFieldIds: Array = []; for (const fieldId of planningFieldIds) { diff --git a/client/components/planning-editor-standalone/storage-adapter.ts b/client/components/planning-editor-standalone/storage-adapter.ts index e8118d10a..663746422 100644 --- a/client/components/planning-editor-standalone/storage-adapter.ts +++ b/client/components/planning-editor-standalone/storage-adapter.ts @@ -6,7 +6,7 @@ import { IStorageAdapter, } from 'superdesk-api'; import {superdeskApi} from '../../superdeskApi'; -import {getFieldDefinitions} from './field-definitions/index'; +import {getFieldDefinitions} from './profile'; export const storageAdapterPlanningItem: IStorageAdapter = { storeValue: (value, fieldId, item, config, fieldType) => { From 6f7325d5b48119f00b82460f9f41ae979c3fe0b6 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 12 Dec 2024 16:08:59 +0200 Subject: [PATCH 4/6] Small improvements --- .../planning-editor-standalone/field-definitions/index.ts | 4 +++- .../field-definitions/place-field.ts | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/components/planning-editor-standalone/field-definitions/index.ts b/client/components/planning-editor-standalone/field-definitions/index.ts index def4aac08..6d16d5b5b 100644 --- a/client/components/planning-editor-standalone/field-definitions/index.ts +++ b/client/components/planning-editor-standalone/field-definitions/index.ts @@ -12,6 +12,8 @@ import {IFieldDefinitions, IFieldDefinition} from './interfaces'; import {getTextFieldConfig} from './text-field-config'; import {getPlaceField} from './place-field'; +export type IFieldGetter = () => IFieldDefinition; + export function getFieldDefinitions(): IFieldDefinitions { const {gettext} = superdeskApi.localization; const result: Array = [ @@ -63,7 +65,7 @@ export function getFieldDefinitions(): IFieldDefinitions { return field; }, }, - getPlaceField(gettext), + getPlaceField(), { fieldId: 'coverages', getField: ({id, required}) => { diff --git a/client/components/planning-editor-standalone/field-definitions/place-field.ts b/client/components/planning-editor-standalone/field-definitions/place-field.ts index 17279189c..24b3c8037 100644 --- a/client/components/planning-editor-standalone/field-definitions/place-field.ts +++ b/client/components/planning-editor-standalone/field-definitions/place-field.ts @@ -1,7 +1,8 @@ import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; import {superdeskApi} from '../../../superdeskApi'; +import {IFieldGetter} from '.'; -export const getPlaceField = (gettext: (val: string) => string) => ({ +export const getPlaceField: IFieldGetter = () => ({ fieldId: 'place', getField: ({id, required}) => { const fieldConfig: IDropdownConfigVocabulary = { @@ -13,7 +14,7 @@ export const getPlaceField = (gettext: (val: string) => string) => ({ const field: IAuthoringFieldV2 = { id: id, - name: gettext('Place'), + name: superdeskApi.localization.gettext('Place'), fieldType: 'dropdown', fieldConfig: fieldConfig, }; From b204fa6da415bd56cb1a6dda51ca18e183642d58 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Fri, 13 Dec 2024 12:44:58 +0200 Subject: [PATCH 5/6] Fix storage adapter import --- client/components/planning-editor-standalone/storage-adapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/planning-editor-standalone/storage-adapter.ts b/client/components/planning-editor-standalone/storage-adapter.ts index 663746422..53ccfcb52 100644 --- a/client/components/planning-editor-standalone/storage-adapter.ts +++ b/client/components/planning-editor-standalone/storage-adapter.ts @@ -6,7 +6,7 @@ import { IStorageAdapter, } from 'superdesk-api'; import {superdeskApi} from '../../superdeskApi'; -import {getFieldDefinitions} from './profile'; +import {getFieldDefinitions} from './field-definitions'; export const storageAdapterPlanningItem: IStorageAdapter = { storeValue: (value, fieldId, item, config, fieldType) => { From df8c70944d0bf0d74c487cd4dd6161e704e902b9 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Fri, 13 Dec 2024 13:27:25 +0200 Subject: [PATCH 6/6] Changes after review --- .../field-definitions/agendas-field.ts | 33 +++++++++++++++++++ .../field-definitions/index.ts | 4 +-- .../field-definitions/place-field.ts | 4 +-- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 client/components/planning-editor-standalone/field-definitions/agendas-field.ts diff --git a/client/components/planning-editor-standalone/field-definitions/agendas-field.ts b/client/components/planning-editor-standalone/field-definitions/agendas-field.ts new file mode 100644 index 000000000..9281f7017 --- /dev/null +++ b/client/components/planning-editor-standalone/field-definitions/agendas-field.ts @@ -0,0 +1,33 @@ +import {IAgenda} from 'interfaces'; +import {IDropdownConfigManualSource, IAuthoringFieldV2} from 'superdesk-api'; +import {planningApi} from 'superdeskApi'; +import {gettext} from 'utils'; +import {IFieldDefinition} from './interfaces'; + +export const getAgendasField = (): IFieldDefinition => ({ + fieldId: 'agendas', + getField: ({id, required}) => { + 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, + }; + + const field: IAuthoringFieldV2 = { + id: id, + name: gettext('Agendas'), + fieldType: 'dropdown', + fieldConfig: fieldConfig, + }; + + return field; + }, +}); diff --git a/client/components/planning-editor-standalone/field-definitions/index.ts b/client/components/planning-editor-standalone/field-definitions/index.ts index 6d16d5b5b..b71d36fe6 100644 --- a/client/components/planning-editor-standalone/field-definitions/index.ts +++ b/client/components/planning-editor-standalone/field-definitions/index.ts @@ -11,8 +11,7 @@ import {getDateTimeField} from './date-time-config'; import {IFieldDefinitions, IFieldDefinition} from './interfaces'; import {getTextFieldConfig} from './text-field-config'; import {getPlaceField} from './place-field'; - -export type IFieldGetter = () => IFieldDefinition; +import {getAgendasField} from './agendas-field'; export function getFieldDefinitions(): IFieldDefinitions { const {gettext} = superdeskApi.localization; @@ -66,6 +65,7 @@ export function getFieldDefinitions(): IFieldDefinitions { }, }, getPlaceField(), + getAgendasField(), { fieldId: 'coverages', getField: ({id, required}) => { diff --git a/client/components/planning-editor-standalone/field-definitions/place-field.ts b/client/components/planning-editor-standalone/field-definitions/place-field.ts index 24b3c8037..28df5ef8a 100644 --- a/client/components/planning-editor-standalone/field-definitions/place-field.ts +++ b/client/components/planning-editor-standalone/field-definitions/place-field.ts @@ -1,8 +1,8 @@ import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; import {superdeskApi} from '../../../superdeskApi'; -import {IFieldGetter} from '.'; +import {IFieldDefinition} from './interfaces'; -export const getPlaceField: IFieldGetter = () => ({ +export const getPlaceField = (): IFieldDefinition => ({ fieldId: 'place', getField: ({id, required}) => { const fieldConfig: IDropdownConfigVocabulary = {