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

[SDESK-6564] Allow configuring All Day & Default Duration in EventProfile #1709

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions client/components/ContentProfiles/FieldTab/FieldEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IProps {
systemRequired: boolean;
closeEditor(): void;
saveField(): void;
updateFieldSchema(field: string, value: string | number | boolean | Array<string>): void;
updateField(field: string, value: string | number | boolean | Array<string>): void;
}

export class FieldEditor extends React.PureComponent<IProps> {
Expand All @@ -35,7 +35,7 @@ export class FieldEditor extends React.PureComponent<IProps> {
}

onChange(field: string, value: string | number | boolean | Array<string>) {
this.props.updateFieldSchema(field.replace('schema.', ''), value);
this.props.updateField(field, value);
}

render() {
Expand All @@ -53,6 +53,8 @@ export class FieldEditor extends React.PureComponent<IProps> {
'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)
Expand Down Expand Up @@ -130,6 +132,8 @@ export class FieldEditor extends React.PureComponent<IProps> {
'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,
Expand Down
24 changes: 11 additions & 13 deletions client/components/ContentProfiles/FieldTab/index.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -44,7 +44,7 @@ export class FieldTab extends React.Component<IProps, IState> {
};

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);
Expand All @@ -62,16 +62,14 @@ export class FieldTab extends React.Component<IProps, IState> {
}
}

updateFieldSchema(field: string, value: number | boolean) {
this.setState((prevState: Readonly<IState>) => ({
selectedField: {
...prevState.selectedField,
schema: {
...prevState.selectedField.schema,
[field]: value,
},
},
}));
updateField(field: string, value: number | boolean) {
this.setState((prevState: Readonly<IState>) => {
const selectedField = cloneDeep(prevState.selectedField);

set(selectedField, field, value);

return {selectedField};
});
}

isEditorDirty() {
Expand Down Expand Up @@ -272,7 +270,7 @@ export class FieldTab extends React.Component<IProps, IState> {
systemRequired={systemRequiredFields.includes(this.state.selectedField.name)}
closeEditor={this.closeEditor}
saveField={this.saveField}
updateFieldSchema={this.updateFieldSchema}
updateField={this.updateField}
/>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/components/Events/EventEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class EventEditorComponent extends React.PureComponent<IProps> {
},
dates: {
required: true,
showAllDay: true,
showAllDay: this.props.formProfile.editor.dates.all_day.enabled,
showTimeZone: true,
enabled: !this.props.itemExists,
onChange: this.onDatesChanged,
Expand Down
22 changes: 22 additions & 0 deletions client/components/fields/resources/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);