Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/devextreme/js/__internal/core/m_devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ class Devices {

const deviceOrName = sessionStorage.getItem('dx-force-device');

if (deviceOrName === null) {
return null;
}

try {
return JSON.parse(deviceOrName);
} catch (ex) {
Expand Down
4 changes: 2 additions & 2 deletions packages/devextreme/js/__internal/core/utils/m_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getWindow } from '@js/core/utils/window';

const window = getWindow();

const getSessionStorage = function () {
let sessionStorage;
const getSessionStorage = function (): Storage | undefined {
let sessionStorage: Storage | undefined;

try {
sessionStorage = window.sessionStorage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export const USER_STATE_FIELD_NAMES_15_1 = ['filterValues', 'filterType', 'fixed', 'fixedPosition'];
export const USER_STATE_FIELD_NAMES = ['visibleIndex', 'dataField', 'name', 'dataType', 'width', 'visible', 'sortOrder', 'lastSortOrder', 'sortIndex', 'groupIndex', 'filterValue', 'bufferedFilterValue', 'selectedFilterOperation', 'bufferedSelectedFilterOperation', 'added'].concat(USER_STATE_FIELD_NAMES_15_1);
export const USER_STATE_FIELD_NAMES_15_1 = ['filterValues', 'filterType', 'fixed', 'fixedPosition'] as const;
export const USER_STATE_FIELD_NAMES = [
'visibleIndex', 'dataField', 'name', 'dataType', 'width', 'visible', 'sortOrder',
'lastSortOrder', 'sortIndex', 'groupIndex', 'filterValue', 'bufferedFilterValue',
'selectedFilterOperation', 'bufferedSelectedFilterOperation', 'added',
...USER_STATE_FIELD_NAMES_15_1,
] as const;
// eslint-disable-next-line @stylistic/max-len
export const IGNORE_COLUMN_OPTION_NAMES = { visibleWidth: true, bestFitWidth: true, bufferedFilterValue: true };
export const COMMAND_EXPAND_CLASS = 'dx-command-expand';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export const applyUserState = function (that: ColumnsController) {

if (fieldName === 'dataType') {
column[fieldName] = column[fieldName] || userStateColumn[fieldName];
} else if (USER_STATE_FIELD_NAMES_15_1.includes(fieldName)) {
} else if ((USER_STATE_FIELD_NAMES_15_1 as readonly string[]).includes(fieldName)) {
if (fieldName in userStateColumn) {
column[fieldName] = userStateColumn[fieldName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type ColumnIndex = number | {

export type FilterField = Omit<Column, 'filterOperations'> & { filterOperations?: string[] | null };

export type AddedColumn = string | (Column & { columns?: (Column | string)[] });

export interface Column extends ColumnBase {
parseValue?: (text: string) => unknown;
index?: number;
Expand All @@ -25,6 +27,10 @@ export interface Column extends ColumnBase {
command?: string;
rowspan?: number;
colspan?: number;
lastSortOrder?: ColumnBase['sortOrder'];
bufferedFilterValue?: ColumnBase['filterValue'];
bufferedSelectedFilterOperation?: ColumnBase['selectedFilterOperation'];
added?: AddedColumn;
}

export interface ColumnsChanges {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface UserState {
searchText: string | undefined;
pageIndex: number;
pageSize: number;
expandedRowKeys?: unknown;
expandedRowKeys?: unknown[];
}

export interface ItemProcessingOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type TemporarlyOptionsTakenFromDataGrid = Pick<DataGridOptions,
| 'summary'
| 'remoteOperations'
| 'keyExpr'
| 'selectionFilter'
>;

type TemporarlyOptionsTakenFromTreeList = Pick<TreeListdOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ export class SelectionController extends modules.Controller {
}

if (isDeferredMode) {
// @ts-expect-error
that.option('selectionFilter', selectionFilter);
selectionChangedOptions = {};
} else if (args.addedItemKeys.length || args.removedItemKeys.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { StateStoringController } from '../m_state_storing_controller';

export interface StateStoringDataControllerExtension {
stateLoaded: Callback<[]>;
isStateLoading: () => boolean;
}

export const stateStoringDataControllerExtender = (
Expand Down Expand Up @@ -53,9 +54,10 @@ export const stateStoringDataControllerExtender = (
this.stateLoaded.fire();
deferred.resolve();
})
.fail((error: Error) => {
// NOTE: DeferredObj types fail() with the resolved value, not the rejection reason
.fail((error: unknown) => {
this.stateLoaded.fire();
this.loadErrorHandler(error ?? 'Unknown error');
this.loadErrorHandler((error as Error | undefined) ?? 'Unknown error');
deferred.reject();
});
});
Expand All @@ -75,7 +77,7 @@ export const stateStoringDataControllerExtender = (
return super.isLoading() || this._stateStoringController.isLoading();
}

private isStateLoading(): boolean {
public isStateLoading(): boolean {
return isDefined(this._restoreStateTimeoutID);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,95 +1,10 @@
/* eslint-disable max-classes-per-file */
import { equalByValue, getKeyHash } from '@js/core/utils/common';
import { extend } from '@js/core/utils/extend';
import { isDefined } from '@js/core/utils/type';

import type { ColumnsController } from '../columns_controller/m_columns_controller';
import type { DataController } from '../data_controller/data_controller';
import type { ModuleType } from '../m_types';
import type { SelectionController } from '../selection/m_selection';
import type { RowsView } from '../views/m_rows_view';
import type { StateStoringDataControllerExtension } from './extenders/state_storing_data_controller';
import type { StateStoringController } from './m_state_storing_controller';

const getDataState = (that) => {
// TODO getView
const pagerView = that.getView('pagerView');
// TODO getController
const dataController = that.getController('data');
const state = {
allowedPageSizes: pagerView ? pagerView.getPageSizes() : undefined,
filterPanel: { filterEnabled: that.option('filterPanel.filterEnabled') },
filterValue: that.option('filterValue'),
focusedRowKey: that.option('focusedRowEnabled') ? that.option('focusedRowKey') : undefined,
};

return extend(state, dataController.getUserState());
};

// TODO move processLoadState to target modules (data, columns, pagerView)
const processLoadState = (that) => {
// TODO getController
const columnsController = that.getController('columns');
const selectionController = that.getController('selection');
const exportController = that.getController('export');
const dataController = that.getController('data');

if (columnsController) {
columnsController.columnsChanged.add(() => {
that.updateState({
columns: columnsController.getUserState(),
});
});
}

if (selectionController) {
selectionController.selectionChanged.add((e) => {
that.updateState({
selectedRowKeys: e.selectedRowKeys,
selectionFilter: e.selectionFilter,
});
});
}

if (dataController) {
that._initialPageSize = that.option('paging.pageSize');
that._initialFilterValue = that.option('filterValue');

dataController.changed.add(() => {
const state = getDataState(that);

that.updateState(state);
});
}

if (exportController) {
exportController.selectionOnlyChanged.add(() => {
that.updateState({
exportSelectionOnly: exportController.selectionOnly(),
});
});
}
};

const getFilterValue = (that, state) => {
// TODO: getController
const filterSyncController = that.getController('filterSync');
if (!filterSyncController) {
return null;
}

if (state.filterValue !== undefined) {
return state.filterValue;
}

const filterValueFromColumns = filterSyncController.getFilterValueFromColumns?.(state.columns);
if (filterValueFromColumns?.length > 0) {
return filterValueFromColumns;
}

const columns = that.getController('columns').getColumns();
return that._initialFilterValue ?? filterSyncController.getFilterValueFromColumns(columns);
};

export const rowsView = (Base: ModuleType<RowsView>) => class StateStoringRowsViewExtender extends Base {
protected _dataController!: DataController & StateStoringDataControllerExtension;
Expand All @@ -110,106 +25,6 @@ export const rowsView = (Base: ModuleType<RowsView>) => class StateStoringRowsVi
}
};

export const stateStoring = (Base: ModuleType<StateStoringController>) => class StateStoringExtender extends Base {
private readonly _initialPageSize: any;

public init() {
// @ts-expect-error
super.init.apply(this, arguments);
processLoadState(this);

return this;
}

public isLoading() {
// @ts-expect-error
return super.isLoading() || this.getDataController().isStateLoading();
}

protected state(state?) {
// @ts-expect-error
const result = super.state.apply(this, arguments);

if (state !== undefined) {
this.applyState(extend(true, {}, state));
}

return result;
}

private updateState(state) {
if (this.isEnabled()) {
const oldState = this.state();
const newState = extend({}, oldState, state);
const oldStateHash = getKeyHash(oldState);
const newStateHash = getKeyHash(newState);

if (!equalByValue(oldStateHash, newStateHash)) {
state = extend(true, {}, state);
extend(this._state, state);

this.save();
}
} else {
extend(this._state, state);
}
}

/**
* @extended: TreeList's state_storing
*/
protected applyState(state) {
const { allowedPageSizes } = state;
const { searchText } = state;
const { selectedRowKeys } = state;
const { selectionFilter } = state;
const scrollingMode = this.option('scrolling.mode');
const isVirtualScrollingMode = scrollingMode === 'virtual' || scrollingMode === 'infinite';
const showPageSizeSelector = this.option('pager.visible') === true && this.option('pager.showPageSizeSelector');
// TODO getView
const hasHeight = this.getView('rowsView')?.hasHeight();

this.component.beginUpdate();

if (this.getColumnsController()) {
this.getColumnsController().setUserState(state.columns);
}

if (this.getExportController()) {
this.getExportController().selectionOnly(state.exportSelectionOnly);
}

if (!this.option('selection.deferred')) {
this.option('selectedRowKeys', selectedRowKeys || []);
}

// @ts-expect-error
this.option('selectionFilter', selectionFilter);

if (allowedPageSizes && this.option('pager.allowedPageSizes') === 'auto') {
this.option('pager')!.allowedPageSizes = allowedPageSizes;
}

if (this.option('focusedRowEnabled')) {
this.option('focusedRowIndex', -1);
this.option('focusedRowKey', state.focusedRowKey ?? null);
}

this.component.endUpdate();

this.option('searchPanel.text', searchText || '');

this.option('filterValue', getFilterValue(this, state));

this.option('filterPanel.filterEnabled', state.filterPanel ? state.filterPanel.filterEnabled : true);

this.option('paging.pageIndex', (!isVirtualScrollingMode || hasHeight) && state.pageIndex || 0);
this.option('paging.pageSize', (!isVirtualScrollingMode || showPageSizeSelector) && isDefined(state.pageSize) ? state.pageSize : this._initialPageSize);

this.getDataController() && this.getDataController().reset();
}
};

export const columns = (Base: ModuleType<ColumnsController>) => class StateStoringColumnsExtender extends Base {
protected _shouldReturnVisibleColumns() {
// @ts-expect-error
Expand Down
Loading
Loading