Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

1.6 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import type { WorkflowNode } from "@carbon/ee/workflows";
import { useWorkflowLabel } from "../Builder/catalog";
import { useDataOperationLabel } from "../Builder/dataOperationLabels";
import { nodeTitle } from "../Builder/labelKeys";
import { NODE_KIND_META } from "../Builder/nodes/meta";

export type NodeLabel = {
  /** The row's heading: the user's name for the step, else what it does. */
  title: string;
  /** What the step does, shown under the title. Empty when it repeats the title. */
  subtitle: string;
  /** The kind chip: Trigger / Compute / Condition / Action / Find / Filter. */
  kind: string;
};

/** One place deciding how a step is named, so the step list, the outcome sentence
 * and any future surface cannot disagree. */
export function useNodeLabel(): (node: WorkflowNode) => NodeLabel {
  const label = useWorkflowLabel();
  const operationLabel = useDataOperationLabel();

  return (node: WorkflowNode) => {
    const meta = NODE_KIND_META[node.type];
    const catalogId = meta.catalogId?.(node);
    const describes =
      (catalogId === undefined ? undefined : label(catalogId, catalogId)) ??
      meta.title?.(node) ??
      meta.summary?.(node, { operation: operationLabel }) ??
      meta.defaultTitle;

    const title = nodeTitle(node.name, describes);

    return {
      title,
      subtitle: title === describes ? "" : describes,
      kind: meta.name
    };
  };
}