fix(core): report config error when external media lib is missing (#3255)
This commit is contained in:
parent
02ef2010e7
commit
1d63038e78
@ -5,6 +5,7 @@
|
||||
import { once } from 'lodash';
|
||||
import { getMediaLibrary } from './lib/registry';
|
||||
import store from './redux';
|
||||
import { configFailed } from './actions/config';
|
||||
import { createMediaLibrary, insertMedia } from './actions/mediaLibrary';
|
||||
import { MediaLibraryInstance } from './types/redux';
|
||||
|
||||
@ -18,10 +19,17 @@ interface MediaLibrary {
|
||||
}
|
||||
|
||||
const initializeMediaLibrary = once(async function initializeMediaLibrary(name, options) {
|
||||
const lib = (getMediaLibrary(name) as unknown) as MediaLibrary;
|
||||
const handleInsert = (url: string) => store.dispatch(insertMedia(url, undefined));
|
||||
const instance = await lib.init({ options, handleInsert });
|
||||
store.dispatch(createMediaLibrary(instance));
|
||||
const lib = (getMediaLibrary(name) as unknown) as MediaLibrary | undefined;
|
||||
if (!lib) {
|
||||
const err = new Error(
|
||||
`Missing external media library '${name}'. Please use 'registerMediaLibrary' to register it.`,
|
||||
);
|
||||
store.dispatch(configFailed(err));
|
||||
} else {
|
||||
const handleInsert = (url: string) => store.dispatch(insertMedia(url, undefined));
|
||||
const instance = await lib.init({ options, handleInsert });
|
||||
store.dispatch(createMediaLibrary(instance));
|
||||
}
|
||||
});
|
||||
|
||||
store.subscribe(() => {
|
||||
|
@ -3,7 +3,9 @@ import { CONFIG_REQUEST, CONFIG_SUCCESS, CONFIG_FAILURE, CONFIG_MERGE } from '..
|
||||
import { Config, ConfigAction } from '../types/redux';
|
||||
import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
|
||||
|
||||
const config = (state = Map({ isFetching: true }), action: ConfigAction) => {
|
||||
const defaultState: Map<string, boolean | string> = Map({ isFetching: true });
|
||||
|
||||
const config = (state = defaultState, action: ConfigAction) => {
|
||||
switch (action.type) {
|
||||
case CONFIG_MERGE:
|
||||
return state.mergeDeep(action.payload);
|
||||
@ -17,7 +19,10 @@ const config = (state = Map({ isFetching: true }), action: ConfigAction) => {
|
||||
*/
|
||||
return action.payload.delete('isFetching');
|
||||
case CONFIG_FAILURE:
|
||||
return Map({ error: action.payload.toString() });
|
||||
return state.withMutations(s => {
|
||||
s.delete('isFetching');
|
||||
s.set('error', action.payload.toString());
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ export type Config = StaticallyTypedRecord<{
|
||||
site_id?: string;
|
||||
site_url?: string;
|
||||
show_preview_links?: boolean;
|
||||
isFetching?: boolean;
|
||||
}>;
|
||||
|
||||
type PagesObject = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user