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

Add codesandbox links to our documentation #2728

Merged
merged 30 commits into from
Jun 5, 2020
Merged

Conversation

snide
Copy link
Contributor

@snide snide commented Jan 2, 2020

Summary

Adds dynamic code sandbox docs to our documentation.

How it works

  • Using a bunch of regex, any src-doc example gets built into a reformatted index.js file and uploaded to code sandbox that is told to use the latest version of our dependencies.
  • In special cases like form examples, it also adds the display toggles component, which is used it a lot of our examples.
  • If it sees a simple outside dependency imported into one of our docs example (like faker in data grid) it will add it to the sandbox.

Limitations

  • If our src-doc examples get complicated and include internal components for the docs (say a helper file to generate content for the example) then we don't generate a link. The regex checks are smart enough to make this decision automatically. I don't think we want to recursively run regex on imported files.
  • The exception to the above is examples using display toggles. Since we lean on that toggle system quite a bit I went ahead and added some extra logic to check if the example includes them and then tell codesandbox to generate an imported file for them. This again, happens automatically and should be carry over changes we make to any of those files.
  • Currently only works for JS src-doc examples. We have a couple TS docs files. It gracefully fails.
  • This requires docs examples to export as default functions. I've changed any that weren't to make them work and match our more common style for docs.

Here is a list of examples that don't work and the reason. We should clean these up in separate PRs.

🙈 = doesn't show a link to CS, no one will see it break
💔 = brittle regex causes an error in CS

  • 🙈 EuiHeader, EuiNavDrawer, EuiCollapsableNav, EuiColorPalette, EuiFocusTrap, EuiWindowEvent uses helper docs includes that should be moved to the example code.
  • 🙈 EuiTable uses special includes that could likely be switched to faker
  • 🙈 EuiHorizontalRule, EuiSpacer, EuiCommentList, EuiSelectable, EuiScreenReadOnly demo examples are TypeScript files.
  • 🙈 EuiToastList uses a non-standard way to build the example page.
  • 💔 EuiCodeEditor breaks because of the way we import Brace deps
  • 🙈 EuiSearchBar has a bunch of hidden docs utils that are included in src and screw up the imports. They should be replaced with doc level functions.
  • 🙈 Elastic Charts examples need something custom and have no links.

For review

  • This includes a lot of regex, some of which is written by your lowly narratar! Besides regex being fairly brittle, I'd appreciate a check on the patterns I'm using to make sure they are fairly tolerant to change.

image

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in IE11 and Firefox
  • Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@snide snide marked this pull request as ready for review January 12, 2020 17:55
@snide snide changed the title [WIP] Add codesandbox links to our documentation Add codesandbox links to our documentation Jan 12, 2020
@@ -9,7 +9,7 @@ import {
EuiSpacer,
} from '../../../../src/components';

import { VISUALIZATION_COLORS } from '../../../../src/services/color/visualization_colors';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we deprecate this now that we have real palettes?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about that too as I was messing with the palettes and I don't think it makes sense to have two ways to export the viz palette.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. I'll add it to our list then. They are definitely duplicative, and the new one is a more reliable method of pulling those values.

