Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@
"styles": {
"tab": "Style",
"no-source": "Please select a source before configuring style",
"secondarylabels": "Secondary styles"
"secondarylabels": "Secondary styles",
"step": "Step"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@
"styles": {
"tab": "Style",
"no-source": "Veuillez choisir une source de données avant de configurer les styles",
"secondarylabels": "Styles secondaires"
"secondarylabels": "Styles secondaires",
"step": "Borne"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import randomColor from 'randomcolor';

import { makeStyles } from '@material-ui/core/styles';

import { number, useTranslate } from 'react-admin';
import { Field } from 'react-final-form';
import { TextField } from '@material-ui/core';
import ColorPicker from '../../../../../../../components/react-admin/ColorPicker';
import Condition from '../../../../../../../components/react-admin/Condition';

import styles from './styles';

const useStyles = makeStyles(styles);

const DEFAULT_MAX_CLASSES = 15;

const ColorListField = ({ value, onChange = () => {}, maxClasses = DEFAULT_MAX_CLASSES }) => {
const ColorListField = ({ path, value, onChange = () => {}, maxClasses = DEFAULT_MAX_CLASSES }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a colorListField anymore...

const classes = useStyles();
const translate = useTranslate();

const handleColorChange = index => newValue => {
const newColorList = [...value];
Expand All @@ -35,13 +40,54 @@ const ColorListField = ({ value, onChange = () => {}, maxClasses = DEFAULT_MAX_C
return (
<div className={classes.colorList}>
{(value || []).map((color, index) => (
<ColorPicker
// eslint-disable-next-line react/no-array-index-key
key={index}
value={color}
onChange={handleColorChange(index)}
/>
// eslint-disable-next-line react/no-array-index-key
<React.Fragment key={index}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a validation for step order ?

<Condition when={`${path}.method`} is="manual">
<Field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use react-admin NumberInput here ?

name={`${path}.boundaries[${index}]`}
parse={v => Number(v)}
>
{({ meta, input: { value: boundValue, onChange: onBoundChange } }) => (
<TextField
style={{ width: '10%' }}
type="number"
label={translate('datalayer.form.styles.step')}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use same translation prefix as other field.

value={boundValue}
onChange={onBoundChange}
error={meta.error && meta.touched}
helperText={(meta.error && meta.touched ? meta.error : '')}
/>
)}
</Field>
</Condition>
<ColorPicker
value={color}
onChange={handleColorChange(index)}
/>
<Condition
when={`${path}.method`}
is={v => (v === 'manual' && index === (value.length - 1))}
>
<Field
name={`${path}.boundaries[${value.length}]`}
parse={v => Number(v)}
>
{({ meta, input: { value: boundValue, onChange: onBoundChange } }) => (
<TextField
type="number"
style={{ width: '10%' }}
label={translate('datalayer.form.styles.step')}
value={boundValue}
onChange={onBoundChange}
error={meta.error && meta.touched}
helperText={meta.error && meta.touched ? meta.error : ''}
/>
)}
</Field>
</Condition>
</React.Fragment>
))}

<button type="button" className="action" onClick={removeColor(value.length - 1)}>
-
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const GraduateValue = ({ path, Component = ValueListField, defaultValue = defVal
{ id: 'jenks', name: translate('style-editor.graduate.method.jenks') },
{ id: 'quantile', name: translate('style-editor.graduate.method.quantiles') },
{ id: 'equal_interval', name: translate('style-editor.graduate.method.equal-interval') },
/* { id: 'manual', name: translate('style-editor.graduate.method.manual') }, */
{ id: 'manual', name: translate('style-editor.graduate.method.manual') },
]}
/>
</div>

<FormLabel>{translate('style-editor.graduate.steps')}</FormLabel>
<Field name={`${path}.values`} defaultValue={defaultValue}>
{({ input: { value, onChange } }) => (
<Component value={value} onChange={onChange} />
<Component value={value} onChange={onChange} path={path} />
)}
</Field>
</>
Expand Down