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

storybook: create type table component #84282

Merged
merged 19 commits into from
Jan 30, 2025
Merged

storybook: create type table component #84282

merged 19 commits into from
Jan 30, 2025

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Jan 29, 2025

This PR exposes the type documentation generated in #84169 and #84166 to the user via a searchable table component and a story provided documentation helper.

You can see an example of prop documentation added to the button.stories.tsx, which follows the current convention of storybook providing the helper that should be called by the user.

export default storyBook('Button', (story, APIReference) => {
  APIReference(types.Button);
  story('Default', () => ... );

Note that the call order does not matter, the documentation (if provided) is being displayed under the components. In a perfect world, this should really work by passing the component itself to the API (the types can be stored directly on the function itself), however that is currently just not feasible as a broader loader implementation cripples the devserver to a point where it is not usable...

The only notable design decision is that given how exhaustive our type generation is, I have decided to prioritize the props that are defined inside the component while other types which the component might extend from remain collapsed (users can expand them and they will show when searching), which

CleanShot.2025-01-29.at.18.42.12.mp4

I do not consider this final and there are still aspects of this that I would like to improve, such as adding visual cues to indicate prop types, improving the type extraction and possibly breaking this down into smaller type definitions instead of files (sometimes the props are a merge of multiple different types defined in a single component)

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jan 29, 2025
Copy link
Contributor

@TkDodo TkDodo left a comment

Choose a reason for hiding this comment

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

looks great on the video 👏

static/app/views/stories/storyTypes.tsx Outdated Show resolved Hide resolved
Comment on lines 330 to 340
function groupByParent(props: PropItem[]) {
return props.reduce(
(acc, prop) => {
acc[prop.parent?.fileName ?? ''] = (acc[prop.parent?.fileName ?? ''] ?? []).concat(
prop
);
return acc;
},
{} as Record<string, PropItem[]>
);
}
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 we could leverage the built-in Object.groupBy method here:

Object.groupBy(props, prop => prop.parent?.fileName ?? '');

Copy link
Member Author

Choose a reason for hiding this comment

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

Til about this method

static/app/views/stories/type-loader.ts Outdated Show resolved Hide resolved
Base automatically changed from jb/feat/typegen-flag to master January 30, 2025 16:09
@JonasBa JonasBa requested review from a team as code owners January 30, 2025 16:09
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #84282       +/-   ##
===========================================
+ Coverage   56.15%   87.64%   +31.49%     
===========================================
  Files        9572     9564        -8     
  Lines      542163   540723     -1440     
  Branches    21264    21279       +15     
===========================================
+ Hits       304434   473943   +169509     
+ Misses     237377    66425   -170952     
- Partials      352      355        +3     

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

LGTM overall, huge improvement! Few suggestions but will leave the final call up to you.

static/app/stories/storyBook.tsx Show resolved Hide resolved
static/app/views/stories/storyTypes.tsx Outdated Show resolved Hide resolved
@JonasBa JonasBa merged commit 06a526f into master Jan 30, 2025
43 checks passed
@JonasBa JonasBa deleted the jb/feat/type-table branch January 30, 2025 18:17
andrewshie-sentry pushed a commit that referenced this pull request Feb 5, 2025
This PR exposes the type documentation generated in
#84169 and
#84166 to the user via a
searchable table component and a story provided documentation helper.

You can see an example of prop documentation added to the
button.stories.tsx, which follows the current convention of storybook
providing the helper that should be called by the user.

```
export default storyBook('Button', (story, APIReference) => {
  APIReference(types.Button);
  story('Default', () => ... );
```

Note that the call order does not matter, the documentation (if
provided) is being displayed under the components. In a perfect world,
this should really work by passing the component itself to the API (the
types can be stored directly on the function itself), however that is
currently just not feasible as a broader loader implementation cripples
the devserver to a point where it is not usable...

The only notable design decision is that given how exhaustive our type
generation is, I have decided to prioritize the props that are defined
inside the component while other types which the component might extend
from remain collapsed (users can expand them and they will show when
searching), which


https://github.com/user-attachments/assets/53fbea3c-7aea-4054-bfb9-1b4079b80f2d

I do not consider this final and there are still aspects of this that I
would like to improve, such as adding visual cues to indicate prop
types, improving the type extraction and possibly breaking this down
into smaller type definitions instead of files (sometimes the props are
a merge of multiple different types defined in a single component)

---------

Co-authored-by: Nate Moore <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants