Skip to content

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

2.7 KB
Raw Blame
import type { ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { Icon } from "@editor/ui/Icon";
import { Banner, EmptyState } from "@editor/ui";
import "@processor/theme/surface.css";
import "@processor/components/pipelines/PipelineInspector.css";
import { PrivateContent } from "@editor/components/shared/PrivateContent";

export interface PipelineInspectorProps {
  /** Names what is selected, e.g. the step's tool or "Input". Absent when nothing is. */
  title?: string;
  icon?: ReactNode;
  /**
   * Why the last test run failed on this step. Only ever set for the one step the run stopped at -
   * the run reports a single failing step, so no other node can claim the error.
   */
  error?: string | null;
  /**
   * Shown instead of any editor - for a selection with no single thing to configure, such as
   * several steps at once.
   */
  message?: string;
  /** The selected node's own editor. Absent when nothing is selected. */
  children?: ReactNode;
}

/**
 * The builder's right-hand panel: the settings of whatever node is selected, and nothing else.
 *
 * Deliberately node-scoped. The definition and a test run's produced files belong to the whole
 * pipeline, so they live with the other pipeline-scoped controls in the header - putting them in a
 * switch here implied they were scoped to the selected node, which they never were.
 */
export function PipelineInspector({
  title,
  icon,
  error,
  message,
  children,
}: PipelineInspectorProps) {
  const { t } = useTranslation();

  if (message) {
    return (
      <aside className="portal-surface portal-inspector">
        <EmptyState
          size="compact"
          title={message}
          description={t("portal.pipelines.inspector.multipleBody")}
        />
      </aside>
    );
  }

  if (!children) {
    return (
      <aside className="portal-surface portal-inspector">
        <EmptyState
          size="compact"
          title={t("portal.pipelines.inspector.noSelectionTitle")}
          description={t("portal.pipelines.inspector.noSelectionBody")}
        />
      </aside>
    );
  }

  return (
    <aside className="portal-surface portal-inspector">
      {/* The title stays put while the settings scroll: it names the node being edited, which is
          what makes a long form legible. */}
      <div className="portal-inspector__title">
        {icon ?? <Icon name="sliders-horizontal" size={"1.125rem"} />}
        <span>{title}</span>
      </div>
      <div className="portal-inspector__body">
        {error && (
          <Banner tone="danger">
            <PrivateContent>{error}</PrivateContent>
          </Banner>
        )}
        {children}
      </div>
    </aside>
  );
}