mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(core): add usePermission hook
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
import { observer } from 'mobx-react';
|
||||
import styled, { css } from 'reshadow';
|
||||
|
||||
import { usePermission } from '@dbeaver/core/root';
|
||||
|
||||
import { PUBLIC_PERMISSION } from '../shared/NodesManager/NodesManagerService';
|
||||
import { useChildren } from '../shared/useChildren';
|
||||
import { NavigationTreeNode } from './NavigationTreeNode/NavigationTreeNode';
|
||||
|
||||
@@ -38,6 +41,11 @@ const navigationTreeStyles = css`
|
||||
|
||||
export const NavigationTree = observer(function NavigationTree() {
|
||||
const nodeChildren = useChildren();
|
||||
const isEnabled = usePermission(PUBLIC_PERMISSION);
|
||||
|
||||
if (!isEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!nodeChildren || nodeChildren.children.length === 0) {
|
||||
return styled(navigationTreeStyles)(
|
||||
|
||||
@@ -3,3 +3,4 @@ export * from './ServerService';
|
||||
export * from './PermissionsService';
|
||||
export * from './ServerSettingsService';
|
||||
export * from './SessionSettingsService';
|
||||
export * from './usePermission';
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { useService } from '@dbeaver/core/di';
|
||||
|
||||
import { PermissionsService } from './PermissionsService';
|
||||
|
||||
export function usePermission(key: string) {
|
||||
const permissionsService = useService(PermissionsService);
|
||||
|
||||
return permissionsService.has(key);
|
||||
}
|
||||
Reference in New Issue
Block a user