function setSubmitErrors()

in experimenter/experimenter/nimbus-ui/src/components/PageEditBranches/FormBranches/reducer/actions.ts [270:310]


function setSubmitErrors(
  state: FormBranchesState,
  action: SetSubmitErrorsAction,
): FormBranchesState {
  let { referenceBranch, treatmentBranches } = state;
  const { submitErrors } = action;
  const globalErrors = [];

  if (!submitErrors) {
    return state;
  }

  for (const name of ["*", "feature_config"]) {
    if (Array.isArray(submitErrors[name])) {
      globalErrors.push(...submitErrors[name]);
    }
  }

  if (referenceBranch && submitErrors["reference_branch"]) {
    referenceBranch = {
      ...referenceBranch,
      // TODO: EXP-614 submitErrors type is any, but in practical use it's AnnotatedBranch["errors"]
      errors: (submitErrors["reference_branch"] ||
        {}) as AnnotatedBranch["errors"],
    };
  }

  if (treatmentBranches && submitErrors["treatment_branches"]) {
    treatmentBranches = treatmentBranches.map((treatmentBranch, idx) => ({
      ...treatmentBranch,
      errors: submitErrors["treatment_branches"][idx] || {},
    }));
  }

  return {
    ...state,
    globalErrors,
    referenceBranch,
    treatmentBranches,
  };
}