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(deps): update storybook to v6 #1638

Merged
merged 19 commits into from
Nov 6, 2020
Merged

Conversation

teimurjan
Copy link
Contributor

@teimurjan teimurjan commented Oct 22, 2020

FX-1154

Closes #1597

Description

Updating Storybook from v5 to v6 is a pretty big thing. It includes some breaking changes. In terms of this PR, all the breaking changes are taken into account:

  • Typescript is working with the storybook out of the box.
  • Changed the stories' hierarchy.
  • Added core-js library.
  • Added main.js file.

Problems

  • ⚠️ 1 visual test is broken for an unknown reason. Would like to have a hand for it, cause I tried everything I knew.

Investigation

Reason: The problem was caused by the conflict of the new story layout and our own body styles. In v5 there was no padding for layout at all, so there was no conflict. In v6 there is a default padding equals to 1rem. It can be avoided by using export const parameters = { layout: 'padded' } in preview.js file. However, when we run visual testing we don't use Storybook's index.html with all the stories. We use the iframe.html with the only story in it. The body inside this iframe has the padding I've mentioned above. So the trouble is layout styles are controlled when iframe.html is used inside the index.html. When it's rendered separately the default style is used.

Solution: We apply our own styles because of the better look of the image snapshots. However, now these styles are applied by default in Storybook (the only difference is: we use margin: 10px and Storybook uses padding: 1rem). So I got rid of our own styles and made the layout property to be padded in the parameters. It affected all the images snapshots but I manually compared every diff and can claim that nothing is broken.

How to test

  • Check out the new storybook on this PR's temploy.

Screenshots

Before. After.

Review

  • Read CONTRIBUTING.md and Component API principles
  • Make sure you've converted all js/jsx file into ts/tsx in your PR
  • Annotate all props in component with documentation
  • Create examples for component
  • Ensure that deployed demo has expected results and good examples
  • Ensure that unit tests pass by running yarn test
  • Ensure that visuals tests pass by running yarn test:visual. If not - check the documentation how to fix visual tests
PR commands

List of available commands:

  • @toptal-bot run all - Run whole pipeline
  • @toptal-bot run danger - Danger checks
  • @toptal-bot run lint - Run linter
  • @toptal-bot run test - Run jest
  • @toptal-bot run build - Check build
  • @toptal-bot run test:visual or @toptal-bot run visual - Run visual tests
  • @toptal-bot run deploy:documentation - Deploy documentation
  • @toptal-bot run package:alpha-release - Release alpha version

@havenchyk
Copy link
Contributor

🥇

@teimurjan teimurjan changed the title Update storybook to v6 chore(deps): update storybook to v6 Oct 23, 2020
@teimurjan teimurjan marked this pull request as ready for review October 23, 2020 05:39
@teimurjan teimurjan requested a review from a team as a code owner October 23, 2020 05:39
@teimurjan teimurjan removed the no-jira label Oct 23, 2020
@teimurjan teimurjan force-pushed the update-storybook-to-v6 branch from f9a4136 to b5d4a90 Compare October 26, 2020 08:39
@teimurjan teimurjan force-pushed the update-storybook-to-v6 branch from baef09f to c88fbd5 Compare October 28, 2020 07:03
@denieler
Copy link
Collaborator

Kapture 2020-10-28 at 10 43 19

Still not that cool as it was before 😁 Maybe we can write an addon to do that job?

@teimurjan
Copy link
Contributor Author

@denieler not sure about an addon, but I think it's possible. However, I think that the current version is OK before we find a stable solution for customizing the sidebar. I'd do it within another story.

@denieler
Copy link
Collaborator

@denieler not sure about an addon, but I think it's possible. However, I think that the current version is OK before we find a stable solution for customizing the sidebar. I'd do it within another story.

I think we can't deploy it like this to picasso.toptal.net. It can confuse other devs, who are using Picasso site every day

@denieler
Copy link
Collaborator

This sounds a bit scary to merge all screenshot images updated 😨

@teimurjan
Copy link
Contributor Author

@denieler Getting rid of custom body styles is an advantage that worth it. We should assume that no component code has been touched (except types) meaning the components are the same. It took me 10 minutes to check all the screenshots.

.storybook/components/PicassoBook/Book.js Show resolved Hide resolved
.storybook/components/PicassoBook/Page.js Show resolved Hide resolved
@@ -23,8 +23,8 @@ export interface PropDocumentationMap {
}

