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

Fix: MenuButton accepts falsy children #1934

Closed
wants to merge 214 commits into from

Conversation

chrispulsinelli-okta
Copy link
Contributor

Description

Fixes the typing for the MenuButton component's children so that it may accept falsy-like values

edburyenegren-okta and others added 30 commits May 23, 2023 14:55
chore(odyssey-react-mui): translations for odyssey-react-mui.properties
…theme

fix: use odyssey tokens inside mui components style override
refactor(odyssey-react-mui): migrate Circular Progress to design tokens
fix: added incremental to root TSconfig
fix: memoized the Link component
@@ -91,7 +91,7 @@ const storybookMeta: Meta<MenuButtonProps> = {
description: "The <MenuItem> components within the Menu",
table: {
type: {
summary: "[MenuItem | Divider | ListSubheader]",
summary: "[MenuItem | Divider | ListSubheader | NullElement]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this documentation only?

Does it need to be in the props table?

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'm not quite sure what you're asking here. Can you clarify?

Copy link
Contributor

Choose a reason for hiding this comment

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

Props table is just a string. We don't need to put TypeScript types in here in our docs; TS handles that for you in the component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm missing something, but this is supposed to reflect the children props of MenuButton, no?
To clarify, are you asking for this to be reverted too?

Comment on lines 179 to 206
/**
* Note that the falsy children in the following MenuButton won't appear in the source
* code in the actual story in your browser, but this illustrates that there are no
* compile-time issues with the falsy items passed as children.
*/
export const FalsyChildren: StoryObj<MenuButtonProps> = {
args: {
buttonLabel: "More actions",
children: [
<MenuItem key="1">Truthy Menu Item</MenuItem>,
false,
null,
undefined,
],
},
play: async ({
args,
canvasElement,
step,
}: {
args: MenuButtonProps;
canvasElement: HTMLElement;
step: PlaywrightProps<MenuButtonProps>["step"];
}) => {
clickMenuButton({ canvasElement, step })(args, "Menu Button Simple");
},
};

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want a story for this. Seems like a unit test is enough, but we're unit testing our types right? It always accepted falsy children just that TS complained.

We shouldn't be adding unit tests for type checks. We should expect TS works as-expected right?

Unless we want to add TS-specific unit tests, then those should happen outside of Storybook because we'd be verifying that the types we defined work as we expect.

We don't want people to pass no items, it's just that sometimes they do right?

I can't remember the previous reason we added that NullElement.

Why would someone pass null to this component? There was a reason for it though. Shouldn't they just wrap the whole MenuButton in a condition instead of passing it nothing? items.length > 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It always accepted falsy children just that TS complained.

It worked in JS with falsy children because the type-checking no longer applies. I don't believe it's a good dev-experience though for consumers to get TS errors and need to squash them with a ts-ignore because our typing is wrong and possibly leading to build failures on their end.

We shouldn't be adding unit tests for type checks. We should expect TS works as-expected right?

Just because TS is happy with the type, doesn't mean its typed to our expectations, hence the bug that I am addressing here.

I'm OK with removing this and I agree that a story may not be the right place for a compile-time test to prove that the type works as expected. I wanted a way to show though, that a) this works and b) that it doesn't break again.

Is there a better way going forward to include a regression test for something like this?

@KevinGhadyani-Okta
Copy link
Contributor

You'll need to rebase from main since you branched from develop originally.

@KevinGhadyani-Okta KevinGhadyani-Okta changed the base branch from develop to main August 28, 2023 19:43
@KevinGhadyani-Okta
Copy link
Contributor

Closing this as it's too hard to merge now because develop vs main.

New PR with all commits cherry-picked: #1999

@mohamed-okta
Copy link
Contributor

Closing in favour of #1999

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.

10 participants