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

@ -12,6 +12,8 @@ Unreleased:
waralee:
- Added the Waralee wrap Pants pattern by @woutervdub
Changed:
css-theme:
- Made tweaks to the main/sidebar layout
core:
- The pattern super constructor now sets a `config` property that
holds the pattern configuration. This means that unlike before, there
@ -19,6 +21,7 @@ Unreleased:
import the pattern, and it's config property will contain the pattern config.
components:
- Added Penelope and Waralee linedrawings
- Changed animation of the Spinner component
simon:
- "[#123](https://github.com/freesewing/freesewing/issues/123):
Added a box pleat option to Simon"
@ -32,6 +35,8 @@ Unreleased:
package has been deprecated. Please import our patterns individually.
Removed:
Fixed:
css-theme:
- Reduced the sidebar height by 64px to take navbar into account
components:
- Fixed display of nested option in SampleConfigurator
- Fixed conflicting key values in React components
@ -40,6 +45,8 @@ Unreleased:
to be set incorrectly
- Added a missing paperless dimension for the waist
- Fixed an issue where the split yoke option was not taken into account correctly
utils:
- Fixed an issue where optionDefault was not handling list options correctly
Security:
2.0.4:

View file

@ -264,3 +264,5 @@ cutting: Cutting
instructions: Instructions
hide: Hide
show: Show
oneMomentPlease: One moment please
loadingMagic: We are loading the magic

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