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

copy language and translation when creating a planning from event and vice versa #1826

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
106 changes: 58 additions & 48 deletions client/actions/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,54 +248,64 @@ const createPlanningFromEvent = (
event: IEventItem,
planningDate: Moment = null,
agendas: Array<string> = []
) => (
(dispatch) => (
dispatch(planning.api.save({}, {
event_item: event._id,
slugline: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'slugline',
'slugline',
event.slugline
),
planning_date: planningDate || event._sortDate || event.dates.start,
internal_note: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'internal_note',
'internal_note',
event.internal_note
),
name: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'name',
'name',
event.name
),
place: event.place,
subject: event.subject,
anpa_category: event.anpa_category,
description_text: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'definition_short',
'description_text',
event.definition_short
),
ednote: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'ednote',
'ednote',
event.ednote
),
agendas: agendas,
language: event.language,
}))
)
);
) => {
const newPlanningItem: Partial<IPlanningItem> = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we should extract this out into a util function, and used both here and https://github.com/superdesk/superdesk-planning/blob/develop/client/api/editor/item_events.ts#L83, so we're only defining this conversion once

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but it seems it's being done in a different way in createPlanningFromEvent and addPlanningItem. Is it possible to drop one and use the remaining one in both places?

event_item: event._id,
slugline: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'slugline',
'slugline',
event.slugline
),
planning_date: planningDate || event._sortDate || event.dates.start,
internal_note: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'internal_note',
'internal_note',
event.internal_note
),
name: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'name',
'name',
event.name
),
place: event.place,
subject: event.subject,
anpa_category: event.anpa_category,
description_text: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'definition_short',
'description_text',
event.definition_short
),
ednote: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'ednote',
'ednote',
event.ednote
),
agendas: agendas,
language: event.language,
};

if (event.languages != null) {
newPlanningItem.languages = event.languages;
}

if (event.translations != null) {
newPlanningItem.translations = event.translations;
}

return (dispatch) => (
dispatch(planning.api.save({}, newPlanningItem))
);
};

/**
* Action dispatcher that fetches all planning items for the
Expand Down
8 changes: 8 additions & 0 deletions client/actions/events/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,14 @@ const createEventFromPlanning = (plan: IPlanningItem) => (
language: plan.language,
};

if (plan.languages != null) {
newEvent.languages = plan.languages;
}

if (plan.translations != null) {
newEvent.translations = plan.translations;
}

if (get(eventProfile, 'editor.slugline.enabled', false)) {
newEvent.slugline = stringUtils.convertStringFieldForProfileFieldType(
'planning',
Expand Down
14 changes: 12 additions & 2 deletions client/api/editor/item_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function getEventsInstance(type: EDITOR_TYPE): IEditorAPI['item']['events
const plans = cloneDeep(event.associated_plannings || []);
const id = generateTempId();

plans.push({
const newPlanningItem: DeepPartial<IPlanningItem> = {
_id: id,
type: 'planning',
event_item: event._id,
Expand All @@ -95,7 +95,17 @@ export function getEventsInstance(type: EDITOR_TYPE): IEditorAPI['item']['events
ednote: event.ednote,
agendas: [],
language: event.language,
});
};

if (event.languages != null) {
newPlanningItem.languages = event.languages;
}

if (event.translations != null) {
newPlanningItem.translations = event.translations;
}

plans.push(newPlanningItem);

editor.form.changeField('associated_plannings', plans)
.then(() => {
Expand Down
Loading