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.

feat(tasks): copy branch name to clipboard for tasks (#1803)

Seamus9639a9b38249
diff --git a/js/app/packages/app/component/ResponsiveBlockToolbar.tsx b/js/app/packages/app/component/ResponsiveBlockToolbar.tsx
index 363e42625d..caac255ca6 100644
--- a/js/app/packages/app/component/ResponsiveBlockToolbar.tsx
+++ b/js/app/packages/app/component/ResponsiveBlockToolbar.tsx
@@ -17,6 +17,8 @@ import {
import { Button } from '@ui/components/Button';
import { Dynamic } from 'solid-js/web';
import { SplitPermissionsBadge } from './split-layout/components/SplitLabel';
+import { LabelAndHotKey } from '@core/component/Tooltip';
+import type { HotkeyToken } from '@core/hotkey/tokens';
export type BlockTool = {
label: string | (() => string);
@@ -26,16 +28,27 @@ export type BlockTool = {
isActive?: () => boolean;
buttonComponent?: () => JSX.Element;
divideAbove?: boolean;
+ hotkeyToken?: HotkeyToken;
};
export function ToolButton(props: { tool: BlockTool }) {
+ const label = () =>
+ typeof props.tool.label === 'function'
+ ? props.tool.label()
+ : props.tool.label;
+
return (
<Button
onClick={props.tool.action}
tooltip={
- typeof props.tool.label === 'function'
- ? props.tool.label()
- : props.tool.label
+ props.tool.hotkeyToken ? (
+ <LabelAndHotKey
+ label={label()}
+ hotkeyToken={props.tool.hotkeyToken}
+ />
+ ) : (
+ label()
+ )
}
class={cn(
'px-1',
diff --git a/js/app/packages/app/component/next-soup/actions/index.ts b/js/app/packages/app/component/next-soup/actions/index.ts
index 7c59ecdf81..1cec9259e8 100644
--- a/js/app/packages/app/component/next-soup/actions/index.ts
+++ b/js/app/packages/app/component/next-soup/actions/index.ts
@@ -4,6 +4,7 @@ export { makeRenameAction } from './make-rename-action';
export { makeCopyAction } from './make-copy-action';
export { makeMoveToProjectAction } from './make-move-to-project-action';
export { makeCopyLinkAction } from './make-copy-link-action';
+export { makeCopyBranchNameAction } from './make-copy-branch-name-action';
export { makeShareAction } from './make-share-action';
export { useEntityActionHotkeys } from './use-entity-action-hotkeys';
diff --git a/js/app/packages/app/component/next-soup/actions/make-copy-branch-name-action.ts b/js/app/packages/app/component/next-soup/actions/make-copy-branch-name-action.ts
new file mode 100644
index 0000000000..fa8dfb1a8f
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/actions/make-copy-branch-name-action.ts
@@ -0,0 +1,21 @@
+import { copyBranchNameToClipboard } from '@core/util/branchName';
+import { isTaskEntity, type EntityData } from '@entity';
+import type { SoupState } from '../create-soup-state';
+
+export const makeCopyBranchNameAction = () => {
+ const canExecute = (entity: EntityData): boolean => {
+ return isTaskEntity(entity);
+ };
+
+ const execute = async (entities: EntityData[]) => {
+ const entity = entities[0];
+ if (!entity || !isTaskEntity(entity)) return;
+ await copyBranchNameToClipboard(entity.id, entity.name);
+ };
+
+ const executeWithSoup = async (entities: EntityData[], _soup: SoupState) => {
+ await execute(entities);
+ };
+
+ return { canExecute, execute, executeWithSoup };
+};
diff --git a/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts b/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
index 490c30890e..2bfdd2ec67 100644
--- a/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
+++ b/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
@@ -5,6 +5,7 @@ import type { EntityData } from '@entity';
import type { SoupState } from '../create-soup-state';
import {
makeCopyAction,
+ makeCopyBranchNameAction,
makeCopyLinkAction,
makeDeleteAction,
makeMarkDoneAction,
@@ -53,6 +54,8 @@ export const useEntityActionHotkeys = (
const copyLinkAction = makeCopyLinkAction();
+ const copyBranchNameAction = makeCopyBranchNameAction();
+
const shareAction = makeShareAction();
const getEntitiesForAction = (): EntityData[] => {
@@ -226,6 +229,30 @@ export const useEntityActionHotkeys = (
tags: [HotkeyTags.SelectionModification],
}).withGroup(group);
+ // Copy branch name - 'shift+cmd+b'
+ registerHotkey({
+ hotkey: ['shift+cmd+b'],
+ hotkeyToken: TOKENS.entity.action.copyBranchName,
+ scopeId,
+ description: 'Copy branch name',
+ keyDownHandler: () => {
+ const entities = getEntitiesForAction();
+ if (entities.length === 0) return false;
+ if (!copyBranchNameAction.canExecute(entities[0])) return false;
+ copyBranchNameAction.executeWithSoup(entities, soup);
+ return true;
+ },
+ condition: () => {
+ if (condition && !condition()) return false;
+ const entities = getEntitiesForAction();
+ return (
+ entities.length === 1 && copyBranchNameAction.canExecute(entities[0])
+ );
+ },
+ displayPriority: 10,
+ tags: [HotkeyTags.SelectionModification],
+ }).withGroup(group);
+
// Share
registerHotkey({
hotkeyToken: TOKENS.entity.action.share,
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx
index 5fbd85612a..e707cc9870 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx
@@ -5,6 +5,7 @@ import { fileTypeToBlockName } from '@core/constant/allBlocks';
import type { EntityData } from '@entity';
import {
makeCopyAction,
+ makeCopyBranchNameAction,
makeCopyLinkAction,
makeDeleteAction,
makeMarkDoneAction,
@@ -44,6 +45,8 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
const copyLinkAction = makeCopyLinkAction();
+ const copyBranchNameAction = makeCopyBranchNameAction();
+
const shareAction = makeShareAction();
const canExecuteAny = (canExecute: (e: EntityData) => boolean) =>
@@ -134,6 +137,15 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
onClick={() => handleAction(copyLinkAction.executeWithSoup)}
/>
+ <MenuItem
+ text="Copy Branch Name"
+ disabled={
+ props.entities.length !== 1 ||
+ !copyBranchNameAction.canExecute(props.entities[0])
+ }
+ onClick={() => handleAction(copyBranchNameAction.executeWithSoup)}
+ />
+
<MenuItem
text="Share"
disabled={
diff --git a/js/app/packages/block-md/component/TopBar.tsx b/js/app/packages/block-md/component/TopBar.tsx
index 5cca17f505..1c94b0e337 100644
--- a/js/app/packages/block-md/component/TopBar.tsx
+++ b/js/app/packages/block-md/component/TopBar.tsx
@@ -45,6 +45,7 @@ import { buildSimpleEntityUrl } from '@core/util/url';
import ShowComments from '@icon/regular/chat-circle-dots.svg';
import HideComments from '@icon/regular/chat-circle-slash.svg';
import Download from '@icon/regular/download.svg';
+import GitBranch from '@icon/regular/git-branch.svg';
import Bell from '@icon/regular/bell.svg';
import Quotes from '@icon/regular/quotes.svg';
import IconShared from '@icon/regular/share.svg';
@@ -52,7 +53,11 @@ import IconLink from '@icon/regular/link.svg';
import ClockIcon from '@icon/regular/clock-counter-clockwise.svg';
import TagIcon from '@icon/regular/tag.svg';
import { blockNameToItemType } from '@service-storage/client';
-import { For, Show, type JSX } from 'solid-js';
+import { copyBranchNameToClipboard } from '@core/util/branchName';
+import { TOKENS } from '@core/hotkey/tokens';
+import { registerHotkey } from '@core/hotkey/hotkeys';
+import { blockHotkeyScopeSignal } from '@core/signal/blockElement';
+import { createEffect, For, on, Show, type JSX } from 'solid-js';
import { HISTORY_DRAWER_ID } from './History';
import { DRAWER_ID as PROPERTIES_DRAWER_ID } from './MarkdownPropertiesModal';
@@ -60,6 +65,7 @@ export function TopBar() {
const canEdit = useCanEdit();
const blockName = useBlockName();
const blockId = useBlockId();
+ const scopeId = blockHotkeyScopeSignal.get;
const name = useBlockDocumentName();
const notificationSource = useGlobalNotificationSource();
const itemType = blockNameToItemType(blockName);
@@ -74,6 +80,7 @@ export function TopBar() {
const propertiesControl = useDrawerControl(PROPERTIES_DRAWER_ID);
const shareCtx = useShareDialogContext();
const blockAliasedName = useBlockAliasedName();
+ const isTask = blockAliasedName === 'task';
const copyLink = () => {
const url = buildSimpleEntityUrl(
@@ -87,10 +94,42 @@ export function TopBar() {
);
};
+ const copyBranchName = () => copyBranchNameToClipboard(blockId, name());
+
+ if (isTask) {
+ let cleanupKbShortcut = () => {};
+
+ createEffect(
+ on(scopeId, (id) => {
+ cleanupKbShortcut();
+ registerHotkey({
+ hotkey: 'shift+cmd+b',
+ scopeId: id,
+ hotkeyToken: TOKENS.entity.action.copyBranchName,
+ description: 'Copy branch name',
+ keyDownHandler: () => {
+ copyBranchName();
+ return true;
+ },
+ runWithInputFocused: true,
+ });
+ })
+ );
+ }
+
const ops: FileOperation[] = [
{ op: 'copy' },
{ op: 'rename' },
{ op: 'moveToProject' },
+ ...(isTask
+ ? ([
+ {
+ label: 'Copy Branch Name',
+ icon: GitBranch,
+ action: copyBranchName,
+ },
+ ] satisfies FileOperation[])
+ : []),
{
label: 'Download',
icon: Download,
@@ -148,6 +187,13 @@ export function TopBar() {
),
action: () => setShowCommentsPreference(!showCommentsPreference()),
},
+ {
+ label: 'Copy Branch Name',
+ icon: GitBranch,
+ action: copyBranchName,
+ condition: () => isTask,
+ hotkeyToken: TOKENS.entity.action.copyBranchName,
+ },
{
label: 'Properties',
icon: TagIcon,
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index 40cf20fff8..e174556998 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -20,6 +20,7 @@ import {
type PreviewItemNoAccess,
} from '@queries/preview';
import { blockNameToItemType } from '@service-storage/client';
+import { copyBranchNameToClipboard } from '@core/util/branchName';
import { tryMacroId, useDisplayName } from '@core/user';
import { matches } from '@core/util/match';
// Icon imports
@@ -29,6 +30,7 @@ import ExpandInlinePreview from '@icon/regular/arrows-out-line-horizontal.svg';
import MessageIcon from '@icon/regular/chat-circle.svg';
import ThreadIcon from '@icon/regular/chats-circle.svg';
import Clipboard from '@icon/regular/clipboard.svg';
+import GitBranchIcon from '@icon/regular/git-branch.svg';
import ClockIcon from '@icon/regular/clock.svg';
import ColumnsPlusRight from '@icon/regular/columns-plus-right.svg';
import HighlightIcon from '@icon/regular/highlighter-circle.svg';
@@ -376,6 +378,15 @@ export function PopupPreview(props: {
}
};
+ const handleCopyBranchName = () => {
+ const previewItem = item();
+ const docName =
+ props.documentInfo.name ||
+ ('name' in previewItem ? (previewItem.name as string) : '') ||
+ '';
+ copyBranchNameToClipboard(props.documentInfo.id, docName);
+ };
+
const openInNewSplit = createCallback(() => {
const splitManager = globalSplitManager();
if (splitManager) {
@@ -457,6 +468,16 @@ export function PopupPreview(props: {
/>
);
+ if (props.documentInfo.type === 'task') {
+ buttons.push(
+ <PopupIconButton
+ tooltip="Copy Branch Name"
+ onClick={handleCopyBranchName}
+ icon={GitBranchIcon}
+ />
+ );
+ }
+
if (props.documentInfo.isOpenable) {
buttons.push(
<PopupIconButton
diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.ts
index 8295963a2f..51aa69f3b8 100644
--- a/js/app/packages/core/hotkey/tokens.ts
+++ b/js/app/packages/core/hotkey/tokens.ts
@@ -48,6 +48,7 @@ export const TOKENS = {
copy: 'entity.action.copy',
copyLink: 'entity.action.copyLink',
share: 'entity.action.share',
+ copyBranchName: 'entity.action.copyBranchName',
properties: 'entity.action.properties',
priority: 'entity.action.priority',
status: 'entity.action.status',
diff --git a/js/app/packages/core/util/branchName.ts b/js/app/packages/core/util/branchName.ts
new file mode 100644
index 0000000000..5f6104e7ef
--- /dev/null
+++ b/js/app/packages/core/util/branchName.ts
@@ -0,0 +1,32 @@
+import { toast } from '@core/component/Toast/Toast';
+import { isOk } from '@core/util/maybeResult';
+import { storageServiceClient } from '@service-storage/client';
+
+const MAX_BRANCH_LENGTH = 200;
+
+const slugify = (title: string): string =>
+ title
+ .toLowerCase()
+ .replace(/[^a-z0-9\s-]/g, '')
+ .replace(/\s+/g, '-')
+ .replace(/-+/g, '-')
+ .replace(/^-|-$/g, '');
+
+export const copyBranchNameToClipboard = async (
+ documentId: string,
+ documentName: string
+) => {
+ const result = await storageServiceClient.getDocumentShortId({ documentId });
+ if (!isOk(result)) {
+ toast.failure('Failed to copy branch name');
+ return;
+ }
+ const shortId = result[1];
+ const slug = slugify(documentName);
+ const branchName = `macro-${shortId}${slug ? `-${slug}` : ''}`.slice(
+ 0,
+ MAX_BRANCH_LENGTH
+ );
+ await navigator.clipboard.writeText(branchName);
+ toast.success('Branch name copied to clipboard');
+};
diff --git a/js/app/packages/service-clients/service-storage/client.ts b/js/app/packages/service-clients/service-storage/client.ts
index 05e279f98c..c6c905fb73 100644
--- a/js/app/packages/service-clients/service-storage/client.ts
+++ b/js/app/packages/service-clients/service-storage/client.ts
@@ -535,6 +535,19 @@ export const storageServiceClient = {
);
},
+ async getDocumentShortId({
+ documentId,
+ }: {
+ documentId: string;
+ }): Promise<MaybeResult<FetchWithTokenErrorCode, string>> {
+ return mapOk(
+ await dssFetch<{ shortId: string }>(`/documents/${documentId}/short_id`, {
+ method: 'GET',
+ }),
+ (result) => result.shortId
+ );
+ },
+
async exportDocument({ documentId }) {
return mapOk(
await dssFetch<ExportDocumentResponse>(