mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
parent
d0b4864e4e
commit
b14fcfe656
5 changed files with 23 additions and 7 deletions
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue