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.

5.8 KB
Raw Blame
import { EntityRowTags } from '@property/tags';
import { EntityType } from '@service-properties/generated/schemas/entityType';
import { cn } from '@ui';
import { Match, Show, Switch } from 'solid-js';
import { Entity } from '../../entity';
import { TaskPropertyControl } from '../../extractors-property/task-property-control';
import {
  isChannelEntity,
  isChannelMessageEntity,
  isEmailEntity,
  isTaskEntity,
} from '../../types/entity';
import { isSearchEntity } from '../../types/search';
import { CalendarEventWhen } from './calendar';
import {
  ChannelActiveCallBadge,
  ChannelJoinButton,
  ChannelMessageSingleLine,
} from './channel';
import { EmailIdentity, EmailInboxChip } from './email';
import { SOUP_ROW_CLASS } from './row-geometry';
import { type LayoutProps, RowIndicator } from './shared';

/**
 * One-line row for mixed-type lists (the Search / "All" view): every entity
 * renders as a single 44px line at the documents list's density — leading
 * entity icon, then a type-specific summary, then the timestamp.
 *
 * - Email: participants (bold) then the subject, with the inbox chip.
 * - Channel message: channel name, sender, then the message text.
 * - Task: title, with its properties in the trailing slot.
 * - Everything else (documents, channels, chats, calls, folders, …): title.
 */
export function NarrowSingleLineLayout(props: LayoutProps) {
  return (
    <Entity.Layout
      class={cn(
        SOUP_ROW_CLASS.narrow,
        'w-full gap-x-(--soup-row-column-gap) items-center text-sm pr-2 pl-(--soup-row-padding-l) grid'
      )}
      style={{
        'grid-template-columns':
          'var(--soup-row-indicator-width) 1fr max-content',
        'grid-template-rows': '44px',
        'grid-template-areas': '"indicator title timestamp"',
      }}
    >
      <Entity.Slot placement="indicator" class="relative">
        <RowIndicator
          checked={props.checked}
          hideCheckbox={props.hideCheckbox}
          onChecked={props.onChecked}
          unread={props.unread}
        />
      </Entity.Slot>

      <Entity.Slot
        placement="title"
        class="ph-no-capture flex min-w-0 items-center gap-2 truncate"
      >
        <Show when={isTaskEntity(props.entity) && props.entity}>
          {(task) => (
            <TaskPropertyControl entity={task()} property="priority" />
          )}
        </Show>
        <div class="size-4 shrink-0">
          <Show
            when={props.icon}
            fallback={
              <Entity.Icon
                entity={props.entity}
                streamState={props.streamState}
              />
            }
          >
            {props.icon}
          </Show>
        </div>
        <Switch>
          <Match when={isEmailEntity(props.entity) && props.entity}>
            {(entity) => (
              <>
                <span class="flex max-w-1/2 min-w-0 shrink-0 items-center gap-2 font-semibold">
                  <EmailIdentity entity={entity()} />
                </span>
                <span class="min-w-0 truncate font-normal text-ink/70">
                  <Entity.Title entity={entity()} />
                </span>
                <EmailInboxChip entity={entity()} class="ml-auto" />
              </>
            )}
          </Match>
          <Match when={isChannelMessageEntity(props.entity) && props.entity}>
            {(entity) => <ChannelMessageSingleLine entity={entity()} />}
          </Match>
          <Match when={true}>
            <span class="min-w-0 truncate font-semibold">
              <Entity.Title entity={props.entity} />
            </span>
            <Show when={isChannelEntity(props.entity) && props.entity}>
              {(entity) => (
                <span class="ml-auto shrink-0 flex items-center">
                  <ChannelActiveCallBadge channelId={entity().id} />
                </span>
              )}
            </Show>
            <Show
              when={
                isChannelEntity(props.entity) &&
                props.entity.isParticipant === false &&
                props.entity
              }
            >
              {(entity) => (
                <ChannelJoinButton entity={entity()} class="ml-auto shrink-0" />
              )}
            </Show>
          </Match>
        </Switch>
        {props.titleTrailing}
        <Show when={isTaskEntity(props.entity) ? props.entity : undefined}>
          {(task) => (
            <EntityRowTags
              entityId={task().id}
              entityType={EntityType.TASK}
              properties={task().properties}
              maxVisible={0}
              onFilterByTag={props.onFilterByTag}
              class="ml-auto shrink-0"
            />
          )}
        </Show>
      </Entity.Slot>

      <Show
        when={
          props.referenceProperties ||
          props.scheduleStatus ||
          (!props.hasNotifications &&
            !(isChannelEntity(props.entity) && isSearchEntity(props.entity)))
        }
      >
        <Entity.Slot
          placement="timestamp"
          class="flex items-center justify-end gap-1 text-xs text-right text-ink-extra-muted font-light"
        >
          {props.referenceProperties}
          {props.scheduleStatus}
          <Show when={!props.hasNotifications}>
            <Switch fallback={<Entity.Timestamp entity={props.entity} />}>
              <Match when={isTaskEntity(props.entity)}>
                <Entity.Properties
                  entity={props.entity}
                  maxUserStackUsers={1}
                  showCaret={false}
                  hidePriority
                />
              </Match>
              <Match
                when={props.entity.type === 'calendar_event' && props.entity}
              >
                {(entity) => <CalendarEventWhen entity={entity()} />}
              </Match>
            </Switch>
          </Show>
        </Entity.Slot>
      </Show>
    </Entity.Layout>
  );
}