Skip to content

Commit

Permalink
Fix documentation link and provide dynamic troubleshooting link
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Oct 10, 2024
1 parent c8cdccd commit 6670087
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
35 changes: 24 additions & 11 deletions code/addons/test/src/components/GlobalErrorModal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useState } from 'react';

import { ManagerContext } from 'storybook/internal/manager-api';

import type { Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, within } from '@storybook/test';

Expand All @@ -9,21 +11,32 @@ import { GlobalErrorModal } from './GlobalErrorModal';

type Story = StoryObj<typeof meta>;

const managerContext: any = {
state: {},
api: {
getDocsUrl: fn(({ subpath }) => `https://storybook.js.org/docs/${subpath}`).mockName(
'api::getDocsUrl'
),
},
};

const meta = {
component: GlobalErrorModal,
decorators: [
(storyFn) => (
<div
style={{
width: '100%',
minWidth: '1200px',
height: '800px',
background:
'repeating-linear-gradient(45deg, #000000, #ffffff 50px, #ffffff 50px, #ffffff 80px)',
}}
>
{storyFn()}
</div>
<ManagerContext.Provider value={managerContext}>
<div
style={{
width: '100%',
minWidth: '1200px',
height: '800px',
background:
'repeating-linear-gradient(45deg, #000000, #ffffff 50px, #ffffff 50px, #ffffff 80px)',
}}
>
{storyFn()}
</div>
</ManagerContext.Provider>
),
],
args: {
Expand Down
20 changes: 14 additions & 6 deletions code/addons/test/src/components/GlobalErrorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';

import { Button, IconButton, Modal } from 'storybook/internal/components';
import { useStorybookApi } from 'storybook/internal/manager-api';

import { CloseIcon, SyncIcon } from '@storybook/icons';
import { styled } from '@storybook/theming';

import { TROUBLESHOOTING_LINK } from '../constants';

interface GlobalErrorModalProps {
error: string;
open: boolean;
Expand Down Expand Up @@ -45,9 +48,15 @@ const TroubleshootLink = styled.a(({ theme }) => ({
color: theme.color.defaultText,
}));

const TROUBLESHOOT_LINK = `https://storybook.js.org/docs/vitest/troubleshooting`;

export function GlobalErrorModal({ onRerun, onClose, error, open }: GlobalErrorModalProps) {
const api = useStorybookApi();

const troubleshootURL = api.getDocsUrl({
subpath: TROUBLESHOOTING_LINK,
versioned: true,
renderer: true,
});

return (
<Modal onEscapeKeyDown={onClose} onInteractOutside={onClose} open={open}>
<ModalBar>
Expand All @@ -58,8 +67,7 @@ export function GlobalErrorModal({ onRerun, onClose, error, open }: GlobalErrorM
Rerun
</Button>
<Button variant="ghost" asChild>
{/* TODO: Is this the right link? */}
<a target="_blank" href={TROUBLESHOOT_LINK} rel="noreferrer">
<a target="_blank" href={troubleshootURL} rel="noreferrer">
Troubleshoot
</a>
</Button>
Expand All @@ -73,8 +81,8 @@ export function GlobalErrorModal({ onRerun, onClose, error, open }: GlobalErrorM
<br />
<br />
Troubleshoot:{' '}
<TroubleshootLink target="_blank" href={TROUBLESHOOT_LINK}>
{TROUBLESHOOT_LINK}
<TroubleshootLink target="_blank" href={troubleshootURL}>
{troubleshootURL}
</TroubleshootLink>
</ModalStackTrace>
</Modal>
Expand Down
1 change: 1 addition & 0 deletions code/addons/test/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const PANEL_ID = `${ADDON_ID}/panel`;

export const TUTORIAL_VIDEO_LINK = 'https://youtu.be/Waht9qq7AoA';
export const DOCUMENTATION_LINK = 'writing-tests/component-testing';
export const TROUBLESHOOTING_LINK = `${DOCUMENTATION_LINK}#troubleshooting`;

0 comments on commit 6670087

Please sign in to comment.