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): open new and existing files, databases and forms inline in Drive (#8074)

teoef682d341ad4
diff --git a/apps/web/src/features/command/Launcher.test.tsx b/apps/web/src/features/command/Launcher.test.tsx
index 8bb252c810..5f36dbbda4 100644
--- a/apps/web/src/features/command/Launcher.test.tsx
+++ b/apps/web/src/features/command/Launcher.test.tsx
@@ -1,5 +1,6 @@
import { MemoryRouter, Route } from '@solidjs/router';
import { cleanup, fireEvent, render } from '@solidjs/testing-library';
+import { ok } from 'neverthrow';
import { createSignal } from 'solid-js';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
@@ -7,6 +8,9 @@ const host = vi.hoisted(() => ({
popoverSplit: vi.fn(),
openWithSplit: vi.fn(),
createFolder: vi.fn(),
+ createSpreadsheet: vi.fn(async () => 'sheet-1' as string | undefined),
+ createDatabase: vi.fn(),
+ createForm: vi.fn(),
projectFlag: (): boolean | undefined => true,
carouselFlag: (): boolean | undefined => undefined,
}));
@@ -17,6 +21,10 @@ vi.mock('@components/app/split-layout/layout', () => ({
vi.mock('@queries/storage/projects', () => ({
createProject: host.createFolder,
}));
+vi.mock('@queries/storage/databases', () => ({
+ createDatabase: host.createDatabase,
+}));
+vi.mock('@queries/storage/forms', () => ({ createForm: host.createForm }));
// Other creation flows are independent of the native project composer.
vi.mock('@app/features/agents-view/primitives/open-composer', () => ({}));
@@ -26,15 +34,14 @@ vi.mock(
'@app/features/block-spreadsheet/primitives/use-spreadsheet-access',
() => ({ useSpreadsheetAccess: () => () => false })
);
-vi.mock(
- '@app/features/block-spreadsheet/queries/create-spreadsheet',
- () => ({})
-);
+vi.mock('@app/features/block-spreadsheet/queries/create-spreadsheet', () => ({
+ createSpreadsheetDocument: host.createSpreadsheet,
+}));
vi.mock('@app/features/block-ai/queries/create-ai', () => ({}));
vi.mock('@app/features/block-psd/queries/create-psd', () => ({}));
vi.mock('@app/features/block-fig/queries/create-fig', () => ({}));
vi.mock('@app/features/block-spreadsheet/queries/spreadsheet-access', () => ({
- isSpreadsheetEnabledForCurrentUser: () => false,
+ isSpreadsheetEnabledForCurrentUser: () => true,
}));
vi.mock('@app/features/email-compose/core/constants', () => ({}));
vi.mock('@app/features/reminders/reminder-composer', () => ({}));
@@ -50,7 +57,9 @@ vi.mock('@app/lib/analytics/posthog', () => ({
vi.mock('@core/constant/featureFlags', async (importOriginal) => ({
...(await importOriginal<typeof import('@core/constant/featureFlags')>()),
isFeatureEnabled: (flag: { key: string }) =>
- flag.key === 'enable-projects' && host.projectFlag() === true,
+ flag.key === 'enable-databases' ||
+ flag.key === 'enable-forms' ||
+ (flag.key === 'enable-projects' && host.projectFlag() === true),
}));
vi.mock('@block-md/observability', () => ({}));
vi.mock('@channel/CreateChannelModal', () => ({}));
@@ -197,6 +206,86 @@ it('offers Project in the shared create menu and opens its native composer', ()
expect(host.createFolder).not.toHaveBeenCalled();
});
+it('shows a loading pane while a document is created, then opens it there', async () => {
+ const replace = vi.fn();
+ host.openWithSplit.mockReturnValueOnce({ split: { replace } });
+
+ runCreateAction('spreadsheet', { projectId: 'folder-1', source: 'drive' });
+
+ expect(host.openWithSplit).toHaveBeenCalledExactlyOnceWith(
+ { type: 'component', id: 'loading' },
+ { referredFrom: 'launcher', preferNewSplit: false }
+ );
+ await vi.waitFor(() => expect(replace).toHaveBeenCalledOnce());
+ expect(replace).toHaveBeenCalledWith({
+ next: { type: 'spreadsheet', id: 'sheet-1', params: undefined },
+ mergeHistory: true,
+ referredFrom: 'launcher',
+ });
+});
+
+it('lets the requesting surface keep its content and open the new document itself', async () => {
+ const openCreated = vi.fn(() => true);
+
+ runCreateAction('spreadsheet', {
+ projectId: 'folder-1',
+ source: 'drive',
+ openCreated,
+ });
+
+ await vi.waitFor(() =>
+ expect(openCreated).toHaveBeenCalledExactlyOnceWith({
+ blockName: 'spreadsheet',
+ id: 'sheet-1',
+ })
+ );
+ expect(host.createSpreadsheet).toHaveBeenCalledWith({
+ projectId: 'folder-1',
+ source: 'drive',
+ });
+ expect(host.openWithSplit).not.toHaveBeenCalled();
+});
+
+it.each([
+ {
+ blockName: 'database',
+ arrange: () => host.createDatabase.mockResolvedValueOnce(ok('db-1')),
+ id: 'db-1',
+ },
+ {
+ blockName: 'form',
+ arrange: () =>
+ host.createForm.mockResolvedValueOnce(ok({ form: { id: 'form-1' } })),
+ id: 'form-1',
+ },
+] as const)(
+ 'lets the requesting surface open a new $blockName the same way',
+ async ({ blockName, arrange, id }) => {
+ arrange();
+ const openCreated = vi.fn(() => true);
+
+ runCreateAction(blockName, { source: 'drive', openCreated });
+
+ await vi.waitFor(() =>
+ expect(openCreated).toHaveBeenCalledExactlyOnceWith({ blockName, id })
+ );
+ expect(host.openWithSplit).not.toHaveBeenCalled();
+ }
+);
+
+it('opens the new document in a split when the requesting surface declines it', async () => {
+ const openCreated = vi.fn(() => false);
+
+ runCreateAction('spreadsheet', { openCreated });
+
+ await vi.waitFor(() => expect(host.openWithSplit).toHaveBeenCalledOnce());
+ expect(openCreated).toHaveBeenCalledOnce();
+ expect(host.openWithSplit).toHaveBeenCalledWith(
+ { type: 'spreadsheet', id: 'sheet-1' },
+ { referredFrom: 'launcher', preferNewSplit: false }
+ );
+});
+
it('opens the Folder composer without creating a folder immediately', () => {
const folder = CREATABLE_BLOCKS.find((item) => item.label === 'Folder');
expect(folder).toBeDefined();
diff --git a/apps/web/src/features/command/Launcher.tsx b/apps/web/src/features/command/Launcher.tsx
index 79451044d3..787b84076f 100644
--- a/apps/web/src/features/command/Launcher.tsx
+++ b/apps/web/src/features/command/Launcher.tsx
@@ -91,7 +91,7 @@ import {
} from './core/launcher-history';
import { createCallCommand } from './create-call-command';
import { MobileCreateSheet } from './mobile/MobileCreateSheet';
-import type { CreatableBlock, CreatableName } from './types';
+import type { CreatableBlock, CreatableName, OpenCreatedItem } from './types';
const LAUNCHER_FRECENCY_STORE = 'launcher-frecency-v1';
const LAUNCHER_SEARCH_MODE_STORE = 'launcher-search-mode-v1';
@@ -150,17 +150,19 @@ const createBlock = async (spec: {
createFn: () => Promise<string | undefined>;
loading?: boolean;
shouldInsert?: boolean;
+ openCreated?: OpenCreatedItem;
/** Active creation span; registered by document id after creation. */
span?: Span;
}) => {
const { openWithSplit } = useSplitLayout();
- const { blockName, createFn, loading, span } = spec;
+ const { blockName, createFn, loading, openCreated, span } = spec;
setCreateMenuOpen(false, false);
// On mobile, navigate directly after creation instead of showing an
- // intermediate loading pane during the swipe transition.
- const showLoadingFirst = loading && !isMobile();
+ // intermediate loading pane during the swipe transition. The loading pane
+ // would also unmount a surface that opens the document itself.
+ const showLoadingFirst = loading && !isMobile() && !openCreated;
const split = showLoadingFirst
? openWithSplit(
@@ -180,6 +182,11 @@ const createBlock = async (spec: {
span?.setAttr('document.id', id);
if (span) registerDocumentSpan(id, span);
+ if (openCreated?.({ blockName, id })) {
+ span?.event('doc.navigated');
+ return;
+ }
+
// If we are creating a new markdown document "from scratch" then we can let
// them instantly start editing
const createMdParams =
@@ -252,9 +259,12 @@ export function runCreateAction(
source?: string;
projectId?: string;
destination?: string;
+ /** Creatables that open a composer instead ignore it. */
+ openCreated?: OpenCreatedItem;
} = {}
) {
const shouldInsert = options.shouldInsert ?? false;
+ const openCreated = options.openCreated;
// Creation analytics fire at the data-layer chokepoints (create.ts /
// projects.ts); `source` just attributes which surface initiated it.
const source = options.source ?? 'create_menu';
@@ -278,6 +288,7 @@ export function runCreateAction(
source,
}),
shouldInsert,
+ openCreated,
})
)
.catch((error) => {
@@ -298,6 +309,7 @@ export function runCreateAction(
source,
}),
shouldInsert,
+ openCreated,
});
return;
case 'psd':
@@ -308,6 +320,7 @@ export function runCreateAction(
createFn: () =>
createPsdDocument({ projectId: options.projectId, source }),
shouldInsert,
+ openCreated,
});
return;
case 'fig':
@@ -318,6 +331,7 @@ export function runCreateAction(
createFn: () =>
createFigDocument({ projectId: options.projectId, source }),
shouldInsert,
+ openCreated,
});
return;
case 'ai':
@@ -328,6 +342,7 @@ export function runCreateAction(
createFn: () =>
createAiDocument({ projectId: options.projectId, source }),
shouldInsert,
+ openCreated,
});
return;
case 'canvas':
@@ -345,6 +360,7 @@ export function runCreateAction(
return result.documentId ?? undefined;
},
shouldInsert,
+ openCreated,
});
return;
case 'task':
@@ -372,6 +388,7 @@ export function runCreateAction(
source,
}),
shouldInsert,
+ openCreated,
});
return;
case 'email':
@@ -417,6 +434,7 @@ export function runCreateAction(
return result.chatId;
},
shouldInsert,
+ openCreated,
});
return;
case 'project':
@@ -447,6 +465,7 @@ export function runCreateAction(
return created.value;
},
shouldInsert,
+ openCreated,
});
return;
case 'form':
@@ -466,6 +485,7 @@ export function runCreateAction(
return created.value.form.id;
},
shouldInsert,
+ openCreated,
});
return;
case 'code':
@@ -484,6 +504,7 @@ export function runCreateAction(
return result.value.documentId ?? undefined;
},
shouldInsert,
+ openCreated,
});
return;
case 'routine':
diff --git a/apps/web/src/features/command/types.ts b/apps/web/src/features/command/types.ts
index ff4875e64d..313e87a3a2 100644
--- a/apps/web/src/features/command/types.ts
+++ b/apps/web/src/features/command/types.ts
@@ -4,6 +4,15 @@ import type { HotkeyRegistrationOptions } from '@core/hotkey/types';
export type CreatableName = BlockName | BlockAlias | 'initiative';
+/**
+ * Shows a created item in the surface that asked to create it, which stays
+ * mounted while the item is created. Returning false opens it in a split.
+ */
+export type OpenCreatedItem = (item: {
+ blockName: BlockName | BlockAlias;
+ id: string;
+}) => boolean;
+
export type CreatableBlock = Omit<HotkeyRegistrationOptions, 'scopeId'> & {
label: string;
launcherHint?: string;
diff --git a/apps/web/src/features/drive-view/components/DriveDetailView.tsx b/apps/web/src/features/drive-view/components/DriveDetailView.tsx
index 45142f8ec3..6c5da3b42e 100644
--- a/apps/web/src/features/drive-view/components/DriveDetailView.tsx
+++ b/apps/web/src/features/drive-view/components/DriveDetailView.tsx
@@ -52,6 +52,19 @@ function markdownKind(target: DocumentDetailTarget): MarkdownDocumentKind {
return 'document';
}
+/**
+ * Spreadsheets, databases and forms use their live block in PreviewPanel,
+ * which supplies its own title, sharing controls and the enclosing ViewShell's
+ * sidebar toggle.
+ */
+function hasBlockHeader(target: EntityDetailTarget) {
+ return (
+ target.type === 'database' ||
+ target.type === 'form' ||
+ entityDetailBlockType(target) === 'spreadsheet'
+ );
+}
+
function DriveDetailTopBar() {
const navigationStack = useDriveDetailNavigation();
const panel = useSplitPanelOrThrow();
@@ -155,19 +168,10 @@ function StackEntityDetail(props: {
}}
</Match>
<Match when={true}>
- <Show when={props.entry.data.type !== 'document'}>
- <EntityDetailBreadcrumbItem
- entry={props.entry}
- order={props.order}
- setsSplitDisplayName
- />
- </Show>
<EntityDetail
target={props.entry.data}
previewHeaderLeading={
- <Show
- when={entityDetailBlockType(props.entry.data) === 'spreadsheet'}
- >
+ <Show when={hasBlockHeader(props.entry.data)}>
<DriveBreadcrumbsOutlet
aria-label="File location"
class="max-w-[min(40vw,24rem)] overflow-hidden"
@@ -216,11 +220,9 @@ export function DriveDetailView() {
const breadcrumbOrderOffset = () =>
driveLocationBreadcrumbs(state.value().location, sidebar.folders()).length;
const navigationStack = useDriveDetailNavigation();
- // Spreadsheets use their live block in PreviewPanel, which supplies its own
- // header, sharing controls and the enclosing ViewShell's sidebar toggle.
- const hasBlockHeader = () => {
+ const activeHasBlockHeader = () => {
const target = navigationStack.active()?.data;
- return target && entityDetailBlockType(target) === 'spreadsheet';
+ return target !== undefined && hasBlockHeader(target);
};
return (
@@ -228,7 +230,7 @@ export function DriveDetailView() {
<DriveDetailAncestorBreadcrumbs orderOffset={breadcrumbOrderOffset()} />
<SidePanel.Root floating>
<div class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden">
- <Show when={!hasBlockHeader()}>
+ <Show when={!activeHasBlockHeader()}>
<DriveDetailTopBar />
</Show>
<div class="relative min-h-0 min-w-0 flex-1">
diff --git a/apps/web/src/features/drive-view/context/drive-context.tsx b/apps/web/src/features/drive-view/context/drive-context.tsx
index c7db2affa0..8c5cffdb1a 100644
--- a/apps/web/src/features/drive-view/context/drive-context.tsx
+++ b/apps/web/src/features/drive-view/context/drive-context.tsx
@@ -1,3 +1,4 @@
+import type { OpenCreatedItem } from '@app/features/command/types';
import type { EntityData, ProjectEntity, SearchLocation } from '@entity';
import type { Favorite } from '@service-storage/generated/schemas/favorite';
import { type Accessor, createContext, useContext } from 'solid-js';
@@ -15,6 +16,7 @@ export type DriveHostActions = {
newSplit?: boolean
) => void;
openFavorite: (favorite: Favorite, name: string, event: MouseEvent) => void;
+ openCreated: OpenCreatedItem;
openFolderInNewSplit: (folder: ProjectEntity) => void;
shareFolder: (folder: ProjectEntity) => void;
uploadFiles: () => void;
diff --git a/apps/web/src/features/drive-view/drive-create-menu.test.tsx b/apps/web/src/features/drive-view/drive-create-menu.test.tsx
index 27a641ea24..6a8b213e94 100644
--- a/apps/web/src/features/drive-view/drive-create-menu.test.tsx
+++ b/apps/web/src/features/drive-view/drive-create-menu.test.tsx
@@ -6,6 +6,7 @@ import { DriveCreateMenu } from './drive-create-menu';
const host = vi.hoisted(() => ({
runCreateAction: vi.fn(),
selectFolder: vi.fn(),
+ openCreated: vi.fn(),
}));
const [projectId, setProjectId] = createSignal<string | undefined>('child');
@@ -40,7 +41,11 @@ vi.mock('./context/drive-context', () => ({
{ id: 'child', name: 'Wireframes', parentId: 'root', userId: 'user' },
],
},
- actions: { uploadFiles: vi.fn(), uploadFolder: vi.fn() },
+ actions: {
+ uploadFiles: vi.fn(),
+ uploadFolder: vi.fn(),
+ openCreated: host.openCreated,
+ },
}),
}));
@@ -69,7 +74,7 @@ it('names the open folder as the destination', async () => {
expect(menu.textContent).toContain('Wireframes');
});
-it('creates files inside the open folder', async () => {
+it('creates files inside the open folder and opens them there', async () => {
await openMenu();
fireEvent.keyDown(screen.getByRole('menuitem', { name: 'Document' }), {
key: 'Enter',
@@ -79,6 +84,7 @@ it('creates files inside the open folder', async () => {
projectId: 'child',
source: 'drive',
destination: 'Wireframes',
+ openCreated: host.openCreated,
});
});
@@ -91,6 +97,7 @@ it('opens a folder composer inside the current folder', async () => {
projectId: 'child',
source: 'drive',
destination: 'Wireframes',
+ openCreated: host.openCreated,
});
});
@@ -111,6 +118,7 @@ it('offers the same menu from the list header toolbar', async () => {
projectId: 'child',
source: 'drive',
destination: 'Wireframes',
+ openCreated: host.openCreated,
});
});
@@ -129,5 +137,6 @@ it('opens a folder composer at the Drive root outside a folder', async () => {
projectId: undefined,
source: 'drive',
destination: 'Drive',
+ openCreated: host.openCreated,
});
});
diff --git a/apps/web/src/features/drive-view/drive-create-menu.tsx b/apps/web/src/features/drive-view/drive-create-menu.tsx
index bf458d62f7..733a5a1562 100644
--- a/apps/web/src/features/drive-view/drive-create-menu.tsx
+++ b/apps/web/src/features/drive-view/drive-create-menu.tsx
@@ -79,6 +79,7 @@ export function DriveCreateMenu(props: {
projectId: state.projectId(),
source: 'drive',
destination: destination(),
+ openCreated: actions.openCreated,
});
};
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 4df045b49c..b8875da097 100644
--- a/apps/web/src/features/drive-view/drive-detail-navigation.tsx
+++ b/apps/web/src/features/drive-view/drive-detail-navigation.tsx
@@ -20,9 +20,9 @@ import {
import type { DriveLocation } from './core/types';
import { driveDestination } from './drive-route-navigation';
import {
- type DriveDocumentTarget,
- documentRouteFromTarget,
- documentTargetFromRoute,
+ type DriveDetailTarget,
+ detailRouteFromTarget,
+ detailTargetFromRoute,
sameDocumentRoute,
} from './primitives/drive-detail-trail';
import {
@@ -77,17 +77,17 @@ export function DriveDetailNavigationProvider(
const activeDocument = createMemo(() => driveDocumentFromParams(params));
const activeCallId = () => params.callId;
const activeTarget = createMemo(() =>
- documentTargetFromRoute(activeDocument())
+ detailTargetFromRoute(activeDocument())
);
createEffect(on(activeTarget, (target) => selectPreview(target)));
- const trail = (): DriveDocumentTarget[] => {
+ const trail = (): DriveDetailTarget[] => {
const restored = routeTrail();
const endpoint = restored?.at(-1);
const endpointMatches =
endpoint !== undefined &&
- sameDocumentRoute(documentRouteFromTarget(endpoint), activeDocument());
+ sameDocumentRoute(detailRouteFromTarget(endpoint), activeDocument());
if (restored && endpointMatches) return restored;
const target = activeTarget();
@@ -97,7 +97,7 @@ export function DriveDetailNavigationProvider(
const entries = createMemo<EntityDetailNavigationEntry[]>(() =>
trail().map((target, index) => ({
- value: `drive-detail:${index}:${documentRouteFromTarget(target).type}:${target.id}`,
+ value: `drive-detail:${index}:${detailRouteFromTarget(target).type}:${target.id}`,
data: target,
}))
);
@@ -107,11 +107,23 @@ export function DriveDetailNavigationProvider(
target: EntityDetailTarget,
options?: EntityDetailNavigationOptions
):
- | { target: DriveDocumentTarget; document: DriveDocumentRoute }
+ | { target: DriveDetailTarget; document: DriveDocumentRoute }
| undefined => {
- if (target.type !== 'document') return;
if (!opensInline(options)) return;
+ if (target.type === 'database' || target.type === 'form') {
+ if (!selectPreview(target)) return;
+ return {
+ target: {
+ type: target.type,
+ id: target.id,
+ fallbackName: target.fallbackName,
+ },
+ document: { id: target.id, type: target.type },
+ };
+ }
+ if (target.type !== 'document') return;
+
const blockType = entityDetailBlockType(target);
if (!blockType) return;
if (!selectPreview(target)) return;
@@ -139,7 +151,7 @@ export function DriveDetailNavigationProvider(
const endpoint = currentTrail.at(-1);
const endpointMatches =
endpoint !== undefined &&
- sameDocumentRoute(documentRouteFromTarget(endpoint), resolved.document);
+ sameDocumentRoute(detailRouteFromTarget(endpoint), resolved.document);
if (endpointMatches) return true;
navigate(driveDestination(props.location(), resolved.document), {
@@ -183,14 +195,16 @@ export function DriveDetailNavigationProvider(
.slice(0, entryIndex + 1)
.map((candidate) => candidate.data)
.filter(
- (candidate): candidate is DriveDocumentTarget =>
- candidate.type === 'document'
+ (candidate): candidate is DriveDetailTarget =>
+ candidate.type === 'document' ||
+ candidate.type === 'database' ||
+ candidate.type === 'form'
);
const target = nextTrail.at(-1);
if (!target) return;
navigate(
- driveDestination(props.location(), documentRouteFromTarget(target)),
+ driveDestination(props.location(), detailRouteFromTarget(target)),
{ state: nextTrail }
);
},
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 9cf931e47e..03e11f3be3 100644
--- a/apps/web/src/features/drive-view/drive-host-actions.ts
+++ b/apps/web/src/features/drive-view/drive-host-actions.ts
@@ -1,4 +1,7 @@
-import { entityDetailTarget } from '@app/components/entity-detail/entity-detail-target';
+import {
+ type EntityDetailTarget,
+ entityDetailTarget,
+} from '@app/components/entity-detail/entity-detail-target';
import { makeShareAction } from '@app/features/next-soup/actions';
import {
markCalendarNotificationSeenOnOpen,
@@ -20,9 +23,31 @@ import {
openFilePicker,
openFolderPicker,
} from '@core/util/upload';
+import type { EntityData } from '@entity';
import type { Accessor } from 'solid-js';
import type { DriveHostActions } from './context/drive-context';
import { useDriveDetailNavigation } from './drive-detail-navigation';
+import { detailTargetFromRoute } from './primitives/drive-detail-trail';
+import { driveDocumentFromContent } from './primitives/drive-route';
+
+function inlineDetailTarget(
+ entity: EntityData
+): EntityDetailTarget | undefined {
+ if (entity.type === 'document') {
+ return entityDetailTarget.document({
+ id: entity.id,
+ fileType: entity.fileType,
+ subType: entity.subType,
+ fallbackName: entity.name,
+ });
+ }
+ if (entity.type === 'database' || entity.type === 'form') {
+ return entityDetailTarget.fromSelection(
+ { type: entity.type, id: entity.id },
+ entity.name
+ );
+ }
+}
/** App-specific navigation, upload and sharing adapters for the Drive workspace. */
export function createDriveHostActions(options: {
@@ -71,16 +96,9 @@ export function createDriveHostActions(options: {
markCalendarNotificationSeenOnOpen(entity, notificationSource);
- if (entity.type === 'document' && !openInNewSplit && !location) {
- const target = entityDetailTarget.document({
- id: entity.id,
- fileType: entity.fileType,
- subType: entity.subType,
- fallbackName: entity.name,
- });
-
- if (navigation.openRoot(target, { event })) return;
- }
+ const target =
+ openInNewSplit || location ? undefined : inlineDetailTarget(entity);
+ if (target && navigation.openRoot(target, { event })) return;
void openEntityInSplitFromUnifiedList(entity, {
splitHandle: panel.handle,
@@ -126,6 +144,19 @@ export function createDriveHostActions(options: {
return;
}
+ if (
+ (favorite.entityType === 'database' ||
+ favorite.entityType === 'form') &&
+ navigation.openRoot(
+ entityDetailTarget.fromSelection(
+ { type: favorite.entityType, id: favorite.entityId },
+ name
+ ),
+ { event, location: { kind: 'tab', tab: 'owned' } }
+ )
+ )
+ return;
+
const result = layout.openWithSplit(favoriteSplitContent(favorite), {
referredFrom: 'sidebar',
preferNewSplit: event.shiftKey,
@@ -135,6 +166,17 @@ export function createDriveHostActions(options: {
}
},
+ openCreated({ blockName, id }) {
+ const target =
+ blockName === 'database' || blockName === 'form'
+ ? { type: blockName, id }
+ : detailTargetFromRoute(
+ driveDocumentFromContent({ type: blockName, id })
+ );
+
+ return target !== undefined && navigation.openRoot(target);
+ },
+
openFolderInNewSplit: (folder) => {
layout.openWithSplit(
{ type: 'project', id: folder.id },
diff --git a/apps/web/src/features/drive-view/primitives/drive-detail-trail.test.ts b/apps/web/src/features/drive-view/primitives/drive-detail-trail.test.ts
new file mode 100644
index 0000000000..7b8196f245
--- /dev/null
+++ b/apps/web/src/features/drive-view/primitives/drive-detail-trail.test.ts
@@ -0,0 +1,106 @@
+import {
+ createRoutesManifest,
+ decodePane,
+ routeParams,
+} from '@app/lib/split-router';
+import {
+ appRoute,
+ driveFolderDocumentRoute,
+ driveFolderRoute,
+ driveRootDocumentRoute,
+ driveSplitRoute,
+ homeDocumentRoute,
+ homePreviewRoute,
+ homeSplitRoute,
+} from '@app/routes/routes';
+import { describe, expect, it, vi } from 'vitest';
+import {
+ detailRouteFromTarget,
+ detailTargetFromRoute,
+ driveDetailTrailSchema,
+} from './drive-detail-trail';
+
+vi.mock('@service-storage/websocket', () => ({
+ storageWS: { reconnectIfDisconnected: vi.fn() },
+ createWebSocketJob: vi.fn(),
+}));
+vi.mock('@service-connection/websocket', () => ({
+ ws: { addEventListener: vi.fn(), send: vi.fn() },
+ state: () => 'closed',
+ createConnectionBlockWebsocketEffect: vi.fn(),
+ createConnectionWebsocketEffect: vi.fn(),
+}));
+
+const routes = createRoutesManifest({
+ definitions: [
+ {
+ ...appRoute,
+ children: [
+ {
+ ...driveSplitRoute,
+ children: [
+ { ...driveFolderRoute, children: [driveFolderDocumentRoute] },
+ driveRootDocumentRoute,
+ ],
+ },
+ {
+ ...homeSplitRoute,
+ children: [homeDocumentRoute, homePreviewRoute],
+ },
+ ],
+ },
+ ],
+ defaultRoute: () => ({ matches: [{ id: 'app', params: {} }] }),
+});
+
+const leaf = (path: string) => {
+ const route = decodePane(routes, path.split('/'));
+ return route && { id: route.matches.at(-1)?.id, ...routeParams(route) };
+};
+
+describe('Drive details for databases and forms', () => {
+ it.each(['database', 'form'] as const)(
+ 'opens a %s inline in Drive and keeps Home on its block preview',
+ (type) => {
+ expect(leaf(`drive/${type}/item-1`)).toMatchObject({
+ id: 'drive-document',
+ documentType: type,
+ documentId: 'item-1',
+ });
+ expect(leaf(`drive/folder/folder-1/${type}/item-1`)).toMatchObject({
+ id: 'drive-folder-document',
+ documentType: type,
+ });
+ expect(leaf(`home/${type}/item-1`)).toMatchObject({
+ id: 'home-preview',
+ blockType: type,
+ });
+ }
+ );
+
+ it.each(['database', 'form'] as const)(
+ 'round-trips a %s between its route and its trail entry',
+ (type) => {
+ const target = detailTargetFromRoute({ id: 'item-1', type });
+
+ expect(target).toEqual({ type, id: 'item-1' });
+ expect(detailRouteFromTarget(target!)).toEqual({ id: 'item-1', type });
+ expect(driveDetailTrailSchema.safeParse([target]).success).toBe(true);
+ }
+ );
+
+ it('keeps document subtypes on their markdown file type', () => {
+ const snippet = detailTargetFromRoute({ id: 'doc-1', type: 'snippet' });
+
+ expect(snippet).toEqual({
+ type: 'document',
+ id: 'doc-1',
+ fileType: 'md',
+ subType: { type: 'snippet' },
+ });
+ expect(detailRouteFromTarget(snippet!)).toEqual({
+ id: 'doc-1',
+ type: 'snippet',
+ });
+ });
+});
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
index e12d7cdfae..9d229240a1 100644
--- a/apps/web/src/features/drive-view/primitives/drive-detail-trail.ts
+++ b/apps/web/src/features/drive-view/primitives/drive-detail-trail.ts
@@ -16,13 +16,24 @@ export const driveDocumentTargetSchema = z.object({
fallbackName: z.string().optional(),
});
-export const driveDetailTrailSchema = z.array(driveDocumentTargetSchema).min(1);
+const driveDatabaseTargetSchema = z.object({
+ type: z.enum(['database', 'form']),
+ id: z.string().min(1),
+ fallbackName: z.string().optional(),
+});
-export type DriveDocumentTarget = z.infer<typeof driveDocumentTargetSchema>;
+const driveDetailTargetSchema = z.union([
+ driveDocumentTargetSchema,
+ driveDatabaseTargetSchema,
+]);
-export function documentTargetFromRoute(
+export const driveDetailTrailSchema = z.array(driveDetailTargetSchema).min(1);
+
+export type DriveDetailTarget = z.infer<typeof driveDetailTargetSchema>;
+
+export function detailTargetFromRoute(
document: DriveDocumentRoute | undefined
-): DriveDocumentTarget | undefined {
+): DriveDetailTarget | undefined {
if (!document) return;
const target = {
@@ -31,6 +42,9 @@ export function documentTargetFromRoute(
};
switch (document.type) {
+ case 'database':
+ case 'form':
+ return { type: document.type, id: document.id };
case 'task':
return {
...target,
@@ -49,9 +63,11 @@ export function documentTargetFromRoute(
}
}
-export function documentRouteFromTarget(
- target: DriveDocumentTarget
+export function detailRouteFromTarget(
+ target: DriveDetailTarget
): DriveDocumentRoute {
+ if (target.type !== 'document') return { id: target.id, type: target.type };
+
return driveDocumentRoute({
id: target.id,
fileType: target.fileType ?? 'unknown',
diff --git a/apps/web/src/features/drive-view/primitives/drive-route-schema.ts b/apps/web/src/features/drive-view/primitives/drive-route-schema.ts
index 749bcfb3a0..1683a048f6 100644
--- a/apps/web/src/features/drive-view/primitives/drive-route-schema.ts
+++ b/apps/web/src/features/drive-view/primitives/drive-route-schema.ts
@@ -15,6 +15,18 @@ export const DRIVE_DOCUMENT_TYPES = [
export type DriveDocumentType = (typeof DRIVE_DOCUMENT_TYPES)[number];
+/**
+ * Everything Drive opens inline. Databases and forms open here only from
+ * Drive itself: their links keep their own routes rather than redirecting.
+ */
+export const DRIVE_DETAIL_TYPES = [
+ ...DRIVE_DOCUMENT_TYPES,
+ 'database',
+ 'form',
+] as const;
+
+export type DriveDetailType = (typeof DRIVE_DETAIL_TYPES)[number];
+
export function driveDocumentBlockType(type: string) {
if (type === 'task' || type === 'snippet' || type === 'skill') return 'md';
return type === 'csv' ? 'code' : 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 bc833bda5e..5e7bbe6a1c 100644
--- a/apps/web/src/features/drive-view/primitives/drive-route.ts
+++ b/apps/web/src/features/drive-view/primitives/drive-route.ts
@@ -4,16 +4,16 @@ import { z } from 'zod';
import type { DriveLocation, DriveTab } from '../core/types';
import {
DRIVE_DOCUMENT_TYPES,
- type DriveDocumentType,
+ type DriveDetailType,
} from './drive-route-schema';
-export type DriveDocumentRoute = { id: string; type: DriveDocumentType };
+export type DriveDocumentRoute = { id: string; type: DriveDetailType };
export type DriveRouteParams = SplitRouteParams & {
tab?: DriveTab;
view?: 'folder';
folderId?: string;
documentId?: string;
- documentType?: DriveDocumentType;
+ documentType?: DriveDetailType;
};
const documentType = z.enum(DRIVE_DOCUMENT_TYPES);
diff --git a/apps/web/src/routes/routes.ts b/apps/web/src/routes/routes.ts
index e0d54bcf07..d0cae619bc 100644
--- a/apps/web/src/routes/routes.ts
+++ b/apps/web/src/routes/routes.ts
@@ -12,6 +12,7 @@ import { changesSearch } from '@app/features/changes/changes-search';
import { crmViewReference } from '@app/features/crm/crm-route';
import { driveDetailTrailSchema } from '@app/features/drive-view/primitives/drive-detail-trail';
import {
+ DRIVE_DETAIL_TYPES,
DRIVE_DOCUMENT_TYPES,
driveDocumentBlockType,
} from '@app/features/drive-view/primitives/drive-route-schema';
@@ -189,7 +190,7 @@ export const driveCallRoute = defineRoute({
});
const driveDocumentParams = z.object({
- documentType: z.enum(DRIVE_DOCUMENT_TYPES),
+ documentType: z.enum(DRIVE_DETAIL_TYPES),
documentId: z.string().min(1),
});
@@ -370,6 +371,11 @@ export const homeChannelRoute = defineRoute({
export const homeDocumentRoute = defineRoute({
...driveRootDocumentRoute,
id: 'home-document',
+ // Home previews databases and forms as blocks under `home-preview`.
+ params: z.object({
+ documentType: z.enum(DRIVE_DOCUMENT_TYPES),
+ documentId: z.string().min(1),
+ }),
externalSearch: (entry: Readonly<Entry>) => {
const type = routeParams(entry.location.route).documentType;
if (
diff --git a/docs/AGENT_GUIDE/databases.md b/docs/AGENT_GUIDE/databases.md
index 6ea6b455ac..da3d7337f5 100644
--- a/docs/AGENT_GUIDE/databases.md
+++ b/docs/AGENT_GUIDE/databases.md
@@ -15,7 +15,9 @@ it before the module loads cancels creation.
A successful create opens its new editor while database discovery refreshes in
the background; a slow discovery refresh must not delay the new database card.
Databases open at
-`/app/database/<uuid>`. A database contains tables; records belong to a table and
+`/app/database/<uuid>`; from Drive (its list, favorites, or **New → Database**)
+they open inline at `/app/drive/database/<uuid>` with Drive's sidebar in place.
+A database contains tables; records belong to a table and
its properties describe each record. The database name in the split header is an
inline input for editors: click it to rename. Enter or leaving it saves; Escape
cancels, and a failed rename shows a toast. Viewers without edit access see the
diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.md
index 7e8cae6b45..ce24d272cf 100644
--- a/docs/AGENT_GUIDE/documents.md
+++ b/docs/AGENT_GUIDE/documents.md
@@ -149,7 +149,10 @@ flag in every environment. Team targeting is configured in PostHog; ordinary
document permissions continue to control access to each workbook.
Choose **Create → Spreadsheet**, or **New → Spreadsheet** in Files or a folder.
-Native workbooks open at `/app/spreadsheet/<uuid>` and use the normal document
+From Files the new workbook opens inline in the open folder or tab
+(`/app/drive/.../spreadsheet/<uuid>`) without reloading Drive.
+`/app/spreadsheet/<uuid>` links redirect into Drive on desktop. Native workbooks
+use the normal document
title bar with **Ask Macro** and **Share** at the top right. The **File actions**
ellipsis beside the title uses the same menu as documents, including rename,
favorite, move, copy, and permission-appropriate file actions. Native spreadsheets
diff --git a/docs/AGENT_GUIDE/forms.md b/docs/AGENT_GUIDE/forms.md
index 66a73ff952..1a5b918f2a 100644
--- a/docs/AGENT_GUIDE/forms.md
+++ b/docs/AGENT_GUIDE/forms.md
@@ -15,7 +15,8 @@ decides who may respond.
- **Create → Form** (shortcut **C → Q**, **Shift** opens it in a new split)
creates "Untitled form" with a new database whose table is "Responses",
- and opens the builder at `/app/form/<uuid>`.
+ and opens the builder at `/app/form/<uuid>`. Drive's **New → Form** opens
+ it inline instead, at `/app/drive/form/<uuid>`.
- On a database page you own, **+ → New form** in the table selector makes
a form with a question per existing column while no form writes to the current
table. Each table has at most one form; the control opens that form once created.
@@ -140,7 +141,8 @@ rows stay.
## Finding forms
-Drive lists forms you can open (type facet **Form**), and Quick Access has a
+Drive lists forms you can open (type facet **Form**) and opens them inline at
+`/app/drive/form/<uuid>`, and Quick Access has a
Forms bucket. Both come from `/forms/accessible`, so a form shared with you
appears without access to its database. Deleting a database table warns which
forms it deletes; deleting a column warns which forms ask it (both say so
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 629283d323..2d1f9ad56c 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -105,7 +105,7 @@ successfully rather than hashing the empty JavaScript placeholder.
| `/app/drive/<recent-or-shared>` | A Drive tab (`/app/drive/tab/<...>` remains a compatibility alias) |
| `/app/drive/folder/<uuid>` | A Drive folder; breadcrumbs resolve from current accessible folder data |
| `/app/drive/<document-type>/<uuid>` | An item opened inline in My Files |
-| `/app/drive/folder/<uuid>/<document-type>/<uuid>` | An item opened inline in its Drive folder; document types include `md`, `task`, `skill`, `snippet`, `canvas`, `pdf`, `code`, `csv`, `image`, `video`, `spreadsheet`, and `unknown` |
+| `/app/drive/folder/<uuid>/<document-type>/<uuid>` | An item opened inline in its Drive folder; document types include `md`, `task`, `skill`, `snippet`, `canvas`, `pdf`, `code`, `csv`, `image`, `video`, `spreadsheet`, and `unknown`. Databases and forms opened from Drive use `database` and `form` |
| `/app/tasks` | Tasks table |
| `/app/tasks/<uuid>` | Tasks with a task document opened inline |
| `/app/agents` | AI chats / agents list |
@@ -122,7 +122,7 @@ successfully rather than hashing the empty JavaScript placeholder.
| `/app/activity` | Activity heatmap + feed |
| `/app/calendar/<month-or-week-or-day>` | Calendar; the focused event, its occurrence, and the locator range use `sN.calendar.*` |
| `/app/<document-type>/<uuid>` | Legacy document URL (including `md`, `pdf`, `canvas`, `spreadsheet`, and the other Drive document types); redirects to `/app/drive/<document-type>/<uuid>` |
-| `/app/database/<uuid>` | A database with table and board views; stays at this URL rather than moving into Drive (requires the Databases flag) |
+| `/app/database/<uuid>` | A database with table and board views (requires the Databases flag). Links and opens outside Drive stay at this URL; opened from Drive, it shows inline at `/app/drive/database/<uuid>` |
| `/app/documents`, `/app/files` | Legacy Files views; redirect to `/app/drive` |
| `/app/chat/<uuid>` | A standalone AI chat |
| `/app/routines` | Routines list in the Agents workspace |
@@ -239,8 +239,13 @@ buttons; beside the title in narrow layouts) is headed
**Create in &lt;folder&gt;** and creates everything in the open folder; on a tab or
the Drive root it reads **Create in Drive**. **Folder** opens a **New folder**
dialog with `Untitled folder` preselected; creating keeps Drive where it is, adds
-the folder to the open folder's list, and shows a toast with **Open**. Other
-items open after creation. **Database** is offered only outside folders.
+the folder to the open folder's list, and shows a toast with **Open**. Every other
+item opens as an inline detail in the open folder or tab once created
+(`/app/drive/folder/<uuid>/spreadsheet/<uuid>`, `/app/drive/database/<uuid>`),
+the same as opening an existing file: the Drive sidebar stays mounted and no
+loading pane replaces Drive. Databases and forms opened from Drive's list or
+favorites show inline the same way. **Database** and **Form** are offered only
+outside folders.
Home, Email, Tasks, Channels, and Drive keep their workspace provider mounted
while typed child routes own the accepted inline detail. Tasks and Email replace
the list with detail, capturing its focus and scroll state before disposal. Their child