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.4 KB
Raw Blame
import type { EntityType } from '@service-properties/generated/schemas/entityType';
import { Match, Switch } from 'solid-js';
import { useProperty } from '../../core/context';
import type { EntityPickerOptions } from '../selectors/types';
import { DateEditor, DateSheetEditor } from './DateEditor';
import { DateRangeEditor } from './DateRangeEditor';
import { EntityEditor, EntitySheetEditor } from './EntityEditor';
import { SelectEditor } from './SelectEditor';

type PopoverEditorProps = {
  /**
   * Forwarded to EntityEditor to filter the owning entity out of the picker.
   * Has no effect for non-entity properties.
   */
  entitySelfFilter?: { entityType: EntityType; blockId?: string };
  /** Forwarded to EntityEditor; has no effect for non-entity properties. */
  entityPicker?: EntityPickerOptions;
};

/**
 * Dispatches to the right popover editor based on property.valueType. Renders
 * nothing for inline types (STRING / NUMBER / BOOLEAN / LINK) — those use
 * <Property.InlineEditor /> in place of a display.
 */
export function PopoverEditor(props: PopoverEditorProps) {
  const ctx = useProperty();
  const type = () => ctx.property().valueType;

  return (
    <Switch>
      <Match when={type() === 'DATE'}>
        <DateEditor />
      </Match>
      <Match when={type() === 'DATE_RANGE'}>
        <DateRangeEditor />
      </Match>
      <Match when={type() === 'SELECT_STRING' || type() === 'SELECT_NUMBER'}>
        <SelectEditor />
      </Match>
      <Match when={type() === 'ENTITY'}>
        <EntityEditor
          selfFilter={props.entitySelfFilter}
          entityPicker={props.entityPicker}
        />
      </Match>
    </Switch>
  );
}

/**
 * `PopoverEditor` for pills inside a touch sheet: ENTITY properties (people,
 * projects) and dates pick in a `PickerSheet` stacked over it; selects keep
 * their popovers, which fit above the keyboard.
 */
export function SheetEditor(props: PopoverEditorProps) {
  const ctx = useProperty();
  const type = () => ctx.property().valueType;
  return (
    <Switch
      fallback={
        <PopoverEditor
          entitySelfFilter={props.entitySelfFilter}
          entityPicker={props.entityPicker}
        />
      }
    >
      <Match when={type() === 'ENTITY'}>
        <EntitySheetEditor
          selfFilter={props.entitySelfFilter}
          entityPicker={props.entityPicker}
        />
      </Match>
      <Match when={type() === 'DATE'}>
        <DateSheetEditor />
      </Match>
    </Switch>
  );
}