Skip to content

Commit 21afac9

Browse files
author
Alyar
committed
CardView - Header Filter: Fix reset select state after search
1 parent 6a0383e commit 21afac9

File tree

4 files changed

+105
-55
lines changed

4 files changed

+105
-55
lines changed

e2e/testcafe-devextreme/tests/cardView/headerFilter/common.functional.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,48 @@ test('Filter values should be filtered by SearchPanel', async (t) => {
258258
},
259259
});
260260
});
261+
262+
test('Select item state should be correct after search', async (t) => {
263+
// arrange
264+
const cardView = new CardView('#container');
265+
266+
await t
267+
.click(cardView.getHeaderPanel().getHeaderItem(0).getFilterIcon());
268+
269+
// assert
270+
await t
271+
.expect(cardView.getHeaderFilterList().getItems().count)
272+
.eql(4);
273+
274+
const firstHeaderFilterItem = cardView.getHeaderFilterList().getItem(0);
275+
276+
// act
277+
await t
278+
.click(firstHeaderFilterItem.element);
279+
280+
// assert
281+
await t
282+
.expect(firstHeaderFilterItem.isSelected)
283+
.ok();
284+
285+
// act
286+
await t
287+
.typeText(cardView.getHeaderFilterList().searchInput, '1');
288+
289+
// assert
290+
await t
291+
.expect(cardView.getHeaderFilterList().getItems().count)
292+
.eql(1)
293+
.expect(cardView.getHeaderFilterList().getItem(0).isSelected)
294+
.ok();
295+
}).before(async () => {
296+
await createWidget('dxCardView', {
297+
...baseConfig,
298+
headerFilter: {
299+
visible: true,
300+
search: {
301+
enabled: true,
302+
},
303+
},
304+
});
305+
});

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ const _processGroupItems = (
137137

138138
export const getDataSourceOptions = (
139139
storeLoadAdapter,
140-
column,
140+
popupOptions,
141141
headerFilterOptions,
142142
filter,
143143
) => {
144+
const { column } = popupOptions;
145+
144146
if (!storeLoadAdapter) {
145147
return undefined;
146148
}
@@ -199,7 +201,11 @@ export const getDataSourceOptions = (
199201
let items = data;
200202

201203
items = origPostProcess?.call(this, items) || items;
202-
_updateSelectedState(items, column);
204+
_updateSelectedState(items, {
205+
...column,
206+
filterType: popupOptions.filterType,
207+
filterValues: popupOptions.filterValues,
208+
});
203209
return items;
204210
};
205211

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

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -45,70 +45,65 @@ export class HeaderFilterViewController {
4545
const rootDataSource = this.dataController.getStoreLoadAdapter();
4646
const rootHeaderFilterOptions = this.options.oneWay('headerFilter').peek();
4747
const filterExpression = this.getFilterExpressionWithoutCurrentColumn(column);
48+
const type = getFilterType(column);
49+
const { columnsController } = this;
50+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51+
const popupOptions: any = {
52+
type,
53+
column: { ...column },
54+
isFilterBuilder,
55+
headerFilter: { ...column.headerFilter },
56+
filterType: column.filterType,
57+
// NOTE: Copy array because of mutations in legacy code
58+
filterValues: Array.isArray(column.filterValues)
59+
? [...column.filterValues]
60+
: column.filterValues,
61+
apply(): void {
62+
if (customApply) {
63+
customApply(this.filterValues);
64+
} else {
65+
columnsController.updateColumns(
66+
(columns) => {
67+
const index = getColumnIndexByName(columns, column.name);
68+
const newColumns = [...columns];
69+
70+
newColumns[index] = {
71+
...newColumns[index],
72+
headerFilter: {
73+
...newColumns[index].headerFilter,
74+
},
75+
// NOTE: Copy array because of mutations in legacy code
76+
filterValues: Array.isArray(this.filterValues)
77+
? [...this.filterValues]
78+
: this.filterValues,
79+
filterType: this.filterType,
80+
};
81+
return newColumns;
82+
},
83+
);
84+
}
85+
86+
onFilterCloseCallback?.();
87+
},
88+
hidePopupCallback: (): void => {
89+
this.popupStateInternal.value = null;
90+
onFilterCloseCallback?.();
91+
},
92+
};
4893

49-
const filterDataSourceOptions = getDataSourceOptions(
94+
popupOptions.dataSource = getDataSourceOptions(
5095
rootDataSource,
51-
{
52-
...column,
53-
filterType: column.filterType,
54-
filterValues: column.filterValues,
55-
},
96+
popupOptions,
5697
// NOTE: Only text used from root options
5798
{
5899
texts: rootHeaderFilterOptions.texts,
59100
},
60-
61101
filterExpression,
62102
);
63103

64-
const type = getFilterType(column);
65-
const { columnsController } = this;
66-
67104
this.popupStateInternal.value = {
68105
element,
69-
options: {
70-
type,
71-
isFilterBuilder,
72-
headerFilter: { ...column.headerFilter },
73-
dataSource: filterDataSourceOptions,
74-
filterType: column.filterType,
75-
// NOTE: Copy array because of mutations in legacy code
76-
filterValues: Array.isArray(column.filterValues)
77-
78-
? [...column.filterValues]
79-
: column.filterValues,
80-
apply(): void {
81-
if (customApply) {
82-
customApply(this.filterValues);
83-
} else {
84-
columnsController.updateColumns(
85-
(columns) => {
86-
const index = getColumnIndexByName(columns, column.name);
87-
const newColumns = [...columns];
88-
89-
newColumns[index] = {
90-
...newColumns[index],
91-
headerFilter: {
92-
...newColumns[index].headerFilter,
93-
},
94-
// NOTE: Copy array because of mutations in legacy code
95-
filterValues: Array.isArray(this.filterValues)
96-
? [...this.filterValues]
97-
: this.filterValues,
98-
filterType: this.filterType,
99-
};
100-
return newColumns;
101-
},
102-
);
103-
}
104-
105-
onFilterCloseCallback?.();
106-
},
107-
hidePopupCallback: (): void => {
108-
this.popupStateInternal.value = null;
109-
onFilterCloseCallback?.();
110-
},
111-
},
106+
options: popupOptions,
112107
};
113108
}
114109

packages/testcafe-models/list/item.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const CLASS = {
55
disabled: 'dx-state-disabled',
66
focused: 'dx-state-focused',
77
hovered: 'dx-state-hover',
8+
selected: 'dx-list-item-selected',
89
reorderHandle: 'dx-list-reorder-handle',
910
};
1011

@@ -19,6 +20,8 @@ export default class ListItem {
1920

2021
isHovered: Promise<boolean>;
2122

23+
isSelected: Promise<boolean>;
24+
2225
radioButton: RadioButton;
2326

2427
reorderHandle: Selector;
@@ -31,6 +34,7 @@ export default class ListItem {
3134
this.isDisabled = element.hasClass(CLASS.disabled);
3235
this.isFocused = element.hasClass(CLASS.focused);
3336
this.isHovered = element.hasClass(CLASS.hovered);
37+
this.isSelected = element.hasClass(CLASS.selected);
3438
this.radioButton = new RadioButton(element);
3539
this.reorderHandle = element.find(`.${CLASS.reorderHandle}`);
3640
this.text = element.textContent;

0 commit comments

Comments
 (0)