Skip to content

Commit

Permalink
housekeeping: Updating Storybook to v8 (#3125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdslaugh authored Oct 18, 2024
1 parent 56d96b2 commit 45a288d
Show file tree
Hide file tree
Showing 13 changed files with 988 additions and 4,072 deletions.
23 changes: 19 additions & 4 deletions frontend/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/** @format */

import { dirname, join } from "path";
import { StorybookConfig } from "@storybook/react-webpack5";

const config: StorybookConfig = {
stories: ["../packages/**/*.stories.@(tsx|jsx)"],

typescript: {
reactDocgen: "react-docgen-typescript",
reactDocgenTypescriptOptions: {
Expand All @@ -11,10 +15,12 @@ const config: StorybookConfig = {
},
},
},

framework: {
name: "@storybook/react-webpack5",
name: getAbsolutePath("@storybook/react-webpack5"),
options: { fastRefresh: true },
},

webpackFinal: async (config, { configType }) => {
config?.module?.rules?.push({
test: /\.(ts|tsx)$/,
Expand All @@ -32,6 +38,7 @@ const config: StorybookConfig = {

return config;
},

babel: async (options) => ({
...options,
plugins: [
Expand All @@ -41,11 +48,19 @@ const config: StorybookConfig = {
["@babel/plugin-proposal-class-properties", { loose: true }],
],
}),

addons: [
"@storybook/addon-essentials",
"@storybook/addon-links",
"@storybook/addon-a11y",
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-a11y"),
getAbsolutePath("@storybook/preset-create-react-app"),
],

docs: {},
};

export default config;

function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
}
4 changes: 2 additions & 2 deletions frontend/.storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addons } from "@storybook/addons";
import { addons } from "@storybook/manager-api";
import storybookTheme from "./theme";

addons.setConfig({
theme: storybookTheme,
});
});
3 changes: 3 additions & 0 deletions frontend/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @format */

import React from "react";
import { Theme } from "./../packages/core/src/AppProvider/themes";

Expand Down Expand Up @@ -28,6 +30,7 @@ export const parameters = {
const preview = {
decorators,
parameters,
tags: ["autodocs"],
};

export default preview;
20 changes: 11 additions & 9 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,24 @@
"typescript": "^4.2.3"
},
"devDependencies": {
"@storybook/addon-a11y": "^7.6.0",
"@storybook/addon-actions": "^7.6.0",
"@storybook/addon-essentials": "^7.6.0",
"@storybook/addon-links": "^7.6.0",
"@storybook/node-logger": "^7.6.0",
"@storybook/preset-typescript": "^3.0.0",
"@storybook/react-webpack5": "^7.6.0",
"@storybook/theming": "^7.6.0",
"@storybook/addon-a11y": "^8.3.3",
"@storybook/addon-actions": "^8.3.3",
"@storybook/addon-essentials": "^8.3.3",
"@storybook/addon-links": "^8.3.3",
"@storybook/addon-themes": "^8.3.3",
"@storybook/manager-api": "^8.3.3",
"@storybook/node-logger": "^8.3.3",
"@storybook/preset-create-react-app": "^8.3.3",
"@storybook/react-webpack5": "^8.3.3",
"@storybook/theming": "^8.3.3",
"@types/eslint": "^8",
"jest": "^27.0.0",
"license-checker": "^25.0.1",
"pre-commit": "^1.2.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sort-package-json": "^1.48.1",
"storybook": "^7.6.0",
"storybook": "^8.3.3",
"typescript": "^4.2.3"
},
"engines": {
Expand Down
12 changes: 10 additions & 2 deletions frontend/packages/core/src/AppLayout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ interface HeaderProps extends AppConfiguration {
* Will enable the user information component in the header
*/
userInfo?: boolean;
/**
* The banners to render
*/
banners?: AppBanners;
/**
* The children to render
*/
children?: React.ReactNode;
}

const AppBar = styled(MuiAppBar)(({ theme }: { theme: Theme }) => ({
Expand Down Expand Up @@ -72,7 +79,7 @@ const StyledLogo = styled("img")({
verticalAlign: "middle",
});

const Header: React.FC<HeaderProps> = ({
const Header = ({
title = "clutch",
logo = <Logo />,
banners,
Expand All @@ -83,7 +90,7 @@ const Header: React.FC<HeaderProps> = ({
notifications = false,
userInfo = true,
children = null,
}) => {
}: HeaderProps) => {
return (
<>
<AppBar position="fixed" elevation={0}>
Expand Down Expand Up @@ -129,3 +136,4 @@ const Header: React.FC<HeaderProps> = ({
};

export default Header;
export { Header };
2 changes: 1 addition & 1 deletion frontend/packages/core/src/AppLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Loadable from "../loading";
import type { AppConfiguration } from "../Types";

import Drawer from "./drawer";
import Header, { APP_BAR_HEIGHT } from "./header";
import { APP_BAR_HEIGHT, Header } from "./header";

const AppGrid = styled(MuiGrid)({
flex: 1,
Expand Down
15 changes: 9 additions & 6 deletions frontend/packages/core/src/AppLayout/stories/drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { MemoryRouter } from "react-router";
import { Grid } from "@mui/material";
import type { Meta } from "@storybook/react";

import { UserPreferencesProvider } from "../../Contexts";
import { ApplicationContext } from "../../Contexts/app-context";
import Drawer from "../drawer";
import Header from "../header";
import { Header } from "../header";

export default {
title: "Core/AppLayout/Drawer",
title: "Core/Layout/Drawer",
component: Drawer,
decorators: [
StoryFn => (
Expand Down Expand Up @@ -64,8 +65,10 @@ export default {
export const Primary = () => <Drawer />;

export const WithHeader = () => (
<Grid container direction="column">
<Header />
<Drawer />
</Grid>
<UserPreferencesProvider>
<Grid container direction="column">
<Header />
<Drawer />
</Grid>
</UserPreferencesProvider>
);
116 changes: 62 additions & 54 deletions frontend/packages/core/src/AppLayout/stories/header.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,70 @@
import * as React from "react";
import { MemoryRouter } from "react-router";
import type { Meta } from "@storybook/react";
import type { Meta, StoryObj } from "@storybook/react";

import { ApplicationContext } from "../../Contexts/app-context";
import HeaderComponent from "../header";
import { ApplicationContext, UserPreferencesProvider } from "../../Contexts";
import { Header } from "../header";

export default {
title: "Core/AppLayout/Header",
component: HeaderComponent,
const workflows = [
{
developer: { name: "Lyft", contactUrl: "mailto:hello@clutch.sh" },
displayName: "EC2",
group: "AWS",
icon: { path: "" },
path: "ec2",
routes: [
{
component: () => <div>Terminate Instance</div>,
componentProps: { resolverType: "clutch.aws.ec2.v1.Instance" },
description: "Terminate an EC2 instance.",
displayName: "Terminate Instance",
path: "instance/terminate",
requiredConfigProps: ["resolverType"],
trending: true,
},
{
component: () => <div>Resize ASG</div>,
componentProps: { resolverType: "clutch.aws.ec2.v1.AutoscalingGroup" },
description: "Resize an autoscaling group.",
displayName: "Resize Autoscaling Group",
path: "asg/resize",
requiredConfigProps: ["resolverType"],
},
],
},
];

const meta: Meta<typeof Header> = {
title: "Core/Layout/Header",
component: Header,
argTypes: {
logo: {
control: "text",
},
},
decorators: [
() => (
<MemoryRouter>
<HeaderComponent />
</MemoryRouter>
),
StoryFn => {
return (
<ApplicationContext.Provider
// eslint-disable-next-line react/jsx-no-constructed-context-values
value={{
workflows: [
{
developer: { name: "Lyft", contactUrl: "mailto:hello@clutch.sh" },
displayName: "EC2",
group: "AWS",
icon: { path: "" },
path: "ec2",
routes: [
{
component: () => <div>Terminate Instance</div>,
componentProps: { resolverType: "clutch.aws.ec2.v1.Instance" },
description: "Terminate an EC2 instance.",
displayName: "Terminate Instance",
path: "instance/terminate",
requiredConfigProps: ["resolverType"],
trending: true,
},
{
component: () => <div>Resize ASG</div>,
componentProps: { resolverType: "clutch.aws.ec2.v1.AutoscalingGroup" },
description: "Resize an autoscaling group.",
displayName: "Resize Autoscaling Group",
path: "asg/resize",
requiredConfigProps: ["resolverType"],
},
],
},
],
}}
>
StoryFn => (
<ApplicationContext.Provider
// eslint-disable-next-line react/jsx-no-constructed-context-values
value={{
workflows,
}}
>
<UserPreferencesProvider>
<StoryFn />
</ApplicationContext.Provider>
);
},
</UserPreferencesProvider>
</ApplicationContext.Provider>
),
],
parameters: {
layout: "fullscreen",
},
} as Meta;
};

export default meta;
type Story = StoryObj<typeof Header>;

export const Header: React.FC<{}> = () => <HeaderComponent />;
export const Basic: Story = {
render: args => (
<MemoryRouter>
<Header {...args} />
</MemoryRouter>
),
};
2 changes: 1 addition & 1 deletion frontend/packages/core/src/AppProvider/registrar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const registeredWorkflows = async (
): Promise<Workflow[]> => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async resolve => {
let validWorkflows = Object.keys(workflows || [])
let validWorkflows: Workflow[] = Object.keys(workflows || [])
.map((workflowId: string) => {
const workflow = workflows[workflowId]();
const icon = configuration?.[workflowId]?.icon || { path: "" };
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/core/src/AppProvider/workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface Workflow extends BaseWorkflowConfiguration, WorkflowShortlinkCo
* this will override the default avatar.
* { path: string }
*/
icon: WorkflowIcon;
icon?: WorkflowIcon;
/**
* Configured routes allow for the optional properties of `trending` (whether to display
* on homepage) and `componentProps` which allow the passing of workflow/route
Expand Down
14 changes: 8 additions & 6 deletions frontend/packages/core/src/NPS/stories/banner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from "react";
import { MemoryRouter } from "react-router";
import type { Meta } from "@storybook/react";

import Header from "../../AppLayout/header";
import { Header } from "../../AppLayout/header";
import { HappyEmoji, NeutralEmoji, SadEmoji } from "../../Assets/emojis";
import { ApplicationContext } from "../../Contexts";
import { ApplicationContext, UserPreferencesProvider } from "../../Contexts";
import type { HeaderItem, TriggeredHeaderData } from "../../Contexts/app-context";
import type { FeedbackBannerProps } from "../banner";
import { Banner } from "../banner";
Expand Down Expand Up @@ -65,10 +65,12 @@ const Template = ({ ...props }: FeedbackBannerProps) => {
triggeredHeaderData,
}}
>
<MemoryRouter>
<Header enableNPS />
<Banner {...props} />
</MemoryRouter>
<UserPreferencesProvider>
<MemoryRouter>
<Header enableNPS />
<Banner {...props} />
</MemoryRouter>
</UserPreferencesProvider>
</ApplicationContext.Provider>
);
};
Expand Down
12 changes: 7 additions & 5 deletions frontend/packages/core/src/NPS/stories/header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from "react";
import { MemoryRouter } from "react-router";
import type { Meta } from "@storybook/react";

import Header from "../../AppLayout/header";
import { ApplicationContext } from "../../Contexts";
import { Header } from "../../AppLayout/header";
import { ApplicationContext, UserPreferencesProvider } from "../../Contexts";
import { NPSHeader } from "..";

export default {
Expand Down Expand Up @@ -46,9 +46,11 @@ const Template = () => (
],
}}
>
<MemoryRouter>
<Header enableNPS />
</MemoryRouter>
<UserPreferencesProvider>
<MemoryRouter>
<Header enableNPS />
</MemoryRouter>
</UserPreferencesProvider>
</ApplicationContext.Provider>
);

Expand Down
Loading

0 comments on commit 45a288d

Please sign in to comment.