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

On bus screen placeholder app #2424

Merged
merged 19 commits into from
Feb 4, 2025
Merged

On bus screen placeholder app #2424

merged 19 commits into from
Feb 4, 2025

Conversation

robbie-sundstrom
Copy link
Contributor

Asana task: [add-on] "hello world" version of on-bus screens

Description

  • Tests added?

mix.exs Outdated Show resolved Hide resolved
@robbie-sundstrom robbie-sundstrom marked this pull request as ready for review January 31, 2025 17:05
@robbie-sundstrom robbie-sundstrom requested a review from a team as a code owner January 31, 2025 17:05
assets/css/v2/on_bus/body/normal.scss Outdated Show resolved Hide resolved
lib/screens/v2/candidate_generator/on_bus.ex Outdated Show resolved Hide resolved
lib/screens/v2/widget_instance/departures_no_service.ex Outdated Show resolved Hide resolved
import Placeholder from "Components/v2/placeholder";

const TYPE_TO_COMPONENT = {
body: Placeholder,
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this isn't working as intended (the blue placeholder doesn't show up, only a blank white screen), and I think it's because this is conflating the layout name with the widget that's being placed in a slot of the layout. To try and break it down:

  • The Placeholder widget on the backend has a widget_type/1 of :placeholder. Normally, that would then appear in this mapping: placeholder: Placeholder. The widget type string is mapped to a React component, and the rest of the widget's serialized fields are passed as props to that component.
  • So, why doesn't this error? Because on the frontend, layouts are also mapped to components, and on this screen type we have a layout named body defined. When a layout is rendered on the frontend, the matching component receives each of the slot names as a prop, with the value being all the fields of the widget that was chosen for that slot (including the type field, so it can be passed straight into the generic Widget component).
  • Putting it all together: The body layout is selected (it's the only layout), and the placeholder widget is chosen to go in the slot named placeholder (the only place it can go). body on the frontend is mapped to the component Placeholder. So this does the equivalent of <Placeholder placeholder={{type: "placeholder", color: "blue", ...}} /> Then Placeholder has no prop named placeholder, so that's silently ignored and it doesn't render with any particular color.

In conclusion, even the most minimal possible layout requires two React components: One for the layout itself (which will receive as props a mapping of slot-name to widget-fields), and one for an actual widget that will be placed in the layout. You can see an example of one of these "layout-components" in normal_body.tsx in most screen types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for breaking this down, this explanation brought it all together for me and I got it working again! Had been trying to debug why the Widget for placeholder was not receiving the correct props.

Copy link
Contributor

@digitalcora digitalcora 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! Had a couple non-blocking nitpicks. Let's merge that screens-config-lib PR, then update this one with the proper hash.

assets/src/components/admin/admin_tables.tsx Outdated Show resolved Hide resolved
assets/src/components/admin/admin_tables.tsx Outdated Show resolved Hide resolved
@robbie-sundstrom robbie-sundstrom merged commit cab1bcd into main Feb 4, 2025
12 checks passed
@robbie-sundstrom robbie-sundstrom deleted the rs/on-bus-screen-app branch February 4, 2025 20:11
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.

3 participants