-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor structure & categories field #2156
Merged
thecalcc
merged 7 commits into
superdesk:authoring-react-planning
from
thecalcc:category-field-port
Dec 13, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
124fbbf
Refactor structure
thecalcc a5b7c74
Categories field implementation
thecalcc ca97a80
Revert "Categories field implementation"
thecalcc 6f7325d
Small improvements
thecalcc cf7db0d
Merge branch 'authoring-react-planning' into category-field-port
thecalcc b204fa6
Fix storage adapter import
thecalcc df8c709
Changes after review
thecalcc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
||
export type IFieldGetter = () => IFieldDefinition; | ||
|
||
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(), | ||
{ | ||
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 {IFieldGetter} from '.'; | ||
|
||
export const getPlaceField: IFieldGetter = () => ({ | ||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IFieldGetter
doesn't server any purpose here compared toconst getPlaceField = (): IFieldDefinition => {...}