Skip to content

Commit a1bb930

Browse files
author
Alyar
committed
code refactoring
1 parent 098253c commit a1bb930

File tree

1 file changed

+28
-25
lines changed
  • packages/devextreme/js/__internal/grids/new/grid_core/filtering/header_filter

1 file changed

+28
-25
lines changed

packages/devextreme/js/__internal/grids/new/grid_core/filtering/header_filter/view_controller.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@ export class HeaderFilterViewController {
4747
const filterExpression = this.getFilterExpressionWithoutCurrentColumn(column);
4848
const type = getHeaderFilterListType(column);
4949
const { columnsController } = this;
50+
const applyFilter = (filterValues, filterType): void => {
51+
if (customApply) {
52+
customApply(filterValues);
53+
} else {
54+
columnsController.updateColumns(
55+
(columns) => {
56+
const index = getColumnIndexByName(columns, column.name);
57+
const newColumns = [...columns];
58+
59+
newColumns[index] = {
60+
...newColumns[index],
61+
headerFilter: {
62+
...newColumns[index].headerFilter,
63+
},
64+
// NOTE: Copy array because of mutations in legacy code
65+
filterValues: Array.isArray(filterValues)
66+
? [...filterValues]
67+
: filterValues,
68+
filterType,
69+
};
70+
return newColumns;
71+
},
72+
);
73+
}
74+
75+
onFilterCloseCallback?.();
76+
};
5077
const popupOptions: PopupOptions = {
5178
type,
5279
column: { ...column },
@@ -58,31 +85,7 @@ export class HeaderFilterViewController {
5885
? [...column.filterValues]
5986
: column.filterValues,
6087
apply(): void {
61-
if (customApply) {
62-
customApply(this.filterValues);
63-
} else {
64-
columnsController.updateColumns(
65-
(columns) => {
66-
const index = getColumnIndexByName(columns, column.name);
67-
const newColumns = [...columns];
68-
69-
newColumns[index] = {
70-
...newColumns[index],
71-
headerFilter: {
72-
...newColumns[index].headerFilter,
73-
},
74-
// NOTE: Copy array because of mutations in legacy code
75-
filterValues: Array.isArray(this.filterValues)
76-
? [...this.filterValues]
77-
: this.filterValues,
78-
filterType: this.filterType,
79-
};
80-
return newColumns;
81-
},
82-
);
83-
}
84-
85-
onFilterCloseCallback?.();
88+
applyFilter(this.filterValues, this.filterType);
8689
},
8790
hidePopupCallback: (): void => {
8891
this.popupStateInternal.value = null;

0 commit comments

Comments
 (0)