-
Notifications
You must be signed in to change notification settings - Fork 0
Frontend Docs need Updated #166
Comments
As of today most of the docs have been updated. The only doc that still needs to be updated is ItemBodyView. The doc for this component gives an error related to the theme palette that we created. Once this issue is addressed all the docs will be updated. |
react-stylguidist does not support context managers therefore AuthProvider and other context dependent components cannot be used in the docs. These components can still be documented though. |
A lack of support for context managers in react-styleguidist and our new dependency on context for Auth and Item management means we cannot document some of our components using this system. We need to look into alternatives. |
Storybook seems to be a solid alternative to react-styleguidist that would allow us to use context managers in our documentation. Storybook includes these features:
It also supports the use of context providers through mocking components. I will update the issue with a more in-depth look at how this works and how it can be used for our project. |
As mentioned in my previous comment, Storybook seems like a good alternative to react-stylguidist due to its large feature set and its ability to work with context providers. I will give an overview of the features that are available with Storybook. DocumentationStorybook offers a variety of ways to document components. Storybook provides by default what they call a DocsPage which requires no configuration and combines all text descriptions, docgen comments, args tables, and code examples into a single page for each component. There is also the option to override the DocsPage with a variety of options:
Currently, all of the documentation for the frontend is written using MD so migrating to MDX and Storybook should be a simple process due to the syntax being similar and its ability to have JSX component blocks in the file. TestingStorybook offers us the ability to work with components individually and save different states as stories. These stories allow us to see each state of the component. Storybook offers these testing methods:
Overall, the testing abilities of Storybook seem useful as we have also been looking into ways to test front end changes as stated in #22 Add-onsAdd-ons allow Storybook to have additional features that are not present in the core build. Most features are implemented as add-ons. There are useful add-ons that allow us to test things like accessibility and responsive design as well as giving us the ability to use our own Context providers. ConclusionStorybook seems to be a powerful tool that will allow us to not only document our components but also offers solid options for implementing frontend testing which is an important aspect of the project that needs to be added. |
For clarification here is the definition of a "story" as defined by Storybook:
Essential a story is the different states that a component can be presented in as well as the props or args as they are referred to by Storybook that allows the components to be dynamically altered to see how different changes impact the component. |
Here is an example of how Storybook docs look and how to write a story. Set upTo install Storybook their docs run this command:
This will install the Storybook CLI. This command is not made for empty projects as it uses you existing project to determine how to setup Storybook for the project. Once installed, run this command to start Storybook:
This will open Storybook on localhost:6006. Here you will find the Storybook welcome screen that has some useful items such as:
Storybook comes with two CLI utilities Naming the DocumentationIn order to write docs with Storybook all documentation files should be named using the following naming convention:
Our current documentation is written in Markdown so it makes the most sense for us to use MDX which allows us to write JSX straight into Markdown documents. In this example I will use the ItemTable component so the docs should be named To write the story we need to add a few import statements to our MDX file import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';
import ItemTable from './ItemTable';
As stated above, the <Meta title="ItemTable" component={ItemTable} /> Getting the props of the componentTo get the props of the component being documented we need to export the component as a export const Template = (props) => <ItemTable {...props} /> Adding a storyTo reiterate, stories are examples of the different states of a component. In this example for Loading <Canvas>
<Story name="Loading" args={{
data: [],
rowCanBeSelected:false,
loading:true,
}}>
{Template.bind({})}
</Story>
</Canvas> Loaded <Canvas>
<Story name="Loaded" args={{
data: [
{"queue": "ce", "number": 9, "lastUpdated": "09-11-20 12:14 PM", "isLocked": false, "userEmail": "lslusher@purdue.edu", "userName": "Slusher, Laura M", "userAlias": "lslusher", "assignedTo": "bekuma", "subject": "RE: New laptop", "status": "waiting on reply/time to call", "priority": "deploy", "department": "che", "building": "frny", "dateReceived": "2020-03-12T18:07:27+0000"},
{"queue": "ce", "number": 42, "lastUpdated": "09-11-20 12:14 PM", "isLocked": false, "userEmail": "feng293@purdue.edu", "userName": "", "userAlias": "feng293", "assignedTo": "schmid22", "subject": "Upgrade system and Abaqus", "status": "", "priority": "", "department": "", "building": "", "dateReceived": "2020-05-14T10:21:32-0400"},
{"queue": "ce", "number": 51, "lastUpdated": "09-11-20 12:14 PM", "isLocked": false, "userEmail": "jclauso@purdue.edu", "userName": "", "userAlias": "jclauso", "assignedTo": "schmid22", "subject": "ECN privileges for future grad student", "status": "Waiting for reply", "priority": "", "department": "", "building": "", "dateReceived": "2020-05-14T15:03:07-0400"}
],
rowCanBeSelected:false,
loading:false,
}}>
{Template.bind({})}
</Story>
</Canvas> In this example first, we wrapped the
Here is the full code for the ItemTable docs using Storybook and what it looks like import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';
import ItemTable from './ItemTable';
The ItemTable is the primary view for webqueue2. It displays item metadata for items of selected queues and allows for filtering by field and opening an item by clicking. Items are passed in as a required parameter. It is to be used with the [ItemTableAppBar](/#/Components/ItemTableAppBar).
It is based on [react-table](https://react-table.tanstack.com/).
<Meta title="ItemTable" component={ItemTable} />
export const Template = (props) => <ItemTable {...props} />
# ItemTable With Content
<Canvas>
<Story name="Loaded" args={{
data: [
{"queue": "ce", "number": 9, "lastUpdated": "09-11-20 12:14 PM", "isLocked": false, "userEmail": "lslusher@purdue.edu", "userName": "Slusher, Laura M", "userAlias": "lslusher", "assignedTo": "bekuma", "subject": "RE: New laptop", "status": "waiting on reply/time to call", "priority": "deploy", "department": "che", "building": "frny", "dateReceived": "2020-03-12T18:07:27+0000"},
{"queue": "ce", "number": 42, "lastUpdated": "09-11-20 12:14 PM", "isLocked": false, "userEmail": "feng293@purdue.edu", "userName": "", "userAlias": "feng293", "assignedTo": "schmid22", "subject": "Upgrade system and Abaqus", "status": "", "priority": "", "department": "", "building": "", "dateReceived": "2020-05-14T10:21:32-0400"},
{"queue": "ce", "number": 51, "lastUpdated": "09-11-20 12:14 PM", "isLocked": false, "userEmail": "jclauso@purdue.edu", "userName": "", "userAlias": "jclauso", "assignedTo": "schmid22", "subject": "ECN privileges for future grad student", "status": "Waiting for reply", "priority": "", "department": "", "building": "", "dateReceived": "2020-05-14T15:03:07-0400"}
],
rowCanBeSelected:false,
loading:false,
}}>
{Template.bind({})}
</Story>
</Canvas>
# ItemTable Loading Content
<Canvas>
<Story name="Loading" args={{
data: [],
rowCanBeSelected:false,
loading:true,
}}>
{Template.bind({})}
</Story>
</Canvas> CanvasThe Canvas view in Storybook allows for interaction with the component in real-time, allowing users to see how changes to the props impact the component. Here is an example of interacting with the component in the canvas view: |
Implementing the docs using Storybook for ItemView has been difficult. I'm having trouble getting the context to be passed to the component so that it will render the data from the item. I think part of the issue is that the |
All of the docs have been migrated from react-styleguidist to Storybook. Some docs may still need to be worked on depending on if they function properly after the changes to how we load items in the table (#8) |
Currently, the docs don't display how components look when the dark mode color palette, which is important not only so that people that look at our documentation can see how the two versions of the component differ but also so that we can see how these changes affect component if we decide to use Storybook for testing docs as well. I'm still testing to see if there is a way to accomplish this without using any more Storybook addons. If its not possible there is a Storybook addon called storybook-dark-mode that seems like it would be easy enough to implement. |
Storybook offers the ability to add icons to the toolbar so that users can interact with the canvas using the toolbar. In our case, we would want users to be able to set the theme palette for a component based on the value that the select with the toolbar button. The problem that I'm facing right now is that based on my understanding of the documentation here only string values can be used for the toolbar button values. This is a problem because of how we define whether the dark mode theme should be the active theme. Our theme is determined based on a boolean. I have tried to use a state variable to set the theme based on which string value is selected with the toolbar icon but that hasn't worked, I think another viable course of action may be to just create a story for the dark mode variant of our components. Based on the docs here we should be able to define a decorator that passes the theme for individual stories in a similar way that we are passing it globally. |
Here is an explanation of how the dark mode toggle was added to the toolbar. GlobalsGlobals in Storybook represent non-story-specific inputs to the rendering of the story. These inputs aren't passed to the story arguments but can be accessed as Creating a toolbar actionTo create a toolbar action in the export const globalTypes = {
//This is the name of the global. To reference this in stories you would use context.globals.theme
theme: {
//The name of the toolbar action
name: 'Set Dark Mode',
//The description of the toolbar action.
//This is displayed when the icon is being hovered over.
description: 'Global theme for components',
//The default value of the global.
defaultValue: false,
//This lets Storybook know that you are creating a toolbar action.
toolbar: {
//Defines the icon that is displayed in the toolbar
icon: 'mirror',
//An array of items that can be selected from the dropdown when the toolbar action is selected.
items: [
//Value is what the global's value will be set to.
//The title is what will show in the dropdown menu.
//The icon is what icon will display when that item is selected.
{ value: true, title: "Dark Mode active", icon: "contrast" },
{ value: false, title: "Dark Mode off", icon: "switchalt" }
],
},
},
}; Creating a decoratorNow that our global is defined we can use it with a decorator to change how our stories are rendered based on the value of the global. In the storybook/preview.js config you can define a decorator to consume that value. In our case we are using the global value in conjunction with our ThemeProvider from Material-UI to toggle dark mode. Below is an example from our code. const withThemeProvider = (Story, context) => {
//Here the them is set to our webqueueTheme which acceprs
const theme = webqueueTheme(context.globals.theme);
return (
<ThemeProvider theme={theme} >
<Story {...context} />
</ThemeProvider>
)
} You can then add this decorator to the array of decorators. Here is the example from our code. export const decorators = [
(Story) => (
<ItemProvider>
<Story />
</ItemProvider>
),
withThemeProvider
]; With that, we have defined a global, gave it an action/icon in the toolbar, passed its value to be used in a decorator, and applied that decorator to all of our stories. Globals can also be passed to stories and addons by referencing the value of the global. In our case, this would be referenced by using |
Working on this. |
Docs have been updated. Styleguidist integrations were removed. Storybook was integrated. Some cleaning was also done to remove stale files. |
Some components have out of date docs. Other components have no docs. These need to be updated.
The text was updated successfully, but these errors were encountered: