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

refactor: add types for DUP widgets #2115

Merged
merged 7 commits into from
Jul 30, 2024
Merged

refactor: add types for DUP widgets #2115

merged 7 commits into from
Jul 30, 2024

Conversation

digitalcora
Copy link
Contributor

@digitalcora digitalcora commented Jul 29, 2024

This ended up being an exercise in stumbling upon a bunch of little things that could be refactored, so best reviewed per-commit (there are some explanations in the commit messages). The main point here is the final commit!


"Normal" is generally not a useful prefix, and this resolves an
inconsistency where the backend refers to this component as just
`departures`.
This aligns with the convention used in the other Departures components
where the props are exactly the "API" used by the server.
In the only places this prop was used, it was always set to `true`.
This DUP-specific logic was a duplicate of logic already incorporated
into `RoutePill`, with an added bug that it would not correctly display
a route numbered `200` at small size (if the MBTA had such a route).
This adds TypeScript types for most DUP widgets that were missing them.

Includes these related changes:

* DUPs have a unique "overnight" departure time type that displays a
  moon icon in place of a time. The backend serialized this as
  `%{type: :icon, icon: :overnight}`, but the frontend didn't use the
  `icon` field and unconditionally rendered a moon icon. This has been
  changed to just `%{type: :overnight}`.

* DUP departure times mistakenly looked at the `type` field of the
  predicted time to determine how to show the scheduled time, rather
  than the scheduled time's own `type`. This worked anyway, because
  scheduled times are currently only produced when the type of both
  times is the same (`timestamp` specifically), but the type checker
  caught this as potentially broken.
Copy link

Coverage of commit 1124c47

Summary coverage rate:
  lines......: 45.1% (2956 of 6551 lines)
  functions..: 40.3% (1054 of 2616 functions)
  branches...: no data found

Files changed coverage rate:
                                                                          |Lines       |Functions  |Branches    
  Filename                                                                |Rate     Num|Rate    Num|Rate     Num
  ==============================================================================================================
  lib/screens/v2/candidate_generator/dup/departures.ex                    |86.3%    146|75.0%    24|    -      0
  lib/screens/v2/widget_instance/departures.ex                            |83.1%    148|84.8%    33|    -      0

Download coverage report

@digitalcora digitalcora marked this pull request as ready for review July 29, 2024 21:33
@digitalcora digitalcora requested a review from a team as a code owner July 29, 2024 21:33
Copy link
Contributor

@cmaddox5 cmaddox5 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. Thanks for adding the helpful comments.

@digitalcora digitalcora merged commit fb9dddc into main Jul 30, 2024
11 checks passed
@digitalcora digitalcora deleted the cfg-dup-types branch July 30, 2024 20:00
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