Skip to content

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

1.3 KB
Raw Blame
import { useEffect } from "react";
import { PolicyPiiField } from "@editor/components/policies/PolicyPiiField";
import type { RedactParameters } from "@editor/hooks/tools/redact/useRedactParameters";

interface PolicyRedactConfigProps {
  parameters: RedactParameters;
  onChange: (parameters: RedactParameters) => void;
  disabled?: boolean;
}

/**
 * Redact configuration for a policy — reduced to just the PII type picker. The
 * runtime params are fixed (mode automatic, regex on, flatten-to-image on so the
 * redacted text is truly removed) and normalised once on mount; the dropdown
 * only chooses which PII patterns are redacted.
 */
export function PolicyRedactConfig({
  parameters,
  onChange,
  disabled,
}: PolicyRedactConfigProps) {
  // Lock the non-PII params once on mount (empty deps); the dropdown manages the
  // pattern list and preserves these via its spread.
  useEffect(() => {
    if (
      parameters.mode !== "automatic" ||
      parameters.useRegex !== true ||
      parameters.convertPDFToImage !== true
    ) {
      onChange({
        ...parameters,
        mode: "automatic",
        useRegex: true,
        convertPDFToImage: true,
      });
    }
  }, []);

  return (
    <PolicyPiiField
      parameters={parameters}
      onChange={onChange}
      disabled={disabled}
    />
  );
}