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) => {