Use reselect to compute our activeContexts
This commit is contained in:
1 parent
88568b1ddd
commit
6050721d33
9 files changed
+255
-100
No files matched your search
@@ -5,22 +5,11 @@ import {
|
||||
|
||||
import ToolbarRow from './ToolbarRow';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
const defaultPlugin = 'cornerstone';
|
||||
import { getActiveContexts } from './../store/layout/selectors.js';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { layout, viewportSpecificData, activeViewportIndex } = state.viewports;
|
||||
const pluginInLayout =
|
||||
layout.viewports[activeViewportIndex] &&
|
||||
layout.viewports[activeViewportIndex].plugin;
|
||||
const pluginInViewportData =
|
||||
viewportSpecificData[activeViewportIndex] &&
|
||||
viewportSpecificData[activeViewportIndex].plugin;
|
||||
const pluginInActiveViewport =
|
||||
pluginInLayout || pluginInViewportData || defaultPlugin;
|
||||
|
||||
return {
|
||||
pluginId: pluginInActiveViewport,
|
||||
activeContexts: getActiveContexts(state),
|
||||
leftSidebarOpen: state.ui.leftSidebarOpen,
|
||||
rightSidebarOpen: state.ui.rightSidebarOpen,
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@ import { connect } from 'react-redux';
|
||||
const {
|
||||
setViewportSpecificData,
|
||||
clearViewportSpecificData,
|
||||
// setActiveViewportSpecificData,
|
||||
} = OHIF.redux.actions;
|
||||
|
||||
const mapStateToProps = state => {
|
||||
@@ -27,9 +26,6 @@ const mapDispatchToProps = dispatch => {
|
||||
clearViewportSpecificData: () => {
|
||||
dispatch(clearViewportSpecificData());
|
||||
},
|
||||
// setActiveViewportSpecificData: viewport => {
|
||||
// dispatch(setActiveViewportSpecificData(viewport));
|
||||
// },
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class ToolbarRow extends Component {
|
||||
rightSidebarOpen: PropTypes.bool.isRequired,
|
||||
setLeftSidebarOpen: PropTypes.func,
|
||||
setRightSidebarOpen: PropTypes.func,
|
||||
pluginId: PropTypes.string,
|
||||
activeContexts: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
@@ -26,20 +26,13 @@ class ToolbarRow extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
const toolbarModules = extensionManager.modules[MODULE_TYPES.TOOLBAR];
|
||||
const toolbarButtonDefinitions = toolbarModules[0].module.definitions;
|
||||
|
||||
const toolbarButtonDefinitions = _getVisibleToolbarButtons.call(this);
|
||||
// TODO:
|
||||
// ToolbarSection for Each ToolbarButton
|
||||
// Render buttons
|
||||
// On click, depending on Type, pass props to registered command in commands manager?
|
||||
// If it's a tool that can be active... Mark it as active?
|
||||
// - Tools that are on/off?
|
||||
// - Tools that can be bound to multiple buttons?
|
||||
|
||||
// Normal ToolbarButtons...
|
||||
// Maybe filtered by the active context(s)?
|
||||
// Buttons can handle their own clicks. No reason for the container to do it?
|
||||
// Just how high do we need to hoist this state?
|
||||
// Why ToolbarRow instead of just Toolbar? Do we have any others?
|
||||
this.state = {
|
||||
@@ -48,6 +41,17 @@ class ToolbarRow extends Component {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const activeContextsChanged =
|
||||
prevProps.activeContexts !== this.props.activeContexts;
|
||||
|
||||
if (activeContextsChanged) {
|
||||
this.setState({
|
||||
toolbarButtons: _getVisibleToolbarButtons.call(this),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onLeftSidebarValueChanged = value => {
|
||||
this.props.setLeftSidebarOpen(!!value);
|
||||
};
|
||||
@@ -146,4 +150,26 @@ function _getButtonComponents(toolbarButtons, activeButtons) {
|
||||
});
|
||||
}
|
||||
|
||||
function _getVisibleToolbarButtons() {
|
||||
const toolbarModules = extensionManager.modules[MODULE_TYPES.TOOLBAR];
|
||||
const toolbarButtonDefinitions = [];
|
||||
|
||||
toolbarModules.forEach(extension => {
|
||||
const { definitions, defaultContext } = extension.module;
|
||||
definitions.forEach(definition => {
|
||||
const context = definition.context || defaultContext;
|
||||
|
||||
console.log(context);
|
||||
if (this.props.activeContexts.includes(context)) {
|
||||
console.log('includes: ', definition.commandName);
|
||||
toolbarButtonDefinitions.push(definition);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(extension);
|
||||
});
|
||||
|
||||
return toolbarButtonDefinitions;
|
||||
}
|
||||
|
||||
export default ToolbarRow;
|
||||
Reference in new issue
Block a user