Skip to content

Commit

Permalink
WIP - agenda field
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Dec 12, 2024
1 parent d0cd58a commit 5532264
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion client/components/planning-editor-standalone/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
ICommonFieldConfig,
IContentProfileV2,
IDateTimeFieldConfig,
IDropdownConfigRemoteSource,
IDropdownConfigVocabulary,
IEditor3Config,
IRestApiResponse,
ITreeWithLookup,
IVocabularyItem,
} from 'superdesk-api';
import {superdeskApi} from '../../superdeskApi';
Expand All @@ -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 = {
Expand Down Expand Up @@ -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<IRestApiResponse<IAgenda>>({
method: 'GET',
path: '/agenda',
urlParams: {
max_results: 200,
name: searchTerm,
},
}).then((res) => {
const tree: ITreeWithLookup<IAgenda> = {
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<string>) => {
const vocabulary = superdeskApi.entities.vocabulary.getAll().get('locators');
const vocabularyItems = new Map<IVocabularyItem['qcode'], IVocabularyItem>(
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(
Expand Down

0 comments on commit 5532264

Please sign in to comment.