public static async loadMissingOnCheck()

in uui-core/src/data/processing/views/tree/Tree.ts [191:250]


    public static async loadMissingOnCheck<TItem, TId, TFilter = any>({
        tree,
        dataSourceState,
        api,
        getChildCount,
        isFolded,
        filter,
        cascadeSelection,
        isRoot,
        isChecked,
        checkedId,
    }: LoadMissingOnCheckOptions<TItem, TId, TFilter>): Promise<ITree<TItem, TId> | ITreeLoadResult<TItem, TId>> {
        const isImplicitMode = cascadeSelection === CascadeSelectionTypes.IMPLICIT;

        if (!cascadeSelection && !isRoot) {
            return tree;
        }

        const parents = this.getParents(checkedId, tree);
        return await FetchingHelper.load<TItem, TId, TFilter>({
            tree,
            options: {
                api,
                getChildCount,
                isFolded,
                filter: { ...dataSourceState?.filter, ...filter },
                loadAllChildren: (itemId) => {
                    const loadAllConfig = { nestedChildren: !isImplicitMode, children: false };
                    if (!cascadeSelection) {
                        return { ...loadAllConfig, children: isChecked && isRoot };
                    }

                    if (!isChecked && isRoot) {
                        return { ...loadAllConfig, children: false };
                    }

                    if (isImplicitMode) {
                        return { ...loadAllConfig, children: itemId === ROOT_ID || parents.some((parent) => isEqual(parent, itemId)) };
                    }

                    const { ids } = tree.getItems(undefined);
                    const rootIsNotLoaded = ids.length === 0;

                    const shouldLoadChildrenAfterSearch = (!!dataSourceState.search?.length
                        && (parents.some((parent) => isEqual(parent, itemId))
                        || (itemId === ROOT_ID && rootIsNotLoaded)));

                    // `isEqual` is used, because complex ids can be recreated after fetching of parents.
                    // So, they should be compared not by reference, but by value.
                    const shouldLoadAllChildren = isRoot
                        || isEqual(itemId, checkedId)
                        || shouldLoadChildrenAfterSearch;

                    return { children: shouldLoadAllChildren, nestedChildren: !shouldLoadChildrenAfterSearch };
                },
                isLoadStrict: true,
            },
            dataSourceState: { ...dataSourceState, search: null },
        });
    }