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.

12.8 KB
Raw Blame
import { formatCallDuration } from '@block-call/utils';
import { EntityRowTags } from '@property/tags';
import { EntityType } from '@service-properties/generated/schemas/entityType';
import type { SoupProperty } from '@service-storage/generated/schemas/soupProperty';
import { cn } from '@ui';
import { Match, Show, Switch } from 'solid-js';
import {
  CallDurationBadge,
  CallStatusBadge,
  SharedBadge,
} from '../../components/Badges';
import { GithubLabelPills } from '../../components/GithubLabelPill';
import { MultiSelectCheckbox } from '../../components/MultiSelectCheckbox';
import { ProjectBreadCrumb } from '../../components/ProjectBreadCrumb';
import { UnreadIndicator } from '../../components/UnreadIndicator';
import { Entity } from '../../entity';
import {
  isCallEntity,
  isChannelEntity,
  isChannelMessageEntity,
  isChatEntity,
  isDocumentEntity,
  isEmailEntity,
  isGithubPrEntity,
  isProjectContainedEntity,
  isProjectEntity,
  isRoutineEntity,
  isTaskEntity,
} from '../../types/entity';
import { isSearchEntity } from '../../types/search';
import { CalendarStamp, CalendarWideContent } from './calendar';
import { CallParticipants, CallWideContent } from './call';
import {
  ChannelActiveCallBadge,
  ChannelJoinButton,
  ChannelMessageWideContent,
  ChannelWideContent,
} from './channel';
import { CompactingPills } from './compacting-pills';
import { EmailWideContent, useOwningInboxForEntity } from './email';
import {
  GithubPullRequestChecksIndicator,
  GithubPullRequestPills,
} from './foreign';
import { RoutineWideContent } from './routine';
import { RowEnd } from './row-end';
import { SOUP_ROW_CLASS } from './row-geometry';
import type { LayoutProps } from './shared';

function RowTags(props: {
  entityId: string;
  entityType: EntityType;
  properties: SoupProperty[] | undefined;
  onFilterByTag?: (optionId: string) => void;
}) {
  return (
    <EntityRowTags
      entityId={props.entityId}
      entityType={props.entityType}
      properties={props.properties}
      onFilterByTag={props.onFilterByTag}
    />
  );
}

