-
Notifications
You must be signed in to change notification settings - Fork 14
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: All day event doesn't disappear after changing the week #182
Conversation
This reverts commit ec438d7.
Temporarily closed due to not all tests have passed. I will refactor the tests related to this feature and reopen the PR again when done. |
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 appreciate you coming up with an approach that works (I tested it). However, I do have some concerns
Dependent Code
This code looks to be branched off #181. The same issues I voiced in that PR apply here. Whenever possible, please avoid making one pending PR dependent on another.
The fix is resource-intensive and has a large code footprint
This implements the fix at the style-level
Here's what I mean by "style-level":
An enum was added to the event category (Category.NotAtThisWeek
). This category is used by the getPosition()
util, which is used by the GridEvent
and AllDayEvent
to determine the height/width of the rectangle.
The shortcomings of this include:
- The
NotAtThisWeek
isn't currently used ingetAllDayEventWidth
, so it just falls back to the default value anyway. - It further entrenches us in the concept of a 'week', which will make it harder to refactor once we need to support other view durations (1 day, 4 day, 10 day, etc)
- These position calculations are expensive, so running them only to determine that an event shouldn't be rendered is a waste of the user's compute/memory resources
Suggestion
Instead of fixing the issue at the util/style level, adjust the lifecycle of an event edit. This will let us remove the event automatically, without having to do additional calculations.
Here's how that'd look specifically
Update the submit handler to check whether an event should still be shown based on the latest data
//useDraftUtil.ts
const submit = (draft: Schema_GridEvent) => {
const event = prepEvtBeforeSubmit(draft);
// get this value by comparing the event's dates to
// the weekProps.component.startOfView and [...].endOfView
// (there's already a util that helps with this comparison)
const shouldRemove = true
const _payload = {_id: event._id, event};
const payload = shouldRemove ? {...payload, shouldRemove} : _payload
const isExisting = event._id;
if (isExisting) {
dispatch(
editEventSlice.actions.request(payload)
);
discard();
} else {
dispatch(createEventSlice.actions.request(event));
}
};
Add a step to the editEvent saga that reacts to the new shouldRemove directive
//event.saga.ts
export function* editEvent({ payload }: Action_EditEvent) {
try {
yield put(eventsEntitiesSlice.actions.edit(payload));
yield call(EventApi.edit, payload._id, payload.event, {
applyTo: payload.applyTo,
});
if (payload.shouldRemove) {
// remove the id from the week view Redux store:
// events.getWeekEvents.value.data
}
yield put(editEventSlice.actions.success());
} catch (error) {
yield put(editEventSlice.actions.error());
handleError(error as Error);
}
}
As a result, any all-day event that changed weeks should be removed from the UI immediately after it's removed from the week view Redux slice. This helps us avoid managing that ourselves in util/styling code.
const endOfWeek = dayjs("2022-12-30"); | ||
const end = dayjs("2022-03-20"); | ||
const startOfWeek = dayjs("2022-03-06"); | ||
const endOfWeek = dayjs("2022-03-12"); |
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.
nice catch!
Understood. I'll discard these changes and start over from a new branch then. |
I'm stuck at the "remove the id from the week view Redux store" part. What do you mean by the "week view" store? I found a |
Yes the The ids in that slice are used to find the corresponding entity in the entity slice. Removing an id from that week slice is an important step to getting this to work, as those ids are what the event selectors are using to decide which events are in view and which arent |
This fixes #178
I realised the problem was the fact that it was assumed that an event starting and ending in a different week would be an event that starts in a past week and ends in a future week, wich is not necessarily true. That was making an event that, say, starts and ends in a past week to be rendered as an event that overlaps the current week, which is unitended.
To fix that, I've added a new
Category
toevent.types.ts
, calledNotAtThisWeek
, which is intended for events that starts and ends in a different week, but are notPastToFutureWeek
.I also refactored the tests for
getAllDayEventWidth
to take into consideration the new logic ofpastToFutureWeek
andnotAtThisWeek
. All automated tests have passed.Obs: this branch was created from my main branch, which was already merged with fix/issue#145. That's why you'll see code unrelated to the current fix. I recommend you to approve this PR first.