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

Navigation component + Page/Layout concept #42

Merged
merged 14 commits into from Oct 18, 2021
Merged

Navigation component + Page/Layout concept #42

merged 14 commits into from Oct 18, 2021

Conversation

oshi97
Copy link
Contributor

@oshi97 oshi97 commented Oct 15, 2021

This PR adds the navigation component, and also reworks the react-router usage into a Page and Layout system.

For the Navigation resizing, I tried to use resize observer, first with https://www.npmjs.com/package/@react-hook/resize-observer and then with ResizeObserver directly. The third party hook did not seem to work well for our use case,
and for using ResizeObserver directly, it turns out the TypeScript types for ResizeObserver are not included by default,
and I felt a little apprehensive to include third party types for it, though it would probably be fine.
microsoft/TypeScript#28502

J=SLAP-1558
TEST=manual

test resizing the page and seeing tabs appear and disappear
test that switching tabs will run searches

@coveralls
Copy link

coveralls commented Oct 15, 2021

Coverage Status

Coverage remained the same at 74.713% when pulling e88666d on dev/navigation-2 into 0bd77b4 on main.

@oshi97 oshi97 requested a review from yen-tt October 15, 2021 18:24
}))
]

export default function Layout({ page }: { page: JSX.Element }) {
Copy link
Member

Choose a reason for hiding this comment

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

can you add some jsdocs to help describe the responsibility of these different components?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added some and also renamed BaseRouter -> PageRouter

export default function BaseRouter({ Layout, routes }: PageProps) {
const pages = routes.map(routeData => {
const { path, page, exact } = routeData;
if (Layout) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if the Layout props adds much value to the router. I would expect that a router would simply render what you give it at a given route. I briefly looked into the react router and I didn't see any sort of layout concept, but it's possible I missed something there. What are some of the reasons that lead you to adding Layout to the router?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to abstract away react-router details for the the kind of use case we would expect theme 2.0 to have, and wanted a way for a given route's page to have shared components. We had some idea of "layouts" for jambo that eventually fizzled out, but I thought made sense here

Comment on lines 10 to 13
interface PageProps {
Layout?: ComponentType<{ page: JSX.Element }>
routes: RouteData[]
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to have a Layout interface defined in typescript? Then the Layout.tsc could implement that and we'd maybe want to rename that Layout since it is a concrete implemenation of the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added!

@oshi97 oshi97 requested a review from cea2aj October 15, 2021 20:37
/**
* A LayoutComponent that provides a SearchBar and Navigation tabs to a given page.
*/
const Layout: LayoutComponent = ({ page }) => {
Copy link
Member

@cea2aj cea2aj Oct 15, 2021

Choose a reason for hiding this comment

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

super nit: It might be easy to mix up the Layout here and the Layout in PageProps because one is a concrete implementation and the other is an arbitrary instance of the the LayoutComponent interface. What do you think about naming this StandardLayout in order to help differentiate them?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that would be good too. It would follow StandardCard and CardComponent and how we name Section stuff as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I like that! I also moved it to the src/pages folder

@oshi97 oshi97 merged commit c85e3de into main Oct 18, 2021
@oshi97 oshi97 deleted the dev/navigation-2 branch October 18, 2021 16:58
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.

None yet

4 participants