Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

700 B
Raw Blame
type Rule = {
  id: string;
  integrationType: string;
  eventType: string;
  columnId: string;
};

type RuleChange =
  | { type: "upsert"; columnId: string }
  | { type: "delete"; id: string }
  | { type: "none" };

export function planRuleChange(
  rules: Rule[],
  integrationType: string,
  eventType: string,
  columnId: string | null,
): RuleChange {
  const rule = rules.find(
    (candidate) =>
      candidate.integrationType === integrationType &&
      candidate.eventType === eventType,
  );

  if (columnId) {
    return rule?.columnId === columnId
      ? { type: "none" }
      : { type: "upsert", columnId };
  }

  return rule ? { type: "delete", id: rule.id } : { type: "none" };
}