-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor structure & categories field (#2156)
- Loading branch information
Showing
8 changed files
with
231 additions
and
215 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
client/components/planning-editor-standalone/field-definitions/agendas-field.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IAgenda>) | ||
.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; | ||
}, | ||
}); |
19 changes: 19 additions & 0 deletions
19
client/components/planning-editor-standalone/field-definitions/date-time-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
99 changes: 99 additions & 0 deletions
99
client/components/planning-editor-standalone/field-definitions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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'; | ||
import {getAgendasField} from './agendas-field'; | ||
|
||
export function getFieldDefinitions(): IFieldDefinitions { | ||
const {gettext} = superdeskApi.localization; | ||
const result: Array<IFieldDefinition> = [ | ||
{ | ||
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(), | ||
getAgendasField(), | ||
{ | ||
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; | ||
} |
13 changes: 13 additions & 0 deletions
13
client/components/planning-editor-standalone/field-definitions/interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {IAuthoringFieldV2} from 'superdesk-api'; | ||
|
||
export interface IFieldDefinition { | ||
fieldId: string; | ||
getField: (options: {required: boolean, id: string}) => IAuthoringFieldV2; | ||
storageAdapter?: { | ||
storeValue: <T extends IPlanningItem>(item: T, operationalValue: unknown) => T; // returns stored value | ||
retrieveStoredValue: | ||
<T extends IPlanningItem>(item: T, fieldId: string) => unknown; // returns operational value | ||
}; | ||
} | ||
|
||
export type IFieldDefinitions = {[fieldId: string]: IFieldDefinition}; |
38 changes: 38 additions & 0 deletions
38
client/components/planning-editor-standalone/field-definitions/place-field.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {IDropdownConfigVocabulary, IAuthoringFieldV2, IVocabularyItem} from 'superdesk-api'; | ||
import {superdeskApi} from '../../../superdeskApi'; | ||
import {IFieldDefinition} from './interfaces'; | ||
|
||
export const getPlaceField = (): IFieldDefinition => ({ | ||
fieldId: 'place', | ||
getField: ({id, required}) => { | ||
const fieldConfig: IDropdownConfigVocabulary = { | ||
source: 'vocabulary', | ||
vocabularyId: 'locators', | ||
multiple: true, | ||
required: required, | ||
}; | ||
|
||
const field: IAuthoringFieldV2 = { | ||
id: id, | ||
name: superdeskApi.localization.gettext('Place'), | ||
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), | ||
}, | ||
}); |
26 changes: 26 additions & 0 deletions
26
client/components/planning-editor-standalone/field-definitions/text-field-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Oops, something went wrong.