Skip to content

feat: create branch picker element - #608

Open
djpowers wants to merge 32 commits into
mainfrom
djp-create-branch-picker-element
Open

feat: create branch picker element#608
djpowers wants to merge 32 commits into
mainfrom
djp-create-branch-picker-element

Conversation

@djpowers

Copy link
Copy Markdown
Member

Asana Task: 🪐 Create Orbit branch picker element

This adds a "branch picker" component to allow focusing of different branches. Right now, this stores the chosen branch in state, and adjusts the active/inactive display of the three branch buttons accordingly. Clicking a train pill will also update the branch selection to the branch containing that train. Light mode versions of colors are used where available.

Related work:

Note: focusing ladders on selection change and other scrolling behavior will be included in subsequent tasks

Alewife

image

Ashmont

image

Braintree

image

Checklist

  • Appearance:
    • Light & dark mode
    • Desktop & mobile sizes
  • Browsers:
    • Chromium
    • Firefox
    • Safari
  • Privacy:
    • Commits free of internal data
    • PR description free of internal data
    • Logging free of internal data
  • Tests:
    • Has tests
    • Doesn't need tests
    • Tests deferred (with justification)

- conditionally set colors for branches based on current state
- refactor button rendering to reduce duplication
- include helper to determine branch for train pill
- pass down branch picker selection setter prop
- update tests to accommodate new prop
These items were not showing up properly after merging in main.
On mobile (specifically Safari on iOS) the address bar (which is now on
the bottom of the screen) blocks the address picker.

This resolves this issue. Of note, I setting `h-screen h-dvh` as
Tailwind variables, but they seemed to conflict and it did not work.
@djpowers
djpowers requested a review from a team as a code owner August 28, 2026 19:56
Comment thread css/app.css
.app-wrapper {
height: 100vh;
height: 100dvh;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Highlighting my commit description: a9e3b0e

If there's a better approach here I'm open to it, but this seemed like the most direct way to ensure the branch picker was not blocked by mobile address bars.

Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
@djpowers
djpowers requested a review from mathcolo September 1, 2026 12:26
Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
@djpowers
djpowers requested a review from mathcolo September 1, 2026 15:55
Comment on lines +151 to +162
// update branch picker to reflect the branch the clicked train is on
const matchingStationList = stationLists.find((stations) =>
stations.some((station) =>
station.stop_ids.some(
(stopId) => stopId === match.vehiclePosition.stopId,
),
),
);
if (matchingStationList) {
setBranchPickerSelection(branchForLadder(matchingStationList));
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: I'm torn on this. spiritually it feels like we shouldn't have to search back through the stations to figure out what branch a train is on. is there a better way?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Tried a different approach in 3b06ead.

This change sets the branch for each ladder on render, so we can avoid the lookup on each click.

djpowers and others added 2 commits September 8, 2026 15:59
(avoiding station lookup on each click)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@djpowers

djpowers commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Note: experimented with using Copilot to resolve a merge conflict, which appeared to retain both my changes and the latest commits from main

@djpowers
djpowers requested a review from mathcolo September 8, 2026 20:30

@mathcolo mathcolo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm close to approving! just a few more spots

Comment thread js/components/ladderPageShared/ladder.tsx Outdated
Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
Comment thread js/components/ladderPageShared/branchPicker.tsx Outdated
Comment thread js/test/components/ladderPageShared/branchPicker.test.tsx Outdated
This makes the data type route-agnostic.

It changes the `branchColors` type definition to match the
ROUTE_DEFAULTS from ladder, as the partial was causing issues.

Update branch button map to temporarily hard-code "Red" as route
@djpowers
djpowers force-pushed the djp-create-branch-picker-element branch from 6f3d53c to b117bcc Compare September 9, 2026 16:31
@djpowers
djpowers requested a review from mathcolo September 9, 2026 16:32
setIsOverflowing(el.scrollWidth > el.clientWidth);
};
check();
window.addEventListener("resize", check);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: does this need to be debounced?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Debounce added in 7be6942.

Comment on lines +72 to +75
return ladderConfig[
// First ladder is Alewife, for other branches use name of last station
Stations[routeId].indexOf(ladderConfig) === 0 ? 0 : ladderConfig.length - 1
].name;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: This is slightly awkward, because Orbit already knows which ladder a station is on—it needed that info to build the ladder in the first place.

can we flip this around and instead set up ladder.tsx:212 to get a BranchPickerSelection that you build at setup time which information you already have?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Discussed over a handle, but the idea was to use an index-based value (using the stations array) instead of a string to avoid needing to lookup the branch by station name. Implemented in 0b91e85.

Storing the branch as a string required performing a reverse-lookup to
determine which branch a particular station was part of (since a branch)
name is not part of the underlying data structure.

This instead uses the index of the defined branch, which we can rely on
to be in a consistent order. This updates related tests to follow this
new structure.
@djpowers
djpowers force-pushed the djp-create-branch-picker-element branch from f2fbd81 to 9528ee0 Compare September 11, 2026 22:07
@djpowers
djpowers requested a review from mathcolo September 11, 2026 22:14
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