Skip to content

chore(site): refactor stories and tests from components directory #9578

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

Merged
merged 47 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8499bcb
Refactor Alert
BrunoQuaresma Sep 6, 2023
848167d
Refactor Avatar and its stories
BrunoQuaresma Sep 6, 2023
1e43257
Refactor AvatarData and its stories
BrunoQuaresma Sep 6, 2023
b091ef8
Refactor CodeExample and its tests
BrunoQuaresma Sep 6, 2023
ad81b13
Refactor ServiceBanner stories
BrunoQuaresma Sep 6, 2023
9f15bee
Refactor Navbar and its tests
BrunoQuaresma Sep 6, 2023
f46a763
Refactor ServiceBanner stories
BrunoQuaresma Sep 6, 2023
1cd9b18
Merge branch 'main' of https://github.com/coder/coder into bq/review-…
BrunoQuaresma Sep 7, 2023
86c76e5
Refactor LicenseBannerView stories
BrunoQuaresma Sep 7, 2023
a8bb51c
Refactor DeploymentBannerView stories
BrunoQuaresma Sep 7, 2023
dab8aab
Extract optionValue into a module
BrunoQuaresma Sep 7, 2023
70ef3da
Refactor DeleteDialog stories
BrunoQuaresma Sep 7, 2023
c164087
Refactor ConfirmDialog tests
BrunoQuaresma Sep 7, 2023
fed2622
Refactor EmptyState tests
BrunoQuaresma Sep 7, 2023
c0cfc3c
Flat ErrorBoundaryState and refactor stories
BrunoQuaresma Sep 7, 2023
bb13012
Refactor Expander stories
BrunoQuaresma Sep 7, 2023
e41349c
Refactor FormFooter stories
BrunoQuaresma Sep 7, 2023
984b55e
Refactor FullPageForm stories
BrunoQuaresma Sep 7, 2023
dd8000f
Refactor EnterpriseSnackbar stories
BrunoQuaresma Sep 7, 2023
92fe723
Refactor GroupAvatar stories
BrunoQuaresma Sep 7, 2023
5f9c165
Refactor HelpTooltip stories and remove index
BrunoQuaresma Sep 7, 2023
c9f1371
Remove unecessary types module from IconField
BrunoQuaresma Sep 7, 2023
c4cd628
Refactor LoadingButton stories
BrunoQuaresma Sep 7, 2023
2800c67
Refactor Margins stories
BrunoQuaresma Sep 7, 2023
f30845b
Refactor Markdown stories
BrunoQuaresma Sep 7, 2023
18611c8
Refactor PageHeader stories
BrunoQuaresma Sep 7, 2023
899b08e
Refactor PageButton tests
BrunoQuaresma Sep 7, 2023
df63af5
Refactor Pill stories
BrunoQuaresma Sep 7, 2023
772d15d
Refactor Resources stories
BrunoQuaresma Sep 7, 2023
8ece699
Refactor RichParameterInput stories and flat MultiTextField
BrunoQuaresma Sep 7, 2023
a6597c0
Remove unecessary Stack story
BrunoQuaresma Sep 7, 2023
fc19d73
Refactor TableRowMenu stories
BrunoQuaresma Sep 7, 2023
807d3b3
Refactor TemplateLayout stories
BrunoQuaresma Sep 7, 2023
dbf2efc
Refactor Typography props
BrunoQuaresma Sep 7, 2023
2fe608f
Refactor UserAutocomplete
BrunoQuaresma Sep 7, 2023
88666c6
Refactor WorkspaceBuildLogs components and tests
BrunoQuaresma Sep 7, 2023
01259db
Refactor WorkspaceStatusBadge stories
BrunoQuaresma Sep 7, 2023
e791954
Fix wrong imports
BrunoQuaresma Sep 7, 2023
e595ca0
Remove Example.args pattern
BrunoQuaresma Sep 7, 2023
fff8f08
Fix wrong import
BrunoQuaresma Sep 7, 2023
7ac6e78
Refactor EmptyState stories
BrunoQuaresma Sep 7, 2023
2320111
Refactor HelpTooltip stories
BrunoQuaresma Sep 7, 2023
780cb6e
Remove not valid ErrorAlert story
BrunoQuaresma Sep 7, 2023
6373408
Fix AvatarData story
BrunoQuaresma Sep 7, 2023
1a3e58b
Add border back to CodeExample
BrunoQuaresma Sep 7, 2023
cd65980
Fix Navbar story
BrunoQuaresma Sep 7, 2023
f6dcba8
Fix AgentRow proxy in the stories
BrunoQuaresma Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions site/src/components/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Alert } from "./Alert";
import Button from "@mui/material/Button";
import Link from "@mui/material/Link";
import type { Meta, StoryObj } from "@storybook/react";

