Skip to content

Commit

Permalink
fix default value
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed May 21, 2021
1 parent 319ad32 commit 604100f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ export const FiltersConfigForm: React.FC<FiltersConfigFormProps> = ({
hasDataset={hasDataset}
form={form}
formData={newFormData}
enableNoResults={enableNoResults}
/>
) : hasFilledDataset ? (
t('Click "Populate" to get "Default Value" ->')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,8 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
};

useEffect(() => {
const firstItem: SelectValue = data[0]
? (groupby.map(col => data[0][col]) as string[])
: null;
if (!isDisabled && defaultToFirstItem && firstItem) {
// initialize to first value if set to default to first item
setValues(firstItem);
} else if (!isDisabled && defaultValue?.length) {
// initialize to saved value
if (!isDisabled && defaultValue?.length) {
// initialize to default value
setValues(defaultValue);
}
// initialize column types (these should only be set once)
Expand All @@ -167,6 +161,19 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
}
}, []);

useEffect(() => {
const firstItem: SelectValue = data[0]
? (groupby.map(col => data[0][col]) as string[])
: null;
if (!isDisabled && defaultToFirstItem && firstItem) {
// initialize to first value if set to default to first item
setValues(firstItem);
} else if (!isDisabled && defaultValue?.length) {
// initialize to saved value
setValues(defaultValue);
}
}, [defaultValue]);

const [col] = groupby;
const datatype: GenericDataType = coltypeMap[col];
const labelFormatter = getDataRecordFormatter({
Expand Down

0 comments on commit 604100f

Please sign in to comment.