Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(list): share and copy-link from list (#1633)
Seamus93ac09ff9897
diff --git a/js/app/packages/app/component/Layout.tsx b/js/app/packages/app/component/Layout.tsxindex e23e1c9d8d..6050978089 100644--- a/js/app/packages/app/component/Layout.tsx+++ b/js/app/packages/app/component/Layout.tsx@@ -15,6 +15,7 @@ import { attachGlobalDOMScope } from 'core/hotkey/hotkeys';import { createEffect, onMount, Show, Suspense } from 'solid-js';import Banner from './banner/Banner';import { GlobalBulkEditEntityModal } from './bulk-edit-entity/BulkEditEntityModal';+import { GlobalShareModal } from './global-share-modal/GlobalShareModal';import { CommandMenu } from './command';import GlobalShortcuts from './GlobalHotkeys';import { ItemDndProvider } from './ItemDragAndDrop';@@ -108,6 +109,7 @@ export function Layout(props: RouteSectionProps) {<PropertyEditorModal /></Suspense><GlobalBulkEditEntityModal />+ <GlobalShareModal /><ShortcutsHelper /></Show><Showdiff --git a/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsx b/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsxnew file mode 100644index 0000000000..4ea3303acd--- /dev/null+++ b/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsx@@ -0,0 +1,84 @@+import { createControlledOpenSignal } from '@core/util/createControlledOpenSignal';+import { ShareModal } from '@core/component/TopBar/ShareButton';+import { Permissions } from '@core/component/SharePermissions';+import { itemToBlockName } from '@core/constant/allBlocks';+import type { BlockAlias, BlockName } from '@core/block';+import type { ItemType } from '@service-storage/client';+import type { EntityData } from '@entity';+import { createSignal, Show } from 'solid-js';++type ShareableEntityType = 'document' | 'chat' | 'project';++export type GlobalShareModalProps = {+ entity: EntityData;+ onClose?: () => void;+};++const [globalModalProps, setGlobalModalProps] =+ createSignal<GlobalShareModalProps | null>(null);+const [modalOpen, setModalOpen] = createControlledOpenSignal();++export const isShareableEntityType = (+ type: EntityData['type']+): type is ShareableEntityType => {+ return type === 'document' || type === 'chat' || type === 'project';+};++const getEntityBlockAlias = (entity: EntityData): BlockName | BlockAlias => {+ return itemToBlockName(entity) ?? 'unknown';+};++const getEntityItemType = (entity: EntityData): ItemType => {+ return entity.type as ItemType;+};++export const openGlobalShareModal = (props: GlobalShareModalProps) => {+ if (!isShareableEntityType(props.entity.type)) {+ console.warn(+ `Cannot share entity of type ${props.entity.type} - not supported`+ );+ return;+ }+ setGlobalModalProps(props);+ setModalOpen(true);+};++export const closeGlobalShareModal = () => {+ const props = globalModalProps();+ setModalOpen(false);+ setGlobalModalProps(null);+ props?.onClose?.();+};++/**+ * Global share modal component - should be mounted once at the app level+ */+export const GlobalShareModal = () => {+ const handleSetIsOpen = (isOpen: boolean) => {+ if (!isOpen) {+ closeGlobalShareModal();+ }+ setModalOpen(isOpen);+ };++ return (+ <Show when={globalModalProps()}>+ {(propsAccessor) => {+ const entity = () => propsAccessor().entity;++ return (+ <ShareModal+ isSharePermOpen={modalOpen()}+ setIsSharePermOpen={handleSetIsOpen}+ id={entity().id}+ blockAlias={getEntityBlockAlias(entity())}+ itemType={getEntityItemType(entity())}+ name={entity().name}+ userPermissions={Permissions.OWNER}+ owner={entity().ownerId}+ />+ );+ }}+ </Show>+ );+};diff --git a/js/app/packages/app/component/next-soup/actions/index.ts b/js/app/packages/app/component/next-soup/actions/index.tsindex a34aaa43f1..7c59ecdf81 100644--- a/js/app/packages/app/component/next-soup/actions/index.ts+++ b/js/app/packages/app/component/next-soup/actions/index.ts@@ -3,5 +3,7 @@ export { makeDeleteAction } from './make-delete-action';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 { 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-link-action.ts b/js/app/packages/app/component/next-soup/actions/make-copy-link-action.tsnew file mode 100644index 0000000000..2b63b5e10d--- /dev/null+++ b/js/app/packages/app/component/next-soup/actions/make-copy-link-action.ts@@ -0,0 +1,47 @@+import { toast } from '@core/component/Toast/Toast';+import { fileTypeToBlockName } from '@core/constant/allBlocks';+import { buildSimpleEntityUrl } from '@core/util/url';+import type { EntityData } from '@entity';+import type { SoupState } from '../create-soup-state';++/**+ * Get the URL type/path segment for an entity+ */+const getEntityUrlType = (entity: EntityData): string => {+ if (entity.type === 'document') {+ const { fileType, subType } = entity;+ return fileTypeToBlockName(subType?.type ?? fileType);+ }+ return entity.type;+};++export const makeCopyLinkAction = () => {+ const canExecute = (_entity: EntityData): boolean => {+ // Can copy link for any entity type+ return true;+ };++ const execute = async (entities: EntityData[]) => {+ // Only copy link for the first entity (doesn't make sense for bulk)+ const entity = entities[0];+ if (!entity) return;++ const url = buildSimpleEntityUrl(+ {+ type: getEntityUrlType(entity),+ id: entity.id,+ },+ {}+ );++ await navigator.clipboard.writeText(url);+ toast.success('Link copied to clipboard');+ };++ const executeWithSoup = async (entities: EntityData[], _soup: SoupState) => {+ await execute(entities);+ // Don't clear selection or change focus for copy link+ };++ return { canExecute, execute, executeWithSoup };+};diff --git a/js/app/packages/app/component/next-soup/actions/make-share-action.ts b/js/app/packages/app/component/next-soup/actions/make-share-action.tsnew file mode 100644index 0000000000..2ffc96efae--- /dev/null+++ b/js/app/packages/app/component/next-soup/actions/make-share-action.ts@@ -0,0 +1,36 @@+import type { EntityData } from '@entity';+import type { SoupState } from '../create-soup-state';+import {+ isShareableEntityType,+ openGlobalShareModal,+} from '@app/component/global-share-modal/GlobalShareModal';++export const makeShareAction = () => {+ /**+ * Check if the share action can be executed+ * Only requires shareable type - the modal handles permissions+ */+ const canExecute = (entity: EntityData): boolean => {+ return isShareableEntityType(entity.type);+ };++ const execute = async (entity: EntityData) => {+ if (!isShareableEntityType(entity.type)) {+ return;+ }++ openGlobalShareModal({+ entity,+ });+ };++ const executeWithSoup = async (entities: EntityData[], _soup: SoupState) => {+ const entity = entities[0];+ if (!entity) return;++ await execute(entity);+ // Don't clear selection or change focus for share+ };++ 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.tsindex cd825c569e..bf94997daa 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,11 +5,14 @@ import type { EntityData } from '@entity';import type { SoupState } from '../create-soup-state';import {makeCopyAction,+ makeCopyLinkAction,makeDeleteAction,makeMarkDoneAction,makeMoveToProjectAction,makeRenameAction,+ makeShareAction,} from './index';+import { isShareableEntityType } from '@app/component/global-share-modal/GlobalShareModal';import { useUserId } from '@core/context/user';import { registerHotkey } from '@core/hotkey/hotkeys';import type { SplitHandle } from '@app/component/split-layout/layoutManager';@@ -47,6 +50,10 @@ export const useEntityActionHotkeys = (const moveToProjectAction = makeMoveToProjectAction();+ const copyLinkAction = makeCopyLinkAction();++ const shareAction = makeShareAction();+const getEntitiesForAction = (): EntityData[] => {const selected = soup.selection.selected();if (selected.length > 0) return selected;@@ -188,4 +195,46 @@ export const useEntityActionHotkeys = (displayPriority: 10,tags: [HotkeyTags.SelectionModification],});++ // Copy link - 'shift+cmd+c'+ registerHotkey({+ hotkey: ['shift+cmd+c'],+ hotkeyToken: TOKENS.entity.action.copyLink,+ scopeId,+ description: 'Copy link',+ keyDownHandler: () => {+ const entities = getEntitiesForAction();+ if (entities.length === 0) return false;+ if (!copyLinkAction.canExecute(entities[0])) return false;+ copyLinkAction.executeWithSoup(entities, soup);+ return true;+ },+ condition: () => {+ if (condition && !condition()) return false;+ const entities = getEntitiesForAction();+ return entities.length === 1 && copyLinkAction.canExecute(entities[0]);+ },+ displayPriority: 10,+ tags: [HotkeyTags.SelectionModification],+ });++ registerHotkey({+ hotkeyToken: TOKENS.entity.action.share,+ scopeId,+ description: 'Share',+ keyDownHandler: () => {+ const entities = getEntitiesForAction();+ if (entities.length === 0) return false;+ if (!shareAction.canExecute(entities[0])) return false;+ shareAction.executeWithSoup(entities, soup);+ return true;+ },+ condition: () => {+ if (condition && !condition()) return false;+ const entities = getEntitiesForAction();+ return entities.length === 1 && isShareableEntityType(entities[0].type);+ },+ displayPriority: 10,+ tags: [HotkeyTags.SelectionModification],+ });};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.tsxindex 95b1cbcde2..5fbd85612a 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,10 +5,12 @@ import { fileTypeToBlockName } from '@core/constant/allBlocks';import type { EntityData } from '@entity';import {makeCopyAction,+ makeCopyLinkAction,makeDeleteAction,makeMarkDoneAction,makeMoveToProjectAction,makeRenameAction,+ makeShareAction,} from '../actions';import type { SoupState } from '../create-soup-state';import { useUserId } from '@core/context/user';@@ -40,6 +42,10 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {const moveToProjectAction = makeMoveToProjectAction();+ const copyLinkAction = makeCopyLinkAction();++ const shareAction = makeShareAction();+const canExecuteAny = (canExecute: (e: EntityData) => boolean) =>props.entities.some(canExecute);@@ -117,11 +123,26 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {/><MenuItem- text="Copy"+ text="Duplicate"disabled={!canExecuteAny(copyAction.canExecute)}onClick={() => handleAction(copyAction.executeWithSoup)}/>+ <MenuItem+ text="Copy Link"+ disabled={props.entities.length !== 1}+ onClick={() => handleAction(copyLinkAction.executeWithSoup)}+ />++ <MenuItem+ text="Share"+ disabled={+ props.entities.length !== 1 ||+ !shareAction.canExecute(props.entities[0])+ }+ onClick={() => handleAction(shareAction.executeWithSoup)}+ />+<Divider /><div class="text-failure-ink w-full">diff --git a/js/app/packages/core/component/TopBar/ShareButton.tsx b/js/app/packages/core/component/TopBar/ShareButton.tsxindex fcbd710f53..e8dd9ccf6e 100644--- a/js/app/packages/core/component/TopBar/ShareButton.tsx+++ b/js/app/packages/core/component/TopBar/ShareButton.tsx@@ -76,7 +76,6 @@ import { ClippedPanel } from '../ClippedPanel';import { DeprecatedIconButton } from '../DeprecatedIconButton';import { DialogWrapper } from '../DialogWrapper';import { ForwardToChannel } from '../ForwardToChannel';-import { MENU_ITEM_CLASS } from '../Menu';import { Permissions } from '../SharePermissions';import { toast } from '../Toast/Toast';import { Tooltip } from '../Tooltip';@@ -576,8 +575,8 @@ export function ShareModal(props: ShareModalProps) {</div><div class="grid gap-3 text-ink text-sm select-none overflow-y-auto scrollbar-hidden pt-[52px] pb-3 px-3 max-h-[159px] h-min"><Show when={props.owner}>- <div class="contents rounded-md">- <div class="flex items-centeroverflow-hidden">+ <div class="flex justify-between bg-panel">+ <div class="flex items-center gap-2 overflow-hidden"><UserIconisDeleted={false}id={props.owner!}@@ -588,7 +587,9 @@ export function ShareModal(props: ShareModalProps) {</div></div><div class="flex items-center">- <div class={MENU_ITEM_CLASS}>Owner</div>+ <div class="font-medium text-ink-muted text-xs">+ Owner+ </div></div></div></Show>diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.tsindex 0c22337b9e..8295963a2f 100644--- a/js/app/packages/core/hotkey/tokens.ts+++ b/js/app/packages/core/hotkey/tokens.ts@@ -46,6 +46,8 @@ export const TOKENS = {rename: 'entity.action.rename',moveToFolder: 'entity.action.moveToFolder',copy: 'entity.action.copy',+ copyLink: 'entity.action.copyLink',+ share: 'entity.action.share',properties: 'entity.action.properties',priority: 'entity.action.priority',status: 'entity.action.status',