From 4538d1e13452b971f5131f351cf66506bd2c9324 Mon Sep 17 00:00:00 2001 From: Mahad Date: Thu, 26 Mar 2020 09:38:35 +0100 Subject: [PATCH] feat: add filter --- src/components/radio.js | 19 +++++++++++-------- src/prefabs/radio.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/radio.js b/src/components/radio.js index e8277bff7..cfd21ff4d 100644 --- a/src/components/radio.js +++ b/src/components/radio.js @@ -22,6 +22,7 @@ position, margin, error, + filter, } = options; const isDev = B.env === 'dev'; const { GetAll, getProperty, useText, getActionInput } = B; @@ -40,7 +41,13 @@ componentHelperText = useText(helperText); } - const [value, setValue] = useState(componentValue); + componentValue = isNaN(Number(componentValue)) + ? componentValue + : Number(componentValue); + + // maintain the type of the value + const getValue = val => (isNaN(Number(val)) ? val : Number(val)); + const [value, setValue] = useState(getValue(componentValue)); const { FormControl: MUIFormControl, @@ -69,7 +76,7 @@ Radios = renderRadio('value', 'Placeholder'); if (!isDev) { Radios = ( - + {({ loading, error: err, data }) => { if (loading) return Loading...; @@ -88,11 +95,7 @@ } const handleChange = evt => { - // radios modify the type of value - let evtValue = evt.target.value; - // maintain the type of the value - evtValue = isNaN(Number(evtValue)) ? evtValue : Number(evtValue); - setValue(evtValue); + setValue(getValue(evt.target.value)); }; const FormControl = ( @@ -101,7 +104,6 @@ required={required} margin={margin} component="fieldset" - aria-label={label} error={error} > {label} @@ -110,6 +112,7 @@ value={value} name={actionInput && actionInput.name} onChange={handleChange} + aria-label={label} > {Radios} diff --git a/src/prefabs/radio.js b/src/prefabs/radio.js index 4a7ce62c0..d2bfeea1a 100644 --- a/src/prefabs/radio.js +++ b/src/prefabs/radio.js @@ -92,6 +92,21 @@ }, }, }, + { + value: {}, + label: 'Filter', + key: 'filter', + type: 'FILTER', + configuration: { + dependsOn: 'model', + condition: { + type: 'SHOW', + option: 'optionType', + comparator: 'EQ', + value: 'data', + }, + }, + }, { type: 'PROPERTY', label: 'Label Property',