Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

ui(task): add code actions to file menu (#4509)

Seamus35970ffc1254
diff --git a/js/app/packages/app/component/ResponsiveBlockToolbar.tsx b/js/app/packages/app/component/ResponsiveBlockToolbar.tsx
index b44bc74d8f..c72388c455 100644
--- a/js/app/packages/app/component/ResponsiveBlockToolbar.tsx
+++ b/js/app/packages/app/component/ResponsiveBlockToolbar.tsx
@@ -18,11 +18,13 @@ import {
SplitTitleFileMenu,
} from './split-layout/components/SplitLabel';
import { SplitToolbarRight } from './split-layout/components/SplitToolbar';
+import type { SplitFileMenuAction } from './split-layout/context';
export type BlockTool = {
label: string | (() => string);
icon: Component;
action: () => void;
+ children?: SplitFileMenuAction[];
condition?: () => boolean;
isActive?: () => boolean;
buttonComponent?: () => JSX.Element;
diff --git a/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx b/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx
index d5f6b4c7cb..f5a4c7aad6 100644
--- a/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx
@@ -10,6 +10,8 @@ import { useIsDocumentOwner } from '@core/signal/permissions';
import { buildEntityData } from '@entity';
import DotsThree from '@icon/dots-three-large.svg';
import ArrowRight from '@phosphor/arrow-right.svg';
+import CaretDown from '@phosphor/caret-down.svg';
+import CaretRight from '@phosphor/caret-right.svg';
import Copy from '@phosphor/copy.svg';
import Rename from '@phosphor/pencil-line.svg';
import Trash from '@phosphor/trash-simple.svg';
@@ -43,7 +45,8 @@ export type DefaultFileOperation = {
export type CustomFileOperation = {
label: string;
icon: Component;
- action: () => void;
+ action?: () => void;
+ children?: SplitFileMenuAction[];
};
const isDefaultFileOperation = (
@@ -84,16 +87,37 @@ function DesktopRender(props: SplitFileMenuRenderProps) {
deleteOps: props.ops.filter((op) => op.group === 'delete'),
});
- const item = (action: SplitFileMenuAction) => (
- <Dropdown.Item
- onSelect={() => {
- action.action();
- props.onOpenChange(false);
- }}
- >
- <SplitMenuItemContent icon={action.icon} label={action.label} />
- </Dropdown.Item>
- );
+ const item = (action: SplitFileMenuAction) => {
+ const children = () => action.children?.filter(Boolean) ?? [];
+
+ return (
+ <Show
+ when={children().length > 0}
+ fallback={
+ <Dropdown.Item
+ onSelect={() => {
+ action.action?.();
+ props.onOpenChange(false);
+ }}
+ >
+ <SplitMenuItemContent icon={action.icon} label={action.label} />
+ </Dropdown.Item>
+ }
+ >
+ <Dropdown.Sub>
+ <Dropdown.SubTrigger>
+ <SplitMenuItemContent icon={action.icon} label={action.label} />
+ <CaretRight class="size-3.5 shrink-0" />
+ </Dropdown.SubTrigger>
+ <Dropdown.SubContent>
+ <Dropdown.Group>
+ <For each={children()}>{item}</For>
+ </Dropdown.Group>
+ </Dropdown.SubContent>
+ </Dropdown.Sub>
+ </Show>
+ );
+ };
return (
<Dropdown open={props.open} onOpenChange={props.onOpenChange}>
@@ -118,18 +142,58 @@ function DesktopRender(props: SplitFileMenuRenderProps) {
}
function MobileRender(props: SplitFileMenuRenderProps) {
- const item = (action: SplitFileMenuAction) => (
- <button
- type="button"
- class="w-full bg-surface flex items-center gap-3 px-4 py-3 text-sm hover:bg-hover hover-transition-bg text-left not-last:mb-px text-ink"
- onClick={(e) => {
- action.action(e);
- props.onOpenChange(false);
- }}
- >
- <SplitMenuItemContent icon={action.icon} label={action.label} />
- </button>
- );
+ const [expandedSubmenu, setExpandedSubmenu] =
+ createSignal<SplitFileMenuAction>();
+
+ const item = (action: SplitFileMenuAction, nested = false) => {
+ const children = () => action.children?.filter(Boolean) ?? [];
+ const expanded = () => expandedSubmenu() === action;
+
+ return (
+ <Show
+ when={children().length > 0}
+ fallback={
+ <button
+ type="button"
+ class={cn(
+ 'w-full bg-surface flex items-center gap-3 py-3 text-sm hover:bg-hover hover-transition-bg text-left not-last:mb-px text-ink',
+ nested ? 'pl-9 pr-4' : 'px-4'
+ )}
+ onClick={(e) => {
+ action.action?.(e);
+ props.onOpenChange(false);
+ }}
+ >
+ <SplitMenuItemContent icon={action.icon} label={action.label} />
+ </button>
+ }
+ >
+ <div class="w-full bg-surface">
+ <button
+ type="button"
+ class={cn(
+ 'w-full flex items-center gap-3 py-3 text-sm hover:bg-hover hover-transition-bg text-left text-ink',
+ nested ? 'pl-9 pr-4' : 'px-4'
+ )}
+ onClick={() => {
+ setExpandedSubmenu(expanded() ? undefined : action);
+ }}
+ >
+ <SplitMenuItemContent icon={action.icon} label={action.label} />
+ <Dynamic
+ component={expanded() ? CaretDown : CaretRight}
+ class="size-3.5 shrink-0"
+ />
+ </button>
+ <Show when={expanded()}>
+ <div class="border-t border-edge-muted/60">
+ <For each={children()}>{(child) => item(child, true)}</For>
+ </div>
+ </Show>
+ </div>
+ </Show>
+ );
+ };
return (
<MobileDrawer
@@ -145,7 +209,7 @@ function MobileRender(props: SplitFileMenuRenderProps) {
<MobileDrawer.Handle />
<Show when={props.tools.length > 0}>
<MobileDrawer.Section class="flex flex-col shrink-0">
- <For each={props.tools}>{item}</For>
+ <For each={props.tools}>{(action) => item(action)}</For>
</MobileDrawer.Section>
</Show>
<Show when={props.ops.length > 0}>
@@ -153,7 +217,7 @@ function MobileRender(props: SplitFileMenuRenderProps) {
<div class="mt-3" />
</Show>
<MobileDrawer.Section class="flex flex-col shrink-0">
- <For each={props.ops}>{item}</For>
+ <For each={props.ops}>{(action) => item(action)}</For>
</MobileDrawer.Section>
</Show>
</MobileDrawer.Content>
@@ -302,6 +366,7 @@ export function SplitFileMenu(props: {
filteredTools().map((tool) => ({
label: typeof tool.label === 'function' ? tool.label() : tool.label,
icon: tool.icon,
+ children: tool.children,
action: (e?: MouseEvent) => {
tool.action();
if (tool.focusTarget) {
diff --git a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx b/js/app/packages/app/component/split-layout/components/SplitLabel.tsx
index a9b6b08096..f5ab24b056 100644
--- a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitLabel.tsx
@@ -3,6 +3,7 @@ import {
ContextMenuContent,
MenuItem,
MenuSeparator,
+ SubTrigger,
} from '@core/component/ContextMenu';
import {
EntityIcon,
@@ -253,13 +254,32 @@ function SplitLabelContextMenu(props: ParentProps) {
});
const hasActions = createMemo(() => sections().length > 0);
- const item = (action: SplitFileMenuAction) => (
- <MenuItem
- icon={action.icon as Component<JSX.SvgSVGAttributes<SVGSVGElement>>}
- text={action.label}
- onClick={() => action.action()}
- />
- );
+ const item = (action: SplitFileMenuAction) => {
+ const children = () => action.children?.filter(Boolean) ?? [];
+
+ return (
+ <Show
+ when={children().length > 0}
+ fallback={
+ <MenuItem
+ icon={action.icon as Component<JSX.SvgSVGAttributes<SVGSVGElement>>}
+ text={action.label}
+ onClick={() => action.action?.()}
+ />
+ }
+ >
+ <ContextMenu.Sub>
+ <SubTrigger
+ icon={action.icon as Component<JSX.SvgSVGAttributes<SVGSVGElement>>}
+ text={action.label}
+ />
+ <ContextMenuContent submenu width="w-fit">
+ <For each={children()}>{item}</For>
+ </ContextMenuContent>
+ </ContextMenu.Sub>
+ </Show>
+ );
+ };
const openOnDoubleClick = (e: MouseEvent) => {
if (!hasActions()) return;
diff --git a/js/app/packages/app/component/split-layout/context.ts b/js/app/packages/app/component/split-layout/context.ts
index 2e8e2fde8b..3fd8de0e41 100644
--- a/js/app/packages/app/component/split-layout/context.ts
+++ b/js/app/packages/app/component/split-layout/context.ts
@@ -49,7 +49,8 @@ export type SplitBottomPanelRegistration = {
export type SplitFileMenuAction = {
label: string | JSX.Element;
icon: Component;
- action: (e?: MouseEvent) => void;
+ action?: (e?: MouseEvent) => void;
+ children?: SplitFileMenuAction[];
group?: 'delete';
};
diff --git a/js/app/packages/block-md/component/DispatchAgentMenu.tsx b/js/app/packages/block-md/component/DispatchAgentMenu.tsx
index 5f25cfc09d..5ce199b304 100644
--- a/js/app/packages/block-md/component/DispatchAgentMenu.tsx
+++ b/js/app/packages/block-md/component/DispatchAgentMenu.tsx
@@ -1,4 +1,5 @@
import { openMacroMcpSetupModal } from '@app/component/macro-mcp-setup-modal/MacroMcpSetupModal';
+import type { SplitFileMenuAction } from '@app/component/split-layout/context';
import { useBlockId } from '@core/block';
import { editorStateAsMarkdown } from '@core/component/LexicalMarkdown/utils';
import { toast } from '@core/component/Toast/Toast';
@@ -198,6 +199,32 @@ export function useDispatchAgentAction() {
};
}
+export function useDispatchAgentSplitFileActions(): SplitFileMenuAction[] {
+ const { executeAction } = useDispatchAgentAction();
+
+ return [
+ {
+ label: COPY_ACTION.name,
+ icon: COPY_ACTION.icon,
+ action: () => {
+ void executeAction(COPY_ACTION);
+ },
+ },
+ ...PLATFORM_ACTIONS.map((action) => ({
+ label: action.name,
+ icon: action.icon,
+ action: () => {
+ void executeAction(action);
+ },
+ })),
+ {
+ label: 'MCP setup instructions',
+ icon: PlugIcon,
+ action: openMacroMcpSetupModal,
+ },
+ ];
+}
+
export function DispatchAgentButton(
props: { showPrimaryLabel?: boolean } = {}
) {
diff --git a/js/app/packages/block-md/component/TopBar.tsx b/js/app/packages/block-md/component/TopBar.tsx
index 4009857256..e2d4b7386b 100644
--- a/js/app/packages/block-md/component/TopBar.tsx
+++ b/js/app/packages/block-md/component/TopBar.tsx
@@ -56,7 +56,10 @@ import {
onCleanup,
Show,
} from 'solid-js';
-import { DispatchAgentButton } from './DispatchAgentMenu';
+import {
+ DispatchAgentButton,
+ useDispatchAgentSplitFileActions,
+} from './DispatchAgentMenu';
import { HISTORY_DRAWER_ID } from './History';
export function TopBar(props: { name?: Accessor<string | undefined> } = {}) {
@@ -76,6 +79,7 @@ export function TopBar(props: { name?: Accessor<string | undefined> } = {}) {
const shareCtx = useShareDialogContext();
const blockAliasedName = useBlockAliasedName();
const isTask = blockAliasedName === 'task';
+ const dispatchAgentActions = useDispatchAgentSplitFileActions();
const copyLink = () => {
const url = buildSimpleEntityUrl({ id: blockId, type: blockAliasedName });
@@ -237,6 +241,16 @@ export function TopBar(props: { name?: Accessor<string | undefined> } = {}) {
fileType: 'md',
}),
},
+ ...(isTask
+ ? ([
+ {
+ label: 'Code Actions',
+ icon: TerminalWindowIcon,
+ action: () => {},
+ children: dispatchAgentActions,
+ },
+ ] satisfies BlockTool[])
+ : []),
];
return (