Chore/kill yalc with fire (#629)
* init * more shifting * Move @babel dependencies up to workspace root * Begin updating dependent libraries to use sync'd webpack builds w/ watches * Commit changes before a long weekend * Split packages into platform and extensions * Consolidate how/where we specify file/module type entrypoints * Make it possible to pass in extensions as App props * Resolve viewer's modules * Target for UMD bundle * Add Webpack Stylus loader * Provide WebPack build options for microscopy, vtk, and ui * Better entrypoint for extensions * Push changes up to switch PCs * Fix ESM symlink build for Viewers * Shift docs to root * Specify additional lerna config props * Begin providing basic readme info * Rename example extension folder * Shift links to bottom of doc * First attempt at a netlify deploy preview * Attempt to fix deploy preview build * push workspace enabled to initial command; remove second yarn install; use npx to call gitbook cli commands * Try to use global gitbook-cli * Export node_modules path * More agressive with modifying PATH * Follow deploy log output advice * try again to set bin path * Try swapping bash with a new shell * Try bash -l instead of exec bash * Annd let's try again * and again * We may have figured it out johnny, boy * We need to pull cornerstone-wado-image-loader files from hoisted node_modules * Attempt to fix ticks/escapes * Change copy syntax; try running tests on viewers from root for circleci * Lower version to match circleci image * Try alternative jest-canvas-mock location and version file syntax * Run version command instead of calling node directly * Try alternative jest transform * Set path and enable workspaces * Add codecov flags * Use cpx so our copying finishes? * Get all platform unit tests to run * Run and report individually and in parallel * Try once relying on codecov yaml to split w/ flags * Add projects to split by flags * Generate separate reports * Trigger codecov after everything has finished running; these may not support flags * Use recommended flags from issue comments for codecov * Fix typo * Remove clear flag * Shift back to calling codecov from root * Generate example for codecov issue * Try fixing paths * Simplify * Try using codecov orb * Bump circleci version * Upload core and viewer * Use full string paths * Remove individual codecov calls * Fix dir * Combine files before upload * Escape anchors * tryfix syntax * Escape string literal * Combine lines to reduce path * long paths * Use home alias * Fix filename * Try to see the contents of our cat'd file * Also upload `core` * Try running with aliased folder * Fix path; split PR and Merge unit tests into separate jobs * Set default threshold * Fix typo * Changing to scoped package names * Adding note * Catch more updates * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.0 - @ohif/extension-dicom-html@0.0.4-alpha.0 - @ohif/extension-dicom-microscopy@0.0.9-alpha.0 - @ohif/extension-dicom-pdf@0.0.8-alpha.0 - @ohif/extension-vtk@0.1.4-alpha.0 - @ohif/core@0.11.1-alpha.0 - @ohif/i18n@0.2.3-alpha.0 - @ohif/ui@0.2.18-alpha.0 - @ohif/viewer@0.0.22-alpha.0 * Clean up primary readme * Support for dev and dev:* commands * Shift build command; satisfy default PWA build * Remove old scripts * Clean up UI to set webpack scripts * Tidy up project links * Clean duplicate code in UI project * Update UI project's docs * Clean up ui and i18n config * Reduce duplicate code in `@ohif/core` * Fix @ohif/ui versions * bump @ohif/core versions * Redux testkit dep * Remove unused/duplicate config files for projects/packages * ohif-core --> @ohif/core * Safer publish command * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.1 - @ohif/extension-dicom-html@0.0.4-alpha.1 - @ohif/extension-dicom-microscopy@0.0.9-alpha.1 - @ohif/extension-dicom-pdf@0.0.8-alpha.1 - @ohif/extension-vtk@0.1.4-alpha.1 - @ohif/core@0.11.1-alpha.1 - @ohif/i18n@0.2.3-alpha.1 - @ohif/ui@0.2.18-alpha.1 - @ohif/viewer@0.0.22-alpha.1 * test version bump * Add global prettier config * chore(release): publish %s [skip ci] - @ohif/viewer@0.0.22-alpha.2 * test lerna publish * Update package.jsons * Fix build scripts * catch changes * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.2 - @ohif/extension-dicom-html@0.0.4-alpha.2 - @ohif/extension-dicom-microscopy@0.0.9-alpha.2 - @ohif/extension-dicom-pdf@0.0.8-alpha.2 - @ohif/extension-vtk@0.1.4-alpha.2 - @ohif/core@0.11.1-alpha.2 - @ohif/i18n@0.2.3-alpha.2 - @ohif/ui@0.2.18-alpha.2 - @ohif/viewer@0.0.22-alpha.3 * fix eslint issues caused by eslint 6 and our react-app config * Publish with canary tag * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.3 - @ohif/extension-dicom-html@0.0.4-alpha.3 - @ohif/extension-dicom-microscopy@0.0.9-alpha.3 - @ohif/extension-dicom-pdf@0.0.8-alpha.3 - @ohif/extension-vtk@0.1.4-alpha.3 - @ohif/core@0.11.1-alpha.3 - @ohif/i18n@0.2.3-alpha.3 - @ohif/ui@0.2.18-alpha.3 - @ohif/viewer@0.0.22-alpha.4 * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.4 - @ohif/extension-dicom-html@0.0.4-alpha.4 - @ohif/extension-dicom-microscopy@0.0.9-alpha.4 - @ohif/extension-dicom-pdf@0.0.8-alpha.4 - @ohif/extension-vtk@0.1.4-alpha.4 - @ohif/core@0.11.1-alpha.4 - @ohif/i18n@0.2.3-alpha.4 - @ohif/ui@0.2.18-alpha.4 - @ohif/viewer@0.0.22-alpha.5 * Simplify build * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.5 - @ohif/extension-dicom-html@0.0.4-alpha.5 - @ohif/extension-dicom-microscopy@0.0.9-alpha.5 - @ohif/extension-dicom-pdf@0.0.8-alpha.5 - @ohif/extension-vtk@0.1.4-alpha.5 - @ohif/core@0.11.1-alpha.5 - @ohif/i18n@0.2.3-alpha.5 - @ohif/ui@0.2.18-alpha.5 - @ohif/viewer@0.0.22-alpha.6 * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.6 - @ohif/extension-dicom-html@0.0.4-alpha.6 - @ohif/extension-dicom-microscopy@0.0.9-alpha.6 - @ohif/extension-dicom-pdf@0.0.8-alpha.6 - @ohif/extension-vtk@0.1.4-alpha.6 - @ohif/core@0.11.1-alpha.6 - @ohif/i18n@0.2.3-alpha.6 - @ohif/ui@0.2.18-alpha.6 - @ohif/viewer@0.0.22-alpha.7 * Split version and publish * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.7 - @ohif/extension-dicom-html@0.0.4-alpha.7 - @ohif/extension-dicom-microscopy@0.0.9-alpha.7 - @ohif/extension-dicom-pdf@0.0.8-alpha.7 - @ohif/extension-vtk@0.1.4-alpha.7 - @ohif/core@0.11.1-alpha.7 - @ohif/i18n@0.2.3-alpha.7 - @ohif/ui@0.2.18-alpha.7 - @ohif/viewer@0.0.22-alpha.8 * Try simplify netlify build * react-viewerbase --> @ohif/ui * add test for stylus loader * Try new way to specify publish path * Use an output folder that won't be ignored * Try move command * fiddle with paths * Dig for some information * Make sure we're in root for our commands * Remove discovery * Setup script-tag example * Fix typo * Move config folder * Update cornerstone extension to use shared/root webpack configs * capture changes * Update extension webpack configs * Don't check in docz output * Fix babel runtime resolution issue * Simplify ui build steps * Push in progress * Shift directories * Get viewer dev path to work * Fix viewer commonjs build * Fix build pwa config for viewers * Make sure our package specific command can be called from root * Update notes * Fix imports and misc. merge notes * Bump wado-image-loader version * Switch up commands to remove webworkers copy * Fix CI config * Fix more broken package references * Add react-dropzone * Persist so e2e test can use * Fix lockfile * Use cypress orb to simplify CI * Fix config * Try again * Install yarn latest for orb * Install yarn a different way * Wait on correct port * Run tests in viewer project * Fix cypress config * Make Cypress happier - use default location * Simplify e2e testing * Capture UI changes since fork * Catch core up * Grab latest deps after merge * Fix broken import * Make sure cornerstone-wado-image-loader resolves to 3+ * Note regarding orbs * Fix refresh on 404 routes * Fix odd error for cornerstone-wado-image-loader * Different target for UMD * Simplify dev script * Try to get fancy with netlify output * Let's do it again * Try to fix measurementTools issue * See if we can get our lerna magic to work on merge to monorepo branch
This commit is contained in:
1 parent
cac911f08e
commit
08ff214ea6
919 files changed
+45652
-52097
No files matched your search
@@ -0,0 +1,114 @@
|
||||
/** Action Creators:
|
||||
* https://redux.js.org/basics/actions#action-creators
|
||||
*/
|
||||
|
||||
import {
|
||||
CLEAR_VIEWPORT,
|
||||
SET_ACTIVE_SPECIFIC_DATA,
|
||||
SET_SERVERS,
|
||||
SET_VIEWPORT,
|
||||
SET_VIEWPORT_ACTIVE,
|
||||
SET_VIEWPORT_LAYOUT,
|
||||
SET_VIEWPORT_LAYOUT_AND_DATA,
|
||||
} from './constants/ActionTypes.js';
|
||||
|
||||
/**
|
||||
* VIEWPORT
|
||||
*/
|
||||
export const setViewportSpecificData = (viewportIndex, data) => ({
|
||||
type: SET_VIEWPORT,
|
||||
viewportIndex,
|
||||
data,
|
||||
});
|
||||
|
||||
export const setViewportActive = viewportIndex => ({
|
||||
type: SET_VIEWPORT_ACTIVE,
|
||||
viewportIndex,
|
||||
});
|
||||
|
||||
export const setLayout = layout => ({
|
||||
type: SET_VIEWPORT_LAYOUT,
|
||||
layout,
|
||||
});
|
||||
|
||||
export const clearViewportSpecificData = viewportIndex => ({
|
||||
type: CLEAR_VIEWPORT,
|
||||
viewportIndex,
|
||||
});
|
||||
|
||||
export const setActiveViewportSpecificData = data => ({
|
||||
type: SET_ACTIVE_SPECIFIC_DATA,
|
||||
data,
|
||||
});
|
||||
|
||||
/**
|
||||
* NOT-VIEWPORT
|
||||
*/
|
||||
export const setStudyLoadingProgress = (progressId, progressData) => ({
|
||||
type: 'SET_STUDY_LOADING_PROGRESS',
|
||||
progressId,
|
||||
progressData,
|
||||
});
|
||||
|
||||
export const clearStudyLoadingProgress = progressId => ({
|
||||
type: 'CLEAR_STUDY_LOADING_PROGRESS',
|
||||
progressId,
|
||||
});
|
||||
|
||||
export const setUserPreferences = state => ({
|
||||
type: 'SET_USER_PREFERENCES',
|
||||
state,
|
||||
});
|
||||
|
||||
export const setExtensionData = (extension, data) => ({
|
||||
type: 'SET_EXTENSION_DATA',
|
||||
extension,
|
||||
data,
|
||||
});
|
||||
|
||||
export const setTimepoints = state => ({
|
||||
type: 'SET_TIMEPOINTS',
|
||||
state,
|
||||
});
|
||||
|
||||
export const setMeasurements = state => ({
|
||||
type: 'SET_MEASUREMENTS',
|
||||
state,
|
||||
});
|
||||
|
||||
export const setStudyData = (studyInstanceUid, data) => ({
|
||||
type: 'SET_STUDY_DATA',
|
||||
studyInstanceUid,
|
||||
data,
|
||||
});
|
||||
|
||||
export const setServers = servers => ({
|
||||
type: SET_SERVERS,
|
||||
servers,
|
||||
});
|
||||
|
||||
export const setViewportLayoutAndData = (layout, viewportSpecificData) => ({
|
||||
type: SET_VIEWPORT_LAYOUT_AND_DATA,
|
||||
layout,
|
||||
viewportSpecificData,
|
||||
});
|
||||
|
||||
const actions = {
|
||||
// VIEWPORT
|
||||
setViewportActive,
|
||||
setViewportSpecificData,
|
||||
setViewportLayoutAndData,
|
||||
setLayout,
|
||||
clearViewportSpecificData,
|
||||
setActiveViewportSpecificData,
|
||||
setStudyLoadingProgress,
|
||||
clearStudyLoadingProgress,
|
||||
setUserPreferences,
|
||||
setExtensionData,
|
||||
setTimepoints,
|
||||
setMeasurements,
|
||||
setStudyData,
|
||||
setServers,
|
||||
};
|
||||
|
||||
export default actions;
|
||||
@@ -0,0 +1,112 @@
|
||||
import * as types from './constants/ActionTypes.js';
|
||||
|
||||
import actions from './actions.js';
|
||||
|
||||
describe('actions', () => {
|
||||
test('exports have not changed', () => {
|
||||
const expectedExports = [
|
||||
'setViewportActive',
|
||||
'setViewportSpecificData',
|
||||
'setViewportLayoutAndData',
|
||||
'setLayout',
|
||||
'clearViewportSpecificData',
|
||||
'setActiveViewportSpecificData',
|
||||
'setStudyLoadingProgress',
|
||||
'clearStudyLoadingProgress',
|
||||
'setUserPreferences',
|
||||
'setExtensionData',
|
||||
'setTimepoints',
|
||||
'setMeasurements',
|
||||
'setServers',
|
||||
'setStudyData',
|
||||
].sort();
|
||||
|
||||
const exports = Object.keys(actions).sort();
|
||||
|
||||
expect(exports).toEqual(expectedExports);
|
||||
});
|
||||
|
||||
describe('viewport action creators', () => {
|
||||
it('should create an action to set the viewport specific data', () => {
|
||||
const data = {
|
||||
displaySetInstanceUid: 'ef859a23-4631-93ab-d26b-7940a822c699',
|
||||
seriesDate: '20151026',
|
||||
seriesTime: '082611.370000',
|
||||
seriesInstanceUid:
|
||||
'1.3.6.1.4.1.25403.345050719074.3824.20170126085406.5',
|
||||
seriesNumber: 2,
|
||||
seriesDescription: 'Chest 3x3 Soft',
|
||||
numImageFrames: 126,
|
||||
modality: 'CT',
|
||||
isMultiFrame: false,
|
||||
instanceNumber: 1,
|
||||
studyInstanceUid:
|
||||
'1.3.6.1.4.1.25403.345050719074.3824.20170126085406.1',
|
||||
sopClassUids: ['1.2.840.10008.5.1.4.1.1.2'],
|
||||
plugin: 'cornerstone',
|
||||
viewport: {
|
||||
zoomScale: null,
|
||||
rotation: 360,
|
||||
resetViewport: null,
|
||||
invert: null,
|
||||
vflip: null,
|
||||
hflip: null,
|
||||
clearTools: null,
|
||||
scrollUp: null,
|
||||
scrollDown: null,
|
||||
scrollFirstImage: null,
|
||||
scrollLastImage: null,
|
||||
previousPanel: null,
|
||||
nextPanel: null,
|
||||
nextSeries: null,
|
||||
previousSeries: null,
|
||||
},
|
||||
};
|
||||
|
||||
const expectedAction = {
|
||||
type: types.SET_ACTIVE_SPECIFIC_DATA,
|
||||
data,
|
||||
};
|
||||
|
||||
expect(actions.setActiveViewportSpecificData(data)).toEqual(
|
||||
expectedAction
|
||||
);
|
||||
});
|
||||
|
||||
it('should create an action to clear clearViewportSpecificData', () => {
|
||||
const viewportIndex = 1;
|
||||
const expectedAction = {
|
||||
type: types.CLEAR_VIEWPORT,
|
||||
viewportIndex,
|
||||
};
|
||||
expect(actions.clearViewportSpecificData(viewportIndex)).toEqual(
|
||||
expectedAction
|
||||
);
|
||||
});
|
||||
|
||||
it('should create an action to set the active viewport', () => {
|
||||
const viewportIndex = 1;
|
||||
const expectedAction = {
|
||||
type: types.SET_VIEWPORT_ACTIVE,
|
||||
viewportIndex,
|
||||
};
|
||||
expect(actions.setViewportActive(viewportIndex)).toEqual(expectedAction);
|
||||
});
|
||||
|
||||
it('should create an action to set the viewport layout', () => {
|
||||
const layout = {
|
||||
viewports: [
|
||||
{
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
],
|
||||
};
|
||||
const expectedAction = {
|
||||
type: types.SET_VIEWPORT_LAYOUT,
|
||||
layout,
|
||||
};
|
||||
expect(actions.setLayout(layout)).toEqual(expectedAction);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* VIEWPORT
|
||||
*/
|
||||
export const SET_VIEWPORT = 'VIEWPORT::SET';
|
||||
export const SET_VIEWPORT_ACTIVE = 'VIEWPORT::SET_ACTIVE';
|
||||
export const SET_VIEWPORT_LAYOUT = 'VIEWPORT::SET_LAYOUT';
|
||||
export const SET_VIEWPORT_LAYOUT_AND_DATA =
|
||||
'VIEWPORT::SET_VIEWPORT_LAYOUT_AND_DATA';
|
||||
export const CLEAR_VIEWPORT = 'VIEWPORT::CLEAR';
|
||||
export const SET_SPECIFIC_DATA = 'VIEWPORT::SET_SPECIFIC_DATA';
|
||||
export const SET_ACTIVE_SPECIFIC_DATA = 'VIEWPORT::SET_ACTIVE_SPECIFIC_DATA';
|
||||
|
||||
/**
|
||||
* SERVERS
|
||||
*/
|
||||
export const ADD_SERVER = 'ADD_SERVER';
|
||||
export const SET_SERVERS = 'SET_SERVERS';
|
||||
|
||||
/**
|
||||
* EXTENSIONS
|
||||
*/
|
||||
export const SET_EXTENSION_DATA = 'SET_EXTENSION_DATA';
|
||||
@@ -0,0 +1,11 @@
|
||||
import actions from './actions.js';
|
||||
import reducers from './reducers';
|
||||
import localStorage from './localStorage.js';
|
||||
|
||||
const redux = {
|
||||
reducers,
|
||||
actions,
|
||||
localStorage,
|
||||
};
|
||||
|
||||
export default redux;
|
||||
@@ -0,0 +1,11 @@
|
||||
import redux from './index.js';
|
||||
|
||||
describe('redux exports', () => {
|
||||
test('have not changed', () => {
|
||||
const expectedExports = ['actions', 'reducers', 'localStorage'].sort();
|
||||
|
||||
const exports = Object.keys(redux).sort();
|
||||
|
||||
expect(exports).toEqual(expectedExports);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
export const loadState = () => {
|
||||
try {
|
||||
const serializedState = window.localStorage.getItem('state');
|
||||
if (!serializedState) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return JSON.parse(serializedState);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const saveState = state => {
|
||||
try {
|
||||
const serializedState = JSON.stringify(state);
|
||||
localStorage.setItem('state', serializedState);
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
const localStorage = {
|
||||
saveState,
|
||||
loadState,
|
||||
};
|
||||
|
||||
export default localStorage;
|
||||
@@ -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