Example #1
0
 [JobFormActionType.AddArrayItem]: (_: any, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   if (!Array.isArray(stateCopy.job.run.args) || !stateCopy.job.run.args) {
     stateCopy.job.run.args = [];
   }
   stateCopy.job.run.args.push("");
   return stateCopy;
 },
Example #2
0
 [JobFormActionType.RemoveArrayItem]: (value: number, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   const args = stateCopy.job.run.args;
   if (args && Array.isArray(args) && args.length >= value + 1) {
     args.splice(value, 1);
   }
   return stateCopy;
 },
Example #3
0
 [JobFormActionType.Set]: (_: string, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   const docker = stateCopy.job.run.docker;
   if (docker) {
     const prevValue = Boolean(docker.privileged);
     docker.privileged = !prevValue;
   }
   return stateCopy;
 }
Example #4
0
 [JobFormActionType.Set]: (value: string, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   const restart = findNestedPropertyInObject(stateCopy, "job.run.restart");
   if (!restart) {
     stateCopy.job.run.restart = {};
   }
   stateCopy.job.run.restart.policy = value;
   return stateCopy;
 }
Example #5
0
 [JobFormActionType.Set]: (value: string, state: JobSpec, path: string[]) => {
   const stateCopy = deepCopy(state);
   const args = stateCopy.job.run.args;
   const [i] = path;
   const index = parseFloat(i);
   if (args && Array.isArray(args) && args.length >= index + 1) {
     args[index] = value;
   }
   return stateCopy;
 }
Example #6
0
 [JobFormActionType.Set]: (value: "true" | "false", state: JobSpec) => {
   const stateCopy = deepCopy(state);
   if (value === "true") {
     stateCopy.cmdOnly = true;
   } else if (value === "false") {
     stateCopy.cmdOnly = false;
   } else {
     throw new Error(`expected 'true' or 'false', received ${value}`);
   }
   return stateCopy;
 }
Example #7
0
 [JobFormActionType.RemoveArrayItem]: (value: number, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   const docker = stateCopy.job.run.docker;
   if (
     docker &&
     Array.isArray(docker.parameters) &&
     docker.parameters.length >= value + 1
   ) {
     docker.parameters.splice(value, 1);
   }
   return stateCopy;
 },
Example #8
0
 [JobFormActionType.Set]: (_: any, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   if (!stateCopy.schedule) {
     stateCopy.schedule = {};
   }
   const prevValue = Boolean(stateCopy.schedule.enabled);
   stateCopy.schedule.enabled = !prevValue;
   if (schedulePropertiesCanBeDiscarded(stateCopy.schedule)) {
     stateCopy.schedule = undefined;
   }
   return stateCopy;
 }
Example #9
0
const updateAt = (state: JobSpec, path: string[], value: any) => {
  const stateCopy = deepCopy(state);
  const assignProp = path.pop();
  if (!assignProp) {
    throw Error(`can not set a prop without a path`);
  }
  path.reduce((acc: any, current) => {
    if (current === "schedule" && !acc[current]) {
      acc[current] = {};
    }
    return acc[current];
  }, stateCopy)[assignProp] = value;

  return stateCopy;
};
Example #10
0
 [JobFormActionType.Set]: (_: any, state: JobSpec) => {
   const stateCopy = deepCopy(state);
   if (!stateCopy.schedule) {
     stateCopy.schedule = {};
   }
   const prevValue = stateCopy.schedule.concurrencyPolicy;
   stateCopy.schedule.concurrencyPolicy =
     !prevValue || prevValue === ConcurrentPolicy.Forbid
       ? (stateCopy.schedule.concurrencyPolicy = ConcurrentPolicy.Allow)
       : (stateCopy.schedule.concurrencyPolicy = ConcurrentPolicy.Forbid);
   if (schedulePropertiesCanBeDiscarded(stateCopy.schedule)) {
     stateCopy.schedule = undefined;
   }
   return stateCopy;
 }