const meta: Meta<typeof Alert> = {
Expand All @@ -21,7 +20,6 @@ export const Success: Story = {
args: {
children: "You're doing great!",
severity: "success",
onRetry: undefined,
},
};

Expand Down Expand Up @@ -56,14 +54,3 @@ export const WarningWithActionAndDismiss: Story = {
severity: "warning",
},
};

export const WithChildren: Story = {
args: {
severity: "warning",
children: (
<div>
This is a message with a <Link href="#">link</Link>
</div>
),
},
};
9 changes: 0 additions & 9 deletions site/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import Box from "@mui/material/Box";
export type AlertProps = MuiAlertProps & {
actions?: ReactNode;
dismissible?: boolean;
onRetry?: () => void;
onDismiss?: () => void;
};

export const Alert: FC<AlertProps> = ({
children,
actions,
onRetry,
dismissible,
severity,
onDismiss,
Expand All @@ -34,13 +32,6 @@ export const Alert: FC<AlertProps> = ({
{/* CTAs passed in by the consumer */}
{actions}

{/* retry CTA */}
{onRetry && (
<Button variant="text" size="small" onClick={onRetry}>
Retry
</Button>
)}

{/* close CTA */}
{dismissible && (
<Button
Expand Down
17 changes: 0 additions & 17 deletions site/src/components/Alert/ErrorAlert.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Button from "@mui/material/Button";
import { mockApiError } from "testHelpers/entities";
import type { Meta, StoryObj } from "@storybook/react";
import { action } from "@storybook/addon-actions";
import { ErrorAlert } from "./ErrorAlert";

const mockError = mockApiError({
Expand All @@ -15,7 +14,6 @@ const meta: Meta<typeof ErrorAlert> = {
args: {
error: mockError,
dismissible: false,
onRetry: undefined,
},
};

Expand Down Expand Up @@ -55,21 +53,6 @@ export const WithActionAndDismiss: Story = {
},
};

export const WithRetry: Story = {
args: {
onRetry: action("retry"),
dismissible: true,
},
};

export const WithActionRetryAndDismiss: Story = {
args: {
actions: [ExampleAction],
onRetry: action("retry"),
dismissible: true,
},
};

export const WithNonApiError: Story = {
args: {
error: new Error("Non API error here"),
Expand Down
86 changes: 47 additions & 39 deletions site/src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,71 @@
import { Story } from "@storybook/react";
import { Avatar, AvatarIcon, AvatarProps } from "./Avatar";
import type { Meta, StoryObj } from "@storybook/react";
import { Avatar, AvatarIcon } from "./Avatar";
import PauseIcon from "@mui/icons-material/PauseOutlined";

export default {
const meta: Meta<typeof Avatar> = {
title: "components/Avatar",
component: Avatar,
};

const Template: Story<AvatarProps> = (args: AvatarProps) => (
<Avatar {...args} />
);
export default meta;
type Story = StoryObj<typeof Avatar>;

export const Letter = Template.bind({});
Letter.args = {
children: "Coder",
export const Letter: Story = {
args: {
children: "Coder",
},
};

export const LetterXL = Template.bind({});
LetterXL.args = {
children: "Coder",
size: "xl",
export const LetterXL = {
args: {
children: "Coder",
size: "xl",
},
};

export const LetterDarken = Template.bind({});
LetterDarken.args = {
children: "Coder",
colorScheme: "darken",
export const LetterDarken = {
args: {
children: "Coder",
colorScheme: "darken",
},
};

export const Image = Template.bind({});
Image.args = {
src: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
export const Image = {
args: {
src: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
},
};

export const ImageXL = Template.bind({});
ImageXL.args = {
src: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
size: "xl",
export const ImageXL = {
args: {
src: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
size: "xl",
},
};

export const MuiIcon = Template.bind({});
MuiIcon.args = {
children: <PauseIcon />,
export const MuiIcon = {
args: {
children: <PauseIcon />,
},
};

export const MuiIconDarken = Template.bind({});
MuiIconDarken.args = {
children: <PauseIcon />,
colorScheme: "darken",
export const MuiIconDarken = {
args: {
children: <PauseIcon />,
colorScheme: "darken",
},
};

export const MuiIconXL = Template.bind({});
MuiIconXL.args = {
children: <PauseIcon />,
size: "xl",
export const MuiIconXL = {
args: {
children: <PauseIcon />,
size: "xl",
},
};

export const AvatarIconDarken = Template.bind({});
AvatarIconDarken.args = {
children: <AvatarIcon src="/icon/database.svg" />,
colorScheme: "darken",
export const AvatarIconDarken = {
args: {
children: <AvatarIcon src="/icon/database.svg" />,
colorScheme: "darken",
},
};
10 changes: 8 additions & 2 deletions site/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import MuiAvatar, { AvatarProps as MuiAvatarProps } from "@mui/material/Avatar";
import { makeStyles } from "@mui/styles";
import { FC } from "react";
import { combineClasses } from "utils/combineClasses";
import { firstLetter } from "./firstLetter";

export type AvatarProps = MuiAvatarProps & {
size?: "sm" | "md" | "xl";
Expand Down Expand Up @@ -32,7 +31,6 @@ export const Avatar: FC<AvatarProps> = ({
fitImage && styles.fitImage,
])}
>
{/* If the children is a string, we always want to render the first letter */}
{typeof children === "string" ? firstLetter(children) : children}
</MuiAvatar>
);
Expand All @@ -46,6 +44,14 @@ export const AvatarIcon: FC<{ src: string }> = ({ src }) => {
return <img src={src} alt="" className={styles.avatarIcon} />;
};

const firstLetter = (str: string): string => {
if (str.length > 0) {
return str[0].toLocaleUpperCase();
}

return "";
};

const useStyles = makeStyles((theme) => ({
// Size styles
sm: {
Expand Down
11 changes: 0 additions & 11 deletions site/src/components/Avatar/firstLetter.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions site/src/components/Avatar/firstLetter.ts

This file was deleted.

30 changes: 14 additions & 16 deletions site/src/components/AvatarData/AvatarData.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { Story } from "@storybook/react";
import { AvatarData, AvatarDataProps } from "./AvatarData";
import type { Meta, StoryObj } from "@storybook/react";
import { AvatarData } from "./AvatarData";

export default {
const meta: Meta<typeof AvatarData> = {
title: "components/AvatarData",
component: AvatarData,
args: {
title: "coder",
subtitle: "coder@coder.com",
},
};

const Template: Story<AvatarDataProps> = (args: AvatarDataProps) => (
<AvatarData {...args} />
);
export default meta;
type Story = StoryObj<typeof AvatarData>;

export const Example = Template.bind({});
Example.args = {
title: "coder",
subtitle: "coder@coder.com",
};
export const WithTitleAndSubtitle: Story = {};

export const WithImage = Template.bind({});
WithImage.args = {
title: "coder",
subtitle: "coder@coder.com",
src: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
export const WithImage: Story = {
args: {
src: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
},
};
4 changes: 2 additions & 2 deletions site/src/components/AvatarData/AvatarData.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Avatar } from "components/Avatar/Avatar";
import { FC, PropsWithChildren } from "react";
import { FC } from "react";
import { Stack } from "components/Stack/Stack";
import { makeStyles } from "@mui/styles";

Expand All @@ -10,7 +10,7 @@ export interface AvatarDataProps {
avatar?: React.ReactNode;
}

export const AvatarData: FC<PropsWithChildren<AvatarDataProps>> = ({
export const AvatarData: FC<AvatarDataProps> = ({
title,
subtitle,
src,
Expand Down
25 changes: 13 additions & 12 deletions site/src/components/CodeExample/CodeExample.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { Story } from "@storybook/react";
import { CodeExample, CodeExampleProps } from "./CodeExample";
import type { Meta, StoryObj } from "@storybook/react";
import { CodeExample } from "./CodeExample";

const sampleCode = `echo "Hello, world"`;

export default {
const meta: Meta<typeof CodeExample> = {
title: "components/CodeExample",
component: CodeExample,
argTypes: {
code: { control: "string", defaultValue: sampleCode },
},
};

const Template: Story<CodeExampleProps> = (args: CodeExampleProps) => (
<CodeExample {...args} />
);
export default meta;
type Story = StoryObj<typeof CodeExample>;

export const Example = Template.bind({});
Example.args = {
code: sampleCode,
export const Example: Story = {
args: {
code: sampleCode,
},
};

export const LongCode = Template.bind({});
LongCode.args = {
code: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICnKzATuWwmmt5+CKTPuRGN0R1PBemA+6/SStpLiyX+L",
export const LongCode: Story = {
args: {
code: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICnKzATuWwmmt5+CKTPuRGN0R1PBemA+6/SStpLiyX+L",
},
};
14 changes: 0 additions & 14 deletions site/src/components/CodeExample/CodeExample.test.tsx

This file was deleted.

Loading