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

chore(storybook) update storybook format and add ltr/rtl support #12911

Merged
merged 1 commit into from
Jun 2, 2022

Conversation

millmason
Copy link
Contributor

@millmason millmason commented May 17, 2022

chore(storybook) add LinkedAccounts to stories

chore(storybook) refactor nav stories

fix(storybook) use addon to get ltr/rtl in storybook

Because

  • Styles in storybook did not match what we were seeing in prod/local/staging. Also, some cases were missing from demos of the Settings page and nav.

This pull request

  • Adds in additional cases (specifically, an account with Linked Accounts) and also adds a storybook addon to enable ltr/rtl specific styles

Issue that this pull request solves

Closes: #12848

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Before (no linked accounts stories):
Screen Shot 2022-05-17 at 11 50 19 AM

After (with linked accounts stories):
Screen Shot 2022-05-17 at 11 44 23 AM

Before (without rtl/ltr addon):
Screen Shot 2022-05-17 at 11 46 32 AM
Screen Shot 2022-05-17 at 11 46 43 AM

After (with rtl/ltr addon):
Screen Shot 2022-05-17 at 11 44 28 AM
Screen Shot 2022-05-17 at 11 44 57 AM

Other information (Optional)

The reason why the styles in storybook looked wrong, even thought they looked fine when rendered outside of storybook, is because some of our styles were only being applied in the case of (under the hood in our CSS), the property selectors [dir='rtl'] or [dir='ltr'] being true. Storybook doesn't have a value for that property available out of the box, so those styles were not being applied. Adding in the storybook-addon-rtl addon, and calling initializeRTL() in preview.js provided that property and fixed the styles. Long-term there is probably future work to be done regularizing some of the styles (so that similar elements have similar styles) and possibly adding a knob so that users can toggle the rtl/ltr in Storybook, but that feels outside of the scope of this ticket.

Testing

Elements where you can see the rtl/ltr fixes in storybook are: the Checkbox story, and the space between the Email Communications label and its associated "link" button, visible in the "basic" story under the Nav story.

@fxa-bananafox
Copy link
Contributor

fxa-bananafox bot commented May 17, 2022

I got u millsoper. 💯

import { Account } from '../../models/Account';
import { MOCK_LINKED_ACCOUNTS } from '../LinkedAccounts/mocks';

const defaultStory = { title: 'Components/Nav', component: Nav };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated format per this comment #12870 (comment)

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 it might be more ideal to format this like:

export default {
  title: 'Components/Nav',
  component: Nav,
} as Meta;

// or "Basic" as you have it further below, I personally prefer "Default" since it's slightly more clear (my opinion)
export const Default = () => <Nav />;

This is more similar to how they recommend it in the docs and how we've done all of our other modern default story SB formatting in the few fxa-settings files as well as our email stories.

@millmason millmason marked this pull request as ready for review May 17, 2022 18:54
@millmason millmason requested a review from a team as a code owner May 17, 2022 18:54
@millmason millmason changed the title [FXA-5072] Update storybook format and add ltr/rtl support chore(storybook) update storybook format and add ltr/rtl support May 17, 2022
@LZoog LZoog self-assigned this May 17, 2022
Copy link
Contributor

@LZoog LZoog left a comment

Choose a reason for hiding this comment

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

Thank you so much for fixing this 🙌

I just had some nits/suggestions, but then a couple of notes as I've dug a little here.

I noticed in the package description, it states:

A storybook addons that lets your users toggle between ltr and rtl.

But I'm not sure I see the toggle shown there, and I know you noted in your description:

Long-term there is probably future work to be done regularizing some of the styles (so that similar elements have similar styles) and possibly adding a knob so that users can toggle the rtl/ltr in Storybook, but that feels outside of the scope of this ticket.

... I actually forgot that we added a toggle for this in fxa-auth-server storybook:

image

I don't think this throws a wrench into your PR (as in, I don't believe you need to uninstall this package and reference auth-server's SB), since I don't think we have any actual RTL specific styles in our emails since they're all centered and pretty basic. I didn't dig further into how that package can toggle vs what we're doing, but I wanted to note that just for consistency's sake whether you do something here with it or we do so in the future.

I noticed we actually have a duplicate ticket for this - #9195 - I didn't realize when I filed the ticket your PR fixes that this was an RTL/LTR problem, and forgot about that ticket until now. We could cancel it in favor of the ticket this closes, but since that ticket actually references a toggle, we could instead slightly modify the title and leave a comment over there saying the style problem was fixed but we'd still like to have an option to switch from RTL/LTR, with maybe a reference to this comment or with just a summary of it so we can make sure whatever we do we're consistent.

import { Account } from '../../models/Account';
import { MOCK_LINKED_ACCOUNTS } from '../LinkedAccounts/mocks';

const defaultStory = { title: 'Components/Nav', component: Nav };
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 it might be more ideal to format this like:

export default {
  title: 'Components/Nav',
  component: Nav,
} as Meta;

// or "Basic" as you have it further below, I personally prefer "Default" since it's slightly more clear (my opinion)
export const Default = () => <Nav />;

