Skip to content

Commit

Permalink
Subject field (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Dec 18, 2024
1 parent b7d729b commit 680c4ae
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IDropdownConfigVocabulary, IAuthoringFieldV2, ISubject, IVocabularyItem} from 'superdesk-api';
import {superdeskApi} from '../../../superdeskApi';
import {IFieldDefinition} from '../field-definitions/interfaces';
import {getPlanningProfileFields} from '../profile-fields';
import {IFieldDefinition} from '../field-definitions/interfaces';

export const getCustomVocabularyFields = () => {
const customVocabularyIds = getPlanningProfileFields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {getTextFieldConfig} from './text-field-config';
import {getPlaceField} from './place-field';
import {getCategoriesField} from './category-field';
import {getAgendasField} from './agendas-field';
import {getSubjectField} from './subject';
import {getPriorityField} from './priority-field';

export function getFieldDefinitions(): IFieldDefinitions {
Expand Down Expand Up @@ -68,6 +69,7 @@ export function getFieldDefinitions(): IFieldDefinitions {
},
getPlaceField(),
getAgendasField(),
getSubjectField(),
getCategoriesField(),
getPriorityField(),
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
IAuthoringFieldV2,
ISubjectCode,
IDropdownConfigManualSource,
} from 'superdesk-api';
import {gettext} from 'core/utils';
import {IFieldDefinition} from './interfaces';
import {planningApi} from '../../../superdeskApi';

export function getSubjectField(): IFieldDefinition {
return {
fieldId: 'subject',
getField: ({id, required}) => {
const fieldConfig: IDropdownConfigManualSource = {
source: 'manual-entry',
options: (planningApi.redux.store.getState().subjects ?? [])
.map((x) => ({id: x.qcode, label: x.name, parent: x.parent})),
roundCorners: true,
type: 'text',
canSelectBranchWithChildren: true,
multiple: true,
required: required,
};

const fieldV2: IAuthoringFieldV2 = {
id: 'subject',
name: gettext('Subject'),
fieldType: 'dropdown',
fieldConfig: fieldConfig,
};

return fieldV2;
},
storageAdapter: {
retrieveStoredValue: (item) => {
return (item.subject ?? []).map(({qcode}) => qcode);
},
storeValue: (item, operationalValue: Array<ISubjectCode['qcode']>) => {
const subjectsFull: Array<ISubjectCode> = (planningApi.redux.store.getState().subjects ?? [])
.filter((x) => operationalValue.includes(x.qcode));

return {
...item,
subject: subjectsFull,
};
},
}
};
}
193 changes: 163 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"simulant": "^0.2.2",
"sinon": "^4.5.0",
"superdesk-code-style": "1.5.0",
"superdesk-core": "github:superdesk/superdesk-client-core#develop",
"superdesk-core": "github:thecalcc/superdesk-client-core#rework-dropdown-fields",
"superdesk-ui-framework": "^4.0.5",
"ts-node": "~7.0.1",
"tslint": "5.11.0",
Expand Down

0 comments on commit 680c4ae

Please sign in to comment.