Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface DataAdapterOptions {
onNodeChanged: (node: InternalNode) => void;

searchMode: SearchMode;

allowDisabledNodeSelection: boolean;
}

SearchBoxController.setEditorClass(TextBox);
Expand All @@ -69,6 +71,7 @@ class DataAdapter {
dataConverter: new HierarchicalDataConverter(),
onNodeChanged: noop,
sort: null,
allowDisabledNodeSelection: true,
};

_selectedNodesKeys: ItemKey[] = [];
Expand Down Expand Up @@ -162,8 +165,12 @@ class DataAdapter {
return this.options.multipleSelection ? this.getData() : this.getFullData();
}

_isNodeVisible(node: InternalNode): boolean {
return node.internalFields.item.visible !== false;
_isNodeVisible(node?: InternalNode): boolean {
return node?.internalFields.item.visible !== false;
}

_isNodeDisabled(node?: InternalNode): boolean {
return node?.internalFields.item.disabled === true;
}

_getByKey(data: (InternalNode | null)[], key: ItemKey): InternalNode | null {
Expand Down Expand Up @@ -432,6 +439,10 @@ class DataAdapter {
return this.options.dataConverter.getItemsCount();
}

_getDisabledItemsCount(): number {
return this.options.dataConverter.getDisabledItemsCount();
}

getVisibleItemsCount(): number {
return this.options.dataConverter.getVisibleItemsCount();
}
Expand Down Expand Up @@ -509,7 +520,16 @@ class DataAdapter {
: this._dataStructure;

each(dataStructure, (_index: number, node: InternalNode) => {
if (node && this._isNodeVisible(node)) {
if (!this._isNodeVisible(node)) {
return;
}

if (this.options.allowDisabledNodeSelection) {
this._setFieldState(node, SELECTED, state);
return;
}

if (!this._isNodeDisabled(node)) {
this._setFieldState(node, SELECTED, state);
}
});
Expand All @@ -522,10 +542,14 @@ class DataAdapter {
}

isAllSelected(): boolean | undefined {
if (this.getSelectedNodesKeys().length) {
return this.getSelectedNodesKeys().length === this.getVisibleItemsCount() ? true : undefined;
if (!this.getSelectedNodesKeys().length) {
return false;
}
return false;

const countedNodesAmount = this.getVisibleItemsCount()
- (!this.options.allowDisabledNodeSelection ? this._getDisabledItemsCount() : 0);

return this.getSelectedNodesKeys().length === countedNodesAmount ? true : undefined;
}

toggleExpansion(key: ItemKey, state: boolean): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class DataConverter {

private _visibleItemsCount = 0;

private _disabledItemsCount = 0;

_indexByKey: Record<string | number, number> = {};

private _dataAccessors!: DataAccessors;
Expand Down Expand Up @@ -128,6 +130,10 @@ class DataConverter {
this._visibleItemsCount += 1;
}

if (item.disabled === true) {
this._disabledItemsCount += 1;
}

const { items, ...itemWithoutItems } = item;

const node = {
Expand Down Expand Up @@ -265,6 +271,10 @@ class DataConverter {
return this._itemsCount;
}

getDisabledItemsCount(): number {
return this._disabledItemsCount;
}

getVisibleItemsCount(): number {
return this._visibleItemsCount;
}
Expand Down Expand Up @@ -302,6 +312,7 @@ class DataConverter {
): (InternalNode | null)[] {
this._itemsCount = 0;
this._visibleItemsCount = 0;
this._disabledItemsCount = 0;
this._rootValue = rootValue;
this._dataType = dataType;
this._indexByKey = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface TreeViewBaseProperties extends Properties<TreeViewNode>, Omit<
deferRendering?: boolean;

_supportItemUrl?: boolean;

allowDisabledNodeSelection?: boolean;
}

class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties, TreeViewNode> {
Expand Down Expand Up @@ -281,6 +283,7 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
createChildren: null,
onSelectAllValueChanged: null,
_supportItemUrl: false,
allowDisabledNodeSelection: true,
};

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Expand Down Expand Up @@ -438,6 +441,10 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
case 'collapseIcon':
this.repaint();
break;
case 'allowDisabledNodeSelection':
this._initDataAdapter();
this.repaint();
break;
default:
super._optionChanged(args);
}
Expand Down Expand Up @@ -688,6 +695,7 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
expandNodesRecursive = true,
selectionRequired = false,
dataStructure = 'tree',
allowDisabledNodeSelection,
} = this.option();

return {
Expand All @@ -700,6 +708,7 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
dataType: dataStructure,
sort: this._dataSource?.sort(),
langParams: this._dataSource?.loadOptions?.()?.langParams,
allowDisabledNodeSelection,
};
}

Expand Down
Loading
Loading