Added isFirstLoad to transient state. (#30150) (#30701)

This commit is contained in:
Catherine Liu 2019-02-11 14:05:21 -07:00 committed by GitHub
parent d0b4864e4e
commit b14fcfe656
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 7 deletions

View file

@ -12,7 +12,8 @@ import { setWorkpad } from '../../state/actions/workpad';
import { setAssets, resetAssets } from '../../state/actions/assets';
import { gotoPage } from '../../state/actions/pages';
import { getWorkpad } from '../../state/selectors/workpad';
import { setCanUserWrite } from '../../state/actions/transient';
import { isFirstLoad } from '../../state/selectors/app';
import { setCanUserWrite, setFirstLoad } from '../../state/actions/transient';
import { WorkpadApp } from './workpad_app';
export const routes = [
@ -48,7 +49,9 @@ export const routes = [
path: '/:id(/page/:page)',
action: (dispatch, getState) => async ({ params, router }) => {
// load workpad if given a new id via url param
const currentWorkpad = getWorkpad(getState());
const state = getState();
const currentWorkpad = getWorkpad(state);
const firstLoad = isFirstLoad(state);
if (params.id !== currentWorkpad.id) {
try {
const fetchedWorkpad = await workpadService.get(params.id);
@ -60,11 +63,14 @@ export const routes = [
// tests if user has permissions to write to workpads
// TODO: remove this and switch to checking user privileges when canvas loads when granular app privileges are introduced
// https://github.com/elastic/kibana/issues/20277
workpadService.update(params.id, fetchedWorkpad).catch(err => {
if (err.response && err.response.status === 403) {
dispatch(setCanUserWrite(false));
}
});
if (firstLoad) {
workpadService.update(params.id, fetchedWorkpad).catch(err => {
if (err.response && err.response.status === 403) {
dispatch(setCanUserWrite(false));
}
});
dispatch(setFirstLoad(false));
}
} catch (err) {
notify.error(err, { title: `Couldn't load workpad with ID` });
return router.redirectTo('home');

View file

@ -9,3 +9,4 @@ import { createAction } from 'redux-actions';
export const setCanUserWrite = createAction('setCanUserWrite');
export const setFullscreen = createAction('setFullscreen');
export const selectElement = createAction('selectElement');
export const setFirstLoad = createAction('setFirstLoad');

View file

@ -12,6 +12,7 @@ export const getInitialState = path => {
app: {}, // Kibana stuff in here
assets: {}, // assets end up here
transient: {
isFirstLoad: true,
canUserWrite: true,
fullscreen: false,
selectedElement: null,

View file

@ -32,6 +32,10 @@ export const transientReducer = handleActions(
return set(transientState, 'canUserWrite', Boolean(payload));
},
[actions.setFirstLoad]: (transientState, { payload }) => {
return set(transientState, 'isFirstLoad', Boolean(payload));
},
[actions.setFullscreen]: (transientState, { payload }) => {
return set(transientState, 'fullscreen', Boolean(payload));
},

View file

@ -11,6 +11,10 @@ export function canUserWrite(state) {
return get(state, 'transient.canUserWrite', true);
}
export function isFirstLoad(state) {
return get(state, 'transient.isFirstLoad', true);
}
export function getFullscreen(state) {
return get(state, 'transient.fullscreen', false);
}