OHIF-285/OHIF-274: Fix default hanging of display sets into the ViewportGrid (#1917)
* OHIF-285/OHIF-274: Fix default hanging of display sets into the ViewportGrid Co-authored-by: James A. Petts <jamesapetts@gmail.com>
This commit is contained in:
1 parent
9df57e7f7f
commit
55cf9f2306
33 files changed
+548
-208
No files matched your search
@@ -0,0 +1,153 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useReducer,
|
||||
} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const DEFAULT_STATE = {
|
||||
hangingProtocol: null,
|
||||
hpAlreadyApplied: {},
|
||||
};
|
||||
|
||||
export const HangingProtocolContext = createContext(DEFAULT_STATE);
|
||||
|
||||
export function HangingProtocolProvider({ children, service }) {
|
||||
const hangingProtocolReducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_HANGING_PROTOCOL': {
|
||||
return {
|
||||
...state,
|
||||
...{ hangingProtocol: action.payload.hangingProtocol },
|
||||
};
|
||||
}
|
||||
case 'SET_HANGING_PROTOCOL_APPLIED_FOR_VIEWPORT': {
|
||||
const index = action.payload.index;
|
||||
const newHPAlreadyApplied = Object.assign({}, state.hpAlreadyApplied);
|
||||
|
||||
newHPAlreadyApplied[index] = true;
|
||||
|
||||
return {
|
||||
...state,
|
||||
...{ hpAlreadyApplied: newHPAlreadyApplied },
|
||||
};
|
||||
}
|
||||
case 'RESET': {
|
||||
return {
|
||||
hangingProtocol: null,
|
||||
hpAlreadyApplied: {},
|
||||
};
|
||||
}
|
||||
|
||||
case 'SET': {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
return action.payload;
|
||||
}
|
||||
};
|
||||
|
||||
const [hangingProtocolState, dispatch] = useReducer(
|
||||
hangingProtocolReducer,
|
||||
DEFAULT_STATE
|
||||
);
|
||||
|
||||
console.log('hangingProtocolState', hangingProtocolState);
|
||||
|
||||
const getState = useCallback(() => hangingProtocolState, [
|
||||
hangingProtocolState,
|
||||
]);
|
||||
|
||||
const setHangingProtocol = useCallback(
|
||||
hangingProtocol =>
|
||||
dispatch({
|
||||
type: 'SET_HANGING_PROTOCOL',
|
||||
payload: {
|
||||
hangingProtocol,
|
||||
},
|
||||
}),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const setHangingProtocolAppliedForViewport = useCallback(
|
||||
index =>
|
||||
dispatch({
|
||||
type: 'SET_HANGING_PROTOCOL_APPLIED_FOR_VIEWPORT',
|
||||
payload: {
|
||||
index,
|
||||
},
|
||||
}),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const reset = useCallback(
|
||||
() =>
|
||||
dispatch({
|
||||
type: 'RESET',
|
||||
payload: {},
|
||||
}),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const set = useCallback(
|
||||
payload =>
|
||||
dispatch({
|
||||
type: 'SET',
|
||||
payload,
|
||||
}),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the implementation of the HangingProtocolService that can be used by extensions.
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (service) {
|
||||
service.setServiceImplementation({
|
||||
getState,
|
||||
setHangingProtocol,
|
||||
setHangingProtocolAppliedForViewport,
|
||||
reset,
|
||||
set,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
getState,
|
||||
service,
|
||||
setHangingProtocol,
|
||||
setHangingProtocolAppliedForViewport,
|
||||
reset,
|
||||
set,
|
||||
]);
|
||||
|
||||
const api = {
|
||||
// getState,
|
||||
setHangingProtocol,
|
||||
setHangingProtocolAppliedForViewport,
|
||||
reset,
|
||||
set,
|
||||
};
|
||||
|
||||
return (
|
||||
<HangingProtocolContext.Provider value={[hangingProtocolState, api]}>
|
||||
{children}
|
||||
</HangingProtocolContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
HangingProtocolProvider.propTypes = {
|
||||
children: PropTypes.any,
|
||||
service: PropTypes.shape({
|
||||
setServiceImplementation: PropTypes.func,
|
||||
}).isRequired,
|
||||
};
|
||||
|
||||
export const useHangingProtocol = () => useContext(HangingProtocolContext);
|
||||
@@ -35,3 +35,9 @@ export {
|
||||
ViewportGridProvider,
|
||||
useViewportGrid,
|
||||
} from './ViewportGridProvider';
|
||||
|
||||
export {
|
||||
HangingProtocolContext,
|
||||
HangingProtocolProvider,
|
||||
useHangingProtocol,
|
||||
} from './HangingProtocolProvider';
|
||||
Reference in new issue
Block a user