fix: don't show progress when loading preview status (#2974)
This commit is contained in:
parent
e4272817c2
commit
af61245360
50
packages/netlify-cms-core/src/reducers/__tests__/globalUI.js
Normal file
50
packages/netlify-cms-core/src/reducers/__tests__/globalUI.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { Map } from 'immutable';
|
||||||
|
import { USE_OPEN_AUTHORING } from 'Actions/auth';
|
||||||
|
import {
|
||||||
|
DEPLOY_PREVIEW_REQUEST,
|
||||||
|
DEPLOY_PREVIEW_SUCCESS,
|
||||||
|
DEPLOY_PREVIEW_FAILURE,
|
||||||
|
} from 'Actions/deploys';
|
||||||
|
import { ENTRY_REQUEST, ENTRY_SUCCESS, ENTRY_FAILURE } from 'Actions/entries';
|
||||||
|
import reducer from '../globalUI';
|
||||||
|
|
||||||
|
describe('globalUI', () => {
|
||||||
|
it('should set isFetching to true on entry request', () => {
|
||||||
|
expect(reducer(Map({ isFetching: false }), { type: ENTRY_REQUEST })).toEqual(
|
||||||
|
Map({ isFetching: true }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set isFetching to false on entry success', () => {
|
||||||
|
expect(reducer(Map({ isFetching: true }), { type: ENTRY_SUCCESS })).toEqual(
|
||||||
|
Map({ isFetching: false }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set isFetching to false on entry failure', () => {
|
||||||
|
expect(reducer(Map({ isFetching: true }), { type: ENTRY_FAILURE })).toEqual(
|
||||||
|
Map({ isFetching: false }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change state on deploy preview request', () => {
|
||||||
|
const state = Map({ isFetching: false });
|
||||||
|
expect(reducer(state, { type: DEPLOY_PREVIEW_REQUEST })).toBe(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change state on deploy preview success', () => {
|
||||||
|
const state = Map({ isFetching: true });
|
||||||
|
expect(reducer(state, { type: DEPLOY_PREVIEW_SUCCESS })).toBe(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change state on deploy preview failure', () => {
|
||||||
|
const state = Map({ isFetching: true });
|
||||||
|
expect(reducer(state, { type: DEPLOY_PREVIEW_FAILURE })).toBe(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set useOpenAuthoring to true on USE_OPEN_AUTHORING', () => {
|
||||||
|
expect(reducer(Map({ useOpenAuthoring: false }), { type: USE_OPEN_AUTHORING })).toEqual(
|
||||||
|
Map({ useOpenAuthoring: true }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -1,13 +1,21 @@
|
|||||||
import { Map } from 'immutable';
|
import { Map } from 'immutable';
|
||||||
import { USE_OPEN_AUTHORING } from 'Actions/auth';
|
import { USE_OPEN_AUTHORING } from 'Actions/auth';
|
||||||
|
|
||||||
|
const LOADING_IGNORE_LIST = ['DEPLOY_PREVIEW'];
|
||||||
|
|
||||||
|
const ignoreWhenLoading = action => LOADING_IGNORE_LIST.some(type => action.type.includes(type));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reducer for some global UI state that we want to share between components
|
* Reducer for some global UI state that we want to share between components
|
||||||
* */
|
* */
|
||||||
const globalUI = (state = Map({ isFetching: false, useOpenAuthoring: false }), action) => {
|
const globalUI = (state = Map({ isFetching: false, useOpenAuthoring: false }), action) => {
|
||||||
// Generic, global loading indicator
|
// Generic, global loading indicator
|
||||||
if (action.type.indexOf('REQUEST') > -1) {
|
if (!ignoreWhenLoading(action) && action.type.includes('REQUEST')) {
|
||||||
return state.set('isFetching', true);
|
return state.set('isFetching', true);
|
||||||
} else if (action.type.indexOf('SUCCESS') > -1 || action.type.indexOf('FAILURE') > -1) {
|
} else if (
|
||||||
|
!ignoreWhenLoading(action) &&
|
||||||
|
(action.type.includes('SUCCESS') || action.type.includes('FAILURE'))
|
||||||
|
) {
|
||||||
return state.set('isFetching', false);
|
return state.set('isFetching', false);
|
||||||
} else if (action.type === USE_OPEN_AUTHORING) {
|
} else if (action.type === USE_OPEN_AUTHORING) {
|
||||||
return state.set('useOpenAuthoring', true);
|
return state.set('useOpenAuthoring', true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user