From fc827e33d4247dce4585980916d45bd1e5143f12 Mon Sep 17 00:00:00 2001 From: Mark Pittaway Date: Thu, 18 Aug 2022 16:04:15 +1000 Subject: [PATCH] [SDESK-6564] Allow configuring `All Day` & `Default Duration` in EventProfile --- .../ContentProfiles/FieldTab/FieldEditor.tsx | 8 +++++-- .../ContentProfiles/FieldTab/index.tsx | 24 +++++++++---------- .../components/Events/EventEditor/index.tsx | 2 +- .../components/fields/resources/profiles.ts | 22 +++++++++++++++++ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/client/components/ContentProfiles/FieldTab/FieldEditor.tsx b/client/components/ContentProfiles/FieldTab/FieldEditor.tsx index da4ccc608..a9bc4b33e 100644 --- a/client/components/ContentProfiles/FieldTab/FieldEditor.tsx +++ b/client/components/ContentProfiles/FieldTab/FieldEditor.tsx @@ -16,7 +16,7 @@ interface IProps { systemRequired: boolean; closeEditor(): void; saveField(): void; - updateFieldSchema(field: string, value: string | number | boolean | Array): void; + updateField(field: string, value: string | number | boolean | Array): void; } export class FieldEditor extends React.PureComponent { @@ -35,7 +35,7 @@ export class FieldEditor extends React.PureComponent { } onChange(field: string, value: string | number | boolean | Array) { - this.props.updateFieldSchema(field.replace('schema.', ''), value); + this.props.updateField(field, value); } render() { @@ -53,6 +53,8 @@ export class FieldEditor extends React.PureComponent { 'schema.expandable': {enabled: fieldType === 'multi_line'}, 'schema.format_options': {enabled: fieldType === 'editor_3'}, 'schema.vocabularies': {enabled: this.props.item.name === 'custom_vocabularies'}, + 'field.all_day.enabled': {enabled: this.props.item.name === 'dates'}, + 'field.default_duration_on_change': {enabled: this.props.item.name === 'dates'}, }; const noOptionsAvailable = !( Object.values(fieldProps) @@ -130,6 +132,8 @@ export class FieldEditor extends React.PureComponent { 'schema.maxlength': {enabled: true, index: 5}, 'schema.format_options': {enabled: true, index: 6}, 'schema.vocabularies': {enabled: true, index: 7}, + 'field.all_day.enabled': {enabled: true, index: 8}, + 'field.default_duration_on_change': {enabled: true, index: 9}, }, { item: this.props.item, diff --git a/client/components/ContentProfiles/FieldTab/index.tsx b/client/components/ContentProfiles/FieldTab/index.tsx index f92a7214a..2a22963f6 100644 --- a/client/components/ContentProfiles/FieldTab/index.tsx +++ b/client/components/ContentProfiles/FieldTab/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {cloneDeep, isEqual} from 'lodash'; +import {cloneDeep, isEqual, set} from 'lodash'; import {IIgnoreCancelSaveResponse} from 'superdesk-api'; import { @@ -44,7 +44,7 @@ export class FieldTab extends React.Component { }; this.openEditor = this.openEditor.bind(this); - this.updateFieldSchema = this.updateFieldSchema.bind(this); + this.updateField = this.updateField.bind(this); this.closeEditor = this.closeEditor.bind(this); this.saveField = this.saveField.bind(this); this.updateFieldOrder = this.updateFieldOrder.bind(this); @@ -62,16 +62,14 @@ export class FieldTab extends React.Component { } } - updateFieldSchema(field: string, value: number | boolean) { - this.setState((prevState: Readonly) => ({ - selectedField: { - ...prevState.selectedField, - schema: { - ...prevState.selectedField.schema, - [field]: value, - }, - }, - })); + updateField(field: string, value: number | boolean) { + this.setState((prevState: Readonly) => { + const selectedField = cloneDeep(prevState.selectedField); + + set(selectedField, field, value); + + return {selectedField}; + }); } isEditorDirty() { @@ -272,7 +270,7 @@ export class FieldTab extends React.Component { systemRequired={systemRequiredFields.includes(this.state.selectedField.name)} closeEditor={this.closeEditor} saveField={this.saveField} - updateFieldSchema={this.updateFieldSchema} + updateField={this.updateField} /> )} diff --git a/client/components/Events/EventEditor/index.tsx b/client/components/Events/EventEditor/index.tsx index 27dbbfcf9..37b8d9aa2 100644 --- a/client/components/Events/EventEditor/index.tsx +++ b/client/components/Events/EventEditor/index.tsx @@ -178,7 +178,7 @@ class EventEditorComponent extends React.PureComponent { }, dates: { required: true, - showAllDay: true, + showAllDay: this.props.formProfile.editor.dates.all_day.enabled, showTimeZone: true, enabled: !this.props.itemExists, onChange: this.onDatesChanged, diff --git a/client/components/fields/resources/profiles.ts b/client/components/fields/resources/profiles.ts index 7ec5e7efc..458396c08 100644 --- a/client/components/fields/resources/profiles.ts +++ b/client/components/fields/resources/profiles.ts @@ -90,3 +90,25 @@ registerEditorField( null, true ); + +registerEditorField( + 'field.all_day.enabled', + EditorFieldToggle, + () => ({ + label: superdeskApi.localization.gettext('All Day Toggle'), + field: 'field.all_day.enabled', + }), + null, + true, +); + +registerEditorField( + 'field.default_duration_on_change', + EditorFieldNumber, + () => ({ + label: superdeskApi.localization.gettext('Default Duration'), + field: 'field.default_duration_on_change', + }), + null, + true +);