Skip to content

Commit

Permalink
Merge branch 'main' into 239-sidebarbottom-create-story-for-visual-te…
Browse files Browse the repository at this point in the history
…st-coverage
  • Loading branch information
ghengeveld committed Jun 28, 2024
2 parents 96ff63d + 3465e9d commit cd7ca71
Show file tree
Hide file tree
Showing 26 changed files with 18,889 additions and 12,827 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fetch-depth: 0

- name: Install dependencies
run: yarn install --ignore-scripts
run: yarn install --immutable

- name: Publish to Chromatic
uses: chromaui/action@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: git fetch --unshallow --tags

- name: Install dependencies
run: yarn install --ignore-scripts
run: yarn install --immutable

- name: Create Release
run: yarn run release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
uses: actions/checkout@v3

- name: Install dependencies
run: yarn install --ignore-scripts
run: yarn install --immutable

- name: Lint
run: yarn lint
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ build-storybook.log
chromatic.log
chromatic-build-*.xml
chromatic-diagnostics.json

**/.pnp.*
**/.yarn/*
!**/.yarn/patches
!**/.yarn/plugins
!**/.yarn/releases
!**/.yarn/sdks
!**/.yarn/versions
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"],
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
894 changes: 894 additions & 0 deletions .yarn/releases/yarn-berry.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-berry.cjs
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"prerelease": "zx scripts/prepublish-checks.mjs",
"release": "yarn run build && auto shipit",
"start": "run-p build:watch 'storybook --quiet'",
"storybook": "CHROMATIC_ADDON_NAME='../src/dev.ts' storybook dev -p 6006",
"storybook-from-dist": "CHROMATIC_USE_DIST_VERSION=true CHROMATIC_ADDON_NAME='../dist/index.js' storybook dev -p 6006",
"storybook": "CHROMATIC_ADDON_NAME='../src/dev.ts' storybook dev -p 6004",
"storybook-from-dist": "CHROMATIC_USE_DIST_VERSION=true CHROMATIC_ADDON_NAME='../dist/index.js' storybook dev -p 6004",
"test": "vitest",
"typecheck": "tsc --noemit"
},
Expand Down Expand Up @@ -137,6 +137,7 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"packageManager": "yarn@4.1.1",
"bundler": {
"exportEntries": [
"./src/index.ts"
Expand Down
18 changes: 9 additions & 9 deletions src/components/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ComponentProps } from "react";

import { IconButton } from "./IconButton";

const themeColors = ({ theme, secondary, status }: { theme: Theme } & ActionButtonProps) => {
if (secondary) {
const themeColors = ({ theme, status, variant }: { theme: Theme } & ActionButtonProps) => {
if (variant === "outline") {
return {
color: theme.base === "light" ? theme.color.dark : theme.color.medium,
backgroundColor: theme.background.app,
Expand Down Expand Up @@ -54,29 +54,29 @@ const themeColors = ({ theme, secondary, status }: { theme: Theme } & ActionButt
};

interface ActionButtonProps extends ComponentProps<typeof IconButton> {
containsIcon?: boolean;
square?: boolean;
side?: "left" | "right";
}

export const ActionButton: React.FC<ActionButtonProps> = styled(IconButton)<ActionButtonProps>(
({ containsIcon }) => ({
({ square }) => ({
border: `1px solid transparent`,
boxShadow: "none",
fontSize: 12,
fontWeight: 700,
height: 28,
padding: containsIcon ? "8px 6px" : 8,
padding: square ? "8px 6px" : 8,
transition: "background-color 150ms ease-out",
"@container (min-width: 300px)": {
height: 32,
width: containsIcon ? 32 : "auto",
padding: containsIcon ? "9px 8px" : 9,
width: square ? 32 : "auto",
padding: square ? "9px 8px" : 9,
},
"@container (min-width: 800px)": {
height: 28,
fontSize: 12,
width: containsIcon ? 28 : "auto",
padding: containsIcon ? "8px 6px" : 8,
width: square ? 28 : "auto",
padding: square ? "8px 6px" : 8,
},
}),
themeColors,
Expand Down
5 changes: 2 additions & 3 deletions src/components/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ const getStatusStyles = (theme: Theme, status?: IconButtonProps["status"]) =>
interface IconButtonProps extends ComponentProps<typeof BaseIconButton> {
active?: boolean;
as?: string;
secondary?: boolean;
status?: "positive" | "warning";
}

export const IconButton: React.FC<IconButtonProps> = styled(BaseIconButton)<IconButtonProps>(
({ active, secondary, theme }) => ({
({ active, variant, theme }) => ({
display: "inline-flex",
alignItems: "center",
verticalAlign: "top",
gap: 6,
margin: 0,
color: active || secondary ? theme.color.secondary : theme.color.mediumdark,
color: active || variant === "outline" ? theme.color.secondary : theme.color.mediumdark,
fontWeight: "normal",
"& > svg": {
width: "auto",
Expand Down
32 changes: 11 additions & 21 deletions src/components/SidebarTop.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FailedIcon, PassedIcon } from "@storybook/icons";
import { type API, useStorybookState } from "@storybook/manager-api";
import { color } from "@storybook/theming";
import pluralize from "pluralize";
Expand Down Expand Up @@ -84,10 +85,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
headline: "Build started",
subHeadline: "Check the visual test addon to see the progress of your build.",
},
icon: {
name: "passed",
color: color.positive,
},
icon: <PassedIcon color={color.positive} />,
// @ts-expect-error `duration` and `onClick` require a newer version of Storybook
duration: 8_000,
onClick: clickNotification,
Expand All @@ -104,10 +102,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
headline: "Build canceled",
subHeadline: "Aborted by user.",
},
icon: {
name: "failed",
color: color.negative,
},
icon: <FailedIcon color={color.negative} />,
// @ts-expect-error `duration` and `onClick` require a newer version of Storybook
duration: 8_000,
onClick: clickNotification,
Expand All @@ -132,10 +127,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
)}`
: "No visual changes detected",
},
icon: {
name: "passed",
color: color.positive,
},
icon: <PassedIcon color={color.positive} />,
// @ts-expect-error `duration` and `onClick` require a newer version of Storybook
duration: 8_000,
onClick: clickNotification,
Expand All @@ -152,10 +144,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
headline: "Build error",
subHeadline: "Check the Storybook process on the command line for more details.",
},
icon: {
name: "failed",
color: color.negative,
},
icon: <FailedIcon color={color.negative} />,
// @ts-expect-error `duration` and `onClick` require a newer version of Storybook
onClick: clickNotification,
});
Expand All @@ -169,10 +158,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
subHeadline:
"Your account has insufficient snapshots remaining to run this build. Visit your billing page to find out more.",
},
icon: {
name: "failed",
color: color.negative,
},
icon: <FailedIcon color={color.negative} />,
// @ts-expect-error `duration` and `onClick` require a newer version of Storybook
onClick: clickNotification,
});
Expand All @@ -187,7 +173,10 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
changedStoryCount.length,
]);

const { isRunning, startBuild, stopBuild } = useBuildEvents({ localBuildProgress, accessToken });
const { isDisallowed, isRunning, startBuild, stopBuild } = useBuildEvents({
localBuildProgress,
accessToken,
});

let warning: string | undefined;
if (apiInfo?.connected === false) warning = "Visual tests locked while waiting for network.";
Expand All @@ -208,6 +197,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
return (
<SidebarTopButton
isDisabled={!!warning}
isDisallowed={isDisallowed}
isOutdated={isOutdated}
isRunning={isRunning}
localBuildProgress={localBuildProgress}
Expand Down
9 changes: 8 additions & 1 deletion src/components/SidebarTopButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const WithProgress = (props: ComponentProps<typeof SidebarTopButton>) => {
);
};

export const IsRunning: Story = {
export const Running: Story = {
render: WithProgress,
play: playAll(async ({ canvasElement }) => {
const canvas = within(canvasElement);
Expand All @@ -85,3 +85,10 @@ export const IsRunning: Story = {
await screen.findAllByText("🏗 Building your Storybook...");
}),
};

export const Unstoppable: Story = {
...Running,
args: {
isDisallowed: true,
},
};
46 changes: 33 additions & 13 deletions src/components/SidebarTopButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { WithTooltip } from "@storybook/components";
import { PlayIcon, StopAltIcon, SyncIcon } from "@storybook/icons";
import { PlayIcon, StopAltIcon } from "@storybook/icons";
import { keyframes, styled } from "@storybook/theming";
import React, { ComponentProps } from "react";

import { LocalBuildProgress } from "../types";
import { BuildProgressLabel } from "./BuildProgressLabel";
import { jiggle } from "./design-system/shared/animation";
import { IconButton } from "./IconButton";
import { StatusDotWrapper } from "./StatusDot";
import { TooltipNote } from "./TooltipNote";
Expand Down Expand Up @@ -67,19 +68,28 @@ export const ProgressCircle = styled.svg<{ progress?: boolean; spinner?: boolean
}
);

export const SidebarIconButton = styled(IconButton)<ComponentProps<typeof IconButton>>(
({ theme }) => ({
position: "relative",
overflow: "visible",
color: theme.textMutedColor,
marginTop: 0,
zIndex: 1,
marginRight: 4,
})
);
const WarningText = styled.div(({ theme }) => ({
color: theme.color.warningText,
"&&": { marginTop: 10 },
}));

export const SidebarIconButton = styled(IconButton)<
ComponentProps<typeof IconButton> & { isDisallowed?: boolean }
>(({ isDisallowed, theme }) => ({
position: "relative",
overflow: "visible",
color: theme.textMutedColor,
marginTop: 0,
zIndex: 1,
marginRight: 4,
...(isDisallowed && {
animation: `${jiggle} 700ms ease-out`,
}),
}));

export const SidebarTopButton = ({
isDisabled = false,
isDisallowed = false,
isOutdated = false,
isRunning = false,
localBuildProgress,
Expand All @@ -89,6 +99,7 @@ export const SidebarTopButton = ({
stopBuild,
}: {
isDisabled?: boolean;
isDisallowed?: boolean;
isOutdated?: boolean;
isRunning?: boolean;
localBuildProgress?: LocalBuildProgress;
Expand Down Expand Up @@ -126,17 +137,26 @@ export const SidebarTopButton = ({
tooltip={
<TooltipContent>
<div>
<BuildProgressLabel localBuildProgress={localBuildProgress} withEmoji />
<BuildProgressLabel localBuildProgress={localBuildProgress} small withEmoji />
</div>
<ProgressTrack>
{typeof buildProgressPercentage === "number" && (
<ProgressBar style={{ width: `${buildProgressPercentage}%` }} />
)}
</ProgressTrack>
{isDisallowed && (
<WarningText>
This job has already reached the capture cloud and cannot be stopped locally.
</WarningText>
)}
</TooltipContent>
}
>
<SidebarIconButton aria-label="Stop tests" onClick={() => stopBuild()}>
<SidebarIconButton
aria-label="Stop tests"
isDisallowed={isDisallowed}
onClick={() => stopBuild()}
>
<StopAltIcon style={{ width: 10, margin: 2 }} />
<ProgressCircle xmlns="http://www.w3.org/2000/svg">
<circle />
Expand Down
Loading

0 comments on commit cd7ca71

Please sign in to comment.