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.

4.6 KB
Raw Blame
import type { GroupHeaderProps } from '@app/features/next-soup/create-soup-state';
import { SoupSectionHeader } from '@app/features/next-soup/soup-view/section-header';
import { useSoupView } from '@app/features/next-soup/soup-view/soup-view-context';
import { UserIcon } from '@core/component/UserIcon';
import { getDisplayName, type MacroId, tryMacroId } from '@core/user';
import ChevronRightIcon from '@icon/system/regular/caret-right.svg';
import CircleDashed from '@icon/system/regular/circle-dashed.svg';
import { PROPERTY_OPTION_IDS, SYSTEM_PROPERTY_IDS } from '@property';
import { PropertyValueIcon } from '@property/component/propertyValue';
import { cn, Layer } from '@ui';
import { createMemo, Match, Switch } from 'solid-js';

const AssigneeGroupContent = (props: {
  assigneeId: MacroId;
  fallbackLabel: string;
}) => {
  const assigneeName = () =>
    getDisplayName(props.assigneeId, { emailFallback: 'local-part' });
  return (
    <>
      <UserIcon
        id={props.assigneeId}
        size="sm"
        suppressClick
        showTooltip={false}
      />
      <span class="truncate">
        {assigneeName() || props.assigneeId || props.fallbackLabel}
      </span>
    </>
  );
};

const STATUS_GROUP_HEADER_TINTS: Record<string, string> = {
  [PROPERTY_OPTION_IDS.STATUS.NOT_STARTED]:
    'bg-task-status-not-started/5 border-task-status-not-started/10 data-highlighted:bg-task-status-not-started/10 hover:bg-task-status-not-started/10',
  [PROPERTY_OPTION_IDS.STATUS.IN_PROGRESS]:
    'bg-task-status-in-progress/5 border-task-status-in-progress/10 data-highlighted:bg-task-status-in-progress/10 hover:bg-task-status-in-progress/10',
  [PROPERTY_OPTION_IDS.STATUS.IN_REVIEW]:
    'bg-task-status-in-review/5 border-task-status-in-review/10 data-highlighted:bg-task-status-in-review/10 hover:bg-task-status-in-review/10',
  [PROPERTY_OPTION_IDS.STATUS.COMPLETED]:
    'bg-task-status-completed/5 border-task-status-completed/10 data-highlighted:bg-task-status-completed/10 hover:bg-task-status-completed/10',
  [PROPERTY_OPTION_IDS.STATUS.CANCELED]:
    'bg-task-status-canceled/5 border-task-status-canceled/10 data-highlighted:bg-task-status-canceled/10 hover:bg-task-status-canceled/10',
};

export const TaskGroupHeader = (
  props: GroupHeaderProps & { highlighted?: boolean }
) => {
  const { groupByField } = useSoupView();
  const assigneeId = createMemo(() => {
    const field = groupByField();
    if (
      field?.type !== 'property' ||
      (field.propertyDefinitionId !== SYSTEM_PROPERTY_IDS.ASSIGNEES &&
        field.propertyDefinitionId !== SYSTEM_PROPERTY_IDS.COMPANY_OWNER) ||
      props.group.key === ''
    ) {
      return;
    }
    return tryMacroId(props.group.key);
  });

  const statusTint = createMemo(() => {
    const field = groupByField();
    if (
      field?.type !== 'property' ||
      field.propertyDefinitionId !== SYSTEM_PROPERTY_IDS.STATUS
    ) {
      return;
    }

    const optionId = props.group.value ?? props.group.key;
    if (typeof optionId !== 'string') return;

    return STATUS_GROUP_HEADER_TINTS[optionId];
  });

  return (
    <SoupSectionHeader
      onClick={() => props.group.toggle()}
      highlighted={props.highlighted}
      class={statusTint()}
    >
      <Layer depth={3}>
        <div class="flex items-center justify-center size-4.5 shrink-0 rounded-xs group-hover/header:bg-ink/5">
          <ChevronRightIcon
            class={cn('size-4', {
              'rotate-90': props.group.isExpanded(),
            })}
          />
        </div>
      </Layer>
      <Switch>
        <Match when={assigneeId()}>
          {(id) => (
            <AssigneeGroupContent
              assigneeId={id()}
              fallbackLabel={props.group.label}
            />
          )}
        </Match>
        <Match
          when={typeof props.group.value !== 'string' || !props.group.value}
        >
          <CircleDashed class="size-3.5 text-ink-extra-muted" />

          <span class="truncate">{props.group.label}</span>
        </Match>
        <Match
          when={typeof props.group.value === 'string' && props.group.value}
        >
          {(value) => (
            <>
              <PropertyValueIcon
                optionId={value()}
                class="min-h-4 min-w-4 shrink-0"
              />
              <span class="truncate">{props.group.label}</span>
            </>
          )}
        </Match>
      </Switch>
      <span
        class={cn(
          'shrink-0 tabular-nums text-xs font-medium',
          'px-1.5 py-px rounded-full bg-ink/10 text-ink-extra-muted'
        )}
      >
        {props.group.count}
      </span>
    </SoupSectionHeader>
  );
};