Files
cloudbeaver/webapp/packages/plugin-navigation-tree/src/NodesManager/useNode.ts
T
Alexey 2b25b3ac8e Chore/prettier (#1706)
* chore: add prettier

* chore: format code
2023-05-28 02:42:14 +03:00

47 lines
1.2 KiB
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 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 { useObjectRef } from '@cloudbeaver/core-blocks';
import { useService } from '@cloudbeaver/core-di';
import { type NavNode, NavNodeInfoResource } from '@cloudbeaver/core-navigation-tree';
interface IUseNodeHook {
navNodeId: string;
node: NavNode | undefined;
isLoading: () => boolean;
isLoaded: () => boolean;
isOutdated: () => boolean;
}
const bindActions: Array<keyof IUseNodeHook> = ['isLoading', 'isLoaded', 'isOutdated'];
export function useNode(navNodeId: string): IUseNodeHook {
const navNodeInfoResource = useService(NavNodeInfoResource);
const node = navNodeInfoResource.get(navNodeId);
return useObjectRef<IUseNodeHook>(
() => ({
navNodeId,
node,
isLoading() {
return navNodeInfoResource.isLoading(this.navNodeId);
},
isLoaded() {
return navNodeInfoResource.isLoaded(this.navNodeId);
},
isOutdated() {
return navNodeInfoResource.isOutdated(this.navNodeId);
},
}),
{
navNodeId,
node,
},
bindActions,
);
}