UNPKG

@adaptabletools/adaptable-cjs

Version:

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

134 lines (133 loc) 4.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShortcutReducer = exports.ShortcutReady = exports.ShortcutUnSuspendAll = exports.ShortcutSuspendAll = exports.ShortcutUnSuspend = exports.ShortcutSuspend = exports.ShortcutDelete = exports.ShortcutEdit = exports.ShortcutAdd = exports.SHORTCUT_READY = exports.SHORTCUT_UNSUSPEND_ALL = exports.SHORTCUT_SUSPEND_ALL = exports.SHORTCUT_UNSUSPEND = exports.SHORTCUT_SUSPEND = exports.SHORTCUT_DELETE = exports.SHORTCUT_EDIT = exports.SHORTCUT_ADD = void 0; const tslib_1 = require("tslib"); const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants"); const AdaptableHelper_1 = tslib_1.__importDefault(require("../../Utilities/Helpers/AdaptableHelper")); const utils_1 = require("./utils"); /** * @ReduxAction A Shortcut has been added */ exports.SHORTCUT_ADD = 'SHORTCUT_ADD'; /** * @ReduxAction A Shortcut has been edited */ exports.SHORTCUT_EDIT = 'SHORTCUT_EDIT'; /** * @ReduxAction A Shortcut has been deleted */ exports.SHORTCUT_DELETE = 'SHORTCUT_DELETE'; /** * @ReduxAction A Shortcut has been suspended */ exports.SHORTCUT_SUSPEND = 'SHORTCUT_SUSPEND'; /** * @ReduxAction A Shortcut has been unsuspended or activated */ exports.SHORTCUT_UNSUSPEND = 'SHORTCUT_UNSUSPEND'; /** * @ReduxAction All Shortcuts have been suspended */ exports.SHORTCUT_SUSPEND_ALL = 'SHORTCUT_SUSPEND_ALL'; /** * @ReduxAction All Shortcuts have been unsuspended or activated */ exports.SHORTCUT_UNSUSPEND_ALL = 'SHORTCUT_UNSUSPEND_ALL'; /** * @ReduxAction Shortcut Module is ready */ exports.SHORTCUT_READY = 'SHORTCUT_READY'; const ShortcutAdd = (shortcut) => ({ type: exports.SHORTCUT_ADD, shortcut, }); exports.ShortcutAdd = ShortcutAdd; const ShortcutEdit = (shortcut) => ({ type: exports.SHORTCUT_EDIT, shortcut, }); exports.ShortcutEdit = ShortcutEdit; const ShortcutDelete = (shortcut) => ({ type: exports.SHORTCUT_DELETE, shortcut, }); exports.ShortcutDelete = ShortcutDelete; const ShortcutSuspend = (shortcut) => ({ type: exports.SHORTCUT_SUSPEND, shortcut, }); exports.ShortcutSuspend = ShortcutSuspend; const ShortcutUnSuspend = (shortcut) => ({ type: exports.SHORTCUT_UNSUSPEND, shortcut, }); exports.ShortcutUnSuspend = ShortcutUnSuspend; const ShortcutSuspendAll = () => ({ type: exports.SHORTCUT_SUSPEND_ALL, }); exports.ShortcutSuspendAll = ShortcutSuspendAll; const ShortcutUnSuspendAll = () => ({ type: exports.SHORTCUT_UNSUSPEND_ALL, }); exports.ShortcutUnSuspendAll = ShortcutUnSuspendAll; const ShortcutReady = (shortcutState) => ({ type: exports.SHORTCUT_READY, shortcutState, }); exports.ShortcutReady = ShortcutReady; const initialState = { Shortcuts: GeneralConstants_1.EMPTY_ARRAY, }; const ShortcutReducer = (state = initialState, action) => { let shortcuts; switch (action.type) { case exports.SHORTCUT_ADD: { const actionShortcut = action.shortcut; AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionShortcut); shortcuts = [].concat(state.Shortcuts); shortcuts.push(actionShortcut); return { ...state, Shortcuts: shortcuts }; } case exports.SHORTCUT_EDIT: { const actionShortcut = action.shortcut; return { ...state, Shortcuts: state.Shortcuts.map((abObject) => abObject.Uuid === actionShortcut.Uuid ? actionShortcut : abObject), }; } case exports.SHORTCUT_DELETE: { const actionShortcut = action.shortcut; return { ...state, Shortcuts: state.Shortcuts.filter((abObject) => abObject.Uuid !== actionShortcut.Uuid), }; } case exports.SHORTCUT_SUSPEND: { return { ...state, Shortcuts: (0, utils_1.changeIsSuspendInList)(action.shortcut, state.Shortcuts, true), }; } case exports.SHORTCUT_UNSUSPEND: { return { ...state, Shortcuts: (0, utils_1.changeIsSuspendInList)(action.shortcut, state.Shortcuts, false), }; } case exports.SHORTCUT_SUSPEND_ALL: { return { ...state, Shortcuts: (0, utils_1.suspendAllInList)(state.Shortcuts), }; } case exports.SHORTCUT_UNSUSPEND_ALL: { return { ...state, Shortcuts: (0, utils_1.unsuspendAllInList)(state.Shortcuts), }; } default: return state; } }; exports.ShortcutReducer = ShortcutReducer;