export function createInitialState()

in experimenter/experimenter/nimbus-ui/src/components/PageEditBranches/FormBranches/reducer/state.ts [37:79]


export function createInitialState({
  featureConfigs,
  preventPrefConflicts,
  warnFeatureSchema,
  isRollout,
  referenceBranch,
  treatmentBranches,
  isLocalized,
  localizations,
}: getExperiment_experimentBySlug): FormBranchesState {
  let lastId = 0;

  const equalRatio =
    treatmentBranches !== null &&
    treatmentBranches?.every(
      (branch) => branch?.ratio === referenceBranch?.ratio,
    );

  const annotatedReferenceBranch =
    referenceBranch === null
      ? null
      : annotateExperimentBranch("reference", referenceBranch!);

  const annotatedTreatmentBranches = !Array.isArray(treatmentBranches)
    ? null
    : treatmentBranches.map((branch) =>
        annotateExperimentBranch(lastId++, branch!),
      );

  return {
    lastId,
    equalRatio,
    featureConfigIds: featureConfigs?.map((f) => f?.id || null),
    warnFeatureSchema,
    isRollout,
    globalErrors: [],
    referenceBranch: annotatedReferenceBranch,
    treatmentBranches: annotatedTreatmentBranches,
    preventPrefConflicts: preventPrefConflicts ?? false,
    isLocalized,
    localizations,
  };
}