Skip to content

Commit

Permalink
get back status page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigui committed Jul 27, 2023
1 parent b63d96f commit 202fd9c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 122 deletions.
70 changes: 20 additions & 50 deletions packages/storybook/.storybook/blocks/Badges.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,28 @@
import { Fragment, useContext, useEffect, useState } from 'react';
import { DocsContext } from '@storybook/blocks';
import type { Globals } from '@storybook/csf';
import type { DocsContextProps } from '@storybook/types';
import { Helmet } from 'react-helmet';
import { BackToTop, TableOfContents } from 'storybook-docs-toc';
import { Divider, Form, StackVertical } from '@talend/design-system';
import { useContext } from 'react';
import { DocsContext, Unstyled } from '@storybook/blocks';
import { BackToTop } from 'storybook-docs-toc';
import { BadgeFigma, BadgeI18n, BadgeReact, BadgeStorybook, Badges } from '~docs';
import { GLOBALS_UPDATED } from '@storybook/core-events';
import { ComponentStatus, Status } from '.storybook/docs/StatusTable';
import { Statuses } from '.storybook/docs/StatusTable';
import statuses from '../../src/status.json';

const useGlobalsCustom = (context: DocsContextProps): [Globals] => {
const storyContext = context.getStoryContext(context.storyById());
const [globals, setGlobals] = useState(storyContext.globals);

useEffect(() => {
const cb = (changed: { globals: Globals }) => {
setGlobals(changed.globals);
};
context.channel.on(GLOBALS_UPDATED, cb);
return () => context.channel.off(GLOBALS_UPDATED, cb);
}, []);

return [globals];
};

type BadgesBlockProps = {
status?: ComponentStatus;
figmaLink?: string;
};

