mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
* CB-4541 feat: tree filter * CB-4541 feat: tree empty placeholders * CB-4541 fix: settings overflow scroll effect * CB-4541 fix: settings groups size * CB-4541 fix: sync groups when filtering * CB-4541 chore: performance optimization * chore: review fixes * chore: replace inline styles * chore: replace inline styles * chore: hide extra settings from UI * chore: hide groups view from settings * fix: add override options to devtools * fix: trim filter in settings search * chore: localization --------- Co-authored-by: Evgenia Bezborodova <139753579+EvgeniaBzzz@users.noreply.github.com> Co-authored-by: kseniaguzeeva <112612526+kseniaguzeeva@users.noreply.github.com> Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
/*
|
|
* CloudBeaver - Cloud Database Manager
|
|
* Copyright (C) 2020-2024 DBeaver Corp and others
|
|
*
|
|
* Licensed under the Apache License, Version 2.0.
|
|
* you may not use this file except in compliance with the License.
|
|
*/
|
|
import { computed, type IComputedValue } from 'mobx';
|
|
import { useState } from 'react';
|
|
|
|
import { useObjectRef } from '@cloudbeaver/core-blocks';
|
|
import { MetadataMap } from '@cloudbeaver/core-utils';
|
|
|
|
import type { ITreeData } from './ITreeData.js';
|
|
import type { ITree } from './useTree.js';
|
|
|
|
export interface INodeSizeCache {
|
|
getSize(id: string): number;
|
|
}
|
|
|
|
export function useNodeSizeCache(tree: ITree, treeData: ITreeData): INodeSizeCache {
|
|
const [sizeRangeCache] = useState(
|
|
() =>
|
|
new MetadataMap<string, IComputedValue<number>>((id, metadata) =>
|
|
computed(() => {
|
|
let size = tree.getNodeHeight(id);
|
|
const expanded = treeData.getState(id).expanded;
|
|
|
|
if (expanded) {
|
|
const children = treeData.getChildren(id);
|
|
|
|
for (const child of children) {
|
|
size += metadata.get(child).get();
|
|
}
|
|
}
|
|
|
|
return size;
|
|
}),
|
|
),
|
|
);
|
|
|
|
return useObjectRef(
|
|
() => ({
|
|
getSize(id: string): number {
|
|
return sizeRangeCache.get(id).get();
|
|
},
|
|
}),
|
|
{},
|
|
);
|
|
}
|