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

TimelineContext fixes #1159

Merged
merged 4 commits into from
May 21, 2024
Merged

Conversation

JGreenlee
Copy link
Collaborator

@JGreenlee JGreenlee commented May 21, 2024

fix address names not loading

'timelineMap' is a Map object, not just a plain { } object. So instead of Object.values() we should use Map.values() - which returns an iterator - but we want to reverse it.
So we have to convert to array, then reverse, and then call forEach to fillLocationNamesOfTrip.

Also, we should ensure that only trips, not places, get passed to fillLocationNamesOfTrip
(since places always have the same locations as the trips surrounding them, the place cards will automatically get their location names filled in)


update TimelineScrollList only when the active tab is 'label'

Leaflet map encounters an error when prerendered, so we need to render the TimelineScrollList component when the active tab is 'label'
'shouldUpdateTimeline' state is used to determine whether to render the TimelineScrollList or not


fix LabelTab filtering

The existing implementation used pub/sub events to trigger when filtering should happen. The events were triggered from TimelineContext.
However, this doesn't listen / wait for filterInputs to be defined because filterInputs is inside LabelTab, not TimelineContext. Filtering wasn't working because filterInputs was still empty when the initial filtering occured and LabelTab had no control over when the event was triggered.

A better solution is to listen for changes inside LabelTab. Every time the filters, the loaded trips, or the labels change, filtering occurs. If a trip had a user input in the last 30s, we skip it; but schedule a re-filter when its "immunity" expires.

Now LabelTab is responsible for all the filtering. TimelineContext doesn't have to worry about what LabelTab (its child) does. This is a cleaner, "React-recommended" unidirectional pattern

JGreenlee and others added 3 commits May 21, 2024 12:02
'timelineMap' is a Map object, not just a plain { } object. So instead of Object.values() we should use Map.values() - which returns an iterator - but we want to reverse it.
So we have to convert to array, then reverse, and then call forEach to fillLocationNamesOfTrip.

Also, we should ensure that only trips, not places, get passed to fillLocationNamesOfTrip
(since places always have the same locations as the trips surrounding them, the place cards will automatically get their location names filled in)
Leaflet map encounters an error when prerendered, so we need to render the TimelineScrollList component when the active tab is 'label'
'shouldUpdateTimeline' state is used to determine whether to render the TimelineScrollList or not
The existing implementation used pub/sub events to trigger when filtering should happen. The events were triggered from TimelineContext.
However, this doesn't listen / wait for filterInputs to be defined because filterInputs is inside LabelTab, not TimelineContext. Filtering wasn't working because filterInputs was still empty when the initial filtering occured and LabelTab had no control over when the event was triggered.

A better solution is to listen for changes inside LabelTab. Every time the filters, the loaded trips, or the labels change, filtering occurs. If a trip had a user input in the last 30s, we skip it; but schedule a re-filter when its "immunity" expires.

Now LabelTab is responsible for all the filtering. TimelineContext doesn't have to worry about what LabelTab (its child) does. This is a cleaner, "React-recommended" unidirectional pattern
@JGreenlee
Copy link
Collaborator Author

Observed in testing

  • Addresses loading correctly (from the bottom / most recent up). Also tested on stage-timeuse with places.

  • When picking date range from the Dashboard, then switching back to LabelTab, the maps fill in rather than staying blank

  • When loading trips with existing labels, "To Label" filter is applied. When switching back and forth between "To Label" and "All Trip", filters get re-applied. When a trip is labeled with both mode and purpose, the trip disappears from "To Label" 30 seconds after its most recent label

@JGreenlee JGreenlee marked this pull request as ready for review May 21, 2024 18:02
The 'showsIf' conditions in dfc-fermata currently reference 'confirmedMode'. We want to rename this to 'primary_ble_sensed_mode'.

