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
fix(projects): retarget an open project instead of mounting a second pane (#8525)
gbirman8a6097a44308
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 0cdf895d1c..eacf118ffc 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -136,6 +136,10 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.- Inline agent steps reuse the session code-execution query for live SDK operationnames; completed step snapshots come from the shared fold of the tool receipt.- All API/network calls live in service-clients.+- Open projects through `openProject` (`features/projects/open-project.ts`): it+ retargets an already-open project split to the section or comment in place.+ Opening the legacy `initiative-view` component route beside an open project+ mounts a redirect shim that stays on "Loading project".- Bound Discussion comment readiness waits to ten seconds; recover from initial layout interruptions until the message is visible, and release the target on user input (including scrollbar pointer-down), timeout, or successful arrival.- Keep early DOCX opens loading while exports return processing (409); retry onlythat response, with a bounded wait. See the Word editor walkthrough indiff --git a/apps/web/src/features/projects/open-project.test.ts b/apps/web/src/features/projects/open-project.test.tsnew file mode 100644index 0000000000..38bb76f5e2--- /dev/null+++ b/apps/web/src/features/projects/open-project.test.ts@@ -0,0 +1,91 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { openProject } from './open-project';++const mocks = vi.hoisted(() => ({+ getSplitByContent: vi.fn(),+ replace: vi.fn(),+ activate: vi.fn(),+ openWithSplit: vi.fn(),+}));++vi.mock('@app/signal/splitLayout', () => ({+ globalSplitManager: () => ({ getSplitByContent: mocks.getSplitByContent }),+}));+vi.mock('@core/constant/featureFlags', () => ({+ enableProjects: { key: 'enable-projects' },+ isFeatureEnabled: () => true,+}));++const layout = {+ openWithSplit: mocks.openWithSplit,+} as unknown as Parameters<typeof openProject>[0];++const hostedRoute = (section: string) => ({+ matches: [+ { id: 'app', params: {} },+ { id: 'view-tasks', params: {} },+ { id: 'tasks-project', params: { projectId: 'project-1', section } },+ ],+});++describe('openProject', () => {+ beforeEach(() => {+ mocks.getSplitByContent.mockReset();+ mocks.replace.mockReset();+ mocks.activate.mockReset();+ mocks.openWithSplit.mockReset();+ });++ it('retargets an open project to the comment instead of opening another pane', () => {+ mocks.getSplitByContent.mockReturnValue({+ replace: mocks.replace,+ activate: mocks.activate,+ });++ openProject(layout, 'project-1', {+ discussionId: 'comment-1',+ newSplit: true,+ });++ expect(mocks.getSplitByContent).toHaveBeenCalledWith(+ 'initiative',+ 'project-1'+ );+ expect(mocks.replace).toHaveBeenCalledWith({+ next: {+ type: 'initiative',+ id: 'project-1',+ entryMetadata: {+ route: hostedRoute('overview'),+ search: {+ tasks: { tab: ['projects'] },+ project: { discussionId: ['comment-1'] },+ },+ },+ },+ mergeHistory: true,+ referredFrom: null,+ });+ expect(mocks.activate).toHaveBeenCalled();+ expect(mocks.openWithSplit).not.toHaveBeenCalled();+ });++ it('opens the hosted project route at the requested section when it is not open', () => {+ mocks.getSplitByContent.mockReturnValue(undefined);++ openProject(layout, 'project-1', { section: 'tasks', newSplit: true });++ expect(mocks.openWithSplit).toHaveBeenCalledWith(+ {+ type: 'initiative',+ id: 'project-1',+ entryMetadata: {+ route: hostedRoute('tasks'),+ search: { tasks: { tab: ['projects'] } },+ },+ },+ { preferNewSplit: true }+ );+ expect(mocks.replace).not.toHaveBeenCalled();+ });+});diff --git a/apps/web/src/features/projects/open-project.ts b/apps/web/src/features/projects/open-project.tsindex 8f511caf2f..2fa3bdb371 100644--- a/apps/web/src/features/projects/open-project.ts+++ b/apps/web/src/features/projects/open-project.ts@@ -1,7 +1,36 @@+import { paneRoute } from '@app/routes/app-route';+import { globalSplitManager } from '@app/signal/splitLayout';import type { useSplitLayout } from '@components/app/split-layout/layout';+import type { SplitContent } from '@components/app/split-layout/layoutManager';import { enableProjects, isFeatureEnabled } from '@core/constant/featureFlags';+import { Telemetry } from '@macro-inc/observability';import type { ProjectSection } from './core/project';-import { projectRouteId } from './core/route';++/**+ * The Tasks-hosted project route as split content. Its identity is the project+ * itself, so an open project split is found and retargeted; the legacy+ * `initiative-view` component would mount a redirect shim beside it instead.+ */+export function projectHostedContent(+ id: string,+ section: ProjectSection,+ discussionId?: string+): SplitContent {+ return {+ type: 'initiative',+ id,+ entryMetadata: {+ route: paneRoute(+ { id: 'view-tasks', params: {} },+ { id: 'tasks-project', params: { projectId: id, section } }+ ),+ search: {+ tasks: { tab: ['projects'] },+ ...(discussionId ? { project: { discussionId: [discussionId] } } : {}),+ },+ },+ };+}/** A host action, deliberately outside the reusable feature layers. */export function openProject(@@ -14,17 +43,33 @@ export function openProject(} = {}) {if (!isFeatureEnabled(enableProjects)) return;- layout.openWithSplit(- {- type: 'component',- id: projectRouteId({- id,- section: options.discussionId- ? 'overview'- : (options.section ?? 'overview'),- discussionId: options.discussionId,- }),- },- { preferNewSplit: options.newSplit }- );+ const section = options.discussionId+ ? 'overview'+ : (options.section ?? 'overview');+ const content = projectHostedContent(id, section, options.discussionId);+ const span = Telemetry.span('project.open');+ try {+ span.setAttr('project.id', id);+ span.setAttr('project.section', section);+ span.setAttr('project.has_discussion', options.discussionId !== undefined);+ // A project already on screen moves to the requested section or comment+ // in place; opening it again would only add an empty pane.+ const existing = globalSplitManager()?.getSplitByContent('initiative', id);+ if (existing) {+ existing.replace({+ next: content,+ mergeHistory: true,+ referredFrom: null,+ });+ existing.activate();+ span.setAttr('project.outcome', 'retargeted');+ return;+ }+ const result = layout.openWithSplit(content, {+ preferNewSplit: options.newSplit,+ });+ span.setAttr('project.outcome', result?.status ?? 'unavailable');+ } finally {+ span.end();+ }}diff --git a/apps/web/src/features/projects/project-attachment.test.tsx b/apps/web/src/features/projects/project-attachment.test.tsxindex ea483a07a0..9967090138 100644--- a/apps/web/src/features/projects/project-attachment.test.tsx+++ b/apps/web/src/features/projects/project-attachment.test.tsx@@ -1,7 +1,7 @@import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';import { createSignal, type ParentProps, Show } from 'solid-js';import { afterEach, beforeEach, expect, it, vi } from 'vitest';-import { projectRouteId } from './core/route';+import { projectHostedContent } from './open-project';import { ProjectAttachment } from './project-attachment';const mocks = vi.hoisted(() => ({@@ -52,10 +52,7 @@ it('opens an authorized attachment using native project identity and split prefeshiftKey: true,});expect(mocks.open).toHaveBeenCalledWith(- {- type: 'component',- id: projectRouteId({ id: 'initiative-1', section: 'overview' }),- },+ projectHostedContent('initiative-1', 'overview'),{ preferNewSplit: true });});diff --git a/apps/web/src/lib/core/component/AI/component/tool/Initiatives.test.tsx b/apps/web/src/lib/core/component/AI/component/tool/Initiatives.test.tsxindex b175fdb059..a33c9fa1cf 100644--- a/apps/web/src/lib/core/component/AI/component/tool/Initiatives.test.tsx+++ b/apps/web/src/lib/core/component/AI/component/tool/Initiatives.test.tsx@@ -1,3 +1,4 @@+import { projectHostedContent } from '@app/features/projects/open-project';import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';import {type Component,@@ -110,7 +111,7 @@ it('expands project results and opens a native project view', () => {shiftKey: true,});expect(open).toHaveBeenCalledWith(- { type: 'component', id: `initiative-view~${projectId}~overview` },+ projectHostedContent(projectId, 'overview'),{ preferNewSplit: true });});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.test.tsxindex 6643d6f62e..bddfe10181 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.test.tsx@@ -1,3 +1,4 @@+import { projectHostedContent } from '@app/features/projects/open-project';import { MessageReferenceNavigation } from '@core/messages/message-reference-navigation';import type {ReplyTargetDecoratorProps,@@ -15,6 +16,10 @@ vi.mock('@core/block', () => ({useMaybeBlockId: () => undefined,useMaybeBlockName: () => undefined,}));+vi.mock('@core/constant/featureFlags', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@core/constant/featureFlags')>()),+ isFeatureEnabled: () => true,+}));vi.mock('@core/user', () => ({getDisplayName: () => 'Eric',tryMacroId: (id: string) => id,@@ -72,12 +77,6 @@ it.each<{id: 'parent-id',params: { comment_id: 'message-id' },},- {- parentType: 'initiative',- type: 'component',- id: 'initiative-view~parent-id~overview~message-id',- params: {},- },{parentType: 'document',type: 'md',@@ -110,6 +109,26 @@ it.each<{});+it('opens a quoted project message through the project opener', () => {+ render(() => (+ <ReplyTarget+ parent={{ type: 'initiative', id: 'parent-id' }}+ targetMessageId="message-id"+ targetThreadId="root-id"+ displayText="Quoted text"+ senderId="macro|[email protected]"+ key="node-key"+ theme={{}}+ />+ ));+ fireEvent.click(screen.getByRole('button', { name: 'Quoted message' }));+ expect(mocks.open).not.toHaveBeenCalled();+ expect(mocks.openWithSplit).toHaveBeenCalledWith(+ projectHostedContent('parent-id', 'overview', 'message-id'),+ { preferNewSplit: true }+ );+});+it('reissues call quote navigation with a fresh route request each time', () => {render(() => (<ReplyTargetdiff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsxindex e24c4e0f6f..01d5d0de60 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/ReplyTarget.tsx@@ -1,4 +1,5 @@import { projectRouteId } from '@app/features/projects/core/route';+import { openProject } from '@app/features/projects/open-project';import {callDetailSearch,callDetailSearchCodec,@@ -104,6 +105,14 @@ export function ReplyTarget(props: ReplyTargetDecoratorProps) {event.shiftKey,currentBlockName !== destination.type || currentBlockId !== destination.id);+ if (props.parent.type === 'initiative') {+ // Retargets an open project instead of mounting a second pane for it.+ openProject(useSplitLayout(), props.parent.id, {+ discussionId: props.targetMessageId,+ newSplit: preferNewSplit,+ });+ return;+ }if (props.parent.type === 'call') {// Route search delivers a fresh request even when this call is already open.useSplitLayout().openWithSplit(