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

Addon Test: Only render the TestingModule component in development mode #29501

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion code/core/src/manager/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const Sidebar = React.memo(function Sidebar({
)}
</Search>
</Top>
{isMobile || isLoading ? null : <SidebarBottom />}
{isMobile || isLoading ? null : <SidebarBottom isDevelopment={isDevelopment} />}
</ScrollArea>
</Container>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SidebarBottomBase } from './SidebarBottom';
export default {
component: SidebarBottomBase,
args: {
isDevelopment: true,
api: {
clearNotification: fn(),
emit: fn(),
Expand Down
49 changes: 32 additions & 17 deletions code/core/src/manager/components/sidebar/SidebarBottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ interface SidebarBottomProps {
api: API;
notifications: State['notifications'];
status: State['status'];
isDevelopment?: boolean;
}

export const SidebarBottomBase = ({ api, notifications = [], status = {} }: SidebarBottomProps) => {
export const SidebarBottomBase = ({
api,
notifications = [],
status = {},
isDevelopment = globalThis.CONFIG_TYPE === 'DEVELOPMENT',
}: SidebarBottomProps) => {
const spacerRef = useRef<HTMLDivElement | null>(null);
const wrapperRef = useRef<HTMLDivElement | null>(null);
const [warningsActive, setWarningsActive] = useState(false);
Expand Down Expand Up @@ -228,27 +234,36 @@ export const SidebarBottomBase = ({ api, notifications = [], status = {} }: Side
<div id={SIDEBAR_BOTTOM_SPACER_ID} ref={spacerRef}>
<Content id={SIDEBAR_BOTTOM_WRAPPER_ID} ref={wrapperRef}>
<NotificationList notifications={notifications} clearNotification={api.clearNotification} />
<TestingModule
{...{
testProviders: testProvidersArray,
errorCount: errors.length,
errorsActive,
setErrorsActive,
warningCount: warnings.length,
warningsActive,
setWarningsActive,
onRunTests,
onCancelTests,
onSetWatchMode,
}}
/>
{isDevelopment && (
<TestingModule
{...{
testProviders: testProvidersArray,
errorCount: errors.length,
errorsActive,
setErrorsActive,
warningCount: warnings.length,
warningsActive,
setWarningsActive,
onRunTests,
onCancelTests,
onSetWatchMode,
}}
/>
)}
</Content>
</div>
);
};

export const SidebarBottom = () => {
export const SidebarBottom = ({ isDevelopment }: { isDevelopment?: boolean }) => {
const api = useStorybookApi();
const { notifications, status } = useStorybookState();
return <SidebarBottomBase api={api} notifications={notifications} status={status} />;
return (
<SidebarBottomBase
api={api}
notifications={notifications}
status={status}
isDevelopment={isDevelopment}
/>
);
};
7 changes: 6 additions & 1 deletion code/core/src/manager/components/sidebar/TestingModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ export const TestingModule = ({
const testing = testProviders.length > 0;

return (
<Outline running={running} crashed={crashed} failed={failed || errorCount > 0}>
<Outline
id="storybook-testing-module"
running={running}
crashed={crashed}
failed={failed || errorCount > 0}
>
<Card>
<Collapsible
style={{
Expand Down