Skip to content
Snippets Groups Projects
Commit 838e2fd7 authored by Glenn Fischer's avatar Glenn Fischer
Browse files

#1874: refactors config import

parent 467c60f4
No related branches found
No related tags found
No related merge requests found
...@@ -13,10 +13,11 @@ export class WorkspaceExport extends Component { ...@@ -13,10 +13,11 @@ export class WorkspaceExport extends Component {
*/ */
exportableState() { exportableState() {
const { state } = this.props; const { state } = this.props;
const { config, windows } = state; const { config, viewers, windows } = state;
return JSON.stringify({ return JSON.stringify({
config, config,
viewers,
windows, windows,
}, null, 2); }, null, 2);
} }
......
...@@ -12,7 +12,6 @@ import { App } from '../components/App'; ...@@ -12,7 +12,6 @@ import { App } from '../components/App';
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => (
{ {
errors: state.errors,
isFullscreenEnabled: state.workspace.isFullscreenEnabled, isFullscreenEnabled: state.workspace.isFullscreenEnabled,
language: state.config.language, language: state.config.language,
theme: state.config.theme, theme: state.config.theme,
...@@ -26,7 +25,6 @@ const mapStateToProps = state => ( ...@@ -26,7 +25,6 @@ const mapStateToProps = state => (
* @private * @private
*/ */
const mapDispatchToProps = { const mapDispatchToProps = {
removeError: actions.removeError,
setWorkspaceFullscreen: actions.setWorkspaceFullscreen, setWorkspaceFullscreen: actions.setWorkspaceFullscreen,
}; };
......
...@@ -5,13 +5,6 @@ import { withPlugins } from '../extend'; ...@@ -5,13 +5,6 @@ import { withPlugins } from '../extend';
import WorkspaceImport from '../components/WorkspaceImport'; import WorkspaceImport from '../components/WorkspaceImport';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
/**
* mapStateToProps - to hook up connect
* @memberof WorkspaceImport
* @private
*/
const mapStateToProps = state => ({ state });
/** /**
* mapDispatchToProps - used to hook up connect to action creators * mapDispatchToProps - used to hook up connect to action creators
* @memberof App * @memberof App
...@@ -23,7 +16,7 @@ const mapDispatchToProps = { ...@@ -23,7 +16,7 @@ const mapDispatchToProps = {
}; };
const enhance = compose( const enhance = compose(
connect(mapStateToProps, mapDispatchToProps), connect(null, mapDispatchToProps),
withTranslation(), withTranslation(),
withPlugins('WorkspaceImport'), withPlugins('WorkspaceImport'),
); );
......
import _ from 'lodash'; import { difference, values } from 'lodash';
import ActionTypes from './action-types'; import ActionTypes from './action-types';
import { importConfig } from './config'; import { importConfig } from './config';
import { removeWindow, addWindow, updateWindow } from './window'; import { removeWindow, addWindow, updateWindow } from './window';
...@@ -97,33 +97,33 @@ export function toggleWorkspaceExposeMode() { ...@@ -97,33 +97,33 @@ export function toggleWorkspaceExposeMode() {
export function importWorkspace(stateExport) { export function importWorkspace(stateExport) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch(importConfig(stateExport.config)); dispatch(importConfig(stateExport.config));
const { viewers } = stateExport; const { viewers } = stateExport || {};
const newWindows = stateExport.windows; const imWins = values(stateExport.windows);
const newWindowsKeys = _.keys(newWindows);
const newWindowsCnt = newWindowsKeys.length;
const existingWindows = getState().windows; /* re-use existing windows */
const existingWindowsKeys = _.keys(existingWindows); const exIds = values(getState().windows).map((exWin) => {
const existingWindowsCnt = existingWindowsKeys.length; const imWin = imWins.shift();
const viewer = viewers[imWin.id];
delete imWin.id;
let currentKey = ''; dispatch(fetchManifest(imWin.manifestId));
// re-use existing windows dispatch(updateWindow(exWin.id, imWin));
for (let i = 0; i < newWindowsCnt; i++) { // eslint-disable-line no-plusplus dispatch(updateViewport(exWin.id, viewer));
dispatch(fetchManifest(newWindows[newWindowsKeys[i]].manifestId));
if (i < existingWindowsCnt) {
currentKey = existingWindowsKeys[i];
delete newWindows[newWindowsKeys[i]].id;
dispatch(updateWindow(existingWindowsKeys[i], newWindows[newWindowsKeys[i]]));
} else {
dispatch(addWindow(newWindows[newWindowsKeys[i]]));
currentKey = newWindowsKeys[i];
}
dispatch(updateViewport(currentKey, viewers[newWindowsKeys[i]]));
}
// clean up surplus windows if there are any return exWin.id;
if (existingWindowsCnt > newWindowsCnt) { });
Object.keys(existingWindows).slice(newWindowsCnt).map(windowId => dispatch(removeWindow(windowId))); // eslint-disable-line max-len
} /* create new windows for additionally imported ones */
const imIds = imWins.map((imWin) => {
dispatch(fetchManifest(imWin.manifestId));
dispatch(addWindow(imWin));
dispatch(updateViewport(imWin.id, viewers[imWin.id]));
return imWin.id;
});
/* close surplus windows */
difference(getState().windows, exIds.concat(imIds))
.map(winId => dispatch(removeWindow(winId)));
}; };
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment