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.

2.8 KB
Raw Blame
import { projectRouteId } from '@app/features/projects/core/route';
import { getChannelParams } from '@channel/Channel/link';
import type { SplitContent } from '@components/app/split-layout/layoutManager';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import type { EntityData } from '@entity';
import { match } from 'ts-pattern';

/** size-25.5 = 102px, matching the tile size in MediaGrid. */
export const THUMB_SIZE = 102;
/** gap-1.5 = 6px between tiles. */
export const THUMB_GAP = 6;

/** Number of square thumbnails that fit in a row of the given content width. */
export function itemsPerRow(containerWidth: number): number {
  if (containerWidth <= 0) return 1;
  return Math.max(
    1,
    Math.floor((containerWidth + THUMB_GAP) / (THUMB_SIZE + THUMB_GAP))
  );
}

export function getEntityClickContent(entity: EntityData): SplitContent {
  return match(entity)
    .with({ type: 'initiative' }, (entity) => ({
      type: 'component' as const,
      id: projectRouteId({ id: entity.id, section: 'overview' }),
    }))
    .with({ type: 'document' }, (e) => ({
      type: fileTypeToBlockName(e.subType?.type ?? e.fileType),
      id: e.id,
    }))
    .with({ type: 'agent_session' }, (e) => ({
      type: 'agent' as const,
      id: e.id,
    }))
    .with({ type: 'chat' }, (e) => ({ type: 'chat' as const, id: e.id }))
    .with({ type: 'email' }, (e) => ({ type: 'email' as const, id: e.id }))
    .with({ type: 'channel' }, (e) => ({
      type: 'channel' as const,
      id: e.id,
    }))
    .with({ type: 'project' }, (e) => ({
      type: 'project' as const,
      id: e.id,
    }))
    .with({ type: 'channel_message' }, (e) => ({
      type: 'channel' as const,
      id: e.channelId,
      params: getChannelParams(e.messageId, e.threadId),
    }))
    .with({ type: 'channel_thread' }, (e) => ({
      type: 'channel' as const,
      id: e.channelId,
      params: getChannelParams(e.messageId, e.threadId),
    }))
    .with({ type: 'call' }, (e) => ({
      type: 'call' as const,
      id: e.id,
    }))
    .with({ type: 'routine' }, (e) => ({
      type: 'routine' as const,
      id: e.id,
    }))
    .with({ type: 'foreign' }, () => {
      throw new Error('foreign entities do not support channel attachments');
    })
    .with({ type: 'crm_company' }, () => {
      throw new Error('crm companies are not openable as attachments');
    })
    .with({ type: 'crm_contact' }, () => {
      throw new Error('crm contacts are not openable as attachments');
    })
    .with({ type: 'calendar_event' }, () => {
      throw new Error('calendar events are not openable as attachments');
    })
    .with({ type: 'database' }, () => {
      throw new Error('databases are not openable as attachments');
    })
    .with({ type: 'form' }, (e) => ({ type: 'form' as const, id: e.id }))
    .exhaustive();
}