Skip to content

Open-source status page, incident response and uptime monitoring

926 B
Raw Blame
import type { AgentToolInput } from "@openstatus/services/agent-tools";

import type { ChangeRow } from "@/components/common/changes-table";

type Input = AgentToolInput<"add_status_report_update">;

type Applied = {
  statusReportUpdateId: number;
  notified?: boolean;
};

export function addStatusReportUpdateChanges(
  input: Input,
  applied?: Applied,
): ChangeRow[] {
  const changes: ChangeRow[] = [
    { field: "statusReportId", after: input.statusReportId },
    { field: "status", after: input.status },
    { field: "message", after: input.message },
    {
      field: "notify",
      after: applied?.notified !== undefined ? applied.notified : input.notify,
    },
  ];
  if (input.componentImpacts?.length) {
    changes.push({
      field: "componentImpacts",
      after: input.componentImpacts,
    });
  }
  if (input.date) {
    changes.push({ field: "date", after: input.date });
  }
  return changes;
}