UNPKG

@adaptabletools/adaptable

Version:

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

76 lines (75 loc) 3.52 kB
import { ApiBase } from './ApiBase'; import { DataChangeHistoryClearRow, DataChangeHistoryDisable, DataChangeHistoryEnable, DataChangeHistoryResume, DataChangeHistorySuspend, DataChangeHistoryUndo, DataChangeHistoryAdd, } from '../../Redux/ActionsReducers/InternalRedux'; import * as ModuleConstants from '../../Utilities/Constants/ModuleConstants'; export class DataChangeHistoryApiImpl extends ApiBase { getDataChangeHistoryMode() { return this.getAdaptableState().Internal.DataChangeHistory.currentMode; } activateDataChangeHistory(forceReset) { const currentMode = this.getDataChangeHistoryMode(); if (currentMode === 'ACTIVE' && !forceReset) { return; } if (currentMode === 'SUSPENDED' && !forceReset) { this.dispatchAction(DataChangeHistoryResume()); } else { this.dispatchAction(DataChangeHistoryEnable()); } } deactivateDataChangeHistory() { const currentMode = this.getDataChangeHistoryMode(); if (currentMode !== 'INACTIVE') { this.dispatchAction(DataChangeHistoryDisable()); } } suspendDataChangeHistory() { if (this.getDataChangeHistoryMode() === 'ACTIVE') { this.dispatchAction(DataChangeHistorySuspend()); } } getDataChangeHistoryLog() { const changeLog = this.getAdaptableState().Internal.DataChangeHistory.logs ?? {}; return Object.values(changeLog); } getDataChangeForGridCell(gridCell) { const allChanges = this.getDataChangeHistoryLog(); return allChanges.find((c) => c.primaryKeyValue == gridCell.primaryKeyValue && c.column.columnId == gridCell.column.columnId); } addDataChangeHistoryEntry(dataChangeInfo) { const uniqueKey = this.getDataChangeHistoryKey(dataChangeInfo); const maxDataChangesInStore = this.getDataChangeHistoryOptions().maxDataChangesInStore; this.dispatchAction(DataChangeHistoryAdd(dataChangeInfo, uniqueKey, maxDataChangesInStore)); } undoDataChangeHistoryEntry(dataChangeInfo) { const uniqueKey = this.getDataChangeHistoryKey(dataChangeInfo); this.dispatchAction(DataChangeHistoryUndo(dataChangeInfo, uniqueKey)); return this.getGridApi().getGridCellFromRowNode(dataChangeInfo.rowNode, dataChangeInfo.column.columnId); } undoAllDataChangeHistoryEntries() { const allChanges = this.getDataChangeHistoryLog(); return allChanges .map((dataChange) => this.undoDataChangeHistoryEntry(dataChange)) .filter((gridCell) => gridCell != null); } clearDataChangeHistoryEntry(dataChangeInfo) { const uniqueKey = this.getDataChangeHistoryKey(dataChangeInfo); this.dispatchAction(DataChangeHistoryClearRow(dataChangeInfo, uniqueKey)); } openDataChangeHistorySettingsPanel() { this.showModulePopup(ModuleConstants.DataChangeHistoryModuleId); } getDataChangeHistoryKey = (dataChangeInfo) => { const columnId = dataChangeInfo.column.columnId; const primaryKeyValue = dataChangeInfo.primaryKeyValue; const changedAt = dataChangeInfo.changedAt; const showLastDataChangeOnly = this.getDataChangeHistoryOptions().showLastDataChangeOnly; if (showLastDataChangeOnly) { return `${columnId}\u0000${primaryKeyValue}`; } else { return `${columnId}\u0000${primaryKeyValue}\u0000${changedAt}`; } }; }