UNPKG

@adaptabletools/adaptable

Version:

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

97 lines (96 loc) 3.19 kB
import { EMPTY_ARRAY } from '../../Utilities/Constants/GeneralConstants'; import AdaptableHelper from '../../Utilities/Helpers/AdaptableHelper'; import { changeIsSuspendInList, suspendAllInList, unsuspendAllInList } from './utils'; export const SHORTCUT_ADD = 'SHORTCUT_ADD'; export const SHORTCUT_EDIT = 'SHORTCUT_EDIT'; export const SHORTCUT_DELETE = 'SHORTCUT_DELETE'; export const SHORTCUT_SUSPEND = 'SHORTCUT_SUSPEND'; export const SHORTCUT_UNSUSPEND = 'SHORTCUT_UNSUSPEND'; export const SHORTCUT_SUSPEND_ALL = 'SHORTCUT_SUSPEND_ALL'; export const SHORTCUT_UNSUSPEND_ALL = 'SHORTCUT_UNSUSPEND_ALL'; export const SHORTCUT_READY = 'SHORTCUT_READY'; export const ShortcutAdd = (shortcut) => ({ type: SHORTCUT_ADD, shortcut, }); export const ShortcutEdit = (shortcut) => ({ type: SHORTCUT_EDIT, shortcut, }); export const ShortcutDelete = (shortcut) => ({ type: SHORTCUT_DELETE, shortcut, }); export const ShortcutSuspend = (shortcut) => ({ type: SHORTCUT_SUSPEND, shortcut, }); export const ShortcutUnSuspend = (shortcut) => ({ type: SHORTCUT_UNSUSPEND, shortcut, }); export const ShortcutSuspendAll = () => ({ type: SHORTCUT_SUSPEND_ALL, }); export const ShortcutUnSuspendAll = () => ({ type: SHORTCUT_UNSUSPEND_ALL, }); export const ShortcutReady = (shortcutState) => ({ type: SHORTCUT_READY, shortcutState, }); const initialState = { Shortcuts: EMPTY_ARRAY, }; export const ShortcutReducer = (state = initialState, action) => { let shortcuts; switch (action.type) { case SHORTCUT_ADD: { const actionShortcut = action.shortcut; AdaptableHelper.addAdaptableObjectPrimitives(actionShortcut); shortcuts = [].concat(state.Shortcuts); shortcuts.push(actionShortcut); return { ...state, Shortcuts: shortcuts }; } case SHORTCUT_EDIT: { const actionShortcut = action.shortcut; return { ...state, Shortcuts: state.Shortcuts.map((abObject) => abObject.Uuid === actionShortcut.Uuid ? actionShortcut : abObject), }; } case SHORTCUT_DELETE: { const actionShortcut = action.shortcut; return { ...state, Shortcuts: state.Shortcuts.filter((abObject) => abObject.Uuid !== actionShortcut.Uuid), }; } case SHORTCUT_SUSPEND: { return { ...state, Shortcuts: changeIsSuspendInList(action.shortcut, state.Shortcuts, true), }; } case SHORTCUT_UNSUSPEND: { return { ...state, Shortcuts: changeIsSuspendInList(action.shortcut, state.Shortcuts, false), }; } case SHORTCUT_SUSPEND_ALL: { return { ...state, Shortcuts: suspendAllInList(state.Shortcuts), }; } case SHORTCUT_UNSUSPEND_ALL: { return { ...state, Shortcuts: unsuspendAllInList(state.Shortcuts), }; } default: return state; } };