Skip to content
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

Planning authoring-react fields #2147

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions client/components/fields/editor/CustomVocabularies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import {getVocabularyItemFieldTranslated} from '../../../utils/vocabularies';
import {arrayToTree} from 'superdesk-core/scripts/core/helpers/tree';
import {TreeSelect} from 'superdesk-ui-framework/react';

interface IProps extends IEditorFieldProps {
export interface ICustomVocabulariesProps extends IEditorFieldProps {
schema?: IProfileSchemaTypeList;
}

interface IReduxStateProps {
vocabularies: Array<IVocabulary>;
popupContainer?(): HTMLElement;
onPopupOpen?(): void;
onPopupClose?(): void;
}

type IProps = ICustomVocabulariesProps & IReduxStateProps;

const mapStateToProps = (state) => ({
vocabularies: state.customVocabularies,
});
Expand Down Expand Up @@ -93,4 +95,5 @@ class CustomVocabulariesComponent extends React.PureComponent<IProps> {
}
}

export const EditorFieldCustomVocabularies = connect(mapStateToProps)(CustomVocabulariesComponent);
export const EditorFieldCustomVocabularies =
connect<IReduxStateProps, {}, ICustomVocabulariesProps>(mapStateToProps)(CustomVocabulariesComponent);
78 changes: 73 additions & 5 deletions client/components/planning-editor-standalone/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import {OrderedMap} from 'immutable';

import {
IAuthoringFieldV2,
ICommonFieldConfig,
IContentProfileV2,
IDateFieldConfig,
IDropdownConfigManualSource,
IDateTimeFieldConfig,
IDropdownConfigVocabulary,
IEditor3Config,
IVocabularyItem,
Expand Down Expand Up @@ -41,6 +39,47 @@ function getTextFieldConfig(options: {id: string; label: string, required: boole
return field;
}

function getCustomVocabulariesConfig(options: {
id: string;
label: string;
required: boolean;
vocabIds: Array<string>
}): IAuthoringFieldV2 {
const customVocabulariesConfig = {
vocabularyIds: options.vocabIds,
};

const field: IAuthoringFieldV2 = {
id: options.id,
name: options.label,
fieldType: 'custom_vocabularies',
fieldConfig: {
required: options.required,
...customVocabulariesConfig,
},
};

return field;
}

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;
}

interface IFieldDefinition {
fieldId: string;
getField: (options: {required: boolean, id: string}) => IAuthoringFieldV2;
Expand Down Expand Up @@ -87,6 +126,11 @@ export function getFieldDefinitions(): IFieldDefinitions {
getField: ({required, id}) => getTextFieldConfig({id: id, label: gettext('Headline'), required: required}),
});

result.push({
fieldId: 'planning_date',
getField: ({required, id}) => getDateTimeField({id: id, label: gettext('Planning date'), required: required}),
});

result.push({
fieldId: 'files',
getField: ({required, id}) => {
Expand Down Expand Up @@ -147,6 +191,7 @@ export function getFieldDefinitions(): IFieldDefinitions {
}

export function getProfile() {
const {gettext} = superdeskApi.localization;
const planningProfile = planningApi.contentProfiles.get('planning');
const planningGroups = getEditorFormGroupsFromProfile(planningProfile);
const planningFieldIds = Object.values(planningGroups).flatMap(({fields}) => fields);
Expand All @@ -165,7 +210,17 @@ export function getProfile() {
for (const fieldId of planningFieldIds) {
const required = planningProfile.schema?.[fieldId]?.required ?? false;

if (fieldDefinitions[fieldId] != null) {
if (fieldId === 'custom_vocabularies') {
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
profileV2.header = profileV2.header.set(
fieldId,
getCustomVocabulariesConfig({
id: fieldId,
label: gettext('Custom Vocabularies'),
required: required,
vocabIds: planningProfile.schema?.[fieldId]?.vocabularies,
})
);
} else if (fieldDefinitions[fieldId] != null) {
profileV2.header = profileV2.header.set(
fieldId,
fieldDefinitions[fieldId].getField({id: fieldId, required: required}),
Expand Down Expand Up @@ -285,4 +340,17 @@ export function getProfile() {
// };

// profileV2.header = profileV2.header.set(categoryField.id, categoryField);
// }
// }
// else {
// skipped.push(fieldId);
// }
// }

// profileV2.header.forEach((item) => {
// item.fieldConfig.width = 100;
// });

// console.log('skipped -------------------------------- ', skipped, superdeskApi.entities.vocabulary.getAll());

// return profileV2;
// }
3 changes: 3 additions & 0 deletions client/extension_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {isContentLinkToCoverageAllowed} from './utils/archive';
import PlanningDetailsWidget, {getItemPlanningInfo} from './components/PlanningDetailsWidget';
import {AttachmentsInputStandalone} from './components/AttachmentsInputStandalone';
import {IPropsAttachmentsEditorStandalone} from './components/AttachmentsInputStandalone.interface';
import {EditorFieldCustomVocabularies, ICustomVocabulariesProps} from './components/fields/editor/CustomVocabularies';

// KEEP IN SYNC WITH client/planning-extension/src/extension_bridge.ts
interface IExtensionBridge {
Expand Down Expand Up @@ -54,6 +55,7 @@ interface IExtensionBridge {
};

components: {
EditorFieldCustomVocabularies: React.ComponentType<ICustomVocabulariesProps>;
EditorFieldVocabulary: React.ComponentType<IEditorFieldVocabularyProps>;
PlanningDetailsWidget: React.ComponentType<{item: {assignment_id: string}}>;
AttachmentsInputStandalone: React.ComponentType<IPropsAttachmentsEditorStandalone>;
Expand Down Expand Up @@ -98,6 +100,7 @@ export const extensionBridge: IExtensionBridge = {
isContentLinkToCoverageAllowed,
},
components: {
EditorFieldCustomVocabularies,
EditorFieldVocabulary,
PlanningDetailsWidget,
AttachmentsInputStandalone,
Expand Down
Loading
Loading