Skip to content

Commit 594b53b

Browse files
add checking incompatible nesteds
1 parent 090f9ca commit 594b53b

1,451 files changed

Lines changed: 2195 additions & 2597 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/devextreme-angular/src/core/component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
ICollectionNestedOptionContainer,
3939
CollectionNestedOptionContainerImpl,
4040
checkIncompatibleNestedItems,
41-
41+
CollectionNestedOption,
4242
} from './nested-option';
4343

4444
import { DxIntegrationModule } from './integration';
@@ -63,13 +63,15 @@ export const getServerStateKey = () => {
6363
})
6464
export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterContentChecked, AfterViewInit, AfterViewChecked,
6565
INestedOptionContainer, ICollectionNestedOptionContainer, IDxTemplateHost {
66-
protected _dxClassName = 'DxComponent';
67-
6866
private _initialOptions: any = {};
6967

7068
protected _optionsToUpdate: any = {};
7169

7270
private readonly _collectionContainerImpl: ICollectionNestedOptionContainer;
71+
72+
protected _legacyNestedClassNames: Record<string, any> = {};
73+
74+
protected _dxClassName = 'DxComponent';
7375

7476
eventHelper: EmitterHelper;
7577

@@ -91,11 +93,11 @@ export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterCo
9193

9294
templateUpdateRequired = false;
9395

94-
protected _setChildren(propertyName: string, items: QueryList<ICollectionNestedOption>) {
96+
protected _setChildren(propertyName: string, items: QueryList<CollectionNestedOption>) {
9597
const hasIncopatibleNestedItems = checkIncompatibleNestedItems(
9698
items,
9799
this._dxClassName,
98-
this.getLegacyClassNames()[propertyName],
100+
this._legacyNestedClassNames[propertyName],
99101
);
100102

101103
if (!hasIncopatibleNestedItems) {
@@ -316,8 +318,6 @@ export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterCo
316318
this.templateUpdateRequired = true;
317319
}
318320

319-
protected getLegacyClassNames: () => Record<string, string[]> = () => ({});
320-
321321
setChildren<T extends ICollectionNestedOption>(propertyName: string, items: QueryList<T>) {
322322
this.resetOptions(propertyName);
323323
return this._collectionContainerImpl.setChildren(propertyName, items);

packages/devextreme-angular/src/core/nested-option.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,30 @@ export interface INestedOptionContainer {
2323
export type IOptionPathGetter = () => string;
2424

2525
export const checkIncompatibleNestedItems = (
26-
items: QueryList<ICollectionNestedOption>,
27-
containerClassName,
28-
legacyClassNames,
29-
) =>
30-
/* if (console && console.warn) {
31-
console.warn(`In ${containerClassName},
32-
the nested ${itemClassName} and ${anotherItemClassName} components are incompatible.
26+
items: QueryList<CollectionNestedOption>,
27+
containerClassName: string,
28+
legacyClassNames: string[],
29+
) => {
30+
if (items.length > 0 && legacyClassNames.length > 0 && console && console.warn) {
31+
const itemsLassNames = items.map((item) => item._dxClassName);
32+
const itemLegacyClassName = itemsLassNames.find((itemClassName) => legacyClassNames.includes(itemClassName));
33+
const itemClassName = itemsLassNames.find((itemClassName) => !legacyClassNames.includes(itemClassName));
34+
35+
if (itemLegacyClassName && itemClassName) {
36+
console.warn(`In ${containerClassName},
37+
the nested ${itemClassName} and ${itemLegacyClassName} components are incompatible.
3338
Ensure that all nested components in the content area match.`);
34-
} */
35-
false
36-
;
39+
40+
return true;
41+
}
42+
}
43+
return false;
44+
};
3745

3846
@Component({
3947
template: '',
4048
})
4149
export abstract class BaseNestedOption implements INestedOptionContainer, ICollectionNestedOptionContainer {
42-
protected _dxClassName = 'BaseNestedOption';
43-
4450
protected _host: INestedOptionContainer;
4551

4652
protected _hostOptionPath: IOptionPathGetter;
@@ -50,17 +56,20 @@ export abstract class BaseNestedOption implements INestedOptionContainer, IColle
5056
protected _initialOptions = {};
5157

5258
protected abstract get _optionPath(): string;
59+
60+
_dxClassName = 'BaseNestedOption';
61+
5362
protected abstract _fullOptionPath(): string;
5463

5564
constructor() {
5665
this._collectionContainerImpl = new CollectionNestedOptionContainerImpl(this._setOption.bind(this), this._filterItems.bind(this));
5766
}
5867

59-
protected _setChildren(propertyName: string, items: QueryList<ICollectionNestedOption>) {
68+
protected _setChildren(propertyName: string, items: QueryList<CollectionNestedOption>) {
6069
const hasIncopatibleNestedItems = checkIncompatibleNestedItems(
6170
items,
6271
this._dxClassName,
63-
null,
72+
[],
6473
);
6574

6675
if (!hasIncopatibleNestedItems) {

packages/devextreme-angular/src/ui/accordion/index.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
NestedOptionHost,
4040
IterableDifferHelper,
4141
WatcherHelper,
42-
ICollectionNestedOption,
42+
CollectionNestedOption,
4343
} from 'devextreme-angular/core';
4444

4545
import { DxiItemModule } from 'devextreme-angular/ui/nested';
@@ -70,10 +70,10 @@ import {
7070
]
7171
})
7272
export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent implements OnDestroy, OnChanges, DoCheck {
73-
protected _dxClassName = 'DxAccordionComponent';
73+
_dxClassName = 'DxAccordionComponent';
7474

7575
@ContentChildren(PROPERTY_TOKEN_items)
76-
set _itemsNestedItems(value: QueryList<ICollectionNestedOption>) {
76+
set _itemsNestedItems(value: QueryList<CollectionNestedOption>) {
7777
this._setChildren('items', value);
7878
}
7979

@@ -721,20 +721,11 @@ protected _dxClassName = 'DxAccordionComponent';
721721

722722

723723

724-
protected getLegacyClassNames = () => {
725-
const legacyClassNames = {};
726-
727-
const getLegacyClassNamesForPropertyName = (propName) => {
728-
legacyClassNames[propName] = legacyClassNames[propName] || [];
729-
return legacyClassNames[propName];
730-
};
731-
732-
733-
getLegacyClassNamesForPropertyName('items').push('DxiItemComponent');
734-
735-
736-
return legacyClassNames || {};
737-
};
724+
protected _legacyNestedClassNames: Record<string, string[]> = {
725+
"items": [
726+
"DxiItemComponent"
727+
]
728+
};
738729

739730

740731

packages/devextreme-angular/src/ui/accordion/nested/item-dxi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { PROPERTY_TOKEN_items } from 'devextreme-angular/tokens';
4747
})
4848
export class DxiAccordionItemComponent extends CollectionNestedOption implements AfterViewInit,
4949
IDxTemplateHost {
50-
protected _dxClassName = 'DxiAccordionItemComponent';
50+
_dxClassName = 'DxiAccordionItemComponent';
5151

5252

5353
@Input()

packages/devextreme-angular/src/ui/action-sheet/index.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
NestedOptionHost,
4040
IterableDifferHelper,
4141
WatcherHelper,
42-
ICollectionNestedOption,
42+
CollectionNestedOption,
4343
} from 'devextreme-angular/core';
4444

4545
import { DxiItemModule } from 'devextreme-angular/ui/nested';
@@ -70,10 +70,10 @@ import {
7070
]
7171
})
7272
export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent implements OnDestroy, OnChanges, DoCheck {
73-
protected _dxClassName = 'DxActionSheetComponent';
73+
_dxClassName = 'DxActionSheetComponent';
7474

7575
@ContentChildren(PROPERTY_TOKEN_items)
76-
set _itemsNestedItems(value: QueryList<ICollectionNestedOption>) {
76+
set _itemsNestedItems(value: QueryList<CollectionNestedOption>) {
7777
this._setChildren('items', value);
7878
}
7979

@@ -513,20 +513,11 @@ protected _dxClassName = 'DxActionSheetComponent';
513513

514514

515515

516-
protected getLegacyClassNames = () => {
517-
const legacyClassNames = {};
518-
519-
const getLegacyClassNamesForPropertyName = (propName) => {
520-
legacyClassNames[propName] = legacyClassNames[propName] || [];
521-
return legacyClassNames[propName];
522-
};
523-
524-
525-
getLegacyClassNamesForPropertyName('items').push('DxiItemComponent');
526-
527-
528-
return legacyClassNames || {};
529-
};
516+
protected _legacyNestedClassNames: Record<string, string[]> = {
517+
"items": [
518+
"DxiItemComponent"
519+
]
520+
};
530521

531522

532523

packages/devextreme-angular/src/ui/action-sheet/nested/item-dxi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { PROPERTY_TOKEN_items } from 'devextreme-angular/tokens';
4949
})
5050
export class DxiActionSheetItemComponent extends CollectionNestedOption implements AfterViewInit,
5151
IDxTemplateHost {
52-
protected _dxClassName = 'DxiActionSheetItemComponent';
52+
_dxClassName = 'DxiActionSheetItemComponent';
5353

5454

5555
@Input()

packages/devextreme-angular/src/ui/autocomplete/index.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
NestedOptionHost,
4949
IterableDifferHelper,
5050
WatcherHelper,
51-
ICollectionNestedOption,
51+
CollectionNestedOption,
5252
} from 'devextreme-angular/core';
5353

5454
import { DxiButtonModule } from 'devextreme-angular/ui/nested';
@@ -117,20 +117,20 @@ const CUSTOM_VALUE_ACCESSOR_PROVIDER = {
117117
]
118118
})
119119
export class DxAutocompleteComponent extends DxComponent implements OnDestroy, ControlValueAccessor, OnChanges, DoCheck {
120-
protected _dxClassName = 'DxAutocompleteComponent';
120+
_dxClassName = 'DxAutocompleteComponent';
121121

122122
@ContentChildren(PROPERTY_TOKEN_buttons)
123-
set _buttonsNestedItems(value: QueryList<ICollectionNestedOption>) {
123+
set _buttonsNestedItems(value: QueryList<CollectionNestedOption>) {
124124
this._setChildren('buttons', value);
125125
}
126126

127127
@ContentChildren(PROPERTY_TOKEN_items)
128-
set _itemsNestedItems(value: QueryList<ICollectionNestedOption>) {
128+
set _itemsNestedItems(value: QueryList<CollectionNestedOption>) {
129129
this._setChildren('items', value);
130130
}
131131

132132
@ContentChildren(PROPERTY_TOKEN_toolbarItems)
133-
set _toolbarItemsNestedItems(value: QueryList<ICollectionNestedOption>) {
133+
set _toolbarItemsNestedItems(value: QueryList<CollectionNestedOption>) {
134134
this._setChildren('toolbarItems', value);
135135
}
136136

@@ -1380,22 +1380,14 @@ protected _dxClassName = 'DxAutocompleteComponent';
13801380
@HostListener('onBlur', ['$event']) touched = (_) => {};
13811381

13821382

1383-
protected getLegacyClassNames = () => {
1384-
const legacyClassNames = {};
1385-
1386-
const getLegacyClassNamesForPropertyName = (propName) => {
1387-
legacyClassNames[propName] = legacyClassNames[propName] || [];
1388-
return legacyClassNames[propName];
1389-
};
1390-
1391-
1392-
getLegacyClassNamesForPropertyName('buttons').push('DxiButtonComponent');
1393-
1394-
getLegacyClassNamesForPropertyName('items').push('DxiItemComponent');
1395-
1396-
1397-
return legacyClassNames || {};
1398-
};
1383+
protected _legacyNestedClassNames: Record<string, string[]> = {
1384+
"buttons": [
1385+
"DxiButtonComponent"
1386+
],
1387+
"items": [
1388+
"DxiItemComponent"
1389+
]
1390+
};
13991391

14001392

14011393

packages/devextreme-angular/src/ui/autocomplete/nested/animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { NestedOption } from 'devextreme-angular/core';
3535
],
3636
})
3737
export class DxoAutocompleteAnimationComponent extends NestedOption implements OnDestroy, OnInit {
38-
protected _dxClassName = 'DxoAutocompleteAnimationComponent';
38+
_dxClassName = 'DxoAutocompleteAnimationComponent';
3939

4040

4141
@Input()

packages/devextreme-angular/src/ui/autocomplete/nested/at.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { NestedOption } from 'devextreme-angular/core';
3535
],
3636
})
3737
export class DxoAutocompleteAtComponent extends NestedOption implements OnDestroy, OnInit {
38-
protected _dxClassName = 'DxoAutocompleteAtComponent';
38+
_dxClassName = 'DxoAutocompleteAtComponent';
3939

4040

4141
@Input()

packages/devextreme-angular/src/ui/autocomplete/nested/boundary-offset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { NestedOption } from 'devextreme-angular/core';
3434
],
3535
})
3636
export class DxoAutocompleteBoundaryOffsetComponent extends NestedOption implements OnDestroy, OnInit {
37-
protected _dxClassName = 'DxoAutocompleteBoundaryOffsetComponent';
37+
_dxClassName = 'DxoAutocompleteBoundaryOffsetComponent';
3838

3939

4040
@Input()

0 commit comments

Comments
 (0)