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(core): kill split modal, use entity edit modal for operations (#2784)
Seamusbb5c942c7cfc
diff --git a/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx b/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsxindex cb393ee35f..9af37a8e3f 100644--- a/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx+++ b/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx@@ -20,6 +20,7 @@ const BulkEditEntityModalContent = (props: {entities: EntityData[];onFinish?: () => void;onCancel?: () => void;+ onError?: (error: unknown) => void;}) => {const handleFinish = () => {props.setIsOpen(false);@@ -29,6 +30,9 @@ const BulkEditEntityModalContent = (props: {props.setIsOpen(false);props.onCancel?.();};+ const handleError = (error: unknown) => {+ props.onError?.(error);+ };return (<Dialog@@ -49,6 +53,7 @@ const BulkEditEntityModalContent = (props: {entities={props.entities}onFinish={handleFinish}onCancel={handleCancel}+ onError={handleError}/></Show><Show when={props.view === 'moveToProject'}>@@ -56,6 +61,7 @@ const BulkEditEntityModalContent = (props: {entities={props.entities}onFinish={handleFinish}onCancel={handleCancel}+ onError={handleError}/></Show><Show when={props.view === 'delete'}>@@ -99,6 +105,7 @@ const [globalModalProps, setGlobalModalProps] = createSignal<{entities: EntityData[];onFinish?: () => void;onCancel?: () => void;+ onError?: (error: unknown) => void;} | null>(null);const [modalOpen, setModalOpen] = createControlledOpenSignal(false, {id: 'entity-edit',@@ -109,6 +116,7 @@ export const openBulkEditModal = (props: {entities: EntityData[];onFinish?: () => void;onCancel?: () => void;+ onError?: (error: unknown) => void;}) => {setModalOpen(true);setGlobalModalProps(props);@@ -133,6 +141,10 @@ export const GlobalBulkEditEntityModal = () => {}};+ const handleError = (error: unknown) => {+ globalModalProps()?.onError?.(error);+ };+return (<Show when={modalProps()}>{(props) => (@@ -143,6 +155,7 @@ export const GlobalBulkEditEntityModal = () => {entities={props().entities}onFinish={handleFinish}onCancel={handleCancel}+ onError={handleError}/>)}</Show>diff --git a/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx b/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsxindex b7dc8bb118..c56d19c075 100644--- a/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx+++ b/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx@@ -25,6 +25,7 @@ export const BulkMoveToProjectView = (props: {entities: EntityData[];onFinish: () => void;onCancel: () => void;+ onError?: (error: unknown) => void;}) => {let listRef!: HTMLDivElement;const bulkMoveToProjectMutation = createBulkMoveToProjectDssEntityMutation();@@ -352,6 +353,7 @@ export const BulkMoveToProjectView = (props: {props.onFinish();} catch (error) {console.error('Failed to move entities to folder:', error);+ props.onError?.(error);}}};diff --git a/js/app/packages/app/component/bulk-edit-entity/BulkRenameEntitiesView.tsx b/js/app/packages/app/component/bulk-edit-entity/BulkRenameEntitiesView.tsxindex bda49d8442..2ce1659f30 100644--- a/js/app/packages/app/component/bulk-edit-entity/BulkRenameEntitiesView.tsx+++ b/js/app/packages/app/component/bulk-edit-entity/BulkRenameEntitiesView.tsx@@ -13,6 +13,7 @@ export const BulkRenameEntitiesView = (props: {entities: EntityData[];onFinish: () => void;onCancel: () => void;+ onError?: (error: unknown) => void;}) => {const renameMutation = createBulkRenameDssEntityMutation();@@ -88,11 +89,15 @@ export const BulkRenameEntitiesView = (props: {default:}- await renameMutation.mutateAsync(- props.entities.map((e) => ({ entity: e, newName: renameFn(e.name) }))- );-- props.onFinish();+ try {+ await renameMutation.mutateAsync(+ props.entities.map((e) => ({ entity: e, newName: renameFn(e.name) }))+ );+ props.onFinish();+ } catch (error) {+ console.error('Failed to rename entities:', error);+ props.onError?.(error);+ }};return (diff --git a/js/app/packages/app/component/split-layout/components/SplitContainer.tsx b/js/app/packages/app/component/split-layout/components/SplitContainer.tsxindex 8c1a8c4b3a..fc5af923a8 100644--- a/js/app/packages/app/component/split-layout/components/SplitContainer.tsx+++ b/js/app/packages/app/component/split-layout/components/SplitContainer.tsx@@ -11,7 +11,6 @@ import {import { useSplitPanelOrThrow } from '../layoutUtils';import { SplitDrawerGroup } from './SplitDrawerContext';import { SplitHeader } from './SplitHeader';-import { SplitModalProvider } from './SplitModalContext';import { SplitToolbar } from './SplitToolbar';import {ClippedPanel,@@ -69,64 +68,59 @@ export function SplitContainer(}return (- <SplitModalProvider>- <SplitDrawerGroup- contentOffsetTop={offsetTop}- panelSize={panel.panelSize}- >- <Show when={panel.handle.isSpotLight()}>- <div- class="fixed inset-0 w-screen h-screen z-modal-overlay bg-modal-overlay pattern-diagonal-4 pattern-edge-muted"- onClick={() => panel.handle.toggleSpotlight(false)}- />- <div class="fixed inset-[4rem] bg-panel shadow-xl" />- </Show>-+ <SplitDrawerGroup contentOffsetTop={offsetTop} panelSize={panel.panelSize}>+ <Show when={panel.handle.isSpotLight()}><div- classList={{- 'fixed inset-[4rem] z-modal-overlay isolate opacity-50':- panel.handle.isSpotLight(),- 'opacity-100': panel.isPanelActive() || panel.handle.isSpotLight(),- 'size-full': !panel.handle.isSpotLight(),- 'opacity-85': !panel.isPanelActive() && !isMobile(),- }}- ref={(ref) => {- setRef(ref);- props.ref(ref);- }}- data-split-id={props.id}- class="bracket-never"- data-split-container- data-modal={panel.handle.isSpotLight()}- tabindex={-1}+ class="fixed inset-0 w-screen h-screen z-modal-overlay bg-modal-overlay pattern-diagonal-4 pattern-edge-muted"+ onClick={() => panel.handle.toggleSpotlight(false)}+ />+ <div class="fixed inset-[4rem] bg-panel shadow-xl" />+ </Show>++ <div+ classList={{+ 'fixed inset-[4rem] z-modal-overlay isolate opacity-50':+ panel.handle.isSpotLight(),+ 'opacity-100': panel.isPanelActive() || panel.handle.isSpotLight(),+ 'size-full': !panel.handle.isSpotLight(),+ 'opacity-85': !panel.isPanelActive() && !isMobile(),+ }}+ ref={(ref) => {+ setRef(ref);+ props.ref(ref);+ }}+ data-split-id={props.id}+ class="bracket-never"+ data-split-container+ data-modal={panel.handle.isSpotLight()}+ tabindex={-1}+ >+ <MaybeClippedPanel+ active={+ panel.isPanelActive() &&+ multipleSplits() &&+ !panel.handle.isSpotLight()+ }+ // TODO (seamus) temporary disabling split corners+ // tl={props.tl}+ // bl={props.bl}+ // tr={props.tr}+ // br={props.br}+ // edgeColor="color-accent"+ cornerRadius={'4px'}>- <MaybeClippedPanel- active={- panel.isPanelActive() &&- multipleSplits() &&- !panel.handle.isSpotLight()- }- // TODO (seamus) temporary disabling split corners- // tl={props.tl}- // bl={props.bl}- // tr={props.tr}- // br={props.br}- // edgeColor="color-accent"- cornerRadius={'4px'}- >- <div class="flex flex-col min-h-0 size-full bg-panel overflow-hidden">- <SplitHeader ref={setHeaderRef} />- <SplitToolbar ref={setToolbarRef} />- <div class="@container/split size-full overflow-hidden relative">- {props.children}- </div>- <Show when={panel.handle.isSpotLight()}>- <MacroJump tabbableParent={ref} />- </Show>+ <div class="flex flex-col min-h-0 size-full bg-panel overflow-hidden">+ <SplitHeader ref={setHeaderRef} />+ <SplitToolbar ref={setToolbarRef} />+ <div class="@container/split size-full overflow-hidden relative">+ {props.children}</div>- </MaybeClippedPanel>- </div>- </SplitDrawerGroup>- </SplitModalProvider>+ <Show when={panel.handle.isSpotLight()}>+ <MacroJump tabbableParent={ref} />+ </Show>+ </div>+ </MaybeClippedPanel>+ </div>+ </SplitDrawerGroup>);}diff --git a/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx b/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsxindex 67c4762b7e..bf3b18a679 100644--- a/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx+++ b/js/app/packages/app/component/split-layout/components/SplitFileMenu.tsx@@ -1,4 +1,4 @@-import { useBlockName } from '@core/block';+import { useBlockAliasedName, useBlockName } from '@core/block';import { useItemOperations } from '@core/component/FileList/useItemOperations';import { MenuItem } from '@core/component/Menu';import { useIsDocumentOwner } from '@core/signal/permissions';@@ -22,7 +22,9 @@ import {import type { BlockTool } from '@app/component/ResponsiveBlockToolbar';import { SplitPanelContext } from '../context';import { useSplitLayout } from '../layout';-import { useSplitModal } from './SplitModalContext';+import { openBulkEditModal } from '@app/component/bulk-edit-entity/BulkEditEntityModal';+import { toast } from '@core/component/Toast/Toast';+import { buildEntityData } from '@entity';export type FileOperationName = 'delete' | 'rename' | 'copy' | 'moveToProject';@@ -61,14 +63,13 @@ export function SplitFileMenu(props: {const isOwner = useIsDocumentOwner();const blockName = useBlockName();+ const aliasedBlockName = useBlockAliasedName();const itemType = blockNameToItemType(blockName);if (!itemType) throw new Error(`Using bad item type for block: ${blockName}`);const [open, setOpen] = createSignal(false);const itemOperations = useItemOperations();- const modal = useSplitModal();-const { replaceOrInsertSplit, resetSplit } = useSplitLayout();const ops = createMemo<CustomFileOperation[]>(() => {@@ -99,12 +100,18 @@ export function SplitFileMenu(props: {return {label: 'Rename',action: () => {- setOpen(false);- modal({+ const entity = buildEntityData({id: props.id,name: props.name,- itemType: props.itemType,+ blockName: aliasedBlockName,+ });+ if (!entity) return;+ setOpen(false);+ openBulkEditModal({view: 'rename',+ entities: [entity],+ onFinish: () => toast.success('Renamed'),+ onError: () => toast.failure('Failed to rename'),});},icon: Rename,@@ -145,12 +152,18 @@ export function SplitFileMenu(props: {return {label: 'Move to Folder',action: () => {- setOpen(false);- modal({+ const entity = buildEntityData({id: props.id,name: props.name,- itemType: props.itemType,+ blockName: aliasedBlockName,+ });+ if (!entity) return;+ setOpen(false);+ openBulkEditModal({view: 'moveToProject',+ entities: [entity],+ onFinish: () => toast.success('Moved to folder'),+ onError: () => toast.failure('Failed to move to folder'),});},icon: ArrowRight,diff --git a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx b/js/app/packages/app/component/split-layout/components/SplitLabel.tsxindex f361b3eb74..b63a4c6bcf 100644--- a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx+++ b/js/app/packages/app/component/split-layout/components/SplitLabel.tsx@@ -1,14 +1,10 @@-import {- isInBlock,- useBlockAliasedName,- useBlockId,- useBlockName,-} from '@core/block';+import { isInBlock, useBlockAliasedName, useBlockId } from '@core/block';import {EntityIcon,type EntityIconSelector,isArchiveType,} from '@core/component/EntityIcon';+import { toast } from '@core/component/Toast/Toast';import { Tooltip } from '@core/component/Tooltip';import { blockMetadataSignal } from '@core/signal/load';import {@@ -18,10 +14,10 @@ import {useIsDocumentOwner,} from '@core/signal/permissions';import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';-import { blockNameToItemType, type ItemType } from '@service-storage/client';+import { buildEntityData, type BuildEntityDataArgs } from '@entity';import { createEffect, type JSX, Show } from 'solid-js';+import { openBulkEditModal } from '@app/component/bulk-edit-entity/BulkEditEntityModal';import { useSplitPanelOrThrow } from '../layoutUtils';-import { useRenameSplit } from './SplitModalContext';import { cn } from '@ui/utils/classname';export function StaticSplitLabel(props: {@@ -62,15 +58,14 @@ export function StaticSplitLabel(props: {export function SplitLabel(props: {label: string;- onNameChanged?: (newName: string) => void;lockRename?: boolean;- id?: string;- itemType?: ItemType;+ /** Per-variant fields the block context can't supply (e.g. `channelType`+ * for a channel rename). Merged into the args passed to `buildEntityData`. */+ renameOverrides?: Partial<BuildEntityDataArgs>;}) {const panel = useSplitPanelOrThrow();- const rename = useRenameSplit();- const blockName = useBlockName();const blockId = useBlockId();+ const aliasedBlockName = useBlockAliasedName();createEffect(() => {panel.handle.setDisplayName(props.label);@@ -78,23 +73,22 @@ export function SplitLabel(props: {const startEditing = (e: MouseEvent) => {if (props.lockRename) return;- if (e.type === 'contextmenu') {- e.preventDefault();- }-- if (props.id || props.itemType || blockNameToItemType(blockName)) {- const id = props.id || blockId;- const itemType = props.itemType || blockNameToItemType(blockName);-- if (id && itemType) {- rename({- id,- currentName: props.label,- itemType,- onRename: props.onNameChanged,- });- }- }+ if (e.type === 'contextmenu') e.preventDefault();++ const entity = buildEntityData({+ id: blockId,+ name: props.label,+ blockName: aliasedBlockName,+ ...props.renameOverrides,+ });+ if (!entity) return;++ openBulkEditModal({+ view: 'rename',+ entities: [entity],+ onFinish: () => toast.success('Renamed'),+ onError: () => toast.failure('Failed to rename'),+ });};return (diff --git a/js/app/packages/app/component/split-layout/components/SplitModal.tsx b/js/app/packages/app/component/split-layout/components/SplitModal.tsxdeleted file mode 100644index abe4149c9c..0000000000--- a/js/app/packages/app/component/split-layout/components/SplitModal.tsx+++ /dev/null@@ -1,71 +0,0 @@-import { ScopedPortal } from '@core/component/ScopedPortal';-import clickOutside from '@core/directive/clickOutside';-import { Dialog } from '@kobalte/core/dialog';-import {- type Accessor,- type JSX,- type ParentProps,- type Setter,- Show,-} from 'solid-js';-import { useSplitPanelOrThrow } from '../layoutUtils';--false && clickOutside;--export function SplitModal(- props: ParentProps<{- trigger?: JSX.Element;- open: Accessor<boolean>;- setOpen: Setter<boolean>;- mode?: 'split' | 'global';- scrim?: boolean;- onCloseAutoFocus?: (e: Event) => void;- onOpenAutoFocus?: (e: Event) => void;- }>-) {- const { contentOffsetTop } = useSplitPanelOrThrow();- return (- <Dialog- open={props.open()}- onOpenChange={props.setOpen}- modal={props.mode !== 'split'}- >- <Show when={props.trigger}>- <Dialog.Trigger>{props.trigger}</Dialog.Trigger>- </Show>- <ScopedPortal scope={props.mode ?? 'global'}>- <Dialog.Overlay- as="div"- class="absolute z-modal"- classList={{- 'left-[1px] right-[1px] bottom-[1px]': props.mode === 'split',- 'inset-0': props.mode !== 'split',- 'bg-modal-overlay': props.scrim !== false,- }}- style={{- top: `${props.mode === 'split' ? contentOffsetTop() : 0}px`,- }}- use:clickOutside={() => props.setOpen(false)}- on:click={() => props.setOpen(false)}- />- <div- class="absolute z-modal flex justify-around pointer-events-none"- classList={{- 'left-[1px] right-[1px] bottom-[1px]': props.mode === 'split',- 'inset-0': props.mode !== 'split',- }}- style={{- top: `${contentOffsetTop()}px`,- }}- >- <Dialog.Content- onCloseAutoFocus={props.onCloseAutoFocus}- onOpenAutoFocus={props.onOpenAutoFocus}- >- {props.children}- </Dialog.Content>- </div>- </ScopedPortal>- </Dialog>- );-}diff --git a/js/app/packages/app/component/split-layout/components/SplitModalContext.tsx b/js/app/packages/app/component/split-layout/components/SplitModalContext.tsxdeleted file mode 100644index 0e77011e0c..0000000000--- a/js/app/packages/app/component/split-layout/components/SplitModalContext.tsx+++ /dev/null@@ -1,124 +0,0 @@-import { EntityModal } from '@app/component/EntityModal/EntityModal';-import type { EntityData } from '@entity';-import type { ItemType } from '@service-storage/client';-import {- createContext,- createSignal,- type ParentProps,- useContext,-} from 'solid-js';--type ModalView = 'rename' | 'moveToProject';--type ModalParams = {- id: string;- name: string;- itemType: ItemType;- view: ModalView;- viewId?: string;- onComplete?: (newValue?: string) => void;-};--const SplitModalContext = createContext<(params: ModalParams) => void>();--export function useSplitModal() {- const context = useContext(SplitModalContext);- if (!context) {- throw new Error('useSplitModal must be used within a SplitModalProvider');- }- return context;-}--// Backward compatibility hook-export function useRenameSplit() {- const modal = useSplitModal();- return (params: {- id: string;- currentName: string;- itemType: ItemType;- onRename?: (newName: string) => void;- }) => {- modal({- id: params.id,- name: params.currentName,- itemType: params.itemType,- view: 'rename',- onComplete: params.onRename,- });- };-}--// Helper to convert ItemType to EntityData type-const itemTypeToEntityType = (itemType: ItemType): EntityData['type'] => {- return itemType;-};--export function SplitModalProvider(props: ParentProps) {- const [isOpen, setIsOpen] = createSignal(false);- const [currentView, setCurrentView] = createSignal<ModalView | null>(null);- const [modalParams, setModalParams] = createSignal<ModalParams | null>(null);-- const openModal = (params: ModalParams) => {- setModalParams(params);- setCurrentView(params.view);- setIsOpen(true);- };-- // TODO: we should ideally not be type casting here because- // downstream components might not be aware that some entity data fields are missing- const createEntityData = (): EntityData | undefined => {- const params = modalParams();- if (!params) return undefined;-- const baseEntity = {- id: params.id,- name: params.name,- ownerId: '', // This would need to be filled from context- type: itemTypeToEntityType(params.itemType),- };-- switch (params.itemType) {- case 'document':- return {- ...baseEntity,- type: 'document',- projectId: undefined, // Could be extracted from context if needed- } as EntityData;- case 'chat':- return {- ...baseEntity,- type: 'chat',- projectId: undefined,- } as EntityData;- case 'project':- return {- ...baseEntity,- type: 'project',- parentId: undefined,- } as EntityData;- case 'channel':- return {- ...baseEntity,- type: 'channel',- } as EntityData;- default:- return {- ...baseEntity,- type: 'document',- } as EntityData;- }- };-- return (- <SplitModalContext.Provider value={openModal}>- {props.children}- <EntityModal- isOpen={() => isOpen()}- setIsOpen={setIsOpen}- view={() => currentView() || 'rename'}- entity={createEntityData()}- viewId={modalParams()?.viewId}- />- </SplitModalContext.Provider>- );-}diff --git a/js/app/packages/block-channel/component/Top.tsx b/js/app/packages/block-channel/component/Top.tsxindex b96babe790..9d4b20d499 100644--- a/js/app/packages/block-channel/component/Top.tsx+++ b/js/app/packages/block-channel/component/Top.tsx@@ -93,9 +93,8 @@ export function ChannelTopLeft(props: ChannelTopLeftProps) {/><SplitLabellabel={channelName() ?? 'New Channel'}- id={props.channelId}- itemType="channel"lockRename={props.lockRename}+ renameOverrides={{ channelType: props.channelType }}/></div><Show when={props.tabs && props.activeTab && props.onTabChange}>diff --git a/js/app/packages/entity/src/index.ts b/js/app/packages/entity/src/index.tsindex 5f2c3f3c6a..a3fc3307f0 100644--- a/js/app/packages/entity/src/index.ts+++ b/js/app/packages/entity/src/index.ts@@ -29,6 +29,10 @@ export {} from './utils/notification';export { unreadFilterFn } from './utils/filter';+export {+ buildEntityData,+ type BuildEntityDataArgs,+} from './utils/buildEntityData';export {TASK_STATUS_OPTIONS,getTaskAssigneeIds,diff --git a/js/app/packages/entity/src/utils/buildEntityData.ts b/js/app/packages/entity/src/utils/buildEntityData.tsnew file mode 100644index 0000000000..62b04438c6--- /dev/null+++ b/js/app/packages/entity/src/utils/buildEntityData.ts@@ -0,0 +1,149 @@+import type { BlockAlias, BlockName } from '@core/block';+import { match } from 'ts-pattern';+import type {+ AutomationEntity,+ CallEntity,+ ChannelEntity,+ ChatEntity,+ DocumentEntity,+ EmailEntity,+ EntityData,+ ProjectEntity,+ TaskEntity,+} from '../types/entity';++export type BuildEntityDataArgs = {+ id: string;+ name: string;+ blockName: BlockName | BlockAlias;+ ownerId?: string;+ projectId?: string;+ fileType?: string;+ isCompleted?: boolean;+ channelType?: ChannelEntity['channelType'];+ cron?: string;+ enabled?: boolean;+ channelId?: string;+ isActive?: boolean;+ attended?: boolean;+ participantIds?: string[];+ isRead?: boolean;+ isDraft?: boolean;+ isImportant?: boolean;+ done?: boolean;+};++/**+ * Build a full `EntityData` from the simple shape that's typically+ * available at component level (id, name, blockName).+ *+ * The `blockName` discriminator is funneled into the right `EntityData`+ * variant: e.g. `'task'` becomes `{ type: 'document', fileType: 'md',+ * subType: { type: 'task' } }`, `'pdf'` becomes `{ type: 'document',+ * fileType: 'pdf' }`, etc.+ *+ * Returns `undefined` when required fields for the resolved variant are+ * missing (e.g. a `'channel'` without a `channelType`).+ */+export function buildEntityData(+ args: BuildEntityDataArgs+): EntityData | undefined {+ const { id, name, blockName, ownerId = '' } = args;+ if (!id || !name || !blockName) return undefined;++ const base = { id, name, ownerId };++ return match<BlockName | BlockAlias, EntityData | undefined>(blockName)+ .with(+ 'task',+ (): TaskEntity => ({+ ...base,+ type: 'document',+ fileType: 'md',+ subType: { type: 'task', is_completed: args.isCompleted ?? false },+ projectId: args.projectId,+ })+ )+ .with(+ 'md',+ (): DocumentEntity => ({+ ...base,+ type: 'document',+ fileType: 'md',+ projectId: args.projectId,+ })+ )+ .with(+ 'pdf',+ 'write',+ 'code',+ 'image',+ 'canvas',+ 'video',+ 'contact',+ 'unknown',+ 'csv',+ (name): DocumentEntity => ({+ ...base,+ type: 'document',+ fileType: args.fileType ?? name,+ projectId: args.projectId,+ })+ )+ .with(+ 'chat',+ (): ChatEntity => ({+ ...base,+ type: 'chat',+ projectId: args.projectId,+ })+ )+ .with(+ 'project',+ (): ProjectEntity => ({+ ...base,+ type: 'project',+ projectId: args.projectId,+ })+ )+ .with('channel', (): ChannelEntity | undefined => {+ if (!args.channelType) return undefined;+ return {+ ...base,+ type: 'channel',+ channelType: args.channelType,+ };+ })+ .with(+ 'email',+ (): EmailEntity => ({+ ...base,+ type: 'email',+ isRead: args.isRead ?? true,+ isDraft: args.isDraft ?? false,+ isImportant: args.isImportant ?? false,+ done: args.done ?? false,+ })+ )+ .with('automation', (): AutomationEntity | undefined => {+ if (!args.cron) return undefined;+ return {+ ...base,+ type: 'automation',+ cron: args.cron,+ enabled: args.enabled ?? false,+ };+ })+ .with('call', (): CallEntity | undefined => {+ if (!args.channelId) return undefined;+ return {+ ...base,+ type: 'call',+ channelId: args.channelId,+ isActive: args.isActive ?? false,+ attended: args.attended ?? false,+ participantIds: args.participantIds ?? [],+ };+ })+ .exhaustive();+}diff --git a/js/app/packages/entity/tests/buildEntityData.test.ts b/js/app/packages/entity/tests/buildEntityData.test.tsnew file mode 100644index 0000000000..4f5a28df13--- /dev/null+++ b/js/app/packages/entity/tests/buildEntityData.test.ts@@ -0,0 +1,197 @@+import { describe, expect, it } from 'vitest';+import { buildEntityData } from '../src/utils/buildEntityData';++const base = { id: 'id-1', name: 'Hello', ownerId: 'user-1' };++describe('buildEntityData', () => {+ describe('required base fields', () => {+ it('returns undefined when id is missing', () => {+ expect(+ buildEntityData({ ...base, id: '', blockName: 'md' })+ ).toBeUndefined();+ });++ it('returns undefined when name is missing', () => {+ expect(+ buildEntityData({ ...base, name: '', blockName: 'md' })+ ).toBeUndefined();+ });++ it('defaults ownerId to empty string when omitted', () => {+ const e = buildEntityData({ id: 'a', name: 'b', blockName: 'md' });+ expect(e?.ownerId).toBe('');+ });+ });++ describe('document variants', () => {+ it('builds an md document', () => {+ expect(buildEntityData({ ...base, blockName: 'md' })).toEqual({+ ...base,+ type: 'document',+ fileType: 'md',+ projectId: undefined,+ });+ });++ it('passes projectId through', () => {+ const e = buildEntityData({+ ...base,+ blockName: 'md',+ projectId: 'p-1',+ });+ expect(e).toMatchObject({ type: 'document', projectId: 'p-1' });+ });++ it('uses blockName as fileType for typed documents', () => {+ const e = buildEntityData({ ...base, blockName: 'pdf' });+ expect(e).toMatchObject({ type: 'document', fileType: 'pdf' });+ });++ it('lets explicit fileType override the blockName', () => {+ const e = buildEntityData({+ ...base,+ blockName: 'code',+ fileType: 'py',+ });+ expect(e).toMatchObject({ type: 'document', fileType: 'py' });+ });+ });++ describe('task', () => {+ it('builds a task with subType filled in', () => {+ expect(buildEntityData({ ...base, blockName: 'task' })).toEqual({+ ...base,+ type: 'document',+ fileType: 'md',+ subType: { type: 'task', is_completed: false },+ projectId: undefined,+ });+ });++ it('respects isCompleted', () => {+ const e = buildEntityData({+ ...base,+ blockName: 'task',+ isCompleted: true,+ });+ expect(e).toMatchObject({+ subType: { type: 'task', is_completed: true },+ });+ });+ });++ describe('chat / project', () => {+ it('builds a chat', () => {+ expect(buildEntityData({ ...base, blockName: 'chat' })).toEqual({+ ...base,+ type: 'chat',+ projectId: undefined,+ });+ });++ it('builds a project', () => {+ expect(buildEntityData({ ...base, blockName: 'project' })).toEqual({+ ...base,+ type: 'project',+ projectId: undefined,+ });+ });+ });++ describe('channel', () => {+ it('returns undefined without channelType', () => {+ expect(+ buildEntityData({ ...base, blockName: 'channel' })+ ).toBeUndefined();+ });++ it('builds a channel when channelType is provided', () => {+ const e = buildEntityData({+ ...base,+ blockName: 'channel',+ channelType: 'team',+ });+ expect(e).toEqual({ ...base, type: 'channel', channelType: 'team' });+ });+ });++ describe('email', () => {+ it('defaults flags', () => {+ expect(buildEntityData({ ...base, blockName: 'email' })).toEqual({+ ...base,+ type: 'email',+ isRead: true,+ isDraft: false,+ isImportant: false,+ done: false,+ });+ });++ it('respects provided flags', () => {+ const e = buildEntityData({+ ...base,+ blockName: 'email',+ isRead: false,+ isDraft: true,+ isImportant: true,+ done: true,+ });+ expect(e).toMatchObject({+ isRead: false,+ isDraft: true,+ isImportant: true,+ done: true,+ });+ });+ });++ describe('automation', () => {+ it('returns undefined without cron', () => {+ expect(+ buildEntityData({ ...base, blockName: 'automation' })+ ).toBeUndefined();+ });++ it('builds an automation with cron', () => {+ expect(+ buildEntityData({+ ...base,+ blockName: 'automation',+ cron: '* * * * *',+ enabled: true,+ })+ ).toEqual({+ ...base,+ type: 'automation',+ cron: '* * * * *',+ enabled: true,+ });+ });+ });++ describe('call', () => {+ it('returns undefined without channelId', () => {+ expect(buildEntityData({ ...base, blockName: 'call' })).toBeUndefined();+ });++ it('builds a call with defaults', () => {+ expect(+ buildEntityData({ ...base, blockName: 'call', channelId: 'c-1' })+ ).toEqual({+ ...base,+ type: 'call',+ channelId: 'c-1',+ isActive: false,+ attended: false,+ participantIds: [],+ });+ });+ });++ describe('csv alias', () => {+ it('builds a csv document with fileType: csv', () => {+ const e = buildEntityData({ ...base, blockName: 'csv' });+ expect(e).toMatchObject({ type: 'document', fileType: 'csv' });+ });+ });+});