-
Notifications
You must be signed in to change notification settings - Fork 35
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
Adding related items to plannings and events #2110
Open
tomaskikutis
wants to merge
16
commits into
superdesk:feature/multiple-events-in-planning
Choose a base branch
from
tomaskikutis:adding-related-items-to-plannings-and-events
base: feature/multiple-events-in-planning
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2047486
drag event for events and planning items
tomaskikutis 8f354df
drag and drop planning items to "related plannings" field of an event
tomaskikutis 1a0027f
drag and drop related events to planning items
tomaskikutis 4d5990a
show a message if item is already added
tomaskikutis 04058cf
improve code to use onChange
tomaskikutis bde8dad
make focusing an item after scrolling into view optional
tomaskikutis aaa15a1
expose getting item action
tomaskikutis e0d6f3a
allow adding related events to open planning item from list view 3-do…
tomaskikutis df84ef4
add events as related from bulk actions
tomaskikutis 6d1ab95
add an option to disable focusing after adding a planning item to the…
tomaskikutis 73c033c
add related planning items to event editor
tomaskikutis 82134d1
Merge remote-tracking branch 'upstream/feature/multiple-events-in-pla…
tomaskikutis 2413349
fix unit tests
tomaskikutis 0c42e67
fix accidental passing of event as an argument to addPlanningItem
tomaskikutis ba21a50
only auto-expand coverages for newly created items
tomaskikutis 8a19811
revert test config
tomaskikutis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {get, isEqual, cloneDeep, pickBy, has, find, every, take} from 'lodash'; | ||
import {get, cloneDeep, has, find, every, take} from 'lodash'; | ||
|
||
import {planningApi} from '../../superdeskApi'; | ||
import {ISearchSpikeState, IEventSearchParams, IEventItem, IPlanningItem, IEventTemplate} from '../../interfaces'; | ||
|
@@ -19,14 +19,16 @@ import { | |
isPublishedItemId, | ||
isTemporaryId, | ||
gettext, | ||
getTimeZoneOffset, | ||
} from '../../utils'; | ||
|
||
import planningApis from '../planning/api'; | ||
import eventsUi from './ui'; | ||
import main from '../main'; | ||
import {eventParamsToSearchParams} from '../../utils/search'; | ||
import {getRelatedEventIdsForPlanning} from '../../utils/planning'; | ||
import {planning, searchPlanning} from '../../api/planning'; | ||
import {IRestApiResponse} from 'superdesk-api'; | ||
import * as actions from '../../actions'; | ||
|
||
/** | ||
* Action dispatcher to load a series of recurring events into the local store. | ||
|
@@ -547,6 +549,58 @@ const uploadFiles = (event) => ( | |
} | ||
); | ||
|
||
function getLinkedPlanningItems(eventId: string): Promise<IRestApiResponse<IPlanningItem>> { | ||
return searchPlanning({only_future: false, event_item: [eventId]}); | ||
} | ||
|
||
function updateLinkedPlanningsForEvent( | ||
eventId: IEventItem['_id'], | ||
|
||
/** | ||
* these must be final values | ||
* missing items will be linked, extra items unlinked | ||
*/ | ||
planningIds: Array<IPlanningItem['_id']>, | ||
):Promise<void> { | ||
return getLinkedPlanningItems(eventId).then((res) => { | ||
// note: planning items to which `eventId` is linked | ||
const currentlyLinked: Array<IPlanningItem> = res._items; | ||
|
||
const currentLinkedIds = new Set(currentlyLinked.map((item) => item._id)); | ||
const toLink: Array<IPlanningItem['_id']> = planningIds.filter((id) => currentLinkedIds.has(id) !== true); | ||
const toUnlink = currentlyLinked.filter((planningItem) => planningIds.includes(planningItem._id) !== true); | ||
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. Set.has and Array.includes already return a boolean value, what is the use case for explicitly checking for |
||
|
||
return Promise.all( | ||
[ | ||
...toLink.map((planningId) => { | ||
return planning.getById(planningId).then((planningItem) => { | ||
const patch: Partial<IPlanningItem> = { | ||
related_events: [ | ||
...(planningItem.related_events ?? []), | ||
{_id: eventId, link_type: 'secondary'}, | ||
], | ||
}; | ||
|
||
return planning.update(planningItem, patch); | ||
}); | ||
}), | ||
...toUnlink.map((planningItem) => { | ||
const patch: Partial<IPlanningItem> = { | ||
related_events: (planningItem.related_events ?? []) | ||
.filter((item) => item._id !== eventId), | ||
}; | ||
|
||
return planning.update(planningItem, patch); | ||
}), | ||
], | ||
).then((updatedPlanningItems) => { | ||
planningApi.redux.store.dispatch<any>(actions.planning.api.receivePlannings(updatedPlanningItems)); | ||
|
||
return null; | ||
}); | ||
}); | ||
} | ||
|
||
const save = (original, updates) => ( | ||
(dispatch) => { | ||
let promise; | ||
|
@@ -574,9 +628,21 @@ const save = (original, updates) => ( | |
EVENTS.UPDATE_METHODS[0].value : | ||
eventUpdates.update_method?.value ?? eventUpdates.update_method; | ||
|
||
return originalEvent?._id != null ? | ||
const createOrUpdatePromise = originalEvent?._id != null ? | ||
planningApi.events.update(originalItem, eventUpdates) : | ||
planningApi.events.create(eventUpdates); | ||
|
||
return createOrUpdatePromise.then((updatedEvents) => { | ||
if (updates.associated_plannings == null) { | ||
return Promise.resolve(); | ||
} | ||
|
||
const nextAssociatedPlanningIds = updates.associated_plannings.map(({_id}) => _id); | ||
|
||
return Promise.all( | ||
updatedEvents.map((event) => updateLinkedPlanningsForEvent(event._id, nextAssociatedPlanningIds)), | ||
).then(() => updatedEvents); | ||
}); | ||
}); | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm thinking this function might be useful in other places, so it would be good to have this available under
IPlanningAPI.events.getLinkedPlanningItems
(to be implemented in client/api/events.ts)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.
Would it be good to just return
Array<IPlanningItem>
instead ofIRestApiResponse<IPlanningItem>
? The function name statesget me the list of Planning items
, or do you see the need for attributes under theIRestApiResponse
as well?