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
No related branches found
No related tags found
No related merge requests found
import * as actions from '../../../src/state/actions'; import * as actions from '../../../src/state/actions';
import ActionTypes from '../../../src/state/actions/action-types'; import ActionTypes from '../../../src/state/actions/action-types';
import configFixture from '../../fixtures/config/export.example.json';
describe('config actions', () => { describe('config actions', () => {
describe('setConfig', () => { describe('setConfig', () => {
...@@ -22,4 +23,15 @@ describe('config actions', () => { ...@@ -22,4 +23,15 @@ describe('config actions', () => {
expect(actions.updateConfig(config)).toEqual(expectedAction); 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 { ...@@ -27,6 +27,7 @@ export class ErrorDialog extends Component {
/* extract 'items' value and get first key-value-pair (an error) */ /* extract 'items' value and get first key-value-pair (an error) */
const error = first(values(omit(errors, 'items'))); const error = first(values(omit(errors, 'items')));
const hasError = !isUndefined(error); const hasError = !isUndefined(error);
return ( return (
<div> <div>
{ hasError && ( { hasError && (
......
import { difference, values } from 'lodash'; import {
difference,
keys,
slice,
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';
...@@ -99,9 +104,16 @@ export function importWorkspace(stateExport) { ...@@ -99,9 +104,16 @@ export function importWorkspace(stateExport) {
dispatch(importConfig(stateExport.config)); dispatch(importConfig(stateExport.config));
const { viewers } = stateExport || {}; const { viewers } = stateExport || {};
const imWins = values(stateExport.windows); 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 imWin = imWins.shift();
const viewer = viewers[imWin.id]; const viewer = viewers[imWin.id];
delete imWin.id; delete imWin.id;
...@@ -123,7 +135,7 @@ export function importWorkspace(stateExport) { ...@@ -123,7 +135,7 @@ export function importWorkspace(stateExport) {
}); });
/* close surplus windows */ /* close surplus windows */
difference(getState().windows, exIds.concat(imIds)) difference(keys(getState().windows), exIds.concat(imIds))
.map(winId => dispatch(removeWindow(winId))); .map(winId => dispatch(removeWindow(winId)));
}; };
} }
...@@ -82,6 +82,10 @@ export const windowsReducer = (state = {}, action) => { ...@@ -82,6 +82,10 @@ export const windowsReducer = (state = {}, action) => {
y: action.payload.size.y, 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: case ActionTypes.SET_CANVAS:
return setCanvasIndex(state, action.windowId, currentIndex => action.canvasIndex); return setCanvasIndex(state, action.windowId, currentIndex => action.canvasIndex);
case ActionTypes.ADD_COMPANION_WINDOW: case ActionTypes.ADD_COMPANION_WINDOW:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment