Split packages into platform and extensions
This commit is contained in:
1 parent
f175d4b96b
commit
e8969fba11
992 files changed
+2
-1
No files matched your search
@@ -0,0 +1,25 @@
|
||||
export const defaultState = {};
|
||||
|
||||
const extensions = (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_EXTENSION_DATA':
|
||||
const extensionName = action.extension;
|
||||
const currentData = state[extensionName] || {};
|
||||
|
||||
const incomingData = action.data;
|
||||
|
||||
const extension = {
|
||||
[extensionName]: {
|
||||
...currentData,
|
||||
...incomingData,
|
||||
},
|
||||
};
|
||||
|
||||
return { ...state, ...extension };
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default extensions;
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Reducer } from 'redux-testkit';
|
||||
|
||||
import reducer, { defaultState } from './extensions';
|
||||
import * as actionTypes from './../constants/ActionTypes.js';
|
||||
|
||||
describe('viewports reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(defaultState);
|
||||
});
|
||||
|
||||
it('should set new data on first SET_EXTENSION_DATA', () => {
|
||||
const initialState = defaultState;
|
||||
|
||||
const action = {
|
||||
type: actionTypes.SET_EXTENSION_DATA,
|
||||
extension: 'uber plugin',
|
||||
data: { greeting: 'Hello!' },
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
'uber plugin': { greeting: 'Hello!' },
|
||||
};
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(expectedState);
|
||||
});
|
||||
|
||||
it('should shallow-merge extension data, keeping unmodified fields, on SET_EXTENSION_DATA', () => {
|
||||
const initialState = {
|
||||
'uber plugin': { greeting: 'Hello!', "Can't touch this": 42 },
|
||||
};
|
||||
|
||||
const action = {
|
||||
type: actionTypes.SET_EXTENSION_DATA,
|
||||
extension: 'uber plugin',
|
||||
data: { greeting: 'Aloha!' },
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
'uber plugin': { greeting: 'Aloha!', "Can't touch this": 42 },
|
||||
};
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(expectedState);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import extensions from './extensions';
|
||||
import loading from './loading';
|
||||
import preferences from './preferences';
|
||||
import servers from './servers';
|
||||
import studies from './studies';
|
||||
import timepointManager from './timepointManager';
|
||||
import viewports from './viewports';
|
||||
|
||||
const reducers = {
|
||||
extensions,
|
||||
loading,
|
||||
preferences,
|
||||
servers,
|
||||
studies,
|
||||
timepointManager,
|
||||
viewports,
|
||||
};
|
||||
|
||||
export default reducers;
|
||||
@@ -0,0 +1,33 @@
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
|
||||
const defaultState = {
|
||||
progress: {},
|
||||
lastUpdated: null,
|
||||
};
|
||||
|
||||
const loading = (state = defaultState, action) => {
|
||||
let progress;
|
||||
let lastUpdated;
|
||||
switch (action.type) {
|
||||
case 'SET_STUDY_LOADING_PROGRESS':
|
||||
progress = cloneDeep(state).progress;
|
||||
progress[action.progressId] = action.progressData;
|
||||
|
||||
// This is a workaround so we can easily identify changes
|
||||
// to the progress object without doing deep comparison.
|
||||
lastUpdated = new Date().getTime();
|
||||
|
||||
return Object.assign({}, state, { progress, lastUpdated });
|
||||
case 'CLEAR_STUDY_LOADING_PROGRESS':
|
||||
progress = cloneDeep(state).progress;
|
||||
delete progress[action.progressId];
|
||||
|
||||
lastUpdated = new Date().getTime();
|
||||
|
||||
return Object.assign({}, state, { progress, lastUpdated });
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default loading;
|
||||
@@ -0,0 +1,31 @@
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
|
||||
const defaultState = {
|
||||
// Top level key
|
||||
viewer: {
|
||||
// First tab
|
||||
hotKeysData: {
|
||||
// hotkeyName, label, keys, column
|
||||
// zoom: { label: 'Zoom', command: 'Z', column: 0 },
|
||||
},
|
||||
// Second tab
|
||||
windowLevelData: {
|
||||
// order, description, window (int), level (int)
|
||||
// 0: { description: 'Soft tissue', window: '', level: '' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const preferences = (state, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_USER_PREFERENCES': {
|
||||
const newState = action.state ? action.state : cloneDeep(defaultState);
|
||||
|
||||
return Object.assign({}, state, newState);
|
||||
}
|
||||
default:
|
||||
return cloneDeep(state) || cloneDeep(defaultState);
|
||||
}
|
||||
};
|
||||
|
||||
export default preferences;
|
||||
@@ -0,0 +1,22 @@
|
||||
import uniqBy from 'lodash/uniqBy';
|
||||
|
||||
export const defaultState = {
|
||||
servers: [],
|
||||
};
|
||||
|
||||
const servers = (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'ADD_SERVER':
|
||||
let servers = uniqBy([...state.servers, action.server], 'id');
|
||||
servers.forEach(s => (s.active = true));
|
||||
return { ...state, servers };
|
||||
|
||||
case 'SET_SERVERS':
|
||||
return { ...state, servers: action.servers };
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default servers;
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Reducer } from 'redux-testkit';
|
||||
|
||||
import reducer, { defaultState } from './servers';
|
||||
import * as types from './../constants/ActionTypes.js';
|
||||
|
||||
describe('viewports reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(defaultState);
|
||||
});
|
||||
|
||||
it('should result in one server when there were no servers before on ADD_SERVER', () => {
|
||||
const initialState = defaultState;
|
||||
|
||||
const action = { type: types.ADD_SERVER, server: { id: 'some-server-id' } };
|
||||
|
||||
const expectedState = { servers: [action.server] };
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(expectedState);
|
||||
});
|
||||
|
||||
it('should add to servers list on ADD_SERVER', () => {
|
||||
const initialState = {
|
||||
servers: [
|
||||
{ id: 'one', active: true },
|
||||
{ id: 'two', active: true },
|
||||
{ id: 'three', active: true },
|
||||
{ id: 'four', active: true },
|
||||
],
|
||||
};
|
||||
|
||||
const action = {
|
||||
type: types.ADD_SERVER,
|
||||
server: { id: 'five', active: true },
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
servers: [...initialState.servers, action.server],
|
||||
};
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(expectedState);
|
||||
});
|
||||
|
||||
it('should not add duplicated servers on ADD_SERVER', () => {
|
||||
const initialState = {
|
||||
servers: [
|
||||
{ id: 'one', active: true },
|
||||
{ id: 'two', active: true },
|
||||
{ id: 'three', active: true },
|
||||
{ id: 'four', active: true },
|
||||
],
|
||||
};
|
||||
|
||||
const action = {
|
||||
type: types.ADD_SERVER,
|
||||
server: { id: 'two', active: true },
|
||||
};
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(initialState);
|
||||
});
|
||||
|
||||
it('should replace servers on SET_SERVERS', () => {
|
||||
const initialState = {
|
||||
servers: [{ id: 'one' }, { id: 'two' }, { id: 'three' }, { id: 'four' }],
|
||||
};
|
||||
|
||||
const action = {
|
||||
type: types.SET_SERVERS,
|
||||
servers: [{ id: 'un' }, { id: 'deux' }, { id: 'trois' }],
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
servers: action.servers,
|
||||
};
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(expectedState);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
|
||||
const defaultState = {
|
||||
studyData: {},
|
||||
};
|
||||
|
||||
const servers = (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_STUDY_DATA':
|
||||
const updatedStudyData = cloneDeep(state).studyData;
|
||||
updatedStudyData[action.studyInstanceUid] = action.data;
|
||||
|
||||
return Object.assign({}, state, { studyData: updatedStudyData });
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default servers;
|
||||
@@ -0,0 +1,17 @@
|
||||
const defaultState = {
|
||||
timepoints: [],
|
||||
measurements: [],
|
||||
};
|
||||
|
||||
const timepointManager = (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_TIMEPOINTS':
|
||||
return Object.assign({}, state, { timepoints: action.state });
|
||||
case 'SET_MEASUREMENTS':
|
||||
return Object.assign({}, state, { measurements: action.state });
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default timepointManager;
|
||||
@@ -0,0 +1,97 @@
|
||||
import {
|
||||
CLEAR_VIEWPORT,
|
||||
SET_ACTIVE_SPECIFIC_DATA,
|
||||
SET_SPECIFIC_DATA,
|
||||
SET_VIEWPORT,
|
||||
SET_VIEWPORT_ACTIVE,
|
||||
SET_VIEWPORT_LAYOUT,
|
||||
SET_VIEWPORT_LAYOUT_AND_DATA,
|
||||
} from './../constants/ActionTypes.js';
|
||||
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
import merge from 'lodash.merge';
|
||||
|
||||
const defaultState = {
|
||||
activeViewportIndex: 0,
|
||||
layout: {
|
||||
viewports: [
|
||||
{
|
||||
// plugin: 'cornerstone',
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
],
|
||||
},
|
||||
viewportSpecificData: {},
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} [state=defaultState]
|
||||
* @param {Object} action
|
||||
* @param {string} [action.type]
|
||||
* @param {number} [action.viewportIndex]
|
||||
* @param {Object} [action.layout]
|
||||
* @param {Object} [action.viewportSpecificData]
|
||||
*/
|
||||
const viewports = (state = defaultState, action) => {
|
||||
let currentData;
|
||||
let viewportSpecificData;
|
||||
let useActiveViewport = false;
|
||||
switch (action.type) {
|
||||
case SET_VIEWPORT_LAYOUT_AND_DATA:
|
||||
return Object.assign({}, state, {
|
||||
viewportSpecificData: action.viewportSpecificData,
|
||||
layout: action.layout,
|
||||
});
|
||||
case SET_VIEWPORT_ACTIVE:
|
||||
return Object.assign({}, state, {
|
||||
activeViewportIndex: action.viewportIndex,
|
||||
});
|
||||
case SET_VIEWPORT_LAYOUT:
|
||||
return Object.assign({}, state, { layout: action.layout });
|
||||
case SET_VIEWPORT: {
|
||||
const layout = cloneDeep(state.layout);
|
||||
const hasPlugin = action.data && action.data.plugin;
|
||||
|
||||
viewportSpecificData = cloneDeep(state.viewportSpecificData);
|
||||
viewportSpecificData[action.viewportIndex] = merge(
|
||||
{},
|
||||
viewportSpecificData[action.viewportIndex],
|
||||
action.data
|
||||
);
|
||||
|
||||
if (hasPlugin) {
|
||||
layout.viewports[action.viewportIndex].plugin = action.data.plugin;
|
||||
}
|
||||
|
||||
return Object.assign({}, state, { layout, viewportSpecificData });
|
||||
}
|
||||
case SET_ACTIVE_SPECIFIC_DATA:
|
||||
useActiveViewport = true;
|
||||
// Allow fall-through
|
||||
// eslint-disable-next-line
|
||||
case SET_SPECIFIC_DATA: {
|
||||
const viewportIndex = useActiveViewport
|
||||
? state.activeViewportIndex
|
||||
: action.viewportIndex;
|
||||
currentData = cloneDeep(state.viewportSpecificData[viewportIndex]) || {};
|
||||
viewportSpecificData = cloneDeep(state.viewportSpecificData);
|
||||
viewportSpecificData[viewportIndex] = merge({}, currentData, action.data);
|
||||
|
||||
return Object.assign({}, state, { viewportSpecificData });
|
||||
}
|
||||
case CLEAR_VIEWPORT:
|
||||
viewportSpecificData = cloneDeep(state.viewportSpecificData);
|
||||
if (action.viewportIndex) {
|
||||
viewportSpecificData[action.viewportIndex] = {};
|
||||
return Object.assign({}, state, { viewportSpecificData });
|
||||
} else {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default viewports;
|
||||
@@ -0,0 +1,101 @@
|
||||
// https://medium.com/@netxm/testing-redux-reducers-with-jest-6653abbfe3e1
|
||||
import reducer from './viewports.js';
|
||||
import * as types from './../constants/ActionTypes.js';
|
||||
|
||||
describe('viewports reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual({
|
||||
activeViewportIndex: 0,
|
||||
layout: {
|
||||
viewports: [
|
||||
{
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
],
|
||||
},
|
||||
viewportSpecificData: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle SET_VIEWPORT_ACTIVE', () => {
|
||||
const setViewportActiveAction = {
|
||||
type: types.SET_VIEWPORT_ACTIVE,
|
||||
viewportIndex: 100,
|
||||
};
|
||||
|
||||
const updatedState = reducer({}, setViewportActiveAction);
|
||||
|
||||
expect(updatedState.activeViewportIndex).toEqual(
|
||||
setViewportActiveAction.viewportIndex
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle SET_VIEWPORT_LAYOUT', () => {
|
||||
const setViewportLayoutAction = {
|
||||
type: types.SET_VIEWPORT_LAYOUT,
|
||||
layout: {
|
||||
viewports: [
|
||||
{
|
||||
height: '100%',
|
||||
width: '50%',
|
||||
},
|
||||
{
|
||||
height: '100%',
|
||||
width: '50%',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const updatedState = reducer({}, setViewportLayoutAction);
|
||||
|
||||
expect(updatedState.layout).toEqual(setViewportLayoutAction.layout);
|
||||
});
|
||||
|
||||
// If there were previous keys, this would have
|
||||
// "merge" behavior, not a clear & set
|
||||
// May be worth another test?
|
||||
it('should handle SET_VIEWPORT', () => {
|
||||
const viewportToSet = 0;
|
||||
const setViewportAction = {
|
||||
type: types.SET_VIEWPORT,
|
||||
viewportIndex: viewportToSet,
|
||||
data: {
|
||||
hello: 'this is that data for the viewport',
|
||||
world: 'that will be set for the viewportIndex',
|
||||
},
|
||||
};
|
||||
|
||||
const updatedState = reducer(undefined, setViewportAction);
|
||||
const updatedViewport = updatedState.viewportSpecificData[viewportToSet];
|
||||
|
||||
expect(updatedViewport).toEqual(setViewportAction.data);
|
||||
});
|
||||
|
||||
it('should handle CLEAR_VIEWPORT', () => {
|
||||
const existingViewportData = {
|
||||
viewportSpecificData: {
|
||||
0: {
|
||||
viewportProperty: 'hello world',
|
||||
},
|
||||
1: {
|
||||
viewportProperty: 'fizzbuzz',
|
||||
},
|
||||
},
|
||||
};
|
||||
const clearViewportAction = {
|
||||
type: types.CLEAR_VIEWPORT,
|
||||
viewportIndex: 1,
|
||||
};
|
||||
|
||||
const updatedState = reducer(existingViewportData, clearViewportAction);
|
||||
const clearedViewport =
|
||||
updatedState.viewportSpecificData[clearViewportAction.viewportIndex];
|
||||
const originalOtherViewport = existingViewportData.viewportSpecificData[0];
|
||||
const updatedOtherViewport = updatedState.viewportSpecificData[0];
|
||||
|
||||
expect(clearedViewport).toEqual({});
|
||||
expect(updatedOtherViewport).toEqual(originalOtherViewport);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user