From ec512f9a897a44e912c716902dbe04900eb93913 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 7 May 2020 17:02:25 +0200 Subject: [PATCH] ADD a 'empty' state when stories are set successfully, but it was empty --- lib/ui/src/components/preview/preview.tsx | 3 +-- lib/ui/src/components/sidebar/RefBlocks.tsx | 18 ++++++++++++++++++ lib/ui/src/components/sidebar/RefHelpers.tsx | 10 +++++++++- lib/ui/src/components/sidebar/Refs.tsx | 8 +++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/ui/src/components/preview/preview.tsx b/lib/ui/src/components/preview/preview.tsx index 8f12f04903e..c5bc6218fad 100644 --- a/lib/ui/src/components/preview/preview.tsx +++ b/lib/ui/src/components/preview/preview.tsx @@ -61,8 +61,7 @@ const createCanvas = (id: string, baseUrl = 'iframe.html', withLoader = true): A ]); const isLoading = !!( - (!story && !storiesFailed) || - (!story && storiesConfigured === false) || + (!story && !(storiesFailed || storiesConfigured)) || (story && refId && refs[refId] && !refs[refId].ready) ); diff --git a/lib/ui/src/components/sidebar/RefBlocks.tsx b/lib/ui/src/components/sidebar/RefBlocks.tsx index 29b29258518..7d6babb46ef 100644 --- a/lib/ui/src/components/sidebar/RefBlocks.tsx +++ b/lib/ui/src/components/sidebar/RefBlocks.tsx @@ -220,6 +220,24 @@ export const ErrorBlock: FunctionComponent<{ error: Error }> = ({ error }) => ( ); +export const EmptyBlock: FunctionComponent = () => ( + + + Ow now! something went wrong loading this storybook + There was no error, but there were no stories loaded} + > + + + + +); + export const LoaderBlock: FunctionComponent<{ isMain: boolean }> = ({ isMain }) => ( diff --git a/lib/ui/src/components/sidebar/RefHelpers.tsx b/lib/ui/src/components/sidebar/RefHelpers.tsx index 6fb4bf4e8f8..ae9701ee521 100644 --- a/lib/ui/src/components/sidebar/RefHelpers.tsx +++ b/lib/ui/src/components/sidebar/RefHelpers.tsx @@ -7,7 +7,12 @@ export type Item = StoriesHash[keyof StoriesHash]; export type DataSet = Record; export type FilteredType = 'filtered' | 'unfiltered'; -export const getType = (isLoading: boolean, isAuthRequired: boolean, isError: boolean) => { +export const getType = ( + isLoading: boolean, + isAuthRequired: boolean, + isError: boolean, + isEmpty: boolean +) => { if (isAuthRequired) { return 'auth'; } @@ -17,5 +22,8 @@ export const getType = (isLoading: boolean, isAuthRequired: boolean, isError: bo if (isLoading) { return 'loading'; } + if (isEmpty) { + return 'empty'; + } return 'ready'; }; diff --git a/lib/ui/src/components/sidebar/Refs.tsx b/lib/ui/src/components/sidebar/Refs.tsx index 58792008d37..7224f35cb4a 100644 --- a/lib/ui/src/components/sidebar/Refs.tsx +++ b/lib/ui/src/components/sidebar/Refs.tsx @@ -4,7 +4,7 @@ import { styled } from '@storybook/theming'; import { ExpanderContext, useDataset } from './Tree/State'; import { Expander } from './Tree/ListItem'; import { RefIndicator } from './RefIndicator'; -import { AuthBlock, ErrorBlock, LoaderBlock, ContentBlock } from './RefBlocks'; +import { AuthBlock, ErrorBlock, LoaderBlock, ContentBlock, EmptyBlock } from './RefBlocks'; import { getType, RefType } from './RefHelpers'; export interface RefProps { @@ -69,12 +69,13 @@ export const Ref: FunctionComponent = (ref) => { const combo = useMemo(() => ({ setExpanded, expandedSet }), [setExpanded, expandedSet]); - const isLoading = !length; const isMain = key === 'storybook_internal'; + const isLoading = length === 0 && !ref.ready; const isError = !!error; + const isEmpty = !isLoading && length === 0; const isAuthRequired = !!authUrl; - const type = getType(isLoading, isAuthRequired, isError); + const type = getType(isLoading, isAuthRequired, isError, isEmpty); return isHidden ? null : ( @@ -95,6 +96,7 @@ export const Ref: FunctionComponent = (ref) => { {type === 'auth' && } {type === 'error' && } {type === 'loading' && } + {type === 'empty' && } {type === 'ready' && ( )}