@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
60 lines (59 loc) • 2.83 kB
JavaScript
import { getPersistableState, LoadState, InitState } from '../../Redux/Store/AdaptableStore';
import { ApiBase } from '../Implementation/ApiBase';
export class StateInternalApi extends ApiBase {
getAllStateForDevTools() {
let allState = this.getAdaptableApi().stateApi.getAllState();
if (allState.Layout && Array.isArray(allState.Layout.Layouts)) {
allState = { ...allState };
allState.Layout = { ...allState.Layout };
allState.Layout.Layouts = allState.Layout.Layouts.map((layout) => {
let ColumnSizing = layout.ColumnSizing;
if (Array.isArray(layout.TableColumns)) {
layout.TableColumns.forEach((colId) => {
if (!ColumnSizing[colId]) {
ColumnSizing[colId] = {
Width: this._adaptable.getDefaultColumnWidthForCol(colId),
};
}
});
}
return {
...layout,
ColumnSizing,
};
});
}
return allState;
}
restoreState(state) {
return new Promise((resolve, reject) => {
this.getAdaptableInternalApi().executeWithProgressIndicator('Restoring state from DevTools...', () => {
try {
const agGridOptions = {
columnDefs: this._adaptable.agGridAdapter.getGridOption('columnDefs'),
autoGroupColumnDef: this._adaptable.agGridAdapter.getGridOption('autoGroupColumnDef'),
rowModelType: this._adaptable.agGridAdapter.getGridOption('rowModelType'),
treeData: this._adaptable.agGridAdapter.getGridOption('treeData'),
};
const clonedState = state.Internal
? JSON.parse(JSON.stringify(state))
: getPersistableState(JSON.parse(JSON.stringify(state)));
let processedState = this._adaptable.normalizeAdaptableState(clonedState, agGridOptions);
this.getAdaptableStore().TheStore.dispatch(LoadState(processedState));
this.getAdaptableStore().TheStore.dispatch(InitState());
this._adaptable.refreshLayout();
void this.getAdaptableStore()
.saveStateNow(this._adaptable)
.then(() => resolve())
.catch(reject);
}
catch (error) {
reject(error);
}
finally {
this.getUserInterfaceApi().hideProgressIndicator();
}
});
});
}
}