export function WideLayout(props: LayoutProps) {
  // When a thread resolves to one of the user's inboxes the inbox chip already
  // conveys ownership, so the generic "shared" badge would be redundant.
  const owningInbox = useOwningInboxForEntity(() => props.entity);

  return (
    <Entity.Layout
      class={cn(
        // Leading edge (left padding, indicator column, column gap) comes from
        // the --soup-row-* geometry in ListEntity.css so group headers can line
        // their label up with this row's content.
        SOUP_ROW_CLASS.wide,
        'w-full min-h-[inherit] items-center text-sm pl-(--soup-row-padding-l) pr-2',
        'gap-y-2 gap-x-(--soup-row-column-gap) grid grid-rows-[1fr]',
        // Drop the indicator column entirely when the checkbox is hidden so the
        // content isn't indented by an empty gutter.
        // Action slots and scheduled-send badges size their own column.
        props.actions ||
          props.leadingAction ||
          props.scheduleStatus ||
          (isEmailEntity(props.entity) && props.entity.scheduledSendTime)
          ? props.hideCheckbox
            ? 'grid-cols-[1fr_auto_auto]'
            : 'grid-cols-[var(--soup-row-indicator-width)_1fr_auto_auto]'
          : props.hideCheckbox
            ? 'grid-cols-[1fr_auto_8ch]'
            : 'grid-cols-[var(--soup-row-indicator-width)_1fr_auto_8ch]',
        '[--title-width:10rem]',
        // Pull request pills give way to the title rather than starve it.
        isGithubPrEntity(props.entity) && '[container-type:inline-size]'
      )}
      data-pill-row={isGithubPrEntity(props.entity) ? '' : undefined}
      style={{
        'grid-template-areas': props.hideCheckbox
          ? '"content meta timestamp"'
          : '"indicator content meta timestamp"',
      }}
    >
      <Show when={!props.hideCheckbox}>
        <Entity.Slot placement="indicator" class="relative size-full group">
          <div class="absolute inset-0 grid place-items-center group-hover:opacity-0">
            <UnreadIndicator active={props.unread} />
          </div>
          <div
            class={cn(
              'absolute inset-0 grid place-items-center opacity-0 group-hover:opacity-100',
              {
                'opacity-100': props.checked,
              }
            )}
          >
            <MultiSelectCheckbox
              checked={props.checked}
              onChecked={props.onChecked}
            />
          </div>
        </Entity.Slot>
      </Show>
      <Entity.Slot
        placement="content"
        class={cn(
          'ph-no-capture font-medium truncate items-center gap-2 flex',
          isGithubPrEntity(props.entity) && 'min-w-[min(26rem,50cqw)]'
        )}
      >
        <div class="size-4 shrink-0">
          <Show
            when={props.icon}
            fallback={
              <Entity.Icon
                entity={props.entity}
                streamState={props.streamState}
              />
            }
          >
            {props.icon}
          </Show>
        </div>
        {props.titleLeading}
        <Switch>
          <Match when={isEmailEntity(props.entity) && props.entity}>
            {(entity) => (
              <EmailWideContent
                entity={entity()}
                chars={props.chars}
                showHitSnippet={props.showHitSnippet}
                setContainerRef={props.setSnippetContainerRef}
              />
            )}
          </Match>
          <Match when={isChannelMessageEntity(props.entity) && props.entity}>
            {(entity) => <ChannelMessageWideContent entity={entity()} />}
          </Match>
          <Match when={isChannelEntity(props.entity) && props.entity}>
            {(entity) => (
              <ChannelWideContent
                entity={entity()}
                showLatestMessage={!props.hasNotifications}
              />
            )}
          </Match>
          <Match when={isCallEntity(props.entity) && props.entity}>
            {(entity) => (
              <CallWideContent
                entity={entity()}
                setContainerRef={props.setSnippetContainerRef}
                chars={props.chars}
              />
            )}
          </Match>
          <Match when={isRoutineEntity(props.entity) && props.entity}>
            {(entity) => <RoutineWideContent entity={entity()} />}
          </Match>
          <Match when={props.entity.type === 'calendar_event' && props.entity}>
            {(entity) => <CalendarWideContent entity={entity()} />}
          </Match>
          <Match when={isGithubPrEntity(props.entity) && props.entity}>
            {(entity) => (
              <span class="flex min-w-0 items-center gap-1">
                <span class="min-w-0 truncate">
                  <Entity.Title entity={entity()} />
                </span>
                <GithubPullRequestChecksIndicator entity={entity()} />
              </span>
            )}
          </Match>
          <Match when={props.entity}>
            {(entity) => <Entity.Title entity={entity()} />}
          </Match>
        </Switch>
        {props.titleTrailing}
      </Entity.Slot>
      <Entity.Slot
        placement="meta"
        class={cn(
          'flex items-center gap-2',
          isGithubPrEntity(props.entity) && 'min-w-0 overflow-hidden'
        )}
      >
        <Show
          when={isGithubPrEntity(props.entity) && props.entity}
          fallback={props.meta}
        >
          {(entity) => (
            <CompactingPills>
              {props.meta}
              <GithubLabelPills
                labels={entity().metadata.labels}
                class="contents"
                pillClass="max-w-32 shrink-0"
              />
              <GithubPullRequestPills
                entity={entity()}
                authorDisplayName={props.authorDisplayName}
              />
            </CompactingPills>
          )}
        </Show>
        {props.referenceProperties}
        <Show when={isProjectEntity(props.entity) && props.entity}>
          {(entity) => (
            <RowTags
              entityId={entity().id}
              entityType={EntityType.PROJECT}
              properties={entity().properties}
              onFilterByTag={props.onFilterByTag}
            />
          )}
        </Show>
        <Show when={isDocumentEntity(props.entity) && props.entity}>
          {(entity) => {
            const properties = () => {
              const doc = entity();
              return 'properties' in doc ? doc.properties : undefined;
            };
            return (
              <RowTags
                entityId={entity().id}
                entityType={
                  isTaskEntity(entity()) ? EntityType.TASK : EntityType.DOCUMENT
                }
                properties={properties()}
                onFilterByTag={props.onFilterByTag}
              />
            );
          }}
        </Show>
        <Show when={isEmailEntity(props.entity) && props.entity}>
          {(entity) => (
            <RowTags
              entityId={entity().id}
              entityType={EntityType.THREAD}
              properties={entity().properties}
              onFilterByTag={props.onFilterByTag}
            />
          )}
        </Show>
        <Show when={isChatEntity(props.entity) && props.entity}>
          {(entity) => (
            <RowTags
              entityId={entity().id}
              entityType={EntityType.CHAT}
              properties={entity().properties}
              onFilterByTag={props.onFilterByTag}
            />
          )}
        </Show>
        <Show when={isCallEntity(props.entity) && props.entity}>
          {(entity) => (
            <RowTags
              entityId={entity().id}
              entityType={EntityType.CALL_RECORD}
              properties={entity().properties}
              onFilterByTag={props.onFilterByTag}
            />
          )}
        </Show>
        <Show
          when={
            props.isShared && !owningInbox() && !isGithubPrEntity(props.entity)
          }
        >
          <SharedBadge ownerId={props.entity.ownerId} />
        </Show>
        <Show when={isCallEntity(props.entity) && props.entity}>
          {(entity) => (
            <>
              <Show when={props.showCalendarAttendance !== false}>
                <CallStatusBadge status={entity().status} />
              </Show>
              <Show
                when={entity().durationMs}
                fallback={
                  <Show when={entity().isActive}>
                    <CallDurationBadge duration="In progress" />
                  </Show>
                }
              >
                {(durationMs) => (
                  <CallDurationBadge
                    duration={formatCallDuration(durationMs())}
                  />
                )}
              </Show>
              <span class="flex min-w-10 shrink-0 justify-end">
                <CallParticipants
                  participantIds={entity().participantIds}
                  guests={entity().guests}
                />
              </span>
            </>
          )}
        </Show>
        <Show when={isTaskEntity(props.entity) && props.entity}>
          {(entity) => <Entity.Properties entity={entity()} />}
        </Show>
        <Show when={isProjectContainedEntity(props.entity) && props.entity}>
          {(entity) => (
            <span class="ph-no-capture text-ink-extra-muted text-xs">
              <ProjectBreadCrumb
                entity={entity()}
                onClick={props.onProjectClick}
              />
            </span>
          )}
        </Show>
        <Show when={isChannelEntity(props.entity) && props.entity}>
          {(entity) => <ChannelActiveCallBadge channelId={entity().id} />}
        </Show>
        <Show
          when={
            isChannelEntity(props.entity) &&
            props.entity.isParticipant === false &&
            props.entity
          }
        >
          {(entity) => <ChannelJoinButton entity={entity()} />}
        </Show>
        {props.metaEnd}
      </Entity.Slot>
      <Entity.Slot
        placement="timestamp"
        class="flex items-center justify-end gap-1 text-xs text-right text-ink-extra-muted font-medium"
      >
        {props.scheduleStatus}
        <RowEnd actions={props.actions} leadingAction={props.leadingAction}>
          <Show
            when={
              !props.hasNotifications &&
              !(isChannelEntity(props.entity) && isSearchEntity(props.entity))
            }
          >
            <Switch fallback={<Entity.Timestamp entity={props.entity} />}>
              {/* The event's own date, not its sync time. */}
              <Match
                when={props.entity.type === 'calendar_event' && props.entity}
              >
                {(entity) => <CalendarStamp entity={entity()} />}
              </Match>
            </Switch>
          </Show>
        </RowEnd>
      </Entity.Slot>
    </Entity.Layout>
  );
}