Blocks / Version history

Version history

Versions with their message and changes, the draft on top; restore one as a draft.

import { VersionHistory } from "@forgeron/ui";
/01 → Default

Draft

Changes since v4. Manual runs use the draft; triggers use the published version.

  • Added: Step “Mail the CFO”
  • Changed: Above €5,000?: compare to
import { VersionHistory } from "@forgeron/ui";

export default function Default() {
  return (
    <div style={{ width: "100%", maxWidth: 720 }}>
      <VersionHistory
        live={4}
        draft={[
          { kind: "add", text: "Step “Mail the CFO”" },
          { kind: "change", text: "Above €5,000?: compare to" },
        ]}
        versions={[
          {
            version: 4,
            message: "Escalate amounts above €5,000",
            at: "2026-11-16 17:20",
            by: "Camille Roy",
            changes: [
              { kind: "add", text: "Step “Above €5,000?”" },
              { kind: "add", text: "Wire Above €5,000? → Draft the invoice (true)" },
            ],
          },
          {
            version: 3,
            message: "Thank the client by mail",
            at: "2026-11-09 11:02",
            by: "Hugo Bernard",
            changes: [{ kind: "add", text: "Step “Thank the client”" }],
          },
          {
            version: 2,
            message: "Post in #sales, not #general",
            at: "2026-11-02 09:40",
            by: "Léa Martin",
            changes: [{ kind: "change", text: "Tell #sales: channel" }],
          },
        ]}
        onPublish={() => {}}
        onDiscard={() => {}}
        onRestore={() => {}}
      />
    </div>
  );
}
/02 → Restore a version

v1 · First version

Published by Hugo Bernard on 2026-11-03 14:12

  • Added: Step “Schedule”
  • Added: Step “Fetch carrier rates”
  • Added: Step “Post the cheapest”
Nothing restored
import { VersionHistory, type AutomationVersion } from "@forgeron/ui";
import { useState } from "react";

const versions: AutomationVersion[] = [
  {
    version: 2,
    message: "Retry the carrier three times",
    at: "2026-11-12 08:30",
    by: "Hugo Bernard",
    changes: [{ kind: "change", text: "Fetch carrier rates: settings" }],
  },
  {
    version: 1,
    message: "First version",
    at: "2026-11-03 14:12",
    by: "Hugo Bernard",
    changes: [
      { kind: "add", text: "Step “Schedule”" },
      { kind: "add", text: "Step “Fetch carrier rates”" },
      { kind: "add", text: "Step “Post the cheapest”" },
    ],
  },
];

// No draft: the live version is the last one. Restoring an older one makes it the draft.
export default function RestoreAVersion() {
  const [restored, setRestored] = useState<number | null>(null);
  return (
    <div style={{ display: "grid", gap: 12, width: "100%", maxWidth: 720 }}>
      <VersionHistory versions={versions} live={2} defaultSelected={1} onRestore={setRestored} />
      <span className="t-mono dim">
        {restored ? `v${restored} restored as the draft` : "Nothing restored"}
      </span>
    </div>
  );
}
API → Props
PropTypeDefaultDescription
versions{ version, message, at, by, changes? }[]—Newest first; a change is { kind: add | remove | change, text }.
draftVersionChange[]—Unpublished changes: a Draft entry.
livenumber—The version the triggers run.
selected / onSelectnumber | "draft"—The entry shown.
onRestore / onPublish / onDiscard…—The buttons of the entry.
classNamestring—Extra classes.