UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

120 lines (119 loc) 5.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolPanelReducer = exports.ToolPanelReady = exports.ToolPanelSetModuleButtons = exports.ToolPanelCollapseToolPanel = exports.ToolPanelExpandToolPanel = exports.ToolPanelHideToolPanel = exports.ToolPanelShowToolPanel = exports.ToolPanelSetToolPanels = exports.TOOLPANEL_READY = exports.TOOLPANEL_SET_MODULE_BUTTONS = exports.TOOLPANEL_COLLAPSE_TOOLPANEL = exports.TOOLPANEL_EXPAND_TOOLPANEL = exports.TOOLPANEL_HIDE_TOOLPANEL = exports.TOOLPANEL_SHOW_TOOLPANEL = exports.TOOLPANEL_SET_TOOLPANELS = void 0; /** * @ReduxAction Tool Panels have been set in AdapTable ToolPanel Component */ exports.TOOLPANEL_SET_TOOLPANELS = 'TOOLPANEL_SET_TOOLPANELS'; /** * @ReduxAction A Tool Panel has been made visible */ exports.TOOLPANEL_SHOW_TOOLPANEL = 'TOOLPANEL_SHOW_TOOLPANEL'; /** * @ReduxAction A Tool Panel has been hidden */ exports.TOOLPANEL_HIDE_TOOLPANEL = 'TOOLPANEL_HIDE_TOOLPANEL'; /** * @ReduxAction A Tool Panel has been expanded */ exports.TOOLPANEL_EXPAND_TOOLPANEL = 'TOOLPANEL_EXPAND_TOOLPANEL'; /** * @ReduxAction A Tool Panel has been collapsed */ exports.TOOLPANEL_COLLAPSE_TOOLPANEL = 'TOOLPANEL_COLLAPSE_TOOLPANEL'; /** * @ReduxAction Module Buttons have set in AdapTable ToolPanel Component header */ exports.TOOLPANEL_SET_MODULE_BUTTONS = 'TOOLPANEL_SET_MODULE_BUTTONS'; /** * @ReduxAction AdapTable ToolPanel Component is ready */ exports.TOOLPANEL_READY = 'TOOLPANEL_READY'; const ToolPanelSetToolPanels = (toolPanels) => ({ type: exports.TOOLPANEL_SET_TOOLPANELS, toolPanels, }); exports.ToolPanelSetToolPanels = ToolPanelSetToolPanels; const ToolPanelShowToolPanel = (toolPanel) => ({ type: exports.TOOLPANEL_SHOW_TOOLPANEL, toolPanel, }); exports.ToolPanelShowToolPanel = ToolPanelShowToolPanel; const ToolPanelHideToolPanel = (toolPanel) => ({ type: exports.TOOLPANEL_HIDE_TOOLPANEL, toolPanel, }); exports.ToolPanelHideToolPanel = ToolPanelHideToolPanel; const ToolPanelExpandToolPanel = (toolPanel) => ({ type: exports.TOOLPANEL_EXPAND_TOOLPANEL, toolPanel, }); exports.ToolPanelExpandToolPanel = ToolPanelExpandToolPanel; const ToolPanelCollapseToolPanel = (toolPanel) => ({ type: exports.TOOLPANEL_COLLAPSE_TOOLPANEL, toolPanel, }); exports.ToolPanelCollapseToolPanel = ToolPanelCollapseToolPanel; const ToolPanelSetModuleButtons = (moduleButtons) => ({ type: exports.TOOLPANEL_SET_MODULE_BUTTONS, moduleButtons: moduleButtons, }); exports.ToolPanelSetModuleButtons = ToolPanelSetModuleButtons; const ToolPanelReady = (toolPanelState) => ({ type: exports.TOOLPANEL_READY, toolPanelState, }); exports.ToolPanelReady = ToolPanelReady; const initialState = { // default ToolPanels are set in ToolPanelModule.updateOldConfig() because we have to evaluate the ToolPanelOptions (for CustomToolPanel) ToolPanels: undefined, ModuleButtons: ['SettingsPanel'], }; const ToolPanelReducer = (state = initialState, action) => { const setToolPanels = (state, toolPanels = []) => { return { ...state, ToolPanels: [...toolPanels] }; }; switch (action.type) { case exports.TOOLPANEL_SET_TOOLPANELS: { const actionTyped = action; const toolPanels = actionTyped.toolPanels; return setToolPanels(state, toolPanels); } case exports.TOOLPANEL_SHOW_TOOLPANEL: { const actionTyped = action; const toolPanelDefinition = { Name: actionTyped.toolPanel, VisibilityMode: 'collapsed', }; const toolPanels = [toolPanelDefinition, ...(state.ToolPanels ?? [])]; return setToolPanels(state, toolPanels); } case exports.TOOLPANEL_HIDE_TOOLPANEL: { const actionTyped = action; const toolPanels = (state.ToolPanels ?? []).filter((a) => a.Name !== actionTyped.toolPanel); return setToolPanels(state, toolPanels); } case exports.TOOLPANEL_EXPAND_TOOLPANEL: { const actionTyped = action; const toolPanelDefinitions = state.ToolPanels?.map((toolPanelDefinition) => toolPanelDefinition.Name === actionTyped.toolPanel ? { ...toolPanelDefinition, VisibilityMode: 'expanded' } : toolPanelDefinition); return setToolPanels(state, toolPanelDefinitions); } case exports.TOOLPANEL_COLLAPSE_TOOLPANEL: { const actionTyped = action; const toolPanelDefinitions = state.ToolPanels?.map((toolPanelDefinition) => toolPanelDefinition.Name === actionTyped.toolPanel ? { ...toolPanelDefinition, VisibilityMode: 'collapsed' } : toolPanelDefinition); return setToolPanels(state, toolPanelDefinitions); } case exports.TOOLPANEL_SET_MODULE_BUTTONS: { const actionTyped = action; const moduleButtons = actionTyped.moduleButtons; return Object.assign({}, state, { ModuleButtons: moduleButtons }); } default: return state; } }; exports.ToolPanelReducer = ToolPanelReducer;