Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Canvas] Only runs duplicate workpad load once #30150

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions x-pack/plugins/canvas/public/apps/workpad/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/canvas/public/state/actions/transient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
1 change: 1 addition & 0 deletions x-pack/plugins/canvas/public/state/initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/canvas/public/state/reducers/transient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/canvas/public/state/selectors/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down