-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcalendars.ts
52 lines (47 loc) · 1.76 KB
/
calendars.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {IAuthoringFieldV2, IDropdownConfigManualSource} from 'superdesk-api';
import {planningApi, superdeskApi} from '../../../superdeskApi';
import {getVocabularyItemFieldTranslated} from '../../../utils/vocabularies';
import {calendars} from '../../../selectors/events';
export const getCalendarsField = () => {
const vocabularyFromStore = calendars(planningApi.redux.store.getState());
return {
fieldId: 'calendars',
getField: ({required, id}) => {
const options = vocabularyFromStore.map(
(option) => ({
id: option.qcode,
label: getVocabularyItemFieldTranslated(
option,
'label',
'en',
'name'
),
})
);
const fieldConfig: IDropdownConfigManualSource = {
source: 'manual-entry',
options: options,
type: 'text',
roundCorners: false,
multiple: true,
required: required,
};
const field: IAuthoringFieldV2 = {
id: id,
name: superdeskApi.localization.gettext('Calendars'),
fieldType: 'dropdown',
fieldConfig: fieldConfig,
};
return field;
},
storageAdapterEvent: {
storeValue: (item, operationalValue: Array<string>) => {
return {
...item,
calendars: vocabularyFromStore.filter((x) => operationalValue.includes(x.qcode)),
};
},
retrieveStoredValue: (item) => item.calendars.map((x) => x.qcode),
}
};
};