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

feat(storybook): Add guide for adding tabs to a scene #18495

Merged
merged 9 commits into from
Nov 10, 2023

Conversation

tiina303
Copy link
Contributor

@tiina303 tiina303 commented Nov 8, 2023

Problem

Many of our pages have tabs and we add tabs in many different ways, which lead to it taking way longer for me to figure out how I should be adding tabs to a new scene. Additionally the app doesn't look polished if we do it in different ways - sometimes as /tab/ other times as ?tab=name.

Note that there is a problem with this implementation, that I don't know how to fix. The base URL now shows 404, instead of redirecting to the first tab.

Changes

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

How did you test this code?

checked storybook locally

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Tweaked the code a bit (see comments, hopefully they're useful 😄), overall looks great. Thanks for taking the time to make this!

tabs={Object.values(DashboardsTabs).map((tab) => ({
label: DASHBOARDS_TAB_TO_NAME[tab],
key: tab,
content: DASHBOARDS_TAB_TO_CONTENT[tab],
Copy link
Member

Choose a reason for hiding this comment

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

For non-advanced use cases it's better for the content to be part of the tab's definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could you bring me examples of when it's advanced vs not?

Copy link
Member

Choose a reason for hiding this comment

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

Basically if you want to put some extra UI between the tab bar and tab contents. Otherwise, it's simpler to keep everything together,

Comment on lines +42 to +45
export const DASHBOARDS_TAB_TO_NAME: Record<DashboardsTabs, string> = {
[DashboardsTabs.First]: 'First',
[DashboardsTabs.Second]: 'Second',
}
Copy link
Member

Choose a reason for hiding this comment

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

It was slightly overkill for this to be a function, so turned into an object

Comment on lines +28 to +30
...Object.fromEntries(
Object.values(DashboardsTabs).map((tab) => [urls.dashboards(tab), Scene.Dashboards])
) as Record<string, Scene>,
Copy link
Member

Choose a reason for hiding this comment

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

Object.fromEntries() > Array.prototype.reduce()

2. Update the URL in `frontend/src/scenes/urls.ts` to handle tabs:

```ts title="frontend/src/scenes/urls.ts"
dashboards: (tab: DashboardsTabs = DashboardsTabs.First): string => `/dashboards/${tab}`
Copy link
Member

Choose a reason for hiding this comment

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

Default args > optional args with a constant fallback deeper in the function

@tiina303 tiina303 merged commit c0a18f7 into master Nov 10, 2023
70 checks passed
@tiina303 tiina303 deleted the storybook-scene-building branch November 10, 2023 12:47
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