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

Show in embedded editor field config option #2165

Open
wants to merge 6 commits into
base: authoring-react-planning
Choose a base branch
from
Open
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
37 changes: 22 additions & 15 deletions client/components/ContentProfiles/FieldTab/FieldEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export class FieldEditor extends React.Component<IProps, IState> {
multilingual.isEnabled(this.props.profile);

const fieldProps = {
'schema.show_in_embedded_editor': {
/**
* Coverage fields don't need this field config option, only planning and event
*/
enabled: !this.props.systemRequired && this.props.profile._id !== 'coverage',
},
'schema.required': {enabled: !(this.props.disableRequired || this.props.systemRequired)},
'schema.read_only': {enabled: this.props.item.name === 'related_plannings'},
'schema.planning_auto_publish': {enabled: this.props.item.name === 'related_plannings'},
Expand Down Expand Up @@ -178,21 +184,22 @@ export class FieldEditor extends React.Component<IProps, IState> {
'editor',
{
'schema.required': {enabled: true, index: 1},
'schema.read_only': {enabled: true, index: 2},
'schema.field_type': {enabled: true, index: 3},
'schema.expandable': {enabled: true, index: 4},
'schema.minlength': {enabled: true, index: 5},
'schema.maxlength': {enabled: true, index: 6},
'schema.format_options': {enabled: true, index: 7},
'schema.vocabularies': {enabled: true, index: 8},
'field.all_day.enabled': {enabled: true, index: 9},
'field.default_duration_on_change': {enabled: true, index: 10},
'schema.multilingual': {enabled: true, index: 11},
'schema.languages': {enabled: true, index: 12},
'schema.default_language': {enabled: true, index: 13},
'schema.planning_auto_publish': {enabled: true, index: 14},
'schema.cancel_plan_with_event': {enabled: true, index: 14},
'schema.default_value': {enabled: true, index: 11},
'schema.show_in_embedded_editor': {enabled: true, index: 2},
'schema.read_only': {enabled: true, index: 3},
'schema.field_type': {enabled: true, index: 4},
'schema.expandable': {enabled: true, index: 5},
'schema.minlength': {enabled: true, index: 6},
'schema.maxlength': {enabled: true, index: 7},
'schema.format_options': {enabled: true, index: 8},
'schema.vocabularies': {enabled: true, index: 9},
'field.all_day.enabled': {enabled: true, index: 10},
'field.default_duration_on_change': {enabled: true, index: 11},
'schema.multilingual': {enabled: true, index: 12},
'schema.languages': {enabled: true, index: 13},
'schema.default_language': {enabled: true, index: 14},
'schema.planning_auto_publish': {enabled: true, index: 15},
'schema.cancel_plan_with_event': {enabled: true, index: 16},
'schema.default_value': {enabled: true, index: 17},
},
{
item: this.props.item,
Expand Down
10 changes: 9 additions & 1 deletion client/components/ContentProfiles/FieldTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,15 @@ export class FieldTab extends React.Component<IProps, IState> {
{this.state.selectedField == null ? null : (
<FieldEditor
key={this.state.selectedField?.name}
item={this.state.selectedField}
item={(() => {
const profileRes = cloneDeep(this.state.selectedField);

if (profileRes.schema?.required === true) {
profileRes.schema.show_in_embedded_editor = true;
}

return profileRes;
})()}
profile={this.props.profile}
isDirty={this.isEditorDirty()}
disableMinMax={this.props.disableMinMaxFields?.includes(this.state.selectedField.name)}
Expand Down
4 changes: 4 additions & 0 deletions client/components/fields/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ import {EditorFieldScheduledUpdates} from './ScheduledUpdates';
import {EditorFieldCustomVocabularies} from './CustomVocabularies';
import {EditorFieldAssignedCoverageComponent} from './AssignedCoverage';

/**
* This is the single source of truth for field definitions, allows for registering
* other fields from a different place through `registerEditorField`
*/
export const FIELD_TO_EDITOR_COMPONENT = {
anpa_category: EditorFieldCategories,
featured: EditorFieldFeatured,
Expand Down
12 changes: 12 additions & 0 deletions client/components/fields/resources/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ registerEditorField(
true
);

registerEditorField(
'schema.show_in_embedded_editor',
EditorFieldCheckbox,
(props) => ({
label: superdeskApi.localization.gettext('Show in embedded form'),
field: 'schema.show_in_embedded_editor',
disabled: props.item.schema.required,
}),
null,
true
);

registerEditorField(
'schema.read_only',
EditorFieldCheckbox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const getPlanningProfileFields = (): Array<IFieldConverted> => {
for (const fieldId of planningFieldIds) {
const fieldSchema = planningProfile.schema[fieldId];

/**
* If a field does not have show_in_embedded_editor or required toggled on
* we must not show it in the embedded editor
*/
if (!(fieldSchema.show_in_embedded_editor || fieldSchema.required)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll eventually use getPlanningProfileFields for non-embedded editors too. Add a argument which would tell if you want to get fields for embedded editor or not.

continue;
}

if (fieldSchema?.type === 'list' && ((fieldSchema.vocabularies ?? []).length > 0)) {
for (const vocabId of fieldSchema.vocabularies) {
convertedFieldIds.push({
Expand Down
1 change: 1 addition & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ interface IProfileEditorDatesField extends IProfileEditorField {
interface IBaseProfileSchemaType<T> {
type: T;
required: boolean;
show_in_embedded_editor?: boolean;
validate_on_post?: boolean;
minlength?: number;
maxlength?: number;
Expand Down
Loading