fix(core-app): CB-1675 pass tree context

This commit is contained in:
Naumov Alexey
2022-06-22 13:13:19 +02:00
parent 46e07a4693
commit fa330ce545
3 changed files with 14 additions and 3 deletions
@@ -81,7 +81,7 @@ export const ElementsTreeTools = observer<React.PropsWithChildren<Props>>(functi
<tools>
<actions>
<fill />
<ElementsTreeToolsMenu />
<ElementsTreeToolsMenu tree={tree} />
{tree.settings?.configurable && (
<IconButton
name='/icons/settings_cog_sm.svg'
@@ -12,6 +12,8 @@ import styled, { css } from 'reshadow';
import { MenuBar } from '@cloudbeaver/core-ui';
import { useMenu } from '@cloudbeaver/core-view';
import { DATA_CONTEXT_ELEMENTS_TREE } from '../DATA_CONTEXT_ELEMENTS_TREE';
import type { IElementsTree } from '../useElementsTree';
import { MENU_ELEMENTS_TREE_TOOLS } from './MENU_ELEMENTS_TREE_TOOLS';
const MENU_STYLES = css`
@@ -74,12 +76,15 @@ const style = css`
`;
interface Props {
tree: IElementsTree;
className?: string;
}
export const ElementsTreeToolsMenu = observer<Props>(function ElementsTreeToolsMenu({ className }) {
export const ElementsTreeToolsMenu = observer<Props>(function ElementsTreeToolsMenu({ tree, className }) {
const menu = useMenu({ menu: MENU_ELEMENTS_TREE_TOOLS });
menu.context.set(DATA_CONTEXT_ELEMENTS_TREE, tree);
return styled(style)(
<menu-wrapper className={className}>
<MenuBar menu={menu} style={[MENU_STYLES]} />
@@ -31,12 +31,18 @@ export class ElementsTreeToolsMenuService {
private readonly connectionSchemaManagerService: ConnectionSchemaManagerService,
private readonly menuService: MenuService,
private readonly localizationService: LocalizationService,
) {}
) { }
register() {
this.actionService.addHandler({
id: 'tree-tools-menu-base-handler',
isActionApplicable(context, action) {
const tree = context.tryGet(DATA_CONTEXT_ELEMENTS_TREE);
if (!tree) {
return false;
}
return [ACTION_LINK_OBJECT, ACTION_COLLAPSE_ALL].includes(action);
},
getActionInfo: (context, action) => {