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

#1874: adds test, fixes errorwhen windows to be imported are less than already existing ones

parent da1a19c5
Branches
Tags
No related merge requests found
import * as actions from '../../../src/state/actions';
import ActionTypes from '../../../src/state/actions/action-types';
import configFixture from '../../fixtures/config/export.example.json';
describe('config actions', () => {
describe('setConfig', () => {
......@@ -22,4 +23,15 @@ describe('config actions', () => {
expect(actions.updateConfig(config)).toEqual(expectedAction);
});
});
describe('importConfig', () => {
it('imports the config', () => {
const config = configFixture;
const expectedAction = {
type: ActionTypes.IMPORT_CONFIG,
config,
};
expect(actions.importConfig(config)).toEqual(expectedAction);
});
});
});
......@@ -27,6 +27,7 @@ export class ErrorDialog extends Component {
/* extract 'items' value and get first key-value-pair (an error) */
const error = first(values(omit(errors, 'items')));
const hasError = !isUndefined(error);
return (
<div>
{ hasError && (
......
import { difference, values } from 'lodash';
import {
difference,
keys,
slice,
values,
} from 'lodash';
import ActionTypes from './action-types';
import { importConfig } from './config';
import { removeWindow, addWindow, updateWindow } from './window';
......@@ -99,9 +104,16 @@ export function importWorkspace(stateExport) {
dispatch(importConfig(stateExport.config));
const { viewers } = stateExport || {};
const imWins = values(stateExport.windows);
const exWins = values(getState().windows);
const exWinCnt = exWins.length > imWins.length ? imWins.length : exWins.length;
/* re-use existing windows */
const exIds = values(getState().windows).map((exWin) => {
/*
If the existing workspace already contains windows (exWins),
we can re-use them in order to optimize the performance.
As we only can only re-use the amount of windows to be imported maximally,
slice all additional windows before
*/
const exIds = slice(exWins, 0, exWinCnt).map((exWin) => {
const imWin = imWins.shift();
const viewer = viewers[imWin.id];
delete imWin.id;
......@@ -123,7 +135,7 @@ export function importWorkspace(stateExport) {
});
/* close surplus windows */
difference(getState().windows, exIds.concat(imIds))
difference(keys(getState().windows), exIds.concat(imIds))
.map(winId => dispatch(removeWindow(winId)));
};
}
......@@ -82,6 +82,10 @@ export const windowsReducer = (state = {}, action) => {
y: action.payload.size.y,
},
};
case ActionTypes.NEXT_CANVAS:
return setCanvasIndex(state, action.windowId, currentIndex => currentIndex + 1);
case ActionTypes.PREVIOUS_CANVAS:
return setCanvasIndex(state, action.windowId, currentIndex => currentIndex - 1);
case ActionTypes.SET_CANVAS:
return setCanvasIndex(state, action.windowId, currentIndex => action.canvasIndex);
case ActionTypes.ADD_COMPANION_WINDOW:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment