Skip to content

Commit

Permalink
fix(documentation): edit on Github breaks page without stories attach…
Browse files Browse the repository at this point in the history
…ed (#2267)

Fix Changelog and search for icons page after
#2132. If
`storyIdToCSFFile` is not defined for example on docs page without
stories attached, it breaks the whole page.

![image](https://github.com/swisspost/design-system/assets/12294151/0fea4b6e-ee95-4300-8c5c-17c0af0600ae)
  • Loading branch information
imagoiq authored Nov 20, 2023
1 parent f2675b7 commit 82b07cf
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-files-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-documentation': patch
---

Added attached stories to changelog and search-icons pages to fix "Edit this page on Github" feature.
10 changes: 6 additions & 4 deletions packages/documentation/.storybook/blocks/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ function getGitHubUrl(path: String) {
return `${BASEURL}${path.replace(/^\./, '').replace(/\.stories\.ts$/, '.docs.mdx')}`;
}

export default (params: { pathToStoryFile: String }) => (
export default (params: { pathToStoryFile?: String }) => (
<>
<div className="container mt-huge font-size-18 text-end">
<a href={getGitHubUrl(params.pathToStoryFile)} target="_blank" rel="noopener">
Edit this page on GitHub
</a>
{params.pathToStoryFile && (
<a href={getGitHubUrl(params.pathToStoryFile)} target="_blank" rel="noopener">
Edit this page on GitHub
</a>
)}
</div>
<footer className="docs-footer mt-huge bg-light">
<div className="container">
Expand Down
6 changes: 4 additions & 2 deletions packages/documentation/.storybook/blocks/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PropsWithChildren } from 'react';
import '../styles/layout.scss';
import Footer from './footer';
import Header from './header';
import { ifDefined } from 'lit/directives/if-defined.js';

function shouldShowHeader() {
return new URLSearchParams(window.location.search).get('id') === 'home--docs';
Expand All @@ -18,13 +19,14 @@ export default (props: PropsWithChildren<DocsContainerProps>) => {
context.channel.data.docsPrepared[0].parameters.layout === 'fullscreen'
? 'container-fluid'
: 'container';
const pathToStoryFile = context.storyIdToCSFFile.values().next().value.meta.parameters.fileName;
const pathToStoryFile = context?.storyIdToCSFFile?.values()?.next()?.value?.meta
?.parameters?.fileName;
return (
<DocsContainer context={context}>
<Unstyled>
{shouldShowHeader() && <Header />}
<div className={container}>{children}</div>
{shouldShowFooter() && <Footer pathToStoryFile={pathToStoryFile} />}
{shouldShowFooter() && <Footer pathToStoryFile={ifDefined(pathToStoryFile)} />}
</Unstyled>
</DocsContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The following examples show the different characteristics of the component. Thes
Wrap a pair of `<input>` and `<label>` elements in a `.form-floating` container to enable floating labels.<br/>
But note that the `<input>` element must come first, so we can ensure the correct styles.

Ensure that `placeholder` attribute is set (even with an empty value) so the label can act as a placeholder when no value is set.

<Canvas of={InputStories.FloatingLabel} />

### Sizing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Search extends React.Component {
id="IconSearchFilter_Freetext"
type="text"
className="form-control"
placeholder=""
value={this.state.freetext}
onChange={this.searchFreetext.bind(this)}
ref={this.freetextRef}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Meta } from '@storybook/blocks';
import { Search } from './search-icons.blocks';
import * as SearchIcons from './search-icons.stories';

<Meta title="Icons/Search for Icons" />
<Meta of={SearchIcons} />

# Search for icons

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Meta, StoryObj } from '@storybook/web-components';

const meta: Meta = {
title: 'Icons/Search for Icons',
};

export default meta;

type Story = StoryObj;

export const Default: Story = {};
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Markdown, Meta } from '@storybook/blocks';
import changelog from '../../../../../styles/CHANGELOG.md?raw';
import { CodeOrSourceMdx } from '../../utilities/markdown/CodeOrSourceMdx';
import ChangelogStories from './changelog.stories';

<Meta
title="Misc/Changelog"
/>
<Meta of={ChangelogStories}/>

<Markdown options={{ overrides: { code: CodeOrSourceMdx } }}>{changelog}</Markdown>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Meta, StoryObj } from '@storybook/web-components';

const meta: Meta = {
title: 'Misc/Changelog',
};

export default meta;

type Story = StoryObj;

export const Default: Story = {};

0 comments on commit 82b07cf

Please sign in to comment.