Skip to content

Commit

Permalink
feat: add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahad committed Mar 26, 2020
1 parent ad3465a commit 4538d1e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/components/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
position,
margin,
error,
filter,
} = options;
const isDev = B.env === 'dev';
const { GetAll, getProperty, useText, getActionInput } = B;
Expand All @@ -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,
Expand Down Expand Up @@ -69,7 +76,7 @@
Radios = renderRadio('value', 'Placeholder');
if (!isDev) {
Radios = (
<GetAll modelId={model} skip={0} take={50}>
<GetAll modelId={model} filter={filter} skip={0} take={50}>
{({ loading, error: err, data }) => {
if (loading) return <span>Loading...</span>;

Expand All @@ -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 = (
Expand All @@ -101,7 +104,6 @@
required={required}
margin={margin}
component="fieldset"
aria-label={label}
error={error}
>
<FormLabel component="legend">{label}</FormLabel>
Expand All @@ -110,6 +112,7 @@
value={value}
name={actionInput && actionInput.name}
onChange={handleChange}
aria-label={label}
>
{Radios}
</RadioGroup>
Expand Down
15 changes: 15 additions & 0 deletions src/prefabs/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4538d1e

Please sign in to comment.