-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add manual discretization method for styles #352
base: master
Are you sure you want to change the base?
Changes from all commits
977748d
d98d21f
349e5c1
99c5757
ef98018
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) => { | ||
const classes = useStyles(); | ||
const translate = useTranslate(); | ||
|
||
const handleColorChange = index => newValue => { | ||
const newColorList = [...value]; | ||
|
@@ -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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you use react-admin |
||
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')} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
There was a problem hiding this comment.
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...