Skip to content

Commit

Permalink
Merge pull request #107 from chromaui/ghengeveld/ap-3657-first-build-…
Browse files Browse the repository at this point in the history
…in-progress-state

Show build progress on 'no build' screen
  • Loading branch information
tmeasday committed Sep 16, 2023
2 parents ecacce2 + 70e25d3 commit 05639b3
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/components/BuildProgressLabel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const Upload: Story = {
args: {
localBuildProgress: {
...INITIAL_BUILD_PAYLOAD,
buildProgressPercentage: 50,
buildProgressPercentage: 25,
currentStep: "upload",
stepProgress: {
...INITIAL_BUILD_PAYLOAD.stepProgress,
Expand All @@ -58,7 +58,7 @@ export const Verify: Story = {
args: {
localBuildProgress: {
...INITIAL_BUILD_PAYLOAD,
buildProgressPercentage: 75,
buildProgressPercentage: 50,
currentStep: "verify",
},
},
Expand All @@ -71,7 +71,7 @@ export const Snapshot: Story = {
args: {
localBuildProgress: {
...INITIAL_BUILD_PAYLOAD,
buildProgressPercentage: 90,
buildProgressPercentage: 75,
currentStep: "snapshot",
stepProgress: {
...INITIAL_BUILD_PAYLOAD.stepProgress,
Expand Down
13 changes: 9 additions & 4 deletions src/components/BuildProgressLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import { LocalBuildProgress } from "../types";

interface BuildProgressLabelProps {
localBuildProgress: LocalBuildProgress;
withEmoji?: boolean;
}

export const BuildProgressLabel = ({ localBuildProgress }: BuildProgressLabelProps) => {
export const BuildProgressLabel = ({
localBuildProgress,
withEmoji = false,
}: BuildProgressLabelProps) => {
const { emoji, renderProgress } = BUILD_STEP_CONFIG[localBuildProgress.currentStep];
const label = renderProgress(localBuildProgress);
return (
<>
{emoji} {renderProgress(localBuildProgress)}
</>
<span>
{withEmoji && emoji} {label}
</span>
);
};
2 changes: 1 addition & 1 deletion src/components/SidebarTopButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const SidebarTopButton = ({
tooltip={
<TooltipContent>
<div>
<BuildProgressLabel localBuildProgress={localBuildProgress} />
<BuildProgressLabel localBuildProgress={localBuildProgress} withEmoji />
</div>
<ProgressTrack>
{typeof buildProgressPercentage === "number" && (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/VisualTests/BuildEyebrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const BuildEyebrow = ({
<Header onClick={toggleExpanded}>
<Bar percentage={localBuildProgress.buildProgressPercentage} />
<Label>
<BuildProgressLabel localBuildProgress={localBuildProgress} />
<BuildProgressLabel localBuildProgress={localBuildProgress} withEmoji />
</Label>
<IconButton as="div">
{expanded ? <Icons icon="collapse" /> : <Icons icon="expandalt" />}
Expand Down
37 changes: 25 additions & 12 deletions src/screens/VisualTests/NoBuild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import { Icons, Loader } from "@storybook/components";
import React from "react";
import { CombinedError } from "urql";

import { BuildProgressLabel } from "../../components/BuildProgressLabel";
import { Button } from "../../components/Button";
import { Container } from "../../components/Container";
import { FooterMenu } from "../../components/FooterMenu";
import { Heading } from "../../components/Heading";
import { ProgressIcon } from "../../components/icons/ProgressIcon";
import { Bar, Col, Row, Section, Sections, Text } from "../../components/layout";
import { ProgressBar, ProgressTrack } from "../../components/SidebarTopButton";
import { Text as CenterText } from "../../components/Text";
import { LocalBuildProgress } from "../../types";

interface NoBuildProps {
error: CombinedError;
hasData: boolean;
hasStoryBuild: boolean;
startDevBuild: () => void;
isLocalBuildStarting: boolean;
localBuildProgress: LocalBuildProgress;
branch: string;
setAccessToken: (accessToken: string | null) => void;
}
Expand All @@ -25,7 +27,7 @@ export const NoBuild = ({
hasData,
hasStoryBuild,
startDevBuild,
isLocalBuildStarting,
localBuildProgress,
branch,
setAccessToken,
}: NoBuildProps) => (
Expand All @@ -48,15 +50,26 @@ export const NoBuild = ({
Take an image snapshot of each story to save their &quot;last known good state&quot; as
test baselines.
</CenterText>
<br />
<Button small secondary onClick={startDevBuild} disabled={isLocalBuildStarting}>
{isLocalBuildStarting ? (
<ProgressIcon parentComponent="Button" style={{ marginRight: 6 }} />
) : (
<Icons icon="play" />
)}
Take snapshots
</Button>
{localBuildProgress ? (
<CenterText style={{ display: "flex", flexDirection: "column", gap: 10, width: 200 }}>
<ProgressTrack>
{typeof localBuildProgress.buildProgressPercentage === "number" && (
<ProgressBar
style={{ width: `${localBuildProgress.buildProgressPercentage}%` }}
/>
)}
</ProgressTrack>
<BuildProgressLabel localBuildProgress={localBuildProgress} />
</CenterText>
) : (
<>
<br />
<Button small secondary onClick={startDevBuild}>
<Icons icon="play" />
Take snapshots
</Button>
</>
)}
</Container>
)}
</Section>
Expand Down
3 changes: 2 additions & 1 deletion src/screens/VisualTests/VisualTests.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export const EmptyBranchLocalBuildUploading: Story = {
args: {
localBuildProgress: {
...INITIAL_BUILD_PAYLOAD,
buildProgressPercentage: 25,
currentStep: "upload",
stepProgress: {
...INITIAL_BUILD_PAYLOAD.stepProgress,
Expand All @@ -272,7 +273,7 @@ export const EmptyBranchLocalBuildCapturing: Story = {
args: {
localBuildProgress: {
...INITIAL_BUILD_PAYLOAD,
buildProgressPercentage: 60,
buildProgressPercentage: 75,
currentStep: "snapshot",
stepProgress: {
...INITIAL_BUILD_PAYLOAD.stepProgress,
Expand Down
5 changes: 1 addition & 4 deletions src/screens/VisualTests/VisualTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,14 @@ export const VisualTests = ({
[canSwitchToLastBuildOnBranch, lastBuildOnBranch?.id, storyId]
);

const isLocalBuildStarting =
localBuildProgress && !["success", "error"].includes(localBuildProgress.currentStep);

return !selectedBuild || error ? (
<NoBuild
{...{
error,
hasData: !!data,
hasStoryBuild: !!selectedBuild,
startDevBuild,
isLocalBuildStarting,
localBuildProgress,
branch: gitInfo.branch,
setAccessToken,
}}
Expand Down

0 comments on commit 05639b3

Please sign in to comment.