✨ Added support for loading defaults from recipe
This commit is contained in:
parent
391894b5a3
commit
3a20d35b56
6 changed files with 41 additions and 12 deletions
|
@ -19,6 +19,24 @@ const DraftSettings = props => {
|
||||||
else shown.splice(index, 1);
|
else shown.splice(index, 1);
|
||||||
setExpanded(shown);
|
setExpanded(shown);
|
||||||
};
|
};
|
||||||
|
const getDefault = setting => {
|
||||||
|
if (props.recipe && typeof props.recipe.settings[setting] !== "undefined")
|
||||||
|
return props.recipe.settings[setting];
|
||||||
|
switch (setting) {
|
||||||
|
case "sa":
|
||||||
|
return 10;
|
||||||
|
case "only":
|
||||||
|
return "dflt";
|
||||||
|
case "complete":
|
||||||
|
return true;
|
||||||
|
case "margin":
|
||||||
|
return 2;
|
||||||
|
case "units":
|
||||||
|
return props.units;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let noyes = [
|
let noyes = [
|
||||||
<FormattedMessage id="app.no" />,
|
<FormattedMessage id="app.no" />,
|
||||||
|
@ -49,7 +67,8 @@ const DraftSettings = props => {
|
||||||
key: setting,
|
key: setting,
|
||||||
name: setting,
|
name: setting,
|
||||||
labels: labels[setting],
|
labels: labels[setting],
|
||||||
noDocs: props.noDocs
|
noDocs: props.noDocs,
|
||||||
|
dflt: getDefault(setting)
|
||||||
};
|
};
|
||||||
childProps.title = (
|
childProps.title = (
|
||||||
<FormattedMessage id={"settings." + setting + ".title"} />
|
<FormattedMessage id={"settings." + setting + ".title"} />
|
||||||
|
@ -58,7 +77,6 @@ const DraftSettings = props => {
|
||||||
<FormattedMessage id={"settings." + setting + ".description"} />
|
<FormattedMessage id={"settings." + setting + ".description"} />
|
||||||
);
|
);
|
||||||
if (setting === "only") {
|
if (setting === "only") {
|
||||||
childProps.dflt = "dflt";
|
|
||||||
childProps.customDflt = [];
|
childProps.customDflt = [];
|
||||||
childProps.parts = {};
|
childProps.parts = {};
|
||||||
if (props.config.draftOrder) {
|
if (props.config.draftOrder) {
|
||||||
|
@ -80,17 +98,13 @@ const DraftSettings = props => {
|
||||||
let groups = {
|
let groups = {
|
||||||
preferences: [
|
preferences: [
|
||||||
<DraftSettingSa {...addProps("sa")} />,
|
<DraftSettingSa {...addProps("sa")} />,
|
||||||
<DraftSettingPaperless {...addProps("paperless")} dflt={false} />,
|
<DraftSettingPaperless {...addProps("paperless")} />,
|
||||||
<DraftSettingComplete {...addProps("complete")} dflt={true} />
|
<DraftSettingComplete {...addProps("complete")} />
|
||||||
],
|
],
|
||||||
advanced: [
|
advanced: [
|
||||||
<DraftSettingOnly {...addProps("only")} />,
|
<DraftSettingOnly {...addProps("only")} />,
|
||||||
<DraftSettingMargin {...addProps("margin")} dflt={2} />,
|
<DraftSettingMargin {...addProps("margin")} />,
|
||||||
<DraftSettingUnits
|
<DraftSettingUnits {...addProps("units")} list={units} />,
|
||||||
{...addProps("units")}
|
|
||||||
dflt={props.units}
|
|
||||||
list={units}
|
|
||||||
/>,
|
|
||||||
<DraftSettingLanguage {...addProps("locale")} />
|
<DraftSettingLanguage {...addProps("locale")} />
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ const OptionGroup = props => {
|
||||||
let stringKey = `options.${props.config.name}.${name}.`;
|
let stringKey = `options.${props.config.name}.${name}.`;
|
||||||
let extraProps = {
|
let extraProps = {
|
||||||
name,
|
name,
|
||||||
dflt: optionDefault(props.config.options[name], props.gist),
|
dflt: optionDefault(name, props.config.options[name], props.recipe),
|
||||||
units: props.units,
|
units: props.units,
|
||||||
updateValue: props.updateValue,
|
updateValue: props.updateValue,
|
||||||
raiseEvent: props.raiseEvent,
|
raiseEvent: props.raiseEvent,
|
||||||
|
|
|
@ -28,6 +28,7 @@ const PatternOptions = props => {
|
||||||
units={props.units}
|
units={props.units}
|
||||||
config={props.config}
|
config={props.config}
|
||||||
gist={props.gist}
|
gist={props.gist}
|
||||||
|
recipe={props.recipe}
|
||||||
options={props.config.optionGroups[group]}
|
options={props.config.optionGroups[group]}
|
||||||
updateValue={props.updateValue}
|
updateValue={props.updateValue}
|
||||||
raiseEvent={props.raiseEvent}
|
raiseEvent={props.raiseEvent}
|
||||||
|
|
|
@ -15,6 +15,7 @@ const DraftConfigurator = props => {
|
||||||
noDocs={props.noDocs}
|
noDocs={props.noDocs}
|
||||||
config={props.config}
|
config={props.config}
|
||||||
gist={props.gist}
|
gist={props.gist}
|
||||||
|
recipe={props.recipe}
|
||||||
updateValue={(name, value) =>
|
updateValue={(name, value) =>
|
||||||
props.updateGist(value, "settings", "options", name)
|
props.updateGist(value, "settings", "options", name)
|
||||||
}
|
}
|
||||||
|
@ -28,6 +29,7 @@ const DraftConfigurator = props => {
|
||||||
noDocs={props.noDocs}
|
noDocs={props.noDocs}
|
||||||
config={props.config}
|
config={props.config}
|
||||||
gist={props.gist}
|
gist={props.gist}
|
||||||
|
recipe={props.recipe}
|
||||||
updateValue={(name, value) =>
|
updateValue={(name, value) =>
|
||||||
props.updateGist(value, "settings", name)
|
props.updateGist(value, "settings", name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@ name: Name
|
||||||
newDraftFromGist: New draft from gist
|
newDraftFromGist: New draft from gist
|
||||||
newDraft: New draft
|
newDraft: New draft
|
||||||
newModel: New model
|
newModel: New model
|
||||||
|
newPattern: 'New {pattern}'
|
||||||
|
newPatternForModel: 'New {pattern} for {model}'
|
||||||
noChanges: No changes
|
noChanges: No changes
|
||||||
no: No
|
no: No
|
||||||
noPasswordPolicy: We don't enforce a password policy
|
noPasswordPolicy: We don't enforce a password policy
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
import optionType from "../optionType";
|
import optionType from "../optionType";
|
||||||
|
|
||||||
const optionDefault = option => {
|
const optionDefault = (name, option, recipe) => {
|
||||||
let type = optionType(option);
|
let type = optionType(option);
|
||||||
|
let factor = type === "pct" ? 100 : 1;
|
||||||
|
// Default from recipe?
|
||||||
|
if (
|
||||||
|
recipe &&
|
||||||
|
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;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "constant":
|
case "constant":
|
||||||
return option;
|
return option;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue