Skip to content

Commit

Permalink
Fix templateId assignment when using templates to create an experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Mar 18, 2016
1 parent 70829fc commit 9c19194
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/js/components/experiments/ExperimentWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ class ExperimentWizard extends Wizard {
};

if (this.state.loaded && !this.state.failed) {
let isTemplate = this.state.new && this.props.location.state && "template" in this.props.location.state || this.state.data && "templateId" in this.state.data && this.state.data.templateId;
let isTemplate = this.state.new && this.props.location.state && "template" in this.props.location.state
|| this.state.data && "templateId" in this.state.data && this.state.data.templateId;

if (isTemplate) {
let text;
Expand All @@ -162,7 +163,7 @@ class ExperimentWizard extends Wizard {
template = {
content: this.props.location.state.experiment.description,
answerType: this.props.location.state.experiment.answerType,
id: this.props.location.state.experiment.templateId
id: this.props.location.state.experiment.templateId.value
}
} else {
throw "Invalid state!";
Expand All @@ -182,9 +183,10 @@ class ExperimentWizard extends Wizard {
templateId: {
type: "hidden",
value: template.id,
decoder: (i) => i.value,
encoder: (i) => {
return {value: parseInt(i)};
return {
value: parseInt(i)
};
}
}
});
Expand Down Expand Up @@ -446,16 +448,6 @@ class ExperimentWizard extends Wizard {
encoder: (text) => encodeTextCollection(text, ","),
decoder: (items) => items.map((item) => item.name).join(", ")
},
templateId: {
type: "hidden",
value: "",
encoder: (i) => {
return i ? {value: parseInt(i)} : null;
},
decoder: (i) => {
return i ? i.value : null;
}
},
workerQualityThreshold: {
type: "number",
label: "Worker Quality Threshold",
Expand Down Expand Up @@ -485,6 +477,19 @@ class ExperimentWizard extends Wizard {
}
});

if (!("templateId" in base)) {
base.templateId = {
type: "hidden",
value: "",
encoder: (i) => {
return i ? {value: parseInt(i)} : null;
},
decoder: (i) => {
return i ? i.value : "";
}
};
}

return base;
}

Expand Down

0 comments on commit 9c19194

Please sign in to comment.