export function BadgesBlock({ status = {}, figmaLink }: BadgesBlockProps) {
export function BadgesBlock() {
const context = useContext(DocsContext);
const { story } = context.resolveOf('story', ['story']);
const { id, parameters, title } = story;
const { id, title, componentId } = story;

const [globals] = useGlobalsCustom(context);
const { status = {}, figmaLink, githubLink } = (statuses as Statuses)[componentId];

const titleArray = title.split('/');

const docsTitle = title.replace(/\//gi, ' / ');
const docsCategory = titleArray[0];

console.log('[GNI]-- stop');
const githubLink =
'https://github.com/Talend/ui/tree/master/packages/design-system/' +
parameters.fileName
.split('/')
.slice(1, parameters.fileName.split('/').length - 1)
.join('/')
.replace('/docs', '');

const isDesignSystemElementPage = ['design system'].find(term => {
return title?.toLocaleLowerCase().startsWith(term);
});

return (
<>
<Unstyled>
{/*
Doesn't work because it'll update iframe meta and not page meta, so when we share the link, meta won't be used
<Helmet>
<title>{docsTitle}</title>
<meta property="og:title" content={titleArray[titleArray.length - 1]} />
Expand All @@ -66,10 +33,13 @@ export function BadgesBlock({ status = {}, figmaLink }: BadgesBlockProps) {
content={`https://via.placeholder.com/1000x500/F3F3F3/FF6D70?text=${docsTitle}`}
/>
{titleArray.length > 1 && <meta property="article:section" content={docsCategory} />}
</Helmet>
</Helmet>
{/* <TableOfContents>
</TableOfContents> */}
Doesn't work anymore with SB7 DOM
<TableOfContents/>
*/}

<Badges>
<BadgeFigma status={status.figma} href={figmaLink} />
Expand All @@ -79,6 +49,6 @@ export function BadgesBlock({ status = {}, figmaLink }: BadgesBlockProps) {
</Badges>

<BackToTop />
</>
</Unstyled>
);
}
10 changes: 0 additions & 10 deletions packages/storybook/.storybook/docs/Badges.module.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
@use '~@talend/design-tokens/lib/tokens';

.badges {
position: absolute;
top: 40px;
left: calc(50% - 500px - 170px);
display: flex;
flex-direction: column;
align-items: end;
gap: tokens.$coral-spacing-xxs;
padding: 10px;
width: 150px;
z-index: 9999;
}
10 changes: 6 additions & 4 deletions packages/storybook/.storybook/docs/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import type { ReactElement, PropsWithChildren } from 'react';

import Badge from './Badge';

import theme from './Badges.module.scss';
import { StackHorizontal, StackItem } from '@talend/design-system';

const StatusList = ({ children }: PropsWithChildren<any>) => {
return (
<ul className={theme.badges} role="list">
<StackHorizontal gap="XS" as="ul" role="list" align="center" margin={{ x: 0, y: 'M' }}>
{children.map((child: ReactElement<typeof Badge>, key: number) => (
<li key={key}>{child}</li>
<StackItem as="li" key={key}>
{child}
</StackItem>
))}
</ul>
</StackHorizontal>
);
};

Expand Down
65 changes: 38 additions & 27 deletions packages/storybook/.storybook/docs/StatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { FunctionComponent, Suspense, useEffect, useState } from 'react';
import { addons } from '@storybook/addons';
import { FunctionComponent, Suspense, ReactNode } from 'react';

import { Unstyled } from '@storybook/blocks';
import tokens from '@talend/design-tokens';

import theme from './StatusTable.module.scss';

const channel = addons.getChannel();
import statuses from '../../src/status.json';

export type Statuses = Record<
string,
{
status?: ComponentStatus;
figmaLink?: string;
githubLink?: string;
}
>;

export enum Status {
OK = 'ok',
Expand All @@ -22,13 +32,22 @@ export type ComponentStatus = {
i18n?: Status;
};

type PageWithStatus = {
[pageIdentifier: string]: {
title: string;
componentId: string;
parameters: { status?: ComponentStatus };
};
};
function withLink(children: ReactNode, href?: string) {
return href ? (
<a
{...{
href,
target: '_blank',
rel: 'noopener noreferrer',
}}
>
{children}
</a>
) : (
{ children }
);
}

const getHTMLStatus = (status?: Status) => {
const attrs = {
className: theme.tag,
Expand Down Expand Up @@ -107,15 +126,8 @@ const getComputedHTMLStatus = (status?: ComponentStatus) => {
};

const StatusTable = (props: FunctionComponent & { filter?: string }) => {
const [statuses, setStatuses] = useState<PageWithStatus>();

useEffect(() => {
channel.on('SET_STATUSES_BY_PAGE', setStatuses);
return () => channel.off('SET_STATUSES_BY_PAGE', setStatuses);
}, [channel]);

return (
<>
<Unstyled>
<div className={theme.legend}>
<dl className={theme.dl}>
<dt>Figma</dt>
Expand Down Expand Up @@ -144,10 +156,8 @@ const StatusTable = (props: FunctionComponent & { filter?: string }) => {
</tr>
</thead>
<tbody>
{statuses &&
Object.entries(statuses).map(([name, pageDetails], key) => {
const { componentId, title, parameters } = pageDetails || {};
const { status } = parameters || {};
{Object.entries(statuses as Statuses).map(
([componentId, { status, figmaLink, githubLink }], key) => {
const { figma, react, storybook, i18n } = status || {};
if (props.filter) {
if (!componentId.includes(props.filter)) {
Expand All @@ -158,19 +168,20 @@ const StatusTable = (props: FunctionComponent & { filter?: string }) => {
<tr key={key}>
<td>
{getComputedHTMLStatus(status)}{' '}
<a href={`?path=/docs/${componentId}`}>{title}</a>
{withLink(componentId, `?path=/docs/${componentId}`)}
</td>
<td>{getHTMLStatus(figma)}</td>
<td>{withLink(getHTMLStatus(figma), figmaLink)}</td>
<td>{getHTMLStatus(storybook)}</td>
<td>{getHTMLStatus(react)}</td>
<td>{withLink(getHTMLStatus(react), githubLink)}</td>
<td>{getHTMLStatus(i18n)}</td>
</tr>
);
})}
},
)}
</tbody>
</table>
</Suspense>
</>
</Unstyled>
);
};

Expand Down
27 changes: 0 additions & 27 deletions packages/storybook/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,6 @@ export const i18n = {
),
};

// const channel = addons.getChannel();

// let statusByPage = {};
// channel.once(SET_STORIES, eventData => {
// statusByPage = Object.entries(eventData.stories).reduce(
// (acc, [name, { title, componentId, parameters }]) => {
// ['components', 'templates', 'pages', 'wip-components'].forEach(prefix => {
// if (name.toLocaleLowerCase().startsWith(prefix)) {
// if (!acc[componentId]) {
// acc[componentId] = {
// title,
// componentId,
// parameters,
// };
// }
// }
// });
// return acc;
// },
// {},
// );
// });

export const parameters = {
docs: {
// toc: {
Expand All @@ -90,10 +67,6 @@ export const parameters = {
// },
// },
container: ({ children, context }) => {
// // useEffect(() => {
// // channel.emit('SET_STATUSES_BY_PAGE', statusByPage);
// // }, [statusByPage]);

const themeKey = context.store.globals.globals.theme || 'light';
const theme = create(
{
Expand Down
6 changes: 2 additions & 4 deletions packages/storybook/src/design-system/Accordion/Accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import * as Stories from './Accordion.stories';
import { Accordion, StackVertical, InlineMessageWarning } from '@talend/design-system';

<Meta of={Stories} />
<Badges
status={{ figma: 'OK', storybook: 'wip', react: 'wip', i18n: 'na' }}
figmaLink="https://www.figma.com/file/CDfr4jLz1m6Ud2RNi4qpQJ/Accordion"
/>

# Accordion

<Badges />

<StackVertical
gap="XS"
margin={{
Expand Down
7 changes: 7 additions & 0 deletions packages/storybook/src/status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"design-system-accordion": {
"status": { "figma": "ok", "storybook": "wip", "react": "wip", "i18n": "na" },
"figmaLink": "https://www.figma.com/file/CDfr4jLz1m6Ud2RNi4qpQJ/Accordion",
"githubLink": "https://github.com/Talend/ui/tree/master/packages/design-system/src/components/WIP/Accordion/Accordion.tsx"
}
}

0 comments on commit 202fd9c

Please sign in to comment.