/* * 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 { observer } from 'mobx-react-lite'; import React, { useState } from 'react'; import styled from 'reshadow'; import { ACTION_ICON_BUTTON_STYLES, IconButton, IconButtonStyles, PlaceholderElement, s, SContext, StyleRegistry, useS, useStyles, useTranslate, } from '@cloudbeaver/core-blocks'; import type { ComponentStyle } from '@cloudbeaver/core-theming'; import { useCaptureViewContext } from '@cloudbeaver/core-view'; import { DATA_CONTEXT_ELEMENTS_TREE } from '../DATA_CONTEXT_ELEMENTS_TREE'; import type { IElementsTree } from '../useElementsTree'; import { ElementsTreeFilter } from './ElementsTreeFilter'; import ElementsTreeToolsStyles from './ElementsTreeTools.m.css'; import ElementsTreeToolsIconButtonStyles from './ElementsTreeToolsIconButton.m.css'; import { ElementsTreeToolsMenu } from './ElementsTreeToolsMenu'; import { DATA_CONTEXT_NAV_TREE_ROOT } from './NavigationTreeSettings/DATA_CONTEXT_NAV_TREE_ROOT'; import type { IElementsTreeSettingsProps } from './NavigationTreeSettings/ElementsTreeSettingsService'; import { NavigationTreeSettings } from './NavigationTreeSettings/NavigationTreeSettings'; const registry: StyleRegistry = [ [ IconButtonStyles, { mode: 'append', styles: [ElementsTreeToolsIconButtonStyles], }, ], ]; interface Props { tree: IElementsTree; settingsElements?: PlaceholderElement[]; style?: ComponentStyle; } export const ElementsTreeTools = observer>(function ElementsTreeTools({ tree, settingsElements, style, children }) { const root = tree.root; const translate = useTranslate(); const [opened, setOpen] = useState(false); const deprecatedStyles = useStyles(ACTION_ICON_BUTTON_STYLES, style); const styles = useS(ElementsTreeToolsStyles, ElementsTreeToolsIconButtonStyles); useCaptureViewContext(context => { context?.set(DATA_CONTEXT_NAV_TREE_ROOT, tree.baseRoot); context?.set(DATA_CONTEXT_ELEMENTS_TREE, tree); }); const loading = tree.isLoading(); return styled(deprecatedStyles)( {tree.settings?.configurable && ( setOpen(!opened)} /> )}
tree.refresh(root)} /> {tree.settings && opened && } {children} , ); });