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

Adding related items to plannings and events #2110

Open
wants to merge 16 commits into
base: feature/multiple-events-in-planning
Choose a base branch
from

Conversation

tomaskikutis
Copy link
Member

@tomaskikutis tomaskikutis commented Oct 10, 2024

STT-67
STT-8

Front-end checklist

  • This pull request is adding missing TypeScript types to modified code segments where it's easy to do so with confidence
  • This pull request is using TypeScript interfaces instead of prop-types and updates usages where it's quick to do so
  • This pull request is using memo or PureComponent to define new React components (and updates existing usages in modified code segments)
  • This pull request is replacing lodash.get with optional chaining and nullish coalescing for modified code segments
  • This pull request is not importing anything from client-core directly (use superdeskApi)
  • This pull request is importing UI components from superdesk-ui-framework and superdeskApi when possible instead of using ones defined in this repository.
  • This pull request is not using planningApi where it is possible to use superdeskApi
  • This pull request is not adding redux based modals
  • In this pull request, properties of redux state are not being passed as props to components; instead, we connect it to the component that needs them. Except components where using a react key is required - do not connect those due to performance reasons.
  • This pull request is not adding redux actions that do not modify state (e.g. only calling angular services; those should be moved to planningApi)

@tomaskikutis
Copy link
Member Author

@MarkLark86 If an existing planning item gets drag and dropped as related to an event, I'm adding it using the secondary link. Should it be possible to add coverages to planning items linked using the secondary link type?

Copy link
Collaborator

@MarkLark86 MarkLark86 left a comment

Choose a reason for hiding this comment

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

Looks good, mostly just suggestion about implementing logic around the link config in the front-end

@@ -547,6 +549,58 @@ const uploadFiles = (event) => (
}
);

function getLinkedPlanningItems(eventId: string): Promise<IRestApiResponse<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 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)

Copy link
Collaborator

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 of IRestApiResponse<IPlanningItem>? The function name states get me the list of Planning items, or do you see the need for attributes under the IRestApiResponse as well?

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 !== true?

<Spacer h gap="4">
{
showEditButton && (
<button
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could it be possible to use a button from the UI-Framework instead?

...this.getCurrentValue(),
{
_id: id,
link_type: 'secondary',
Copy link
Collaborator

Choose a reason for hiding this comment

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

The link_type here could be different values, depending on the instance config.

We have a PLANNING_EVENT_LINK_METHOD config available in settings.py. This can be exposed to front-end by adding something like the following in planning/init.py

app.client_config["planning"]["event_link_method"] = get_planning_event_link_method()

And adding event_link_method to IPlanningConfig and in client/config.ts.

Then based on that config value:

one_primary

  • Only 1 Event can be linked, therefor if an Event is already linked this action should not be available, and an error thrown here
  • Otherwise the link_type would be primary

many_secondary

  • link_type is always secondary

one_primary_many_secondary

  • link_type is primary if there are no Event's currently linked
  • link_type is secondary otherwise

* Will return true if there is at least one event that can be added
*/
export function canAddSomeEventsAsRelatedToPlanningEditor(eventIds: Array<IEventItem['_id']>): boolean {
const editor = planningApi.editor(EDITOR_TYPE.INLINE);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is where we would use that event_link_method config to add additional clause if this action should be available (i.e. config is one_primary and currentRelatedEvents is not empty, then return false)

.filter((eventId) => isEventAlreadyAddedAsRelated(eventId) !== true)
.map((eventId): IPlanningRelatedEventLink => ({
_id: eventId,
link_type: 'secondary',
Copy link
Collaborator

Choose a reason for hiding this comment

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

And same here, link_type would depend on the config and currently linked Events (if any)

@MarkLark86
Copy link
Collaborator

@MarkLark86 If an existing planning item gets drag and dropped as related to an event, I'm adding it using the secondary link. Should it be possible to add coverages to planning items linked using the secondary link type?

I might need a little more context here, as I'm not sure I understand the scenario entirely. When adding a Coverage to a Planning item, there is no logic involved around any linked Events that alllows or denies adding these Coverages. Am I missing something here, could you maybe explain more please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants