// Updated ToolbarLayoutSelector.tsx import React, { useCallback } from 'react'; import PropTypes from 'prop-types'; import { CommandsManager } from '@ohif/core'; import { LayoutSelector } from '@ohif/ui-next'; import { useTranslation } from 'react-i18next'; function ToolbarLayoutSelectorWithServices({ commandsManager, servicesManager, rows = 3, columns = 4, ...props }) { const { customizationService } = servicesManager.services; const { t } = useTranslation('ToolbarLayoutSelector'); // Get the presets from the customization service const commonPresets = customizationService?.getCustomization('layoutSelector.commonPresets') || [ { icon: 'layout-single', commandOptions: { numRows: 1, numCols: 1, }, }, { icon: 'layout-side-by-side', commandOptions: { numRows: 1, numCols: 2, }, }, { icon: 'layout-four-up', commandOptions: { numRows: 2, numCols: 2, }, }, { icon: 'layout-three-row', commandOptions: { numRows: 3, numCols: 1, }, }, ]; // Get the advanced presets generator from the customization service const advancedPresetsGenerator = customizationService?.getCustomization( 'layoutSelector.advancedPresetGenerator' ); // Generate the advanced presets const advancedPresets = advancedPresetsGenerator ? advancedPresetsGenerator({ servicesManager }) : [ { title: 'MPR', icon: 'layout-three-col', commandOptions: { protocolId: 'mpr', }, }, { title: '3D four up', icon: 'layout-four-up', commandOptions: { protocolId: '3d-four-up', }, }, { title: '3D main', icon: 'layout-three-row', commandOptions: { protocolId: '3d-main', }, }, { title: 'Axial Primary', icon: 'layout-side-by-side', commandOptions: { protocolId: 'axial-primary', }, }, { title: '3D only', icon: 'layout-single', commandOptions: { protocolId: '3d-only', }, }, { title: '3D primary', icon: 'layout-side-by-side', commandOptions: { protocolId: '3d-primary', }, }, { title: 'Frame View', icon: 'icon-stack', commandOptions: { protocolId: 'frame-view', }, }, ]; // Unified selection handler that dispatches to the appropriate command const handleSelectionChange = useCallback( (commandOptions, isPreset) => { if (isPreset) { // Advanced preset selection commandsManager.run({ commandName: 'setHangingProtocol', commandOptions, }); } else { // Common preset or custom grid selection commandsManager.run({ commandName: 'setViewportGridLayout', commandOptions, }); } }, [commandsManager] ); return (
{/* Left side - Presets */} {(commonPresets.length > 0 || advancedPresets.length > 0) && (
{commonPresets.length > 0 && ( <> {commonPresets.map((preset, index) => ( ))} )} {advancedPresets.length > 0 && ( {advancedPresets.map((preset, index) => ( ))} )}
)} {/* Right Side - Grid Layout */}
{t('Custom')}
{t('Hover to select')}
{t('rows and columns')}
{t('Click to apply')}
); } ToolbarLayoutSelectorWithServices.propTypes = { commandsManager: PropTypes.instanceOf(CommandsManager), servicesManager: PropTypes.object, rows: PropTypes.number, columns: PropTypes.number, }; export default ToolbarLayoutSelectorWithServices;