Skip to content

Commit

Permalink
storybookjs#26642: fix message when title of story ends with "/" and …
Browse files Browse the repository at this point in the history
…render all components in story that were correctly created.

Instead of displaying the message: "Invalid part '${name}', leading to id === parentId ('${id}'), inside title '${title}'", now we have a better message that clarifys the error and then all other components created correctly will be displayed along side the error message
  • Loading branch information
hmcostaa committed Apr 3, 2024
1 parent fbd2aaf commit c868ddd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
4 changes: 1 addition & 3 deletions code/lib/manager-api/src/lib/stories.ts
Expand Up @@ -196,9 +196,7 @@ export const transformStoryIndexToStoriesHash = (
if (parent === id) {
throw new Error(
dedent`
Invalid part '${name}', leading to id === parentId ('${id}'), inside title '${title}'
Did you create a path that uses the separator char accidentally, such as 'Vue <docs/>' where '/' is a separator char? See https://github.com/storybookjs/storybook/issues/6128
Invalid title "${title}" ending in slash: ${id}
`
);
}
Expand Down
42 changes: 41 additions & 1 deletion code/ui/manager/src/components/sidebar/Refs.tsx
Expand Up @@ -17,6 +17,8 @@ import type { Highlight, RefType } from './types';
import { getStateType } from '../../utils/tree';
import { CollapseIcon } from './components/CollapseIcon';

import type { API_IndexHash } from '@storybook/types';

export interface RefProps {
isLoading: boolean;
isBrowsing: boolean;
Expand Down Expand Up @@ -128,6 +130,28 @@ export const Ref: FC<RefType & RefProps & { status?: State['status'] }> = React.
[api, isMain, refId]
);

const filteredIndex = {} as API_IndexHash;

function getLastWord(str: string) {
const words = str.split(' ');
return words[words.length - 1];
}

// Iterate through the index data
for (const key in index) {
// Check if the key starts with id of the error message
if (
indexError &&
indexError.hasOwnProperty('message') &&
key.startsWith(getLastWord(indexError.message))
) {
// Do not include this item in the filtered index
continue;
}
// Otherwise, include it in the filtered index
filteredIndex[key] = index[key];
}

return (
<>
{isMain || (
Expand All @@ -145,7 +169,23 @@ export const Ref: FC<RefType & RefProps & { status?: State['status'] }> = React.
{isExpanded && (
<Wrapper data-title={title} isMain={isMain}>
{state === 'auth' && <AuthBlock id={refId} loginUrl={loginUrl} />}
{state === 'error' && <ErrorBlock error={indexError} />}
{state === 'error' && (
<>
<ErrorBlock error={indexError} />
<Tree
status={props.status}
isBrowsing={isBrowsing}
isMain={isMain}
refId={refId}
data={filteredIndex}
docsMode={docsOptions.docsMode}
selectedStoryId={selectedStoryId}
onSelectStoryId={onSelectStoryId}
highlightedRef={highlightedRef}
setHighlightedItemId={setHighlightedItemId}
/>
</>
)}
{state === 'loading' && <LoaderBlock isMain={isMain} />}
{state === 'empty' && <EmptyBlock isMain={isMain} />}
{state === 'ready' && (
Expand Down

0 comments on commit c868ddd

Please sign in to comment.