1
0
Fork 0

🐛 Fixed issue in utils/optionDefault with list type options

This commit is contained in:
Joost De Cock 2019-10-02 07:50:01 +02:00
parent a08ba518ab
commit eb2dcf9568
3 changed files with 29 additions and 16 deletions

View file

@ -1,27 +1,31 @@
import optionType from "../optionType";
import optionType from '../optionType'
const optionDefault = (name, option, recipe) => {
let type = optionType(option);
let factor = type === "pct" ? 100 : 1;
let type = optionType(option)
// Default from recipe?
let fromRecipe = false
if (
recipe &&
typeof recipe.settings !== "undefined" &&
typeof recipe.settings.options !== "undefined" &&
typeof recipe.settings.options[name] !== "undefined"
typeof recipe.settings !== 'undefined' &&
typeof recipe.settings.options !== 'undefined' &&
typeof recipe.settings.options[name] !== 'undefined'
)
return Math.round(10 * recipe.settings.options[name] * factor) / 10;
fromRecipe = true
switch (type) {
case "constant":
return option;
break;
case "list":
return option.dflt;
break;
case 'constant':
return option
break
case 'list':
if (fromRecipe) return recipe.settings.options[name]
return option.dflt
break
default:
return option[type];
let factor = type === 'pct' ? 100 : 1
if (fromRecipe) return Math.round(10 * recipe.settings.options[name] * factor) / 10
else return option[type]
break
}
};
}
export default optionDefault;
export default optionDefault