-
Notifications
You must be signed in to change notification settings - Fork 305
chore(ui): Unify the logic for timeline item insertions #4331
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
chore(ui): Unify the logic for timeline item insertions #4331
Conversation
780fae9
to
6814b6d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4331 +/- ##
=======================================
Coverage 85.05% 85.06%
=======================================
Files 275 275
Lines 30309 30316 +7
=======================================
+ Hits 25780 25788 +8
+ Misses 4529 4528 -1 ☔ View full report in Codecov by Sentry. |
|
||
// Insert the next item after the latest event item that's not a | ||
// pending local echo, or at the start if there is no such item. | ||
let insert_idx = latest_event_idx.map_or(0, |idx| idx + 1); | ||
let (insert_index, must_push_front) = match position { |
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.
(spoiler alert: we don't need must_push_front
, since inserting at insert_idx = 0
means pushing front…)
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.
(spoiler alert: turns out, we need it :-D)
Imagine we have insert_index = 0
. Should we push front or back? Front!, according to you. But it's gonna break many tests that assume that the first added event, even with position = End
, must be pushed back. So by only looking at insert_index
, in the case it's zero, we don't know whether we have to push it front or back. Hence the must_push_front
that adds a clue.
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.
Alternatively, we can insert inside the match position
. A bit more repetitive code, but it's much much clearer. Let me try that in the last commit.
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 still think what I suggested would work, if you both kept only the insert_idx
and reverted the order of the final push statements as it were back in the original form:
- in the case of inserting at the front, insert_idx would be 0, and when the list is empty that would result in a push_back; when it's not, it would be a push front
- in the case of inserting at the back, we compute the proper insert_idx anyways.
And I mean, it's OK to change the test expectations when they lead to the same outcome ^^ push_back
or push_front
on an empty array yields to the same outcome. But OK, the new code works too.
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.
The commit message looks a bit rough grammar-wise as well, perhaps something like:
chore(ui): Unify the logic for timeline item insertions
This patch unifies the logic for inserting timeline items at Start and End positions. Both TimelineItemPositions can share the same implementation, making separate logic unnecessary. Previously, End included a duplicated events check as well, while Start did not, leading to inconsistency.
The changes strictly involve moving and refactoring, with no functional modifications.
p => unreachable!( | ||
"An unexpected `TimelineItemPosition` has been received: {p:?}" | ||
), |
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.
Err not that happy that this patch is adding an unreachable
call, which we previously avoided. But ok.
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.
Yeah… it's unfortunate this is needed, but the upper match-arm makes this really unreachable. A larger refactoring would be needed to tackle that I think.
This patch unifies the logic for inserting timeline items at `Start` and `End` positions. Both `TimelineItemPositions` can share the same implementation, making separate logic unnecessary. Previously, `End` included a duplicated events check as well, while `Start` did not, leading to inconsistency. The changes strictly involve moving and refactoring, with no functional modifications.
607d488
to
979b6b0
Compare
Poljar did approve it, and all feedback from Ben have been addressed
(Extracted from #3512)
This patch tries to unify the code to insert timeline item at position
Start
andEnd
. We can clearly have the same code for theseTimelineItemPosition
s. It doesn't make sense to have separate implementations, especially knowing thatEnd
had duplicated events check whileStart
had not.This code only and strictly code moving, modulo the
position
handling, but nothing has changed apart from that.Note: this is going to be useful when (i) event deduplication will be removed, and (ii) when
TimelineItemPosition::At
will be added!EventCache
storage #3280