✨ 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);
|
||||
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 = [
|
||||
<FormattedMessage id="app.no" />,
|
||||
|
@ -49,7 +67,8 @@ const DraftSettings = props => {
|
|||
key: setting,
|
||||
name: setting,
|
||||
labels: labels[setting],
|
||||
noDocs: props.noDocs
|
||||
noDocs: props.noDocs,
|
||||
dflt: getDefault(setting)
|
||||
};
|
||||
childProps.title = (
|
||||
<FormattedMessage id={"settings." + setting + ".title"} />
|
||||
|
@ -58,7 +77,6 @@ const DraftSettings = props => {
|
|||
<FormattedMessage id={"settings." + setting + ".description"} />
|
||||
);
|
||||
if (setting === "only") {
|
||||
childProps.dflt = "dflt";
|
||||
childProps.customDflt = [];
|
||||
childProps.parts = {};
|
||||
if (props.config.draftOrder) {
|
||||
|
@ -80,17 +98,13 @@ const DraftSettings = props => {
|
|||
let groups = {
|
||||
preferences: [
|
||||
<DraftSettingSa {...addProps("sa")} />,
|
||||
<DraftSettingPaperless {...addProps("paperless")} dflt={false} />,
|
||||
<DraftSettingComplete {...addProps("complete")} dflt={true} />
|
||||
<DraftSettingPaperless {...addProps("paperless")} />,
|
||||
<DraftSettingComplete {...addProps("complete")} />
|
||||
],
|
||||
advanced: [
|
||||
<DraftSettingOnly {...addProps("only")} />,
|
||||
<DraftSettingMargin {...addProps("margin")} dflt={2} />,
|
||||
<DraftSettingUnits
|
||||
{...addProps("units")}
|
||||
dflt={props.units}
|
||||
list={units}
|
||||
/>,
|
||||
<DraftSettingMargin {...addProps("margin")} />,
|
||||
<DraftSettingUnits {...addProps("units")} list={units} />,
|
||||
<DraftSettingLanguage {...addProps("locale")} />
|
||||
]
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ const OptionGroup = props => {
|
|||
let stringKey = `options.${props.config.name}.${name}.`;
|
||||
let extraProps = {
|
||||
name,
|
||||
dflt: optionDefault(props.config.options[name], props.gist),
|
||||
dflt: optionDefault(name, props.config.options[name], props.recipe),
|
||||
units: props.units,
|
||||
updateValue: props.updateValue,
|
||||
raiseEvent: props.raiseEvent,
|
||||
|
|
|
@ -28,6 +28,7 @@ const PatternOptions = props => {
|
|||
units={props.units}
|
||||
config={props.config}
|
||||
gist={props.gist}
|
||||
recipe={props.recipe}
|
||||
options={props.config.optionGroups[group]}
|
||||
updateValue={props.updateValue}
|
||||
raiseEvent={props.raiseEvent}
|
||||
|
|
|
@ -15,6 +15,7 @@ const DraftConfigurator = props => {
|
|||
noDocs={props.noDocs}
|
||||
config={props.config}
|
||||
gist={props.gist}
|
||||
recipe={props.recipe}
|
||||
updateValue={(name, value) =>
|
||||
props.updateGist(value, "settings", "options", name)
|
||||
}
|
||||
|
@ -28,6 +29,7 @@ const DraftConfigurator = props => {
|
|||
noDocs={props.noDocs}
|
||||
config={props.config}
|
||||
gist={props.gist}
|
||||
recipe={props.recipe}
|
||||
updateValue={(name, value) =>
|
||||
props.updateGist(value, "settings", name)
|
||||
}
|
||||
|
|
|
@ -120,6 +120,8 @@ name: Name
|
|||
newDraftFromGist: New draft from gist
|
||||
newDraft: New draft
|
||||
newModel: New model
|
||||
newPattern: 'New {pattern}'
|
||||
newPatternForModel: 'New {pattern} for {model}'
|
||||
noChanges: No changes
|
||||
no: No
|
||||
noPasswordPolicy: We don't enforce a password policy
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
import optionType from "../optionType";
|
||||
|
||||
const optionDefault = option => {
|
||||
const optionDefault = (name, option, recipe) => {
|
||||
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) {
|
||||
case "constant":
|
||||
return option;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue