-
Notifications
You must be signed in to change notification settings - Fork 36
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
Fix qa reported bugs #2216
base: feature/embedded-events-editor
Are you sure you want to change the base?
Fix qa reported bugs #2216
Changes from 7 commits
ee4936c
4dcbcd0
90ecfc1
5567fc6
82507db
ae7b4d2
079576e
58a869d
7ffcdd0
c4db72a
4a19db0
e66c967
34b6078
eb34e7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ import { | |
IEditorAPI, | ||
IEditorProps, | ||
IEditorState, | ||
IEventOrPlanningItem | ||
IEventOrPlanningItem, | ||
IPlanningRelatedEventLink | ||
} from '../../../interfaces'; | ||
import {planningApi} from '../../../superdeskApi'; | ||
import {ITEM_TYPE, POST_STATE, UI, WORKFLOW_STATE, WORKSPACE, EVENTS} from '../../../constants'; | ||
|
@@ -32,6 +33,8 @@ import { | |
handleEmbeddedItems, | ||
IEmbeddedPlanningsActionType, | ||
} from '../../../components/editor-standalone/save-handling'; | ||
import eventsApi from '../../../actions/events/api'; | ||
import {initialValues} from 'selectors/forms'; | ||
tomaskikutis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export class ItemManager { | ||
editor: EditorComponent; | ||
|
@@ -661,12 +664,18 @@ export class ItemManager { | |
}); | ||
} | ||
|
||
const promise: Promise<any> = handleEmbeddedItems(this.props.editorType, 'SAVE', this.props.itemType) | ||
.then(() => | ||
!updateStates ? Promise.resolve({}) : this.setState({submitting: true, submitFailed: false}), | ||
/** | ||
* Calls internal save of each embedded item - the one of the storage adapter, then returns the saved items. | ||
*/ | ||
const promise = handleEmbeddedItems(this.props.editorType, 'SAVE', this.props.itemType) | ||
.then((res) => | ||
Promise.all([ | ||
tomaskikutis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res, | ||
!updateStates ? {} : this.setState({submitting: true, submitFailed: false}) | ||
]) | ||
); | ||
|
||
return promise.then(() => { | ||
return promise.then(([embeddedItems]) => { | ||
if (this.props.addNewsItemToPlanning) { | ||
return this._saveFromAuthoring({post, unpost}); | ||
} | ||
|
@@ -693,14 +702,23 @@ export class ItemManager { | |
updates.update_method = updateMethod; | ||
|
||
if (Object.keys(planningUpdateMethods).length > 0) { | ||
updates.associated_plannings?.forEach((planningItem) => { | ||
if (planningUpdateMethods[planningItem._id] != null) { | ||
planningItem.update_method = planningUpdateMethods[planningItem._id]; | ||
} | ||
}); | ||
updates.associated_plannings?.forEach((planningItem) => { | ||
if (planningUpdateMethods[planningItem._id] != null) { | ||
planningItem.update_method = planningUpdateMethods[planningItem._id]; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
if (updates.type === 'planning' && (updates.related_events ?? []).length > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you doing here that wasn't working with the previous version of code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm updating |
||
const updatedLinks = eventUtils.addRelatedEvents( | ||
updates.related_events.filter((x) => !isTemporaryId(x._id)) as Array<IPlanningRelatedEventLink>, | ||
embeddedItems as Array<IEventItem>, | ||
); | ||
|
||
updates.related_events = updatedLinks.next; | ||
} | ||
|
||
return this.autoSave.flushAutosave() | ||
.then(() => ( | ||
this.dispatch<any>(actions.main.save( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {IAuthoringFieldV2, ICommonFieldConfig} from 'superdesk-api'; | ||
import {superdeskApi} from '../../../superdeskApi'; | ||
import moment from 'moment'; | ||
|
||
export const getAllDayDatesField = () => { | ||
return { | ||
fieldId: 'dates', | ||
getField: ({required, id}) => { | ||
const fieldConfig: ICommonFieldConfig = { | ||
required: required, | ||
}; | ||
|
||
const field: IAuthoringFieldV2 = { | ||
id: id, | ||
name: superdeskApi.localization.gettext('All Day'), | ||
fieldType: 'boolean', | ||
fieldConfig: fieldConfig, | ||
}; | ||
|
||
return field; | ||
}, | ||
storageAdapterEvent: { | ||
storeValue: (item: IEventItem, operationalValue: boolean | undefined) => { | ||
const dates = item.dates ?? {}; | ||
let newStart, newEnd; | ||
|
||
newStart = moment((dates.start ?? (dates.tz ? moment.tz(dates.tz) : moment()))) | ||
.startOf('day'); | ||
|
||
// If allDay is enabled, then set the event to all day | ||
if (operationalValue) { | ||
newEnd = moment(dates.end ?? (dates.tz ? moment.tz(dates.tz) : moment())) | ||
.endOf('day'); | ||
} else { | ||
// If allDay is disabled, then set the new dates to | ||
// the initial values since last save and time to empty | ||
newEnd = moment(dates?.end ?? newStart) | ||
.hour(0) | ||
.minute(1); | ||
} | ||
|
||
// TODO: Figure out support for _startTime _endTime, _time_to_be_confirmed fields | ||
tomaskikutis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
...item, | ||
dates: { | ||
...item.dates, | ||
start: newStart, | ||
end: newEnd, | ||
all_day: operationalValue, | ||
} | ||
}; | ||
}, | ||
retrieveStoredValue: (item: IEventItem) => item.dates.all_day, | ||
} | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {IAuthoringFieldV2, IDropdownConfigManualSource} from 'superdesk-api'; | ||
import {planningApi, superdeskApi} from '../../../superdeskApi'; | ||
import {getVocabularyItemFieldTranslated} from '../../../utils/vocabularies'; | ||
import {calendars} from '../../../selectors/events'; | ||
|
||
export const getCalendarsField = () => { | ||
const vocabularyFromStore = calendars(planningApi.redux.store.getState()); | ||
|
||
return { | ||
fieldId: 'calendars', | ||
getField: ({required, id}) => { | ||
const options = vocabularyFromStore.map( | ||
(option) => ({ | ||
id: option.qcode, | ||
label: getVocabularyItemFieldTranslated( | ||
option, | ||
'label', | ||
'en', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. language shouldn't be hardcoded |
||
'name' | ||
tomaskikutis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
}) | ||
); | ||
|
||
const fieldConfig: IDropdownConfigManualSource = { | ||
source: 'manual-entry', | ||
options: options, | ||
type: 'text', | ||
roundCorners: false, | ||
multiple: true, | ||
required: required, | ||
}; | ||
|
||
const field: IAuthoringFieldV2 = { | ||
id: id, | ||
name: superdeskApi.localization.gettext('Calendars'), | ||
fieldType: 'dropdown', | ||
fieldConfig: fieldConfig, | ||
}; | ||
|
||
return field; | ||
}, | ||
storageAdapterEvent: { | ||
storeValue: (item, operationalValue: Array<string>) => { | ||
return { | ||
...item, | ||
calendars: vocabularyFromStore.filter((x) => operationalValue.includes(x.qcode)), | ||
}; | ||
}, | ||
retrieveStoredValue: (item) => item.calendars.map((x) => x.qcode), | ||
} | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after superdesk/superdesk-client-core#4762 you can revert this line to how it was