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.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomSortReducer = exports.CustomSortReady = exports.CustomSortUnSuspendAll = exports.CustomSortSuspendAll = exports.CustomSortUnSuspend = exports.CustomSortSuspend = exports.CustomSortDelete = exports.CustomSortEdit = exports.CustomSortAdd = exports.CUSTOM_SORT_READY = exports.CUSTOM_SORT_UNSUSPEND_ALL = exports.CUSTOM_SORT_SUSPEND_ALL = exports.CUSTOM_SORT_UNSUSPEND = exports.CUSTOM_SORT_SUSPEND = exports.CUSTOM_SORT_DELETE = exports.CUSTOM_SORT_EDIT = exports.CUSTOM_SORT_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 Custom Sort has been added */ exports.CUSTOM_SORT_ADD = 'CUSTOM_SORT_ADD'; /** * @ReduxAction A Custom Sort has been edited */ exports.CUSTOM_SORT_EDIT = 'CUSTOM_SORT_EDIT'; /** * @ReduxAction A Custom Sort has been deleted */ exports.CUSTOM_SORT_DELETE = 'CUSTOM_SORT_DELETE'; /** * @ReduxAction A Custom Sort has been suspended */ exports.CUSTOM_SORT_SUSPEND = 'CUSTOM_SORT_SUSPEND'; /** * @ReduxAction A Custom Sort has been unsuspended (activated) */ exports.CUSTOM_SORT_UNSUSPEND = 'CUSTOM_SORT_UNSUSPEND'; /** * @ReduxAction Suspend all Custom Sorts */ exports.CUSTOM_SORT_SUSPEND_ALL = 'CUSTOM_SORT_SUSPEND_ALL'; /** * @ReduxAction Unsuspend all Custom Sorts */ exports.CUSTOM_SORT_UNSUSPEND_ALL = 'CUSTOM_SORT_UNSUSPEND_ALL'; /** * @ReduxAction Custom Sort Module is ready */ exports.CUSTOM_SORT_READY = 'CUSTOM_SORT_READY'; const CustomSortAdd = (customSort) => ({ type: exports.CUSTOM_SORT_ADD, customSort, }); exports.CustomSortAdd = CustomSortAdd; const CustomSortEdit = (customSort) => ({ type: exports.CUSTOM_SORT_EDIT, customSort, }); exports.CustomSortEdit = CustomSortEdit; const CustomSortDelete = (customSort) => ({ type: exports.CUSTOM_SORT_DELETE, customSort, }); exports.CustomSortDelete = CustomSortDelete; const CustomSortSuspend = (customSort) => ({ type: exports.CUSTOM_SORT_SUSPEND, customSort, }); exports.CustomSortSuspend = CustomSortSuspend; const CustomSortUnSuspend = (customSort) => ({ type: exports.CUSTOM_SORT_UNSUSPEND, customSort, }); exports.CustomSortUnSuspend = CustomSortUnSuspend; const CustomSortSuspendAll = () => ({ type: exports.CUSTOM_SORT_SUSPEND_ALL, }); exports.CustomSortSuspendAll = CustomSortSuspendAll; const CustomSortUnSuspendAll = () => ({ type: exports.CUSTOM_SORT_UNSUSPEND_ALL, }); exports.CustomSortUnSuspendAll = CustomSortUnSuspendAll; const CustomSortReady = (customSortState) => ({ type: exports.CUSTOM_SORT_READY, customSortState, }); exports.CustomSortReady = CustomSortReady; const initialState = { CustomSorts: GeneralConstants_1.EMPTY_ARRAY, }; const CustomSortReducer = (state = initialState, action) => { let customSorts; switch (action.type) { case exports.CUSTOM_SORT_ADD: { const actionCustomSort = action.customSort; AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionCustomSort); customSorts = [].concat(state.CustomSorts); customSorts.push(actionCustomSort); return { ...state, CustomSorts: customSorts }; } case exports.CUSTOM_SORT_EDIT: { const actionCustomSort = action.customSort; return { ...state, CustomSorts: state.CustomSorts.map((abObject) => abObject.Uuid === actionCustomSort.Uuid ? actionCustomSort : abObject), }; } case exports.CUSTOM_SORT_DELETE: { const actionCustomSort = action.customSort; return { ...state, CustomSorts: state.CustomSorts.filter((abObject) => abObject.Uuid !== actionCustomSort.Uuid), }; } case exports.CUSTOM_SORT_SUSPEND: { return { ...state, CustomSorts: (0, utils_1.changeIsSuspendInList)(action.customSort, state.CustomSorts, true), }; } case exports.CUSTOM_SORT_UNSUSPEND: { return { ...state, CustomSorts: (0, utils_1.changeIsSuspendInList)(action.customSort, state.CustomSorts, false), }; } case exports.CUSTOM_SORT_SUSPEND_ALL: { return { ...state, CustomSorts: (0, utils_1.suspendAllInList)(state.CustomSorts), }; } case exports.CUSTOM_SORT_UNSUSPEND_ALL: { return { ...state, CustomSorts: (0, utils_1.unsuspendAllInList)(state.CustomSorts), }; } default: return state; } }; exports.CustomSortReducer = CustomSortReducer;