Skip to content
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

Align changed story count in notification and sidebar #189

Merged
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions src/SidebarTop.tsx
thafryer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type API, useChannel } from "@storybook/manager-api";
import { type API, useChannel, useStorybookState } from "@storybook/manager-api";
import { color } from "@storybook/theming";
import pluralize from "pluralize";
import React, { useEffect, useRef } from "react";
Expand Down Expand Up @@ -37,6 +37,11 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
const [gitInfoError] = useSharedState<Error>(GIT_INFO_ERROR);

const lastStep = useRef(localBuildProgress?.currentStep);
const { status } = useStorybookState();
const changedStoryCount = Object.values(status).filter(
(value) => value[ADDON_ID]?.status === "warn"
);

thafryer marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (localBuildProgress?.currentStep === lastStep.current) return;
lastStep.current = localBuildProgress?.currentStep;
Expand Down Expand Up @@ -83,8 +88,11 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
// eslint-disable-next-line no-nested-ternary
subHeadline: localBuildProgress.errorCount
? `Encountered ${pluralize("component error", localBuildProgress.errorCount, true)}`
: localBuildProgress.changeCount
? `Found ${pluralize("change", localBuildProgress.changeCount, true)}`
: changedStoryCount.length
? `Found ${pluralize("story", changedStoryCount.length, true)} with ${pluralize(
"change",
changedStoryCount.length
)}`
: "No visual changes detected",
},
icon: {
Expand Down Expand Up @@ -118,6 +126,7 @@ export const SidebarTop = ({ api }: SidebarTopProps) => {
localBuildProgress?.currentStep,
localBuildProgress?.errorCount,
localBuildProgress?.changeCount,
changedStoryCount.length,
]);

const emit = useChannel({});
Expand Down
Loading