Skip to content
Open
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 @@ -22,6 +22,7 @@ import {
getNavigationTreeUserSettingsId,
type IElementsTreeSettings,
NavigationTreeService,
useElementsTreeLimit,
validateElementsTreeSettings,
} from '@cloudbeaver/plugin-navigation-tree';
import { ResourceManagerService } from '@cloudbeaver/plugin-resource-manager';
Expand Down Expand Up @@ -111,6 +112,8 @@ export const ResourceManagerTree: React.FC<Props> = observer(function ResourceMa
return navTreeService.loadNestedNodes(nodeId, manual);
}

const [limit] = useElementsTreeLimit(root);

return (
<CaptureView view={navTreeService} className={s(styles, { captureView: true })}>
<ResourceManagerTreeCaptureViewContext resourceTypeId={resourceTypeId} />
Expand All @@ -131,6 +134,7 @@ export const ResourceManagerTree: React.FC<Props> = observer(function ResourceMa
<div className={s(styles, { message: true })}>{children}</div>
</div>
)}
limit={limit}
onOpen={node => navTreeService.navToNode(node.uri, node.parentId)}
/>
</CaptureView>
Expand Down
1 change: 1 addition & 0 deletions webapp/packages/plugin-navigation-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@cloudbeaver/core-navigation-tree": "workspace:*",
"@cloudbeaver/core-projects": "workspace:*",
"@cloudbeaver/core-resource": "workspace:*",
"@cloudbeaver/core-resource-manager": "workspace:*",
"@cloudbeaver/core-settings": "workspace:*",
"@cloudbeaver/core-ui": "workspace:*",
"@cloudbeaver/core-utils": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface ElementsTreeProps extends IElementsTreeOptions, React.PropsWith
emptyPlaceholder?: React.FC;
className?: string;
settingsElements?: PlaceholderElement<IElementsTreeSettingsProps>[];
limit?: (nodeId: string) => number;
navNodeFilterCompare?: NavNodeFilterCompareFn;
onClick?: (node: NavNode) => Promise<void> | void;
onOpen?: (node: NavNode, folder: boolean) => Promise<void> | void;
Expand All @@ -75,6 +76,7 @@ export const ElementsTree = observer(
renderers = [],
expandStateGetters,
settingsElements,
limit,
className,
getChildren,
loadChildren,
Expand Down Expand Up @@ -121,6 +123,7 @@ export const ElementsTree = observer(
filters: [nameFilter, ...filters, limitFilter],
renderers: [...renderers, elementsTreeLimitRenderer],
expandStateGetters,
limit,
getChildren,
loadChildren,
isGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ interface IOptions extends IElementsTreeOptions {
baseRoot: string;
root: string;
folderExplorer: IFolderExplorerContext;
limit?: (nodeId: string) => number;
}

export interface IElementsTree extends ILoadableState {
Expand Down Expand Up @@ -236,10 +237,9 @@ export function useElementsTree(options: IOptions): IElementsTree {

if (pageInfo) {
const lastOffset = getNextPageOffset(pageInfo);
for (let offset = 0; offset < lastOffset; offset += navTreeResource.childrenLimit) {
await navTreeResource.load(
CachedResourceOffsetPageKey(offset, navTreeResource.childrenLimit).setParent(CachedResourceOffsetPageTargetKey(nodeId)),
);
const limit = options.limit ? options.limit(nodeId) : navTreeResource.childrenLimit;
for (let offset = 0; offset < lastOffset; offset += limit) {
await navTreeResource.load(CachedResourceOffsetPageKey(offset, limit).setParent(CachedResourceOffsetPageTargetKey(nodeId)));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2026 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 { useCallback } from 'react';

import { useResource } from '@cloudbeaver/core-blocks';
import { useService } from '@cloudbeaver/core-di';
import { NavTreeResource } from '@cloudbeaver/core-navigation-tree';
import { ProjectInfoResource } from '@cloudbeaver/core-projects';
import { CachedMapAllKey } from '@cloudbeaver/core-resource';

//@TODO probably backend should filter out these nodes and only return projects for the root node cause we dont show them anyway
const NON_PROJECT_NODES_COUNT = 3;

export function useElementsTreeLimit(root: string) {
const navTreeResource = useService(NavTreeResource);

const projectInfoResource = useResource(useElementsTreeLimit, ProjectInfoResource, CachedMapAllKey);
const projects = projectInfoResource.data;

const getLimit = useCallback(
(nodeId: string) => {
const count = projects.length + NON_PROJECT_NODES_COUNT + 1;
if (nodeId === root && count > navTreeResource.childrenLimit) {
return count;
}

return navTreeResource.childrenLimit;
},
[navTreeResource.childrenLimit, projects.length, root],
);

return [getLimit];
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { navigationTreeProjectsRendererRenderer } from './ProjectsRenderer/navig
import { ProjectsSettingsPlaceholderElement } from './ProjectsRenderer/ProjectsSettingsForm.js';
import { useNavigationTree } from './useNavigationTree.js';
import { TableContentsSettingsPlaceholderElement } from './ElementsTree/ElementsTreeTools/NavigationTreeSettings/TableContentsSettingsForm.js';
import { useElementsTreeLimit } from './ElementsTree/useElementsTreeLimit.js';

const registry: StyleRegistry = [
[
Expand All @@ -63,6 +64,7 @@ export const NavigationTree = observer(function NavigationTree() {

const root = ROOT_NODE_PATH;
const { handleOpen, handleSelect, handleSelectReset } = useNavigationTree();
const [limit] = useElementsTreeLimit(root);

const connectionGroupFilter = useMemo(() => navigationTreeConnectionGroupFilter(navNodeInfoResource), [navNodeInfoResource]);

Expand Down Expand Up @@ -129,6 +131,7 @@ export const NavigationTree = observer(function NavigationTree() {
settings={settings}
getChildren={navTreeService.getChildren}
loadChildren={navTreeService.loadNestedNodes}
limit={limit}
onOpen={handleOpen}
/>
</CaptureView>
Expand Down
1 change: 1 addition & 0 deletions webapp/packages/plugin-navigation-tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export * from './TreeNew/useTreeMenu.js';
export type { ITreeDnD } from './TreeNew/useTreeDnD.js';
export type { INodeDnD } from './TreeNew/useNodeDnD.js';
export { useTreeDnD } from './TreeNew/useTreeDnD.js';
export { useElementsTreeLimit } from './NavigationTree/ElementsTree/useElementsTreeLimit.js';

export * from './NodesManager/NodeLinkLoader.js';

Expand Down
3 changes: 3 additions & 0 deletions webapp/packages/plugin-navigation-tree/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
{
"path": "../core-resource"
},
{
"path": "../core-resource-manager"
},
{
"path": "../core-settings"
},
Expand Down
Loading