All files / src/components/board stageConfig.ts

100% Statements 27/27
88.88% Branches 8/9
100% Functions 3/3
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                    6x 6x 4x 4x 6x 6x   1x 1x 1x 1x   1x 1x 1x 3x 3x 3x 3x 1x   1x 2x 4x 4x 4x 4x 4x 4x 2x  
import type { BoardStage, CommandView, ModelProfileView } from "../../types";
 
export type EditableBoardStage = {
  id: string;
  name: string;
  profile_id: string;
  command_id: string;
  auto_start: boolean;
};
 
function sanitizeReference(value: string | null | undefined, allowedIds: Set<string>): string {
  if (!value) {
    return "";
  }
  return allowedIds.has(value) ? value : "";
}
 
export function sanitizeEditableBoardStages(
  stages: EditableBoardStage[],
  profiles: ModelProfileView[],
  commands: CommandView[],
): EditableBoardStage[] {
  const allowedProfileIds = new Set(profiles.map((profile) => profile.id));
  const allowedCommandIds = new Set(commands.map((command) => command.id));
  return stages.map((stage) => ({
    ...stage,
    profile_id: sanitizeReference(stage.profile_id, allowedProfileIds),
    command_id: sanitizeReference(stage.command_id, allowedCommandIds),
  }));
}
 
export function toEditableBoardStages(stages: BoardStage[]): EditableBoardStage[] {
  return stages.map((stage) => ({
    id: stage.id,
    name: stage.name,
    profile_id: stage.profile_id ?? "",
    command_id: stage.command_id ?? "",
    auto_start: stage.auto_start,
  }));
}