Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.5 KB
Raw Blame
import { useTranslation } from "react-i18next";
import { MultiSelect } from "@editor/ui";
import { LABEL_FAMILIES } from "@editor/data/classificationLabels";
import type { MatchesAnyCondition } from "@editor/conditions/types";

interface ClassificationConditionEditorProps {
  condition: MatchesAnyCondition;
  onChange: (condition: MatchesAnyCondition) => void;
  disabled?: boolean;
}

/** Edits classification values without owning the destination or action taken on a match. */
export function ClassificationConditionEditor({
  condition,
  onChange,
  disabled = false,
}: ClassificationConditionEditorProps) {
  const { t } = useTranslation();
  const labelData = LABEL_FAMILIES.map((family) => ({
    group: family.name,
    items: family.labels.map((label) => ({
      value: label.id,
      label: t(`classification.labels.${label.id}`, label.name),
    })),
  }));

  return (
    <MultiSelect
      inputSize="sm"
      aria-label={t(
        "portal.policies.wizard.routing.labelAria",
        "Document types",
      )}
      placeholder={
        condition.values.length === 0
          ? t(
              "portal.policies.wizard.routing.labelPlaceholder",
              "Choose document types",
            )
          : undefined
      }
      data={labelData}
      value={condition.values}
      onChange={(values) => onChange({ ...condition, values })}
      invalid={condition.values.length === 0}
      disabled={disabled}
      searchable
      clearable
      maxDropdownHeight={280}
      comboboxProps={{ withinPortal: true }}
    />
  );
}