diff --git a/x-pack/plugins/canvas/public/apps/workpad/routes.js b/x-pack/plugins/canvas/public/apps/workpad/routes.js index 62e2fe4fbe859..25d1fd28173b3 100644 --- a/x-pack/plugins/canvas/public/apps/workpad/routes.js +++ b/x-pack/plugins/canvas/public/apps/workpad/routes.js @@ -11,7 +11,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 = [ @@ -47,7 +48,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); @@ -59,11 +62,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'); diff --git a/x-pack/plugins/canvas/public/state/actions/transient.js b/x-pack/plugins/canvas/public/state/actions/transient.js index 93464a23bf500..11d0a43fb2fde 100644 --- a/x-pack/plugins/canvas/public/state/actions/transient.js +++ b/x-pack/plugins/canvas/public/state/actions/transient.js @@ -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'); diff --git a/x-pack/plugins/canvas/public/state/initial_state.js b/x-pack/plugins/canvas/public/state/initial_state.js index b6e54af9ecbb6..0f84079c1df21 100644 --- a/x-pack/plugins/canvas/public/state/initial_state.js +++ b/x-pack/plugins/canvas/public/state/initial_state.js @@ -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, diff --git a/x-pack/plugins/canvas/public/state/reducers/transient.js b/x-pack/plugins/canvas/public/state/reducers/transient.js index a99d85b399c7e..6f2f2dd3bb169 100644 --- a/x-pack/plugins/canvas/public/state/reducers/transient.js +++ b/x-pack/plugins/canvas/public/state/reducers/transient.js @@ -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)); }, diff --git a/x-pack/plugins/canvas/public/state/selectors/app.js b/x-pack/plugins/canvas/public/state/selectors/app.js index 0f13df85a0353..26e5fff11b786 100644 --- a/x-pack/plugins/canvas/public/state/selectors/app.js +++ b/x-pack/plugins/canvas/public/state/selectors/app.js @@ -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); }