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(databases): add Drive context-menu entity actions
Wolf Mermelsteind0a4f2541047
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 44cc0bd295..4e7b5ce021 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -190,6 +190,9 @@ The shared plain-text Lexical codec is `packages/lexical-core/canvas-text.ts`.## Development Patterns+Route database row rename and delete through `renameDatabase` and+`trashDatabase`; use the row grant for rename, delete, and sharing permissions.+Shared diff and Changes views expand files with at most 40 additions + deletionsby default; keep saved per-capture choices and explicit toggles authoritative.Use `/app/debug/diff-view-ui` to exercise the 40/41-line boundary.diff --git a/apps/web/src/features/entity/queries/dss.test.tsx b/apps/web/src/features/entity/queries/dss.test.tsxindex 29e71b324e..91d9c091b4 100644--- a/apps/web/src/features/entity/queries/dss.test.tsx+++ b/apps/web/src/features/entity/queries/dss.test.tsx@@ -4,7 +4,7 @@ import {QueryClient,QueryClientProvider,} from '@tanstack/solid-query';-import { err, ok } from 'neverthrow';+import { err, errAsync, ok, okAsync } from 'neverthrow';import { render } from 'solid-js/web';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import type { TaskEntity } from '../types/entity';@@ -16,6 +16,8 @@ const mocks = vi.hoisted(() => ({deleteCallGraphql: vi.fn(),deleteReminder: vi.fn(),deleteSchedule: vi.fn(),+ trashDatabase: vi.fn(),+ graphqlClient: { mutation: vi.fn() },moveToFolder: vi.fn(),copyItem: vi.fn(),removeSoup: vi.fn(),@@ -25,6 +27,9 @@ const mocks = vi.hoisted(() => ({refresh: vi.fn(),failure: vi.fn(),}));+vi.mock('@block-database/queries/trash-database', () => ({+ trashDatabase: mocks.trashDatabase,+}));vi.mock('@core/component/FileList/itemOperations', () => ({deleteItem: mocks.deleteItem,copyItem: mocks.copyItem,@@ -72,6 +77,9 @@ vi.mock('@service-scheduled-action/client', () => ({vi.mock('@service-storage/client', () => ({storageServiceClient: { reminders: { deleteReminder: mocks.deleteReminder } },}));+vi.mock('@service-storage/graphql-soup', () => ({+ getEntityGraphqlClient: () => mocks.graphqlClient,+}));import { scheduledActionKeys } from '@app/features/routines/queries/keys';import { callKeys } from '@queries/call/keys';@@ -134,6 +142,7 @@ beforeEach(() => {mocks.removeSearch.mockReturnValue({ rollback: mocks.rollbackSearch });mocks.refresh.mockResolvedValue(undefined);mocks.deleteItem.mockResolvedValue(true);+ mocks.trashDatabase.mockReturnValue(okAsync(undefined));mocks.moveToFolder.mockResolvedValue(true);mocks.copyItem.mockResolvedValue('copied-task');onlineManager.setOnline(true);@@ -375,6 +384,34 @@ describe('bulk delete GraphQL optimism', () => {);});+ it('trashes databases through the database API instead of DSS delete', async () => {+ const { mutation } = mount();+ await expect(+ mutation.mutateAsync([entity('db-1', 'database')])+ ).resolves.toEqual([true]);+ expect(mocks.trashDatabase).toHaveBeenCalledWith(+ mocks.graphqlClient,+ 'db-1'+ );+ expect(mocks.deleteItem).not.toHaveBeenCalled();+ });++ it.each([true, false])(+ 'restores a refused database deletion with GraphQL Soup enabled=%s',+ async (enabled) => {+ vi.spyOn(console, 'error').mockImplementation(() => {});+ mocks.graphqlEnabled.mockReturnValue(enabled);+ mocks.trashDatabase.mockReturnValue(errAsync({ kind: 'unreachable' }));+ const { mutation } = mount();+ await expect(+ mutation.mutateAsync([entity('db-1', 'database')])+ ).rejects.toBeDefined();+ expect(mocks.rollbackSoup).toHaveBeenCalled();+ expect(mocks.rollbackSearch).toHaveBeenCalled();+ expect(mocks.failure).toHaveBeenCalled();+ }+ );+it('does not remove or invalidate unsuccessful side-effect entities', async () => {vi.spyOn(console, 'error').mockImplementation(() => {});const invalidate = vidiff --git a/apps/web/src/features/entity/queries/dss.ts b/apps/web/src/features/entity/queries/dss.tsindex f08dfa3bba..857b528f3b 100644--- a/apps/web/src/features/entity/queries/dss.ts+++ b/apps/web/src/features/entity/queries/dss.ts@@ -1,6 +1,8 @@/** Document-storage mutations used by entity surfaces. */+import { databaseEntityMessage } from '@app/features/database/core/write-failure';import { scheduledActionKeys } from '@app/features/routines/queries/keys';+import { trashDatabase } from '@block-database/queries/trash-database';import {canDuplicateItemType,copyItem,@@ -36,6 +38,7 @@ import { ownTouchStamp } from '@queries/soup/normalized-cache/own-touch';import { permanentlyDeleteEntity } from '@queries/storage/entity-mutations';import { callServiceClient } from '@service-call/client';import { scheduledActionClient } from '@service-scheduled-action/client';+import { getEntityGraphqlClient } from '@service-storage/graphql-soup';import { useMutation } from '@tanstack/solid-query';import { batch } from 'solid-js';import { type EntityData, getEntityProjectId } from '../types/entity';@@ -105,7 +108,8 @@ export function createBulkDeleteDssItemsMutation() {type === 'document' ||type === 'project' ||type === 'call' ||- type === 'routine'+ type === 'routine' ||+ type === 'database');};const isCurrentContext = (context: unknown) =>@@ -141,6 +145,17 @@ export function createBulkDeleteDssItemsMutation() {scheduledActionClient.deleteSchedule({ scheduleId: e.id })).then(() => true);}+ if (e.type === 'database') {+ await throwOnErr(() =>+ trashDatabase(getEntityGraphqlClient(), e.id).mapErr((failure) => [+ {+ code: failure.kind,+ message: databaseEntityMessage(failure, 'delete'),+ },+ ])+ );+ return true;+ }return deleteItem({ id: e.id, itemType: e.type });});const results = graphqlSoupEnableddiff --git a/apps/web/src/features/entity/queries/rename.test.tsx b/apps/web/src/features/entity/queries/rename.test.tsxindex 40761448f8..85db5aacd4 100644--- a/apps/web/src/features/entity/queries/rename.test.tsx+++ b/apps/web/src/features/entity/queries/rename.test.tsx@@ -10,6 +10,7 @@ import {type Exchange,type Operation,} from '@urql/core';+import { err, ok } from 'neverthrow';import { render } from 'solid-js/web';import { afterEach, expect, it, vi } from 'vitest';import { filter, map, pipe } from 'wonka';@@ -23,16 +24,22 @@ const mocks = vi.hoisted(() => ({history: vi.fn(),soup: vi.fn(),toast: vi.fn(),+ renameDatabase: vi.fn(),+ renameItem: vi.fn(),+ graphqlEnabled: vi.fn(() => true),+}));+vi.mock('@block-database/queries/rename-database', () => ({+ renameDatabase: mocks.renameDatabase,}));vi.mock('@core/component/FileList/itemOperations', () => ({- renameItem: vi.fn(),+ renameItem: mocks.renameItem,}));vi.mock('@core/component/Toast/Toast', () => ({toast: { failure: mocks.toast },}));vi.mock('@core/constant/featureFlags', () => ({enableGraphqlSoup: {},- isFeatureEnabled: () => true,+ isFeatureEnabled: mocks.graphqlEnabled,}));vi.mock('@queries/agent-session/entity-mutations', () => ({renameAgentSession: vi.fn(),@@ -60,7 +67,10 @@ vi.mock('@service-storage/graphql-soup', () => ({import { callKeys } from '@queries/call/keys';import { channelKeys } from '@queries/channel/keys';-import { createRenameDssEntityMutation } from './rename';+import {+ createBulkRenameDssEntityMutation,+ createRenameDssEntityMutation,+} from './rename';let cache: QueryClient;let dispose: (() => void) | undefined;@@ -68,6 +78,7 @@ afterEach(() => {dispose?.();cache.clear();vi.clearAllMocks();+ mocks.graphqlEnabled.mockReturnValue(true);});it.each(['channel', 'call'] as const)(@@ -150,3 +161,106 @@ it.each(['channel', 'call'] as const)(expect(listeners.size).toBe(0);});++it.each(['After', 'Before', ' Before '])(+ 'renames a database to %s through its API only when changed',+ async (newName) => {+ cache = new QueryClient({+ defaultOptions: { mutations: { retry: false } },+ });+ mocks.client = createClient({+ url: 'http://test.invalid',+ exchanges: [],+ });+ mocks.renameDatabase.mockResolvedValue(ok(undefined));+ let mutation!: ReturnType<typeof createRenameDssEntityMutation>;+ dispose = render(+ () => (+ <QueryClientProvider client={cache}>+ {(() => {+ mutation = createRenameDssEntityMutation();+ return null;+ })()}+ </QueryClientProvider>+ ),+ document.createElement('div')+ );+ const result = await mutation.mutateAsync({+ entity: {+ id: 'db-1',+ type: 'database',+ name: 'Before',+ grant: 'owner',+ },+ newName,+ });+ expect(result).toEqual({ success: true });+ if (newName.trim() === 'Before') {+ expect(mocks.renameDatabase).not.toHaveBeenCalled();+ } else {+ expect(mocks.renameDatabase).toHaveBeenCalledWith(+ mocks.client,+ 'db-1',+ newName+ );+ }+ expect(mocks.preview).not.toHaveBeenCalled();+ expect(mocks.soup).not.toHaveBeenCalled();+ }+);++it.each([true, false])(+ 'rolls back only a failed document after a database rename (document success=%s)',+ async (success) => {+ vi.spyOn(console, 'error').mockImplementation(() => {});+ cache = new QueryClient({+ defaultOptions: { mutations: { retry: false } },+ });+ mocks.graphqlEnabled.mockReturnValue(false);+ mocks.renameDatabase.mockResolvedValue(+ success ? err({ kind: 'unreachable' }) : ok(undefined)+ );+ mocks.renameItem.mockResolvedValue(success);+ const rollback = vi.fn();+ mocks.soup.mockReturnValue({ rollback });+ let mutation!: ReturnType<typeof createBulkRenameDssEntityMutation>;+ dispose = render(+ () => (+ <QueryClientProvider client={cache}>+ {(() => {+ mutation = createBulkRenameDssEntityMutation();+ return null;+ })()}+ </QueryClientProvider>+ ),+ document.createElement('div')+ );+ expect(+ await mutation.mutateAsync([+ {+ entity: {+ id: 'db-1',+ type: 'database',+ name: 'Database before',+ grant: 'owner',+ },+ newName: 'Database after',+ },+ {+ entity: { id: 'doc-1', type: 'document', name: 'Document before' },+ newName: 'Document after',+ },+ ])+ ).toEqual([{ success: !success }, { success }]);+ if (success) expect(rollback).not.toHaveBeenCalled();+ else {+ expect(rollback).toHaveBeenCalledOnce();+ expect(mocks.preview).toHaveBeenLastCalledWith({+ itemId: 'doc-1',+ itemType: 'document',+ name: 'Document before',+ });+ }+ vi.restoreAllMocks();+ }+);diff --git a/apps/web/src/features/entity/queries/rename.ts b/apps/web/src/features/entity/queries/rename.tsindex 9c90b6e2a1..f0598ac0ff 100644--- a/apps/web/src/features/entity/queries/rename.ts+++ b/apps/web/src/features/entity/queries/rename.ts@@ -1,3 +1,4 @@+import { renameDatabase } from '@block-database/queries/rename-database';import { renameItem } from '@core/component/FileList/itemOperations';import { toast } from '@core/component/Toast/Toast';import {@@ -110,8 +111,8 @@ const getEntityRenameData = (// Reminders aren't either — the entity-mutation router rejects them, and a// reminder's name is its description, edited through the reminders API.// Calendar event titles are edited through the calendar mutation API.- // Databases are renamed by the database block's `renameDatabase`, which owns- // the schema cache it updates; forms by the form block's `renameForm`.+ // Databases go through `renameDatabase` (not Soup optimism); forms through+ // `renameForm` on the form block.if (entity.type === 'crm_company' ||entity.type === 'crm_contact' ||@@ -131,6 +132,20 @@ const getEntityRenameData = (};const performEntityRename = async (operation: EntityRenameOperation) => {+ if (operation.entity.type === 'database') {+ if (operation.newName.trim() === operation.entity.name) {+ return { success: true };+ }+ const renamed = await renameDatabase(+ getEntityGraphqlClient(),+ operation.entity.id,+ operation.newName+ );+ if (renamed.isErr()) {+ console.error('Failed to rename database', renamed.error);+ }+ return { success: renamed.isOk() };+ }const data = getEntityRenameData(operation);if (!data) return { success: false };if (data.itemType === 'agent_session') {@@ -268,6 +283,7 @@ const validateEntityRename = (entity: RenamableEntity): void => {case 'chat':case 'project':case 'call':+ case 'database':return;case 'foreign':throw new Error('Foreign entities do not support renaming');@@ -525,7 +541,10 @@ const bulkRenameOnSettled = (data.forEach((result, index) => {if (!result.success) {- const update = onMutateResult.updates[index];+ const { entity } = params[index];+ const update = onMutateResult.updates.find(+ ({ id, itemType }) => id === entity.id && itemType === entity.type+ );if (update) {failedUpdates.push(update);const key = soupTransactionKey(update.itemType, update.id);@@ -546,7 +565,7 @@ const bulkRenameOnSettled = (}};-/** Supports channel/document/chat/project/call/agent-session rename. */+/** Supports channel/document/chat/project/call/agent-session/database rename. */export function createRenameDssEntityMutation(callbacks?: MutationCallbacks<RenameDssEntityMutationData,@@ -584,7 +603,7 @@ export function createRenameDssEntityMutation(}));}-/** Supports channel/document/chat/project/call/agent-session bulk rename. */+/** Supports channel/document/chat/project/call/agent-session/database bulk rename. */export function createBulkRenameDssEntityMutation() {return useMutation<BulkRenameDssEntityMutationData,diff --git a/apps/web/src/features/next-soup/actions/make-delete-action.test.ts b/apps/web/src/features/next-soup/actions/make-delete-action.test.tsindex d20c1aaad3..2937bcafb4 100644--- a/apps/web/src/features/next-soup/actions/make-delete-action.test.ts+++ b/apps/web/src/features/next-soup/actions/make-delete-action.test.ts@@ -499,4 +499,9 @@ describe('makeDeleteAction.canExecute', () => {expect(canExecute(entity('initiative'))).toBe(false);expect(canExecute(entity('foreign'))).toBe(false);});+ it('only offers database deletion to its owner', () => {+ expect(canExecute(entity('database', { grant: 'owner' }))).toBe(true);+ expect(canExecute(entity('database', { grant: 'edit' }))).toBe(false);+ expect(canExecute(entity('database', { grant: 'view' }))).toBe(false);+ });});diff --git a/apps/web/src/features/next-soup/actions/make-delete-action.ts b/apps/web/src/features/next-soup/actions/make-delete-action.tsindex 56a12ba862..d85d5d34cb 100644--- a/apps/web/src/features/next-soup/actions/make-delete-action.ts+++ b/apps/web/src/features/next-soup/actions/make-delete-action.ts@@ -99,6 +99,7 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {const { userId } = options;const canExecute = (entity: EntityData): boolean => {+ if (entity.type === 'database') return entity.grant === 'owner';if (entity.type === 'email') {return true;}diff --git a/apps/web/src/features/next-soup/actions/make-rename-action.test.ts b/apps/web/src/features/next-soup/actions/make-rename-action.test.tsindex 66ff2d496f..9034fc9269 100644--- a/apps/web/src/features/next-soup/actions/make-rename-action.test.ts+++ b/apps/web/src/features/next-soup/actions/make-rename-action.test.ts@@ -33,8 +33,10 @@ const channel = (const { canExecute } = makeRenameAction({ userId: () => ME });describe('makeRenameAction.canExecute', () => {- it('leaves database renaming to the native database block', () => {- expect(canExecute(entity('database', { grant: 'owner' }))).toBe(false);+ it('allows editors and owners to rename a database from the list', () => {+ expect(canExecute(entity('database', { grant: 'owner' }))).toBe(true);+ expect(canExecute(entity('database', { grant: 'edit' }))).toBe(true);+ expect(canExecute(entity('database', { grant: 'view' }))).toBe(false);});it('allows the owner of a private channel to rename it', () => {diff --git a/apps/web/src/features/next-soup/actions/make-rename-action.ts b/apps/web/src/features/next-soup/actions/make-rename-action.tsindex 2fe3e9bee1..3d8410e5d3 100644--- a/apps/web/src/features/next-soup/actions/make-rename-action.ts+++ b/apps/web/src/features/next-soup/actions/make-rename-action.ts@@ -15,6 +15,9 @@ export const makeRenameAction = (options: MakeRenameOptions) => {const canExecute = (entity: EntityData): boolean => {if (entity.type === 'agent_session' && entity.isArchived) return false;+ if (entity.type === 'database') {+ return entity.grant === 'edit' || entity.grant === 'owner';+ }if (entity.type === 'channel') return canEditChannelIdentity(entity);// The types the rename mutation supports; it rejects any other.if (diff --git a/apps/web/src/features/sharing/global-share-modal/GlobalShareModal.tsx b/apps/web/src/features/sharing/global-share-modal/GlobalShareModal.tsxindex a8253eb000..d985a645a6 100644--- a/apps/web/src/features/sharing/global-share-modal/GlobalShareModal.tsx+++ b/apps/web/src/features/sharing/global-share-modal/GlobalShareModal.tsx@@ -1,4 +1,4 @@-import { Permissions } from '@core/component/SharePermissions';+import { getPermissions, Permissions } from '@core/component/SharePermissions';import { toast } from '@core/component/Toast/Toast';import { openShareModal } from '@core/component/TopBar/shareModal';import { itemToBlockName } from '@core/constant/allBlocks';@@ -35,7 +35,12 @@ export const openGlobalShareModal = async (props: {blockAlias: itemToBlockName(entity) ?? 'unknown',itemType: entity.type,name: entity.name,- userPermissions: Permissions.OWNER,+ // Databases carry grant on the list row; other types still open as owner+ // and let the modal load the live permission set.+ userPermissions:+ entity.type === 'database'+ ? getPermissions(entity.grant)+ : Permissions.OWNER,owner: entity.ownerId,});};diff --git a/apps/web/src/features/sharing/global-share-modal/shareable-entity.ts b/apps/web/src/features/sharing/global-share-modal/shareable-entity.tsindex 0eadfd598a..a19b70d1b8 100644--- a/apps/web/src/features/sharing/global-share-modal/shareable-entity.ts+++ b/apps/web/src/features/sharing/global-share-modal/shareable-entity.ts@@ -9,7 +9,8 @@ export type ShareableEntityType =| 'email'| 'form'| 'agent_session'- | 'call';+ | 'call'+ | 'database';/** The subset of {@link EntityData} the global share modal accepts. */export type ShareableEntityData = Extract<@@ -34,6 +35,7 @@ export const isShareableEntityType = (type === 'project' ||type === 'form' ||type === 'agent_session' ||- type === 'call'+ type === 'call' ||+ type === 'database');};diff --git a/apps/web/src/features/sharing/global-share-modal/tests/GlobalShareModal.test.ts b/apps/web/src/features/sharing/global-share-modal/tests/GlobalShareModal.test.tsindex f22b62ea33..01a4bb22f7 100644--- a/apps/web/src/features/sharing/global-share-modal/tests/GlobalShareModal.test.ts+++ b/apps/web/src/features/sharing/global-share-modal/tests/GlobalShareModal.test.ts@@ -51,4 +51,25 @@ describe('openGlobalShareModal', () => {}));});++ it('opens the share dialog for a database at the viewer’s grant', async () => {+ const database = {+ type: 'database',+ id: 'database-1',+ name: 'Roadmap',+ ownerId: 'macro|[email protected]',+ grant: 'edit',+ } as Extract<EntityData, { type: 'database' }>;+ await openGlobalShareModal({ entity: database });+ expect(openFormShareModal).not.toHaveBeenCalled();+ expect(openShareModal).toHaveBeenCalledWith(+ expect.objectContaining({+ id: 'database-1',+ itemType: 'database',+ name: 'Roadmap',+ userPermissions: Permissions.CAN_EDIT,+ owner: 'macro|[email protected]',+ })+ );+ });});diff --git a/apps/web/src/features/sharing/global-share-modal/tests/shareable-entity.test.ts b/apps/web/src/features/sharing/global-share-modal/tests/shareable-entity.test.tsindex ed29be67b3..21c09cde1f 100644--- a/apps/web/src/features/sharing/global-share-modal/tests/shareable-entity.test.ts+++ b/apps/web/src/features/sharing/global-share-modal/tests/shareable-entity.test.ts@@ -10,6 +10,7 @@ describe('isShareableEntityType', () => {expect(isShareableEntityType('agent_session')).toBe(true);expect(isShareableEntityType('form')).toBe(true);expect(isShareableEntityType('call')).toBe(true);+ expect(isShareableEntityType('database')).toBe(true);});it('rejects entity types with no share flow', () => {diff --git a/docs/agent-guide/databases.md b/docs/agent-guide/databases.mdindex e6b51c1128..b7ab34e5e8 100644--- a/docs/agent-guide/databases.md+++ b/docs/agent-guide/databases.md@@ -704,7 +704,9 @@ details**, and the server's summary on query tool rows.or channels and change or remove their access, and an owner on a team sets**Team access** (view, comment, or edit for the owner's team; rows follow thedatabase). Databases do not offer a public link. **Share** and viewer avatars (other people currently looking at the-database) sit at the right of the split header, like other entities.+database) sit at the right of the split header, like other entities. From Drive,+the row context menu offers the same Share action, plus Rename (edit or owner),+Favorite, Copy Link, and Delete (owner).The toolbar's **Database actions** (`…`) menu, beside **AI**, contains **Rename**,**Import CSV**, **Webhooks**, **Download**, and owner-only **Delete**. Rename focuses the inlinediff --git a/docs/agent-guide/files.md b/docs/agent-guide/files.mdindex b3e5cd2e50..ab79f7ea0f 100644--- a/docs/agent-guide/files.md+++ b/docs/agent-guide/files.md@@ -37,8 +37,10 @@ database names and **Filter → Type → Database** narrows the list. **New →Database** creates and opens a database from file tabs or the folder overview;it is absent inside a folder because databases have no folder membership yet.Database rows open their database block, including Enter and Open in new split.-Use the database block's own actions to rename, share or trash it. The list-omits unsupported duplicate, delete and move-to-folder actions for databases.+Right-click (or long-press) a database for the same entity actions as other+Drive rows: Open in new split, Rename (edit or owner), Favorite, Copy Link,+Copy ID, Share, and Delete (owner). Duplicate and Move to folder stay omitted+because databases have no folder membership and no duplicate API.Databases have no view history and do not appear in **Recent**, folder contents,or **Email attachments**. Creation time orders them when the selected sort hasno corresponding database timestamp.