2019-04-25 08:03:20 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import { FormattedMessage } from "react-intl";
|
|
|
|
import DraftSettingSa from "../DraftSettingSa";
|
|
|
|
import DraftSettingMargin from "../DraftSettingMargin";
|
|
|
|
import DraftSettingComplete from "../DraftSettingComplete";
|
|
|
|
import DraftSettingPaperless from "../DraftSettingPaperless";
|
|
|
|
import DraftSettingUnits from "../DraftSettingUnits";
|
|
|
|
import DraftSettingLanguage from "../DraftSettingLanguage";
|
|
|
|
import DraftSettingOnly from "../DraftSettingOnly";
|
2019-06-23 18:00:50 +02:00
|
|
|
import RightIcon from "@material-ui/icons/KeyboardArrowRight";
|
2019-04-25 08:03:20 +02:00
|
|
|
|
|
|
|
const DraftSettings = props => {
|
|
|
|
const [expanded, setExpanded] = useState([]);
|
|
|
|
const toggleGroup = group => {
|
|
|
|
let shown = expanded.slice(0);
|
|
|
|
let index = shown.indexOf(group);
|
|
|
|
if (index === -1) shown.push(group);
|
|
|
|
else shown.splice(index, 1);
|
|
|
|
setExpanded(shown);
|
|
|
|
};
|
|
|
|
|
|
|
|
let noyes = [
|
|
|
|
<FormattedMessage id="app.no" />,
|
|
|
|
<FormattedMessage id="app.yes" />
|
|
|
|
];
|
|
|
|
let units = {
|
|
|
|
metric: <FormattedMessage id="app.metricUnits" />,
|
|
|
|
imperial: <FormattedMessage id="app.imperialUnits" />
|
|
|
|
};
|
|
|
|
|
|
|
|
const addProps = setting => {
|
|
|
|
const labels = {
|
|
|
|
sa: {
|
|
|
|
none: <FormattedMessage id="app.noSeamAllowance" />,
|
|
|
|
dflt: <FormattedMessage id="app.standardSeamAllowance" />,
|
|
|
|
custom: <FormattedMessage id="app.customSeamAllowance" />
|
|
|
|
},
|
|
|
|
only: {
|
|
|
|
dflt: <FormattedMessage id="app.default" />,
|
|
|
|
custom: <FormattedMessage id="app.custom" />
|
|
|
|
},
|
|
|
|
paperless: noyes,
|
|
|
|
complete: noyes
|
|
|
|
};
|
|
|
|
let childProps = {
|
2019-04-30 16:20:43 +02:00
|
|
|
raiseEvent: props.raiseEvent,
|
2019-04-25 08:03:20 +02:00
|
|
|
updateValue: props.updateValue,
|
|
|
|
units: props.units,
|
|
|
|
key: setting,
|
|
|
|
name: setting,
|
2019-05-10 10:53:34 +02:00
|
|
|
labels: labels[setting],
|
|
|
|
noDocs: props.noDocs
|
2019-04-25 08:03:20 +02:00
|
|
|
};
|
|
|
|
childProps.title = (
|
|
|
|
<FormattedMessage id={"settings." + setting + ".title"} />
|
|
|
|
);
|
|
|
|
childProps.desc = (
|
|
|
|
<FormattedMessage id={"settings." + setting + ".description"} />
|
|
|
|
);
|
|
|
|
if (setting === "only") {
|
|
|
|
childProps.dflt = "dflt";
|
|
|
|
childProps.customDflt = [];
|
|
|
|
childProps.parts = {};
|
2019-05-05 17:06:22 +02:00
|
|
|
if (props.config.parts) {
|
|
|
|
for (let part of props.config.parts) // HERE
|
|
|
|
childProps.parts[part] = <FormattedMessage id={"parts." + part} />;
|
|
|
|
}
|
2019-04-25 08:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return childProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
let groups = {
|
|
|
|
preferences: [
|
|
|
|
<DraftSettingSa {...addProps("sa")} />,
|
|
|
|
<DraftSettingPaperless {...addProps("paperless")} dflt={false} />,
|
|
|
|
<DraftSettingComplete {...addProps("complete")} dflt={true} />
|
|
|
|
],
|
|
|
|
advanced: [
|
|
|
|
<DraftSettingOnly {...addProps("only")} />,
|
|
|
|
<DraftSettingMargin {...addProps("margin")} dflt={2} />,
|
|
|
|
<DraftSettingUnits
|
|
|
|
{...addProps("units")}
|
|
|
|
dflt={props.units}
|
|
|
|
list={units}
|
|
|
|
/>,
|
2019-04-27 10:50:44 +02:00
|
|
|
<DraftSettingLanguage {...addProps("locale")} />
|
2019-04-25 08:03:20 +02:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2019-06-23 18:00:50 +02:00
|
|
|
<ul className="config l2">
|
2019-04-25 08:03:20 +02:00
|
|
|
{Object.keys(groups).map(group => {
|
|
|
|
let open = true;
|
|
|
|
if (expanded.indexOf(group) === -1) open = false;
|
2019-04-26 12:59:03 +02:00
|
|
|
let children = null;
|
|
|
|
if (open) children = groups[group].map(component => component);
|
2019-04-25 08:03:20 +02:00
|
|
|
return (
|
2019-05-01 10:43:39 +02:00
|
|
|
<React.Fragment key={group}>
|
2019-04-26 12:59:03 +02:00
|
|
|
<li
|
|
|
|
className={open ? "expanded" : "collapsed"}
|
|
|
|
key={group + "-ghead"}
|
2019-04-25 08:03:20 +02:00
|
|
|
>
|
2019-06-23 18:00:50 +02:00
|
|
|
<span onClick={() => toggleGroup(group)}>
|
|
|
|
<RightIcon
|
2019-04-26 12:59:03 +02:00
|
|
|
className={
|
|
|
|
"icon-col-exp " + (open ? "expanded" : "collapsed")
|
|
|
|
}
|
|
|
|
/>
|
2019-04-25 08:03:20 +02:00
|
|
|
<FormattedMessage id={"optiongroups." + group} />
|
2019-06-23 18:00:50 +02:00
|
|
|
</span>
|
2019-04-26 12:59:03 +02:00
|
|
|
</li>
|
|
|
|
{children}
|
2019-04-25 08:03:20 +02:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
})}
|
2019-04-26 08:25:15 +02:00
|
|
|
</ul>
|
2019-04-25 08:03:20 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
DraftSettings.propTypes = {
|
2019-06-16 16:47:20 +02:00
|
|
|
config: PropTypes.object.isRequired
|
2019-04-25 08:03:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DraftSettings.defaultProps = {};
|
|
|
|
|
|
|
|
export default DraftSettings;
|