Show a "booting" progress message until the story is specified

(Or an error occurs).
This commit is contained in:
Tom Coleman 2022-12-28 21:14:37 +11:00
parent 3f84da1800
commit 2341c67ac6
3 changed files with 34 additions and 4 deletions

View File

@ -54,6 +54,7 @@ export interface SubState {
storiesHash: API_StoriesHash; storiesHash: API_StoriesHash;
storyId: StoryId; storyId: StoryId;
viewMode: ViewMode; viewMode: ViewMode;
storySpecified: boolean;
storiesConfigured: boolean; storiesConfigured: boolean;
storiesFailed?: Error; storiesFailed?: Error;
} }
@ -387,9 +388,11 @@ export const init: ModuleFn<SubAPI, SubState, true> = ({
}) { }) {
const { sourceType } = getEventMetadata(this, fullAPI); const { sourceType } = getEventMetadata(this, fullAPI);
if (fullAPI.isSettingsScreenActive()) return;
if (sourceType === 'local') { if (sourceType === 'local') {
store.setState({ storySpecified: true });
if (fullAPI.isSettingsScreenActive()) return;
// Special case -- if we are already at the story being specified (i.e. the user started at a given story), // Special case -- if we are already at the story being specified (i.e. the user started at a given story),
// we don't need to change URL. See https://github.com/storybookjs/storybook/issues/11677 // we don't need to change URL. See https://github.com/storybookjs/storybook/issues/11677
const state = store.getState(); const state = store.getState();
@ -518,6 +521,7 @@ export const init: ModuleFn<SubAPI, SubState, true> = ({
storiesHash: {}, storiesHash: {},
storyId: initialStoryId, storyId: initialStoryId,
viewMode: initialViewMode, viewMode: initialViewMode,
storySpecified: false,
storiesConfigured: false, storiesConfigured: false,
hasCalledSetOptions: false, hasCalledSetOptions: false,
}, },

View File

@ -107,6 +107,7 @@ describe('stories API', () => {
} as ModuleArgs); } as ModuleArgs);
expect(state).toEqual({ expect(state).toEqual({
storySpecified: false,
storiesConfigured: false, storiesConfigured: false,
storiesHash: {}, storiesHash: {},
storyId: 'id', storyId: 'id',
@ -617,6 +618,23 @@ describe('stories API', () => {
// Can't currently run these tests as cannot set this on the events // Can't currently run these tests as cannot set this on the events
describe('STORY_SPECIFIED event', () => { describe('STORY_SPECIFIED event', () => {
it('sets the storySpecified state', async () => {
const navigate = jest.fn();
const fullAPI = Object.assign(new EventEmitter(), {
isSettingsScreenActive() {
return false;
},
});
const store = createMockStore({});
const { init, api } = initStories({ store, navigate, provider, fullAPI } as any);
Object.assign(fullAPI, api);
init();
fullAPI.emit(STORY_SPECIFIED, { storyId: 'a--1', viewMode: 'story' });
expect(store.getState().storySpecified).toBe(true);
});
it('navigates to the story', async () => { it('navigates to the story', async () => {
const navigate = jest.fn(); const navigate = jest.fn();
const fullAPI = Object.assign(new EventEmitter(), { const fullAPI = Object.assign(new EventEmitter(), {

View File

@ -37,6 +37,7 @@ const canvasMapper = ({ state, api }: Combo) => ({
queryParams: state.customQueryParams, queryParams: state.customQueryParams,
getElements: api.getElements, getElements: api.getElements,
entry: api.getData(state.storyId, state.refId), entry: api.getData(state.storyId, state.refId),
storySpecified: state.storySpecified,
storiesConfigured: state.storiesConfigured, storiesConfigured: state.storiesConfigured,
storiesFailed: state.storiesFailed, storiesFailed: state.storiesFailed,
refs: state.refs, refs: state.refs,
@ -60,6 +61,7 @@ const createCanvas = (id: string, baseUrl = 'iframe.html', withLoader = true): A
viewMode, viewMode,
queryParams, queryParams,
getElements, getElements,
storySpecified,
storiesConfigured, storiesConfigured,
storiesFailed, storiesFailed,
active, active,
@ -90,15 +92,21 @@ const createCanvas = (id: string, baseUrl = 'iframe.html', withLoader = true): A
const isLoading = entry const isLoading = entry
? refLoading || rootLoading ? refLoading || rootLoading
: (!storiesFailed && !storiesConfigured) || rootLoading; : (!storiesFailed && !storiesConfigured) || rootLoading;
const isBooting = !storySpecified && !storiesFailed;
console.log({ withLoader, isLoading, isBooting, progress });
return ( return (
<ZoomConsumer> <ZoomConsumer>
{({ value: scale }) => { {({ value: scale }) => {
return ( return (
<> <>
{withLoader && isLoading && ( {withLoader && (isLoading || isBooting) && (
<S.LoaderWrapper> <S.LoaderWrapper>
<Loader id="preview-loader" role="progressbar" progress={progress} /> <Loader
id="preview-loader"
role="progressbar"
progress={progress || { value: 1, message: 'Booting' }}
/>
</S.LoaderWrapper> </S.LoaderWrapper>
)} )}
<ApplyWrappers <ApplyWrappers