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.

fix(drive): restore breadcrumb trails from history (#6921)

dev-rbc8a81a50bf70
diff --git a/apps/web/src/components/app/split-layout/tests/activity-registration.test.tsx b/apps/web/src/components/app/split-layout/tests/activity-registration.test.tsx
index e69e00eab9..6c6d866937 100644
--- a/apps/web/src/components/app/split-layout/tests/activity-registration.test.tsx
+++ b/apps/web/src/components/app/split-layout/tests/activity-registration.test.tsx
@@ -29,6 +29,11 @@ vi.mock('../layoutUtils', () => ({
vi.mock('@core/component/LoadingBlock', () => ({
LoadingBlock: () => <div>Authenticating</div>,
}));
+vi.mock('@core/constant/allBlocks', () => ({
+ fileTypeToBlockName: (type: string) => type,
+ isBlockAlias: () => false,
+ resolveBlockAlias: (type: string) => type,
+}));
vi.mock('@app/features/activity/views/my-activity-view', () => ({
MyActivityView: () => {
state.mountActivity();
diff --git a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
index befec5e384..58cc99e572 100644
--- a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
+++ b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts
@@ -48,6 +48,7 @@ vi.mock('../componentRegistry', () => ({
}));
vi.mock('@core/constant/allBlocks', () => ({
+ fileTypeToBlockName: vi.fn((type: string) => type),
isBlockAlias: vi.fn(() => false),
resolveBlockAlias: vi.fn((type: string) => type),
}));
diff --git a/apps/web/src/components/entity-detail/EntityDetailBreadcrumbItem.tsx b/apps/web/src/components/entity-detail/EntityDetailBreadcrumbItem.tsx
index 80e231f1b0..879333117a 100644
--- a/apps/web/src/components/entity-detail/EntityDetailBreadcrumbItem.tsx
+++ b/apps/web/src/components/entity-detail/EntityDetailBreadcrumbItem.tsx
@@ -4,6 +4,9 @@ import {
type EntityIconSelector,
} from '@core/component/EntityIcon';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { useItemRawName } from '@queries/preview';
+import type { ItemEntity } from '@queries/preview/types';
+import { Show } from 'solid-js';
import type {
EntityDetailNavigationStackEntry,
EntityDetailTarget,
@@ -25,7 +28,7 @@ function breadcrumbIcon(target: EntityDetailTarget): EntityIconSelector {
return fileTypeToBlockName(target.type, true);
}
-function breadcrumbName(target: EntityDetailTarget) {
+function fallbackBreadcrumbName(target: EntityDetailTarget) {
if (target.fallbackName) return target.fallbackName;
if (target.type === 'document' && target.subType?.type === 'task') {
@@ -41,9 +44,10 @@ function breadcrumbName(target: EntityDetailTarget) {
return 'Untitled';
}
-export function EntityDetailBreadcrumbItem(props: {
+function BreadcrumbItem(props: {
entry: EntityDetailNavigationStackEntry;
order: number;
+ name: string;
}) {
return (
<ViewBreadcrumbs.Item
@@ -56,16 +60,67 @@ export function EntityDetailBreadcrumbItem(props: {
class="gap-1.5"
isActive={item.isActive()}
onClick={item.onSelect}
- tooltip={breadcrumbName(props.entry.data)}
+ tooltip={props.name}
>
<EntityIcon
targetType={breadcrumbIcon(props.entry.data)}
size="xs"
class="shrink-0"
/>
- <span class="truncate">{breadcrumbName(props.entry.data)}</span>
+ <span class="truncate">{props.name}</span>
</ViewBreadcrumbs.Button>
)}
</ViewBreadcrumbs.Item>
);
}
+
+function LiveBreadcrumbItem(props: {
+ entry: EntityDetailNavigationStackEntry;
+ order: number;
+ previewItem: ItemEntity;
+}) {
+ const currentName = useItemRawName(() => props.previewItem);
+ const name = () => {
+ const current = currentName();
+ if (current?.trim()) return current;
+
+ return fallbackBreadcrumbName(props.entry.data);
+ };
+
+ return (
+ <BreadcrumbItem entry={props.entry} order={props.order} name={name()} />
+ );
+}
+
+export function EntityDetailBreadcrumbItem(props: {
+ entry: EntityDetailNavigationStackEntry;
+ order: number;
+}) {
+ return (
+ <Show
+ when={
+ props.entry.data.type === 'reminder'
+ ? undefined
+ : ({
+ id: props.entry.data.id,
+ type: props.entry.data.type,
+ } satisfies ItemEntity)
+ }
+ fallback={
+ <BreadcrumbItem
+ entry={props.entry}
+ order={props.order}
+ name={fallbackBreadcrumbName(props.entry.data)}
+ />
+ }
+ >
+ {(previewItem) => (
+ <LiveBreadcrumbItem
+ entry={props.entry}
+ order={props.order}
+ previewItem={previewItem()}
+ />
+ )}
+ </Show>
+ );
+}
diff --git a/apps/web/src/features/drive-view/drive-detail-navigation.tsx b/apps/web/src/features/drive-view/drive-detail-navigation.tsx
index 538fe62303..c5e1d1373f 100644
--- a/apps/web/src/features/drive-view/drive-detail-navigation.tsx
+++ b/apps/web/src/features/drive-view/drive-detail-navigation.tsx
@@ -4,13 +4,7 @@ import type {
EntityDetailNavigationStackEntry,
EntityDetailTarget,
} from '@app/components/entity-detail/EntityDetailNavigationStack';
-import {
- routeParams,
- useCanGo,
- useNavigate,
- useParams,
- useSplitHistory,
-} from '@app/split-router';
+import { useNavigate, useParams, useRouteState } from '@app/split-router';
import { createPreviewSelectionGuard } from '@components/app/createPreviewSelectionGuard';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import {
@@ -24,24 +18,35 @@ import {
} from 'solid-js';
import type { DriveLocation } from './core/types';
import { driveDestination } from './drive-route-navigation';
+import {
+ type DriveDocumentTarget,
+ documentRouteFromTarget,
+ documentTargetFromRoute,
+ sameDocumentRoute,
+} from './primitives/drive-detail-trail';
import {
type DriveDocumentRoute,
type DriveRouteParams,
driveDocumentFromParams,
driveDocumentRoute,
} from './primitives/drive-route';
+import { driveSplitRoute } from './route';
-type DriveDetailHistoryEntry = EntityDetailNavigationStackEntry & {
- historyIndex: number;
+type DriveDetailRootOptions = EntityDetailNavigationOptions & {
+ location?: DriveLocation;
};
type DriveDetailNavigation = {
- entries: Accessor<readonly DriveDetailHistoryEntry[]>;
- active: Accessor<DriveDetailHistoryEntry | undefined>;
+ entries: Accessor<readonly EntityDetailNavigationStackEntry[]>;
+ active: Accessor<EntityDetailNavigationStackEntry | undefined>;
navigate: (
target: EntityDetailTarget,
options?: EntityDetailNavigationOptions
) => boolean;
+ openRoot: (
+ target: EntityDetailTarget,
+ options?: DriveDetailRootOptions
+ ) => boolean;
pop: () => void;
popTo: (value: string) => void;
clear: (options?: { replace?: boolean }) => void;
@@ -49,60 +54,16 @@ type DriveDetailNavigation = {
const Context = createContext<DriveDetailNavigation>();
-function targetFromDocument(
- document: DriveDocumentRoute | undefined
-): Extract<EntityDetailTarget, { type: 'document' }> | undefined {
- if (!document) return;
-
- const target = {
- type: 'document' as const,
- id: document.id,
- };
-
- switch (document.type) {
- case 'task':
- return {
- ...target,
- fileType: 'md',
- subType: { type: 'task', is_completed: false },
- };
- case 'snippet':
- case 'skill':
- return {
- ...target,
- fileType: 'md',
- subType: { type: document.type },
- };
- default:
- return { ...target, fileType: document.type };
- }
-}
-
-function targetFromParams(params: DriveRouteParams) {
- return targetFromDocument(driveDocumentFromParams(params));
-}
-
-function sameTarget(
- left: EntityDetailTarget | undefined,
- right: EntityDetailTarget | undefined
-) {
- if (left?.type !== 'document' || right?.type !== 'document') {
- return left === right;
- }
-
- return (
- left.id === right.id &&
- left.fileType === right.fileType &&
- left.subType?.type === right.subType?.type
- );
-}
-
function opensInline(options?: EntityDetailNavigationOptions) {
+ if (isTouchDevice()) return false;
+
const event = options?.event;
- return (
- !isTouchDevice() &&
- !(event?.shiftKey || event?.metaKey || event?.ctrlKey || event?.altKey)
- );
+ if (!event) return true;
+ if (event.shiftKey) return false;
+ if (event.metaKey) return false;
+ if (event.ctrlKey) return false;
+ if (event.altKey) return false;
+ return true;
}
export function DriveDetailNavigationProvider(
@@ -110,82 +71,131 @@ export function DriveDetailNavigationProvider(
) {
const params = useParams<DriveRouteParams>();
const navigate = useNavigate();
- const canGoBack = useCanGo(-1);
- const history = useSplitHistory();
+ const routeTrail = useRouteState(driveSplitRoute);
const selectPreview = createPreviewSelectionGuard();
- const activeTarget = createMemo(() => targetFromParams(params));
+ const activeDocument = createMemo(() => driveDocumentFromParams(params));
+ const activeTarget = createMemo(() =>
+ documentTargetFromRoute(activeDocument())
+ );
createEffect(on(activeTarget, (target) => selectPreview(target)));
- const entries = createMemo<DriveDetailHistoryEntry[]>(() => {
- const snapshot = history();
- if (!snapshot) return [];
-
- const result: DriveDetailHistoryEntry[] = [];
- for (let index = 0; index <= snapshot.index; index += 1) {
- const target = targetFromParams(
- routeParams(snapshot.entries[index]?.location.route) as DriveRouteParams
- );
-
- if (!target) {
- result.splice(0);
- continue;
- }
+ const trail = (): DriveDocumentTarget[] => {
+ const restored = routeTrail();
+ const endpoint = restored?.at(-1);
+ const endpointMatches =
+ endpoint !== undefined &&
+ sameDocumentRoute(documentRouteFromTarget(endpoint), activeDocument());
+ if (restored && endpointMatches) return restored;
+
+ const target = activeTarget();
+ if (!target) return [];
+ return [target];
+ };
- const entry = {
- value: `drive-history:${index}`,
- data: target,
- historyIndex: index,
- };
- const previous = result.at(-1);
- if (sameTarget(previous?.data, target)) result[result.length - 1] = entry;
- else result.push(entry);
- }
-
- return result;
- });
+ const entries = createMemo<EntityDetailNavigationStackEntry[]>(() =>
+ trail().map((target, index) => ({
+ value: `drive-detail:${index}:${documentRouteFromTarget(target).type}:${target.id}`,
+ data: target,
+ }))
+ );
const active = () => entries().at(-1);
+ const resolveTarget = (
+ target: EntityDetailTarget,
+ options?: EntityDetailNavigationOptions
+ ):
+ | { target: DriveDocumentTarget; document: DriveDocumentRoute }
+ | undefined => {
+ if (target.type !== 'document') return;
+ if (!opensInline(options)) return;
+
+ const blockType = entityDetailBlockType(target);
+ if (!blockType) return;
+ if (!selectPreview(target)) return;
+
+ return {
+ target,
+ document: driveDocumentRoute({
+ id: target.id,
+ fileType: target.fileType ?? blockType,
+ subType: target.subType?.type,
+ }),
+ };
+ };
+
const value: DriveDetailNavigation = {
entries,
active,
navigate(target, options) {
- if (target.type !== 'document' || !opensInline(options)) return false;
+ const resolved = resolveTarget(target, options);
+ if (!resolved) return false;
+
+ const currentTrail = trail();
+ const endpoint = currentTrail.at(-1);
+ const endpointMatches =
+ endpoint !== undefined &&
+ sameDocumentRoute(documentRouteFromTarget(endpoint), resolved.document);
+ if (endpointMatches) return true;
+
+ navigate(driveDestination(props.location(), resolved.document), {
+ state: [...currentTrail, resolved.target],
+ });
+ return true;
+ },
- const blockType = entityDetailBlockType(target);
- if (!blockType || !selectPreview(target)) return false;
+ openRoot(target, options) {
+ const resolved = resolveTarget(target, options);
+ if (!resolved) return false;
navigate(
driveDestination(
- props.location(),
- driveDocumentRoute({
- id: target.id,
- fileType: target.fileType ?? blockType,
- subType: target.subType?.type,
- })
- )
+ options?.location ?? props.location(),
+ resolved.document
+ ),
+ { state: [resolved.target] }
);
return true;
},
pop() {
- if (canGoBack()) navigate(-1);
- else value.clear({ replace: true });
+ const currentEntries = entries();
+ if (currentEntries.length > 1) {
+ value.popTo(currentEntries.at(-2)!.value);
+ return;
+ }
+ value.clear({ replace: true });
},
popTo(value) {
- const entry = entries().find((candidate) => candidate.value === value);
- const snapshot = history();
- if (!entry || !snapshot) return;
+ const currentEntries = entries();
+ const entryIndex = currentEntries.findIndex(
+ (candidate) => candidate.value === value
+ );
+ if (entryIndex < 0) return;
+ if (entryIndex === currentEntries.length - 1) return;
+
+ const nextTrail = currentEntries
+ .slice(0, entryIndex + 1)
+ .map((candidate) => candidate.data)
+ .filter(
+ (candidate): candidate is DriveDocumentTarget =>
+ candidate.type === 'document'
+ );
+ const target = nextTrail.at(-1);
+ if (!target) return;
- navigate(entry.historyIndex - snapshot.index);
+ navigate(
+ driveDestination(props.location(), documentRouteFromTarget(target)),
+ { state: nextTrail }
+ );
},
clear(options) {
// Location navigation already lands on a list route. Clearing again must
// not climb out of the folder/tab the user just selected.
- if (!driveDocumentFromParams(params)) return;
+ if (!activeDocument()) return;
selectPreview(undefined);
navigate(driveDestination(props.location()), {
replace: options?.replace,
diff --git a/apps/web/src/features/drive-view/drive-host-actions.ts b/apps/web/src/features/drive-view/drive-host-actions.ts
index 6223dc055c..5fa7934364 100644
--- a/apps/web/src/features/drive-view/drive-host-actions.ts
+++ b/apps/web/src/features/drive-view/drive-host-actions.ts
@@ -79,7 +79,7 @@ export function createDriveHostActions(options: {
fallbackName: entity.name,
});
- if (navigation.navigate(target, { event })) return;
+ if (navigation.openRoot(target, { event })) return;
}
void openEntityInSplitFromUnifiedList(entity, {
@@ -100,18 +100,30 @@ export function createDriveHostActions(options: {
if (favorite.entityType === 'document') {
const block = favoriteBlockName(favorite);
+ let subType:
+ | { type: 'task'; is_completed: boolean }
+ | { type: 'snippet' | 'skill' }
+ | undefined;
+ if (block === 'task') {
+ subType = { type: block, is_completed: false };
+ } else if (block === 'snippet' || block === 'skill') {
+ subType = { type: block };
+ }
const target = entityDetailTarget.document({
id: favorite.entityId,
fileType: favorite.fileType ?? undefined,
- subType:
- block === 'snippet' || block === 'skill'
- ? { type: block }
- : undefined,
+ subType,
fallbackName: name,
});
- if (navigation.navigate(target, { event })) return;
+ if (
+ navigation.openRoot(target, {
+ event,
+ location: { kind: 'tab', tab: 'owned' },
+ })
+ )
+ return;
}
const result = layout.openWithSplit(favoriteSplitContent(favorite), {
diff --git a/apps/web/src/features/drive-view/primitives/drive-detail-trail.ts b/apps/web/src/features/drive-view/primitives/drive-detail-trail.ts
new file mode 100644
index 0000000000..e12d7cdfae
--- /dev/null
+++ b/apps/web/src/features/drive-view/primitives/drive-detail-trail.ts
@@ -0,0 +1,72 @@
+import { z } from 'zod';
+import type { DriveDocumentRoute } from './drive-route';
+import { driveDocumentRoute } from './drive-route';
+
+export const driveDocumentTargetSchema = z.object({
+ type: z.literal('document'),
+ id: z.string().min(1),
+ fileType: z.string().optional(),
+ subType: z
+ .object({
+ type: z.enum(['task', 'snippet', 'skill']),
+ is_completed: z.boolean().optional(),
+ })
+ .nullable()
+ .optional(),
+ fallbackName: z.string().optional(),
+});
+
+export const driveDetailTrailSchema = z.array(driveDocumentTargetSchema).min(1);
+
+export type DriveDocumentTarget = z.infer<typeof driveDocumentTargetSchema>;
+
+export function documentTargetFromRoute(
+ document: DriveDocumentRoute | undefined
+): DriveDocumentTarget | undefined {
+ if (!document) return;
+
+ const target = {
+ type: 'document' as const,
+ id: document.id,
+ };
+
+ switch (document.type) {
+ case 'task':
+ return {
+ ...target,
+ fileType: 'md',
+ subType: { type: 'task', is_completed: false },
+ };
+ case 'snippet':
+ case 'skill':
+ return {
+ ...target,
+ fileType: 'md',
+ subType: { type: document.type },
+ };
+ default:
+ return { ...target, fileType: document.type };
+ }
+}
+
+export function documentRouteFromTarget(
+ target: DriveDocumentTarget
+): DriveDocumentRoute {
+ return driveDocumentRoute({
+ id: target.id,
+ fileType: target.fileType ?? 'unknown',
+ subType: target.subType?.type,
+ });
+}
+
+export function sameDocumentRoute(
+ left: DriveDocumentRoute | undefined,
+ right: DriveDocumentRoute | undefined
+): boolean {
+ return (
+ left !== undefined &&
+ right !== undefined &&
+ left.id === right.id &&
+ left.type === right.type
+ );
+}
diff --git a/apps/web/src/features/drive-view/primitives/drive-route.ts b/apps/web/src/features/drive-view/primitives/drive-route.ts
index bee086cba7..9124158a56 100644
--- a/apps/web/src/features/drive-view/primitives/drive-route.ts
+++ b/apps/web/src/features/drive-view/primitives/drive-route.ts
@@ -9,12 +9,12 @@ import {
type SplitRouteParams,
takeLast,
} from '@app/split-router';
+import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { z } from 'zod';
import type { DriveLocation, DriveTab } from '../core/types';
import {
DRIVE_DOCUMENT_TYPES,
type DriveDocumentType,
- driveDocumentBlockType,
} from './drive-route-schema';
export type DriveDocumentRoute = { id: string; type: DriveDocumentType };
@@ -62,22 +62,18 @@ export function driveDocumentRoute(document: {
fileType: string;
subType?: string;
}): DriveDocumentRoute {
- return {
- id: document.id,
- type:
- documentType.safeParse(
- driveDocumentBlockType(document.subType ?? document.fileType)
- ).data ?? 'unknown',
- };
+ const type = documentType.safeParse(
+ fileTypeToBlockName(document.subType ?? document.fileType)
+ ).data;
+ return { id: document.id, type: type ?? 'unknown' };
}
export function driveDocumentFromContent(content: {
type: string;
id: string;
}): DriveDocumentRoute | undefined {
- const type = documentType.safeParse(
- driveDocumentBlockType(content.type)
- ).data;
+ if (content.type === 'component') return;
+ const type = documentType.safeParse(fileTypeToBlockName(content.type)).data;
return type ? { id: content.id, type } : undefined;
}
diff --git a/apps/web/src/features/drive-view/route.tsx b/apps/web/src/features/drive-view/route.tsx
index a6ad0b4d9f..4528d3e523 100644
--- a/apps/web/src/features/drive-view/route.tsx
+++ b/apps/web/src/features/drive-view/route.tsx
@@ -19,6 +19,7 @@ import { mergeQuery } from '../next-soup/filters/filter-store/query-store';
import type { Query } from '../next-soup/filters/filter-store/types';
import { getViewPreset } from '../next-soup/sidebar/soup-filter-presets';
import type { DriveViewProps } from './drive-view';
+import { driveDetailTrailSchema } from './primitives/drive-detail-trail';
import {
DRIVE_DOCUMENT_TYPES,
driveDocumentBlockType,
@@ -102,6 +103,7 @@ export const driveRootDocumentRoute = defineRoute({
id: 'drive-document',
path: ':documentType/:documentId',
params: driveDocumentParams,
+ state: driveDetailTrailSchema,
component: DriveDetailView,
claim: ({ documentType, documentId }) => ({
namespace: 'block',
@@ -113,6 +115,7 @@ export const driveFolderDocumentRoute = defineRoute({
id: 'drive-folder-document',
path: ':documentType/:documentId',
params: driveDocumentParams,
+ state: driveDetailTrailSchema,
component: DriveDetailView,
claim: ({ documentType, documentId }) => ({
namespace: 'block',
@@ -124,6 +127,7 @@ export const driveTabDocumentRoute = defineRoute({
id: 'drive-tab-document',
path: ':documentType/:documentId',
params: driveDocumentParams,
+ state: driveDetailTrailSchema,
component: DriveDetailView,
claim: ({ documentType, documentId }) => ({
namespace: 'block',
@@ -136,7 +140,11 @@ export const driveFolderRoute = defineRoute({
path: 'folder/:folderId?',
params: z
.object({ folderId: z.string().min(1).optional() })
- .transform(({ folderId }) => ({ view: 'folder' as const, folderId })),
+ .transform(({ folderId }) => ({
+ view: 'folder' as const,
+ folderId,
+ })),
+ state: driveDetailTrailSchema,
children: [driveFolderDocumentRoute],
});
@@ -145,6 +153,7 @@ export const driveTabRoute = defineRoute({
path: ':tab',
aliases: ['tab/:tab'],
params: z.object({ tab: z.enum(['recent', 'shared']) }),
+ state: driveDetailTrailSchema,
children: [driveTabDocumentRoute],
});
@@ -154,6 +163,7 @@ export const driveSplitRoute = defineRoute({
aliases: ['drive/owned', 'drive/tab/owned'],
component: DriveRouteView,
search: ['drive'],
+ state: driveDetailTrailSchema,
externalSearch: (entry: Readonly<SplitRouterEntry>) => {
const type = routeParams<{ documentType?: string }>(
entry.location.route
@@ -166,7 +176,8 @@ export const driveSplitRoute = defineRoute({
) {
return Object.values(MARKDOWN_URL_PARAMS);
}
- return type === 'pdf' ? Object.values(PDF_URL_PARAMS) : [];
+ if (type === 'pdf') return Object.values(PDF_URL_PARAMS);
+ return [];
},
children: [driveFolderRoute, driveTabRoute, driveRootDocumentRoute],
});
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 7b2c547b4f..99ffb4a3cc 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -671,8 +671,11 @@ details include Print, and DOCX files include Download DOCX. Markdown details
use the document menu, which already includes Download. Spreadsheets keep the
editor's Import and export menu for Excel and CSV downloads. Choose the current location
breadcrumb to return to the list; choosing an ancestor file drops newer detail
-entries. Opening a list row or sidebar favorite starts a new detail path; only
-navigation originating inside a detail appends to that path. Cmd/Ctrl-clicking a
+entries. Opening a list row or sidebar favorite pushes a new one-item detail path;
+sidebar favorites start from My Files instead of inheriting a previously selected
+folder. Only navigation originating inside a detail appends to that path. Browser
+Back and Forward restore the exact path saved with each entry, and renamed files
+update in mounted ancestor breadcrumbs without rewriting history. Cmd/Ctrl-clicking a
row toggles selection; Shift-clicking a checkbox selects a range, and Shift+Enter
opens the focused row in a new split. Cmd/Ctrl-clicking a row's folder link or
search hit opens a new tab. Short filtered pages load more results automatically;