Also see JGreenlee/e-mission-common@0396339
useEffect(() => {
const { setShouldUpdateTimeline } = timelineContext;
// update TimelineScrollList component only when the active tab is 'label' to fix leaflet map issue
setShouldUpdateTimeline(!index);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine with this for now, but it relies on the fact that the "label" tab is first. That seems fairly fragile - what if we reorder the tabs later? What if we start with the dashboard as the default? Isn't there a way to check the tab/route label instead?

@@ -50,6 +50,8 @@ type ContextProps = {
loadMoreDays: (when: 'past' | 'future', nDays: number) => void;
loadSpecificWeek: (d: string) => void;
refreshTimeline: () => void;
shouldUpdateTimeline: Boolean;
setShouldUpdateTimeline: React.Dispatch<React.SetStateAction<boolean>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding/edification: Why is only this wrapped in React.Dispatch when (say) setDateRange is not?

Comment on lines -138 to -141
publish('applyLabelTabFilters', {
timelineMap,
timelineLabelMap: newTimelineLabelMap,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that moving this into the LabelTab allows us to keep the presentation logic largely in the label which is the right thing to do.

@shankari
Copy link
Contributor

@JGreenlee one test is failing

Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 3.33333% with 29 lines in your changes are missing coverage. Please review.

Project coverage is 28.92%. Comparing base (de7ff39) to head (39d463c).
Report is 43 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1159      +/-   ##
==========================================
+ Coverage   26.57%   28.92%   +2.35%     
==========================================
  Files         114      115       +1     
  Lines        4993     5064      +71     
  Branches     1033     1094      +61     
==========================================
+ Hits         1327     1465     +138     
+ Misses       3666     3597      -69     
- Partials        0        2       +2     
Flag Coverage Δ
unit 28.92% <3.33%> (+2.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
www/js/TimelineContext.ts 50.30% <100.00%> (ø)
www/js/diary/useDerivedProperties.tsx 0.00% <ø> (ø)
www/js/diary/addressNamesHelper.ts 0.00% <0.00%> (ø)
www/js/diary/list/LabelListScreen.tsx 0.00% <0.00%> (ø)
www/js/Main.tsx 0.00% <0.00%> (ø)
www/js/diary/LabelTab.tsx 0.00% <0.00%> (ø)

... and 5 files with indirect coverage changes

@shankari
Copy link
Contributor

@JGreenlee it looked like that was a timing issue (you may want to look at the prior run to see what was going on).
It would also be helpful to add tests for the new functionality as part of the cleanup this week (if you have time).

@shankari shankari merged commit 34238f6 into e-mission:master May 21, 2024
7 of 8 checks passed
@JGreenlee
Copy link
Collaborator Author

I don't see a run where any of the Jest tests failed. All I see is codecov failing because of the token

@shankari
Copy link
Contributor

shankari commented May 21, 2024

Maybe I don't fully understand what where we were supposed to be with the TimelineContext, but I thought from the code, that we would be passing in entries from the timeline to the metrics in the dashboard. However, even with the changes, I still see that recently labeled trips are not reflected in the dashboard

Labeled trips from yesterday Not showing up in the dashboard In the most recent version
simulator_screenshot_34D1F1B0-AA59-4828-A0F1-BE50BDF3ADB6 simulator_screenshot_A549FFA0-C5D8-4C2E-B6F1-D3A58FD602B9 simulator_screenshot_5CA32EAE-07E0-4C4E-B895-5A7ADB387E6C

@shankari
Copy link
Contributor

I don't see any obvious errors, though, so pushing out a release to staging anyway

@shankari
Copy link
Contributor

I don't see a run where any of the Jest tests failed. All I see is codecov failing because of the token

It was the second attempt of the run that finally succeeded
https://github.com/e-mission/e-mission-phone/actions/runs/9179292350/attempts/2

@shankari
Copy link
Contributor

shankari commented May 22, 2024

Update: After restarting the app, the dashboard was updated (but active minutes appears to be blank)

Before update Update After update After refresh (using button at top right)
simulator_screenshot_04D09B28-F4E7-4343-9966-F75E416FAA5C simulator_screenshot_B68E1EA8-22D4-4EAA-B6B6-5D993B969701 simulator_screenshot_44A9B67A-E0D2-41DA-A050-6DFF218DA89E simulator_screenshot_CF6AAC19-4696-45FD-839D-F1440EE11A37

@shankari
Copy link
Contributor

And even after refreshing, the charts seem to be inconsistent with the text in the tables.

No unlabeled trips for the past week Error in the dashboard
simulator_screenshot_F2193258-3948-43AE-83D3-8D18B5393972 simulator_screenshot_C7409145-0380-4742-A579-21B8C449E838
On restart, very little uncertainty Significant unlabeled distance on the 14th (although no unlabeled trips Total unlabeled distance is around that amount, but is it all on the 14th? and what what happened to the 5k in air
simulator_screenshot_B83594E1-99E1-4E7C-A204-1BB26059F1FE simulator_screenshot_6E0E7456-8153-421A-B25C-55AC76C642D5 simulator_screenshot_50E37679-26EB-47E1-A434-AD0A67439116

@shankari
Copy link
Contributor

@JGreenlee and @jiji14 for visibility

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

Successfully merging this pull request may close these issues.

3 participants