Skip to content

Commit 87ebfd9

Browse files
T1325067 — PivotGrid: Field Chooser — The "Cannot read properties of undefined (reading 'isMeasure')" error occurs when dragging fields while data is loading (#33103)
1 parent dc5b588 commit 87ebfd9

3 files changed

Lines changed: 62 additions & 10 deletions

File tree

packages/devextreme/js/__internal/grids/pivot_grid/field_chooser/m_field_chooser_base.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { createPath, foreachTree } from '../m_widget_utils';
2323
import SortableModule from '../sortable/m_sortable';
2424
import { ATTRIBUTES, CLASSES } from './const';
2525
import { dragAndDropItemRender } from './dom';
26-
import { reverseSortOrder } from './utils';
26+
import { reverseSortOrder, shouldCancelDragging } from './utils';
2727

2828
const { Sortable } = SortableModule;
2929

@@ -253,15 +253,7 @@ export class FieldChooserBase extends mixinWidget {
253253
onDragging(e) {
254254
const field = e.sourceElement.data('field');
255255
const { targetGroup } = e;
256-
e.cancel = false;
257-
258-
if (field.isMeasure === true) {
259-
if (targetGroup === 'column' || targetGroup === 'row' || targetGroup === 'filter') {
260-
e.cancel = true;
261-
}
262-
} else if (field.isMeasure === false && targetGroup === 'data') {
263-
e.cancel = true;
264-
}
256+
e.cancel = shouldCancelDragging(field, targetGroup);
265257
},
266258
useIndicator: true,
267259
onChanged(e) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
3+
import { shouldCancelDragging } from './utils';
4+
5+
describe('shouldCancelDragging', () => {
6+
it('should return false when field is undefined', () => {
7+
expect(shouldCancelDragging(undefined, 'column')).toBe(false);
8+
expect(shouldCancelDragging(undefined, 'row')).toBe(false);
9+
expect(shouldCancelDragging(undefined, 'filter')).toBe(false);
10+
expect(shouldCancelDragging(undefined, 'data')).toBe(false);
11+
});
12+
13+
it('should return true when isMeasure is true and target is column', () => {
14+
expect(shouldCancelDragging({ isMeasure: true }, 'column')).toBe(true);
15+
});
16+
17+
it('should return true when isMeasure is true and target is row', () => {
18+
expect(shouldCancelDragging({ isMeasure: true }, 'row')).toBe(true);
19+
});
20+
21+
it('should return true when isMeasure is true and target is filter', () => {
22+
expect(shouldCancelDragging({ isMeasure: true }, 'filter')).toBe(true);
23+
});
24+
25+
it('should return false when isMeasure is true and target is data', () => {
26+
expect(shouldCancelDragging({ isMeasure: true }, 'data')).toBe(false);
27+
});
28+
29+
it('should return true when isMeasure is false and target is data', () => {
30+
expect(shouldCancelDragging({ isMeasure: false }, 'data')).toBe(true);
31+
});
32+
33+
it('should return false when isMeasure is false and target is column', () => {
34+
expect(shouldCancelDragging({ isMeasure: false }, 'column')).toBe(false);
35+
});
36+
37+
it('should return false when isMeasure is undefined', () => {
38+
expect(shouldCancelDragging({}, 'data')).toBe(false);
39+
expect(shouldCancelDragging({}, 'column')).toBe(false);
40+
});
41+
});

packages/devextreme/js/__internal/grids/pivot_grid/field_chooser/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,22 @@ export const reverseSortOrder = (
66
): SortOrderType => (sortOrder === SORT_ORDER.descending
77
? SORT_ORDER.ascending
88
: SORT_ORDER.descending);
9+
10+
export const shouldCancelDragging = (
11+
field: { isMeasure?: boolean } | undefined,
12+
targetGroup: string,
13+
): boolean => {
14+
if (!field) {
15+
return false;
16+
}
17+
18+
if (field.isMeasure === true) {
19+
return targetGroup === 'column' || targetGroup === 'row' || targetGroup === 'filter';
20+
}
21+
22+
if (field.isMeasure === false && targetGroup === 'data') {
23+
return true;
24+
}
25+
26+
return false;
27+
};

0 commit comments

Comments
 (0)