Skip to content

Commit

Permalink
Cb 5831 refresh whole tree (#3129)
Browse files Browse the repository at this point in the history
* CB-5831 outdate children when refresh node

* CB-5831 freeze resource until tree is constructed

---------

Co-authored-by: Evgenia <[email protected]>
  • Loading branch information
devnaumov and EvgeniaBzzz authored Dec 12, 2024
1 parent 2f80d1c commit db9df1f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
7 changes: 7 additions & 0 deletions webapp/packages/core-blocks/src/ResourcesHooks/useResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type ResourceData<TResource extends IResource<any, any, any, any>, TKey, TInclud

interface IActions<TResource extends IResource<any, any, any, any>, TKey, TIncludes> {
active?: boolean;
/** Indicates whether the resource should be loadable without modifying data, unlike the "active" field */
freeze?: boolean;
forceSuspense?: boolean;
silent?: boolean;
onData?: (data: ResourceData<TResource, TKey, TIncludes>, resource: TResource) => any;
Expand Down Expand Up @@ -184,6 +186,7 @@ export function useResource<
}
return propertiesRef.resource.get(propertiesRef.key);
}

return propertiesRef.resource.data;
}

Expand Down Expand Up @@ -290,6 +293,10 @@ export function useResource<
() => ({
preloaded,
get canLoad(): boolean {
if (actions?.freeze) {
return false;
}

return propertiesRef.key !== null && this.preloaded && this.outdated && !this.loading;
},
get resource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export class NavNodeManagerService extends Bootstrap {
await this.navTree.refreshTree(navNodeId);
}

async refreshNode(navNodeId: string): Promise<void> {
await this.navTree.refreshNode(navNodeId);
}

getTree(navNodeId: string): string[] | undefined;
getTree(navNodeKey: NavNodeKey): string[] | undefined;
getTree(navNodeKey: NavNodeKey[]): Array<string[] | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<
}

async refreshTree(navNodeId: string, silent = false): Promise<void> {
this.performUpdate(navNodeId, [], async () => {
await this.graphQLService.sdk.navRefreshNode({
nodePath: navNodeId,
});

if (!silent) {
this.markTreeOutdated(navNodeId);
}
await this.onNodeRefresh.execute(navNodeId);
});
}

async refreshNode(navNodeId: string, silent = false): Promise<void> {
this.performUpdate(navNodeId, [], async () => {
await this.graphQLService.sdk.navRefreshNode({
nodePath: navNodeId,
Expand Down Expand Up @@ -257,7 +270,7 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<
include,
});

this.refreshTree(nodePath);
this.refreshNode(nodePath);
}

async changeName(node: NavNode, name: string): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class ConnectionMenuBootstrap extends Bootstrap {
connection = await this.connectionInfoResource.changeConnectionView(createConnectionParam(connection), settings);

if (connection.nodePath) {
await this.navNodeManagerService.refreshTree(connection.nodePath);
await this.navNodeManagerService.refreshNode(connection.nodePath);
}
} catch (exception: any) {
this.notificationService.logException(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
const key = getRmResourcePath(result.projectId, result.folder ?? root);
await this.resourceManagerResource.create(createPath(key, result.name), true);

this.navTreeResource.refreshTree(getRmProjectNodeId(result.projectId));
this.navTreeResource.refreshNode(getRmProjectNodeId(result.projectId));
} catch (exception: any) {
this.notificationService.logException(exception, 'Error occurred while renaming');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export function useElementsTree(options: IOptions): IElementsTree {
},
async refresh(nodeId: string): Promise<void> {
try {
await navTreeResource.refreshTree(nodeId);
await navTreeResource.refreshNode(nodeId);
} catch (exception: any) {
notificationService.logException(exception, 'app_navigationTree_refresh_error');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
useResource,
useTranslate,
} from '@cloudbeaver/core-blocks';
import { DBObjectResource } from '@cloudbeaver/core-navigation-tree';
import { useService } from '@cloudbeaver/core-di';
import { DBObjectResource, NavNodeInfoResource } from '@cloudbeaver/core-navigation-tree';
import { resourceKeyList } from '@cloudbeaver/core-resource';
import type { ObjectPropertyInfo } from '@cloudbeaver/core-sdk';

interface Props {
Expand All @@ -28,7 +30,10 @@ const emptyArray: ObjectPropertyInfo[] = [];

export const ObjectProperties = observer<Props>(function ObjectProperties({ objectId }) {
const translate = useTranslate();
const dbObject = useResource(ObjectProperties, DBObjectResource, objectId);
const navNodeInfoResource = useService(NavNodeInfoResource);
const dbObject = useResource(ObjectProperties, DBObjectResource, objectId, {
freeze: navNodeInfoResource.isOutdated(resourceKeyList(navNodeInfoResource.getParents(objectId))),
});
const { categories, isUncategorizedExists } = useObjectPropertyCategories(dbObject.data?.object?.properties ?? emptyArray);
const properties = dbObject.data?.object?.properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { observer } from 'mobx-react-lite';
import { getComputed, s, SContext, type StyleRegistry, TextPlaceholder, useResource, useS, useTranslate } from '@cloudbeaver/core-blocks';
import { ConnectionInfoResource } from '@cloudbeaver/core-connections';
import { useService } from '@cloudbeaver/core-di';
import { NavNodeInfoResource } from '@cloudbeaver/core-navigation-tree';
import { NavNodeInfoResource, NavTreeResource } from '@cloudbeaver/core-navigation-tree';
import { resourceKeyList } from '@cloudbeaver/core-resource';
import { TabPanel, TabsBox, TabStyles, useTabLocalState } from '@cloudbeaver/core-ui';
import { MetadataMap } from '@cloudbeaver/core-utils';
import { ConnectionShieldLazy } from '@cloudbeaver/plugin-connections';
Expand All @@ -38,6 +39,7 @@ export const ObjectViewerPanel: TabHandlerPanelComponent<IObjectViewerTabState>
const translate = useTranslate();
const dbObjectPagesService = useService(DBObjectPageService);
const navNodeInfoResource = useService(NavNodeInfoResource);
const navTreeResource = useService(NavTreeResource);
const innerTabState = useTabLocalState(() => new MetadataMap<string, any>());
const style = useS(styles);

Expand All @@ -53,6 +55,7 @@ export const ObjectViewerPanel: TabHandlerPanelComponent<IObjectViewerTabState>
tab.handlerState.tabTitle = data.name;
});
},
freeze: navTreeResource.isOutdated(resourceKeyList(navNodeInfoResource.getParents(objectId))),
active: getComputed(() => !!connection.tryGetData?.connected && !connection.outdated),
});

Expand Down

0 comments on commit db9df1f

Please sign in to comment.