export interface Documentable {
displayName: string
__docgenInfo: any
displayName?: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When using forwardRef it returns ForwardRefExoticComponent. In ForwardRefExoticComponent displayName is an optional string. Indicator is a good example of such a component. So. when passing Indicator to addComponentDocs there is a TS error saying that displayName should be string

Copy link
Collaborator

Choose a reason for hiding this comment

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

why this issue came up only now?

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 happened after TS upgrade

Copy link
Collaborator

Choose a reason for hiding this comment

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

probably not TS upgrade but rather react types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. I think the react types are the same. A lot of TS issues were ignored before the update.

packages/picasso-charts/tsconfig.build.json Show resolved Hide resolved
packages/picasso/src/Indicator/Indicator.tsx Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
@teimurjan teimurjan force-pushed the update-storybook-to-v6 branch from 20673fe to e935208 Compare October 30, 2020 06:11
@denieler
Copy link
Collaborator

denieler commented Oct 30, 2020

Looks like direct links stopped working

Screenshot 2020-10-30 at 10 38 52

@teimurjan
Copy link
Contributor Author

@denieler committed the fix

@borisyordanov
Copy link
Contributor

but I manually compared every diff and can claim that nothing is broken.

🥇

@teimurjan
Copy link
Contributor Author

@toptal-bot run package:alpha-release

1 similar comment
@teimurjan
Copy link
Contributor Author

@toptal-bot run package:alpha-release

@teimurjan
Copy link
Contributor Author

@toptal-bot run package:alpha-release

@havenchyk
Copy link
Contributor

@toptal-bot run package:alpha-release

Copy link
Contributor

@vedrani vedrani left a comment

Choose a reason for hiding this comment

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

I like it, much faster than SP5, do we have some problems to discuss before merge on which I could concentrate?

// we have left here 10px margin for visual tests
// to make prettier screenshots and to avoid hiding
// box shadows from the captured screenshots for some components
document.body.style = 'padding: 0; margin: 10px !important;'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this padding? Or something changed in SB6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SB6 adds padding by default, so I've removed it

@@ -133,5 +130,8 @@
"lodash": "^4.17.12",
"**/marksy/marked": "^0.6.0",
"**/npx/npm": "^5.7.1"
},
"dependencies": {
"@storybook/react": "^6.0.27"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it also be in dev dependencies?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link
Contributor

Choose a reason for hiding this comment

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

but actually for root package json it doesn't really matter

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, how react is used during dev?

Copy link
Contributor

Choose a reason for hiding this comment

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

@OleksandrNechai Storybook needs react to render the JSX

@havenchyk
Copy link
Contributor

@toptal-bot run package:alpha-release

@havenchyk
Copy link
Contributor

@toptal-bot run package:alpha-release

@toptal-devbot
Copy link
Collaborator

Your alpha package is ready 🎉
yarn add @toptal/[email protected]
yarn add @toptal/[email protected]
yarn add @toptal/[email protected]
yarn add @toptal/[email protected]
yarn add @toptal/[email protected]
yarn add @topkit/[email protected]

@teimurjan
Copy link
Contributor Author

@toptal-bot run package:alpha-release

Copy link
Contributor

@havenchyk havenchyk left a comment

Choose a reason for hiding this comment

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

I'm still afraid of typescript related changes, let me try it out locally carefully to make sure nothing is broken

@havenchyk
Copy link
Contributor

@teimurjan consider going one step forward

diff --git a/tsconfig.build.json b/tsconfig.build.json
index 62335ffc..b7a57514 100644
--- a/tsconfig.build.json
+++ b/tsconfig.build.json
@@ -1,13 +1,7 @@
 {
   "extends": "./tsconfig.json",
   "compilerOptions": {
-    "outDir": "dist-package",
-    "paths": {
-      "*": ["@types/*"],
-      "~/*": ["./*"],
-      "@toptal/picasso/*": ["node_modules/@toptal/picasso/src/*"],
-      "@toptal/*": ["node_modules/@toptal/*/src"]
-    }
+    "outDir": "dist-package"
   },
   "exclude": [
     "**/*.example.jsx",
diff --git a/tsconfig.json b/tsconfig.json
index 8d3df2e4..688ffca6 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,20 +16,13 @@
     "baseUrl": ".",
     "typeRoots": ["node_modules/@types", "@types"],
     "paths": {
-      "@toptal/*": ["packages/*/src"],
-      "@topkit/analytics-charts": ["packages/topkit-analytics-charts/src"],
-      "@topkit/analytics-charts/*": ["packages/topkit-analytics-charts/src/*"],
-      "@toptal/picasso/*": ["packages/picasso/src/*"],
-      "@toptal/picasso-lab/*": ["packages/picasso-lab/src/*"],
-      "@toptal/picasso-shared/*": ["packages/shared/src/*"],
-      "@toptal/picasso-shared": ["packages/shared/src"],
-      "@toptal/picasso-forms/*": ["packages/picasso-forms/src/*"],
-      "@toptal/picasso-charts/*": ["packages/picasso-charts/src/*"],
       "*": ["@types/*"],
-      "~/*": ["./*"]
+      "~/*": ["./*"],
+      "@toptal/picasso/*": ["node_modules/@toptal/picasso/src/*"],
+      "@toptal/*": ["node_modules/@toptal/*/src"]
     },
     "types": ["node", "jest", "@testing-library/jest-dom"]
   },
-  "include": ["packages/*/src"],
+  "include": ["packages/*/src", "./cypress/integration", "./node_modules/cypress"],
   "exclude": ["packages/*/dist-package"]
 }

`
}

const withSavingInitialPath = (cb, api) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usually, we don't use abbreviations

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of the callback, maybe it makes sense to return Promise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not possible. The callback is used not as an end function, but it's called in between the steps. It'll be removed once storybookjs/storybook#12980 is merged.

Copy link
Collaborator

@OleksandrNechai OleksandrNechai left a comment

Choose a reason for hiding this comment

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

Well, I myself also have positive impressions from what I have seen so far. Works fast, looks beautiful 👍
Code is clean 👍 although I am not sure about exactly what each line does.
Tested

  • locally
  • deployment
  • a few packages randomly

I could not see the content of the package (Explore tab) https://www.npmjs.com/package/@toptal/picasso/v/4.109.8-alpha-update-storybook-to-v6.1952
I could not make these packages work in code sandbox https://codesandbox.io/s/jovial-meninsky-n7c52?file=/package.json

I am now not sure if we have not broken package deployment here.

@teimurjan
Copy link
Contributor Author

@toptal-bot run all

@toptal-devbot
Copy link
Collaborator

🎉 Last commit is successfully deployed 🎉

Demo is available on:

Your davinci-bot 🚀

@@ -27,8 +27,9 @@
"@toptal/picasso-charts/*": ["packages/picasso-charts/src/*"],
"*": ["@types/*"],
"~/*": ["./*"]
}
},
"types": ["node", "jest", "@testing-library/jest-dom", "cypress"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt it 😄 https://www.staging-typescript.org/tsconfig#types

By default all visible ”@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible. For example, that means packages within ./node_modules/@types/, ../node_modules/@types/, ../../node_modules/@types/, and so on.

If types is specified, only packages listed will be included in the global scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is an error when not using types:

cypress/integration/ModalAndTooltip.spec.ts:17:5 - error TS2304: Cannot find name 'cy'.
17     cy.get('[data-testid="datepicker"]').should('have.value', '11-03-2020')

Previously the problem was solved by adding "./node_modules/cypress" to include. In this case expect function in Jest tests is considered like expect from cypress.

Property 'toMatchSnapshot' does not exist on type 'Assertion'.ts(2339)

That's why the types are required.

Copy link
Contributor

@havenchyk havenchyk 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, except types fields which I doubt about

@teimurjan teimurjan merged commit c800c1b into master Nov 6, 2020
@teimurjan teimurjan deleted the update-storybook-to-v6 branch November 6, 2020 11:56
havenchyk pushed a commit that referenced this pull request Nov 10, 2020
* chore(deps-dev): bump @storybook/react from 5.3.18 to 6.0.26

Bumps [@storybook/react](https://github.com/storybookjs/storybook/tree/HEAD/app/react) from 5.3.18 to 6.0.26.
- [Release notes](https://github.com/storybookjs/storybook/releases)
- [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md)
- [Commits](https://github.com/storybookjs/storybook/commits/v6.0.26/app/react)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* chore: migrate storybook to v6

* chore: add node types to tsconfig

* chore: get rid of tsconfig.build paths

* chore: fix menu expander

* chore: fix storybook links

* chore: update snapshots

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
havenchyk pushed a commit that referenced this pull request Nov 10, 2020
* chore(deps-dev): bump @storybook/react from 5.3.18 to 6.0.26

Bumps [@storybook/react](https://github.com/storybookjs/storybook/tree/HEAD/app/react) from 5.3.18 to 6.0.26.
- [Release notes](https://github.com/storybookjs/storybook/releases)
- [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md)
- [Commits](https://github.com/storybookjs/storybook/commits/v6.0.26/app/react)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* chore: migrate storybook to v6

* chore: add node types to tsconfig

* chore: get rid of tsconfig.build paths

* chore: fix menu expander

* chore: fix storybook links

* chore: update snapshots

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
havenchyk pushed a commit that referenced this pull request Nov 10, 2020
* chore(deps-dev): bump @storybook/react from 5.3.18 to 6.0.26

Bumps [@storybook/react](https://github.com/storybookjs/storybook/tree/HEAD/app/react) from 5.3.18 to 6.0.26.
- [Release notes](https://github.com/storybookjs/storybook/releases)
- [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md)
- [Commits](https://github.com/storybookjs/storybook/commits/v6.0.26/app/react)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* chore: migrate storybook to v6

* chore: add node types to tsconfig

* chore: get rid of tsconfig.build paths

* chore: fix menu expander

* chore: fix storybook links

* chore: update snapshots

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
havenchyk pushed a commit that referenced this pull request Nov 11, 2020
* chore(deps-dev): bump @storybook/react from 5.3.18 to 6.0.26

Bumps [@storybook/react](https://github.com/storybookjs/storybook/tree/HEAD/app/react) from 5.3.18 to 6.0.26.
- [Release notes](https://github.com/storybookjs/storybook/releases)
- [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md)
- [Commits](https://github.com/storybookjs/storybook/commits/v6.0.26/app/react)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* chore: migrate storybook to v6

* chore: add node types to tsconfig

* chore: get rid of tsconfig.build paths

* chore: fix menu expander

* chore: fix storybook links

* chore: update snapshots

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
@teimurjan teimurjan restored the update-storybook-to-v6 branch November 16, 2020 06:23
@teimurjan teimurjan deleted the update-storybook-to-v6 branch November 16, 2020 06:24
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.

7 participants