.map(x => x.groups.import)
.reduce((deps, dep) => {
// Hack because the docs are locked to a specific version of React Router
deps[dep] = dep === 'react-router' ? '^3.2.5' : 'latest';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't think of a way to pull this from package.json automatically?

Copy link
Contributor

Choose a reason for hiding this comment

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

const pkg = require('../../../../package.json'); at the top of the file
and then replace '^3.2.5' with pkg.devDependencies['react-router']

EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
// @ts-ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotta follow up on why this was needed.

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 this is necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

^^ Can delete now?

@chandlerprall chandlerprall self-requested a review January 13, 2020 16:04
@miukimiu
Copy link
Contributor

Hi @snide,

I was thinking if we could have the Codesandbox icon next to the fullscreen icon. I know the fullscreen icon is part of the EuiCodeBlock but maybe is something to think for the future.

codesandbox-01@2x

codesandbox-02@2x

@snide
Copy link
Contributor Author

snide commented Jan 17, 2020

@miukimiu That was my original idea, but people liked the discreet link. I was thinking to add a new prop to EuiCodeBlock for extraControls or something, so you could put other stuff in there.

Easy enough to change if others feel the same, but I'll let the PR get reviews / merged first on all the regex crazyness first before getting to fiddly with the design.

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Icons actually throw errors (not just not render). Is this what you've seen also?

Accordion demo:
Screen Shot 2020-01-31 at 11 27 03 AM

EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
// @ts-ignore
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 this is necessary

.map(x => x.groups.import)
.reduce((deps, dep) => {
// Hack because the docs are locked to a specific version of React Router
deps[dep] = dep === 'react-router' ? '^3.2.5' : 'latest';
Copy link
Contributor

Choose a reason for hiding this comment

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

const pkg = require('../../../../package.json'); at the top of the file
and then replace '^3.2.5' with pkg.devDependencies['react-router']

@snide
Copy link
Contributor Author

snide commented Jan 31, 2020

@thompsongl Looks like it's something happening only in the last couple versions of EUI. Checking it out. You can replicate by moving the EUI req away from latest.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@snide snide requested a review from miukimiu June 3, 2020 16:22
@snide
Copy link
Contributor Author

snide commented Jun 3, 2020

This is mostly reviewable if folks want to poke around. I think the EuiCodeEditor example is the only one I think needs to get fixed.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@miukimiu
Copy link
Contributor

miukimiu commented Jun 4, 2020

I think we have an issue with all the pages using a DisplayToggles.

The exception to the above is examples using display toggles. Since we lean on that toggle system quite a bit I went ahead and added some extra logic to check if the example includes them and then tell codesandbox to generate an imported file for them. This again, happens automatically and should be carry over changes we make to any of those files.

I noticed that this is not working as expected. The file is generated correctly but the import { DisplayToggles } from './display_toggles'; fails.

For example, you can try the first example which uses a DisplayToggles on the EuiComboBox page:
https://eui.elastic.co/pr_2728/#/forms/combo-box

It throws the following error:

Screenshot 2020-06-04 at 13 27 13

Here's another example (Date picker states):
https://eui.elastic.co/pr_2728/#/forms/date-picker

@chandlerprall
Copy link
Contributor

I've pushed a fix for the display toggle import issue, but trying to render the toggles gives this error:

Invariant failed: You should not use outside a

because display_toggles.js has <Link to="/forms/compressed-forms">

@cchaos
Copy link
Contributor

cchaos commented Jun 4, 2020

I think eventually the "Playground" will allow us to get rid of the DisplayToggles. Perhaps just ignore all those examples for now?

@snide
Copy link
Contributor Author

snide commented Jun 4, 2020

I had them working before these latest commits / changes from CS. I'll double check on them and see what's up. It touches a lot of our examples, so i wanted to make sure they worked.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@snide
Copy link
Contributor Author

snide commented Jun 4, 2020

OK. Fix was to just not use react-router for that link, an use a simple href. It acts as it did before. Ultimately we can use playgrounds for this stuff, but for the moment I think it's really important to spin up a CS for any form element really quicky, which is why I think it's worth the very minor inconvenience of having to use an href there.

@snide
Copy link
Contributor Author

snide commented Jun 4, 2020

@cchaos also added a notice in our PR template as we mentioned. I think this one looks good to merge. TY to @chandlerprall for the regex fix.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

👍 Aside from the awesomeness of quickly getting to edit the example, I like that the home page link to Codesandbox is now super generic, that faker works, and TS docs can import from /components now. 🥳

EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

^^ Can delete now?

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@snide
Copy link
Contributor Author

snide commented Jun 4, 2020

retest

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2728/

@snide
Copy link
Contributor Author

snide commented Jun 5, 2020

This is passing, and I think I've gotten to the feedback. I'm going to do a merge since this one touches so many files and I want to avoid conflicts. Since it's a docs level change I think this is pretty safe.

@snide snide merged commit 9d54fd5 into elastic:master Jun 5, 2020
@snide snide deleted the demo/sandbox branch June 5, 2020 01:13
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