This is more similar to how they recommend it in the docs and how we've done all of our other modern default story SB formatting in the few fxa-settings files as well as our email stories.

Comment on lines 25 to 31
const accountWithLinkedAccounts = Object.assign({}, account, {
linkedAccounts: MOCK_LINKED_ACCOUNTS,
});

const configWithoutNewsletterLink = Object.assign({}, getDefault(), {
marketingEmailPreferencesUrl: '',
});
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to leave these as-is since this is just an opinion but I personally prefer this syntax since it reads more clear to me and we're doing similar stuff in emails Storybooks:

const accountWithLinkedAccounts = {
  ...account,
  linkedAccounts: MOCK_LINKED_ACCOUNTS,
});

const configWithoutNewsletterLink = {
  ...getDefault(),
  marketingEmailPreferencesUrl: '',
});

Do you prefer explicitly using Object.assign?

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 don't, this is way clearer to me also! 👍


const account = {
primaryEmail: {
email: 'johndope@example.com',
},
subscriptions: [{ created: 1, productName: 'x' }],
linkedAccounts: [],
} as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly better typing here than any is as unknown as Account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's really cool thank you!!

marketingEmailPreferencesUrl: '',
});

const storyWithAccount = (
Copy link
Contributor

@LZoog LZoog May 18, 2022

Choose a reason for hiding this comment

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

I named a similar wrapper in Security this (storyWithAccount) since account was the only param needed. This might be better named to something like storyWithContext since that's what the story is providing, but I'm open to other name suggestions and it's not a big deal to leave it as-is.

Also, I think you can use the type Config for config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent, great idea!

@@ -26,6 +27,7 @@ storiesOf('Pages/Settings', module)
recoveryKey: false,
totp: { exists: false, verified: false },
attachedClients: SERVICES_NON_MOBILE,
linkedAccounts: MOCK_LINKED_ACCOUNTS,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary for this PR but it would also be super nice for this file to get reformatted to the new Storybook since it was touched 🙈

I think maybe for "Cold start" story (this one), we might want to not show linkedAccounts. That story is supposed to be a "bare minimum" example if someone just created an account - I think in fact it would be nice for attachedClients to just show one session, but that again isn't part of the issue you fixed, so 🤷‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great thinking, will do!

@millmason millmason force-pushed the FXA-5072-storybook-fixes branch from d734ccf to 811c520 Compare May 31, 2022 23:11
@fxa-bananafox
Copy link
Contributor

fxa-bananafox bot commented May 31, 2022

I got u millsoper. 💯

@millmason millmason force-pushed the FXA-5072-storybook-fixes branch from eecf753 to ca1616e Compare June 1, 2022 18:40
@fxa-bananafox
Copy link
Contributor

fxa-bananafox bot commented Jun 1, 2022

I got u millsoper. 💯

Copy link
Contributor

@LZoog LZoog left a comment

Choose a reason for hiding this comment

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

LGTM! Let's be sure to address this comment as I know you said you were going to in Slack 🙂 Also, don't forget to fixup your 2nd commit too and tweak the commit message to follow that because/this commit format.

I'm also fine with us closing that ticket (#9195) saying it's fixed with this PR and you could file a new one with context from this PR, the ticket it closes, and #9195 noting the consistency bit between our SBs. That gives us the advantage of triaging it in our next meeting, but again I'm also personally fine with just tweaking the title and leaving a comment over there since it was part of the issue anyway and I know we'll just backlog it.

return story;
};

export const basic = () => <Nav />;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this should be capitalized conventionally, e.g. Basic

component: PageSettings,
} as Meta;

const coldStartAccount = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yaaaaas thank you for the refactor 😍

linkedAccounts: MOCK_LINKED_ACCOUNTS,
}

const storyWithContext = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking outloud; if we end up using storyWithContext in our other SB refactors, we should definitely consider pulling this out into a helper function to use across stories, we can have it take a children prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mm I like that idea. It would feel nice to do a big sweep refactoring all of these and refactor it out then


export const ColdStart = storyWithContext(
coldStartAccount,
'cold start',
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 mind either way, but you could take out the story names here. They'll just show up in SB as Cold Start vs cold start. 🤷‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh interesting hmmmmm. I liked seeing them in the example I was modeling this on just because it was a little more explicit/less mysterious, but I think that confusion will become less and less frequent the more of these that we transition. Good with going either way!

@pdehaan
Copy link
Contributor

pdehaan commented Jun 1, 2022

Unrelated, but... Should we add this to all the Storybook projects?

Because:

* RTL/LTR styles weren't showing up in storybook.

This commit:
* Uses an addon to add the `dir` value so that rtl/ltr styles are
  applied
* Adds in Linked Accounts to some of the stories
* Update the format for files that were changed

Closes: #12848
@millmason millmason force-pushed the FXA-5072-storybook-fixes branch from b08224d to 6b92c6a Compare June 2, 2022 20:24
@millmason millmason merged commit 285885e into main Jun 2, 2022
@millmason millmason deleted the FXA-5072-storybook-fixes branch July 12, 2022 20:04
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.

Settings Storybook: some styles differ from actuality + Fluent IDs are showing
3 participants