private async groupItems()

in src/tree/LocalRootTreeItemBase.ts [197:239]


    private async groupItems(items: TItem[]): Promise<AzExtTreeItem[]> {
        let itemsWithNoGroup: TItem[] = [];
        const groupMap = new Map<string, TItem[]>();

        if (this.groupBySetting === 'None') {
            itemsWithNoGroup = items;
        } else {
            for (const item of items) {
                const groupName: string | undefined = this.getPropertyValue(item, this.groupBySetting);
                if (!groupName) {
                    itemsWithNoGroup.push(item);
                } else {
                    const groupedItems = groupMap.get(groupName);
                    if (groupedItems) {
                        groupedItems.push(item);
                    } else {
                        groupMap.set(groupName, [item]);
                    }
                }
            }
        }

        return await this.createTreeItemsWithErrorHandling(
            [...itemsWithNoGroup, ...groupMap.entries()],
            'invalidLocalItemOrGroup',
            itemOrGroup => {
                if (Array.isArray(itemOrGroup)) {
                    const [groupName, groupedItems] = itemOrGroup;
                    return new this.childGroupType(this, groupName, groupedItems);
                } else {
                    return new this.childType(this, itemOrGroup);
                }
            },
            itemOrGroup => {
                if (Array.isArray(itemOrGroup)) {
                    const [group] = itemOrGroup;
                    return group;
                } else {
                    return getTreeId(itemOrGroup);
                }
            }
        );
    }