From 2a1e0ba7630b1d301c4491fe1295cfaef6dc4697 Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Thu, 29 Aug 2019 11:34:47 -0400 Subject: [PATCH 1/2] Fix 'workpad flash' when loading new workpad --- .../apps/home/{ => home_app}/home_app.js | 7 ++++--- .../apps/home/{ => home_app}/home_app.scss | 0 .../canvas/public/apps/home/home_app/index.js | 20 +++++++++++++++++++ .../canvas/public/state/actions/workpad.js | 1 + .../public/state/middleware/es_persist.js | 5 ++++- .../canvas/public/state/reducers/workpad.js | 4 ++++ 6 files changed, 33 insertions(+), 4 deletions(-) rename x-pack/legacy/plugins/canvas/public/apps/home/{ => home_app}/home_app.js (79%) rename x-pack/legacy/plugins/canvas/public/apps/home/{ => home_app}/home_app.scss (100%) create mode 100644 x-pack/legacy/plugins/canvas/public/apps/home/home_app/index.js diff --git a/x-pack/legacy/plugins/canvas/public/apps/home/home_app.js b/x-pack/legacy/plugins/canvas/public/apps/home/home_app/home_app.js similarity index 79% rename from x-pack/legacy/plugins/canvas/public/apps/home/home_app.js rename to x-pack/legacy/plugins/canvas/public/apps/home/home_app/home_app.js index 0cb9172d7a2db..bfa4abbf7c56d 100644 --- a/x-pack/legacy/plugins/canvas/public/apps/home/home_app.js +++ b/x-pack/legacy/plugins/canvas/public/apps/home/home_app/home_app.js @@ -6,10 +6,11 @@ import React from 'react'; import { EuiPage, EuiPageBody, EuiPageContent } from '@elastic/eui'; -import { WorkpadManager } from '../../components/workpad_manager'; -import { setDocTitle } from '../../lib/doc_title'; +import { WorkpadManager } from '../../../components/workpad_manager'; +import { setDocTitle } from '../../../lib/doc_title'; -export const HomeApp = () => { +export const HomeApp = ({ onLoad = () => {} }) => { + onLoad(); setDocTitle('Canvas'); return ( diff --git a/x-pack/legacy/plugins/canvas/public/apps/home/home_app.scss b/x-pack/legacy/plugins/canvas/public/apps/home/home_app/home_app.scss similarity index 100% rename from x-pack/legacy/plugins/canvas/public/apps/home/home_app.scss rename to x-pack/legacy/plugins/canvas/public/apps/home/home_app/home_app.scss diff --git a/x-pack/legacy/plugins/canvas/public/apps/home/home_app/index.js b/x-pack/legacy/plugins/canvas/public/apps/home/home_app/index.js new file mode 100644 index 0000000000000..8ecde2cc721e3 --- /dev/null +++ b/x-pack/legacy/plugins/canvas/public/apps/home/home_app/index.js @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { connect } from 'react-redux'; +import { resetWorkpad } from '../../../state/actions/workpad'; +import { HomeApp as Component } from './home_app'; + +const mapDispatchToProps = dispatch => ({ + onLoad() { + dispatch(resetWorkpad()); + }, +}); + +export const HomeApp = connect( + null, + mapDispatchToProps +)(Component); diff --git a/x-pack/legacy/plugins/canvas/public/state/actions/workpad.js b/x-pack/legacy/plugins/canvas/public/state/actions/workpad.js index 4e6e8d7bd91ba..5a7fb76ca868c 100644 --- a/x-pack/legacy/plugins/canvas/public/state/actions/workpad.js +++ b/x-pack/legacy/plugins/canvas/public/state/actions/workpad.js @@ -18,6 +18,7 @@ export const setRefreshInterval = createAction('setRefreshInterval'); export const setWorkpadCSS = createAction('setWorkpadCSS'); export const enableAutoplay = createAction('enableAutoplay'); export const setAutoplayInterval = createAction('setAutoplayInterval'); +export const resetWorkpad = createAction('resetWorkpad'); export const initializeWorkpad = createThunk('initializeWorkpad', ({ dispatch }) => { dispatch(fetchAllRenderables()); diff --git a/x-pack/legacy/plugins/canvas/public/state/middleware/es_persist.js b/x-pack/legacy/plugins/canvas/public/state/middleware/es_persist.js index 5f8d0ea2918c6..154c46d9acdde 100644 --- a/x-pack/legacy/plugins/canvas/public/state/middleware/es_persist.js +++ b/x-pack/legacy/plugins/canvas/public/state/middleware/es_persist.js @@ -7,7 +7,8 @@ import { isEqual } from 'lodash'; import { getWorkpad, getFullWorkpadPersisted, getWorkpadPersisted } from '../selectors/workpad'; import { getAssetIds } from '../selectors/assets'; -import { setWorkpad, setRefreshInterval } from '../actions/workpad'; +import { appReady } from '../actions/app'; +import { setWorkpad, setRefreshInterval, resetWorkpad } from '../actions/workpad'; import { setAssets, resetAssets } from '../actions/assets'; import * as transientActions from '../actions/transient'; import * as resolvedArgsActions from '../actions/resolved_args'; @@ -28,6 +29,8 @@ const assetsChanged = (before, after) => { export const esPersistMiddleware = ({ getState }) => { // these are the actions we don't want to trigger a persist call const skippedActions = [ + appReady, // there's no need to resave the workpad once we've loaded it. + resetWorkpad, // used for resetting the workpad in state setWorkpad, // used for loading and creating workpads setAssets, // used when loading assets resetAssets, // used when creating new workpads diff --git a/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js b/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js index 124af96888b4c..12a2a2761b468 100644 --- a/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js +++ b/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js @@ -6,6 +6,7 @@ import { handleActions } from 'redux-actions'; import { recentlyAccessed } from 'ui/persisted_log'; +import { getDefaultWorkpad } from '../defaults'; import { setWorkpad, sizeWorkpad, @@ -13,6 +14,7 @@ import { setName, setWriteable, setWorkpadCSS, + resetWorkpad, } from '../actions/workpad'; import { APP_ROUTE_WORKPAD } from '../../../common/lib/constants'; @@ -44,6 +46,8 @@ export const workpadReducer = handleActions( [setWorkpadCSS]: (workpadState, { payload }) => { return { ...workpadState, css: payload }; }, + + [resetWorkpad]: () => ({ ...getDefaultWorkpad() }), }, {} ); From 49ef7de420e77c098e51ed03e9289aaafa8189db Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Thu, 29 Aug 2019 16:29:27 -0400 Subject: [PATCH 2/2] Fix SCSS path --- x-pack/legacy/plugins/canvas/public/style/index.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/canvas/public/style/index.scss b/x-pack/legacy/plugins/canvas/public/style/index.scss index 8e9d77664d2d7..0f59142b10a55 100644 --- a/x-pack/legacy/plugins/canvas/public/style/index.scss +++ b/x-pack/legacy/plugins/canvas/public/style/index.scss @@ -5,7 +5,7 @@ @import 'main'; // Canvas apps -@import '../apps/home/home_app'; +@import '../apps/home/home_app/home_app'; @import '../apps/workpad/workpad_app/workpad_app'; @import '../apps/export/export/export_app';