chore: Allows the user to force fetch the default values (#15178)

This commit is contained in:
Michael S. Molina 2021-06-16 08:17:34 -03:00 committed by GitHub
parent 0c22266041
commit 4289929745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 64 deletions

View File

@ -61,7 +61,7 @@ const DefaultValue: FC<DefaultValueProps> = ({
<Loading position="inline-centered" />
) : (
<SuperChart
height={25}
height={32}
width={formFilter?.filterType === 'filter_time' ? 350 : 250}
appSection={AppSection.FILTER_CONFIG_MODAL}
behaviors={[Behavior.NATIVE_FILTER]}

View File

@ -59,6 +59,8 @@ import { getChartDataRequest } from 'src/chart/chartAction';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import { waitForAsyncData } from 'src/middleware/asyncEvent';
import Tabs from 'src/components/Tabs';
import Icons from 'src/components/Icons';
import { Tooltip } from 'src/components/Tooltip';
import BasicErrorAlert from 'src/components/ErrorMessage/BasicErrorAlert';
import { ColumnSelect } from './ColumnSelect';
import { NativeFiltersForm } from '../types';
@ -136,6 +138,17 @@ const CleanFormItem = styled(FormItem)`
margin-bottom: 0;
`;
const DefaultValueContainer = styled.div`
display: flex;
flex-direction: row;
align-items: center;
`;
const RefreshIcon = styled(Icons.Refresh)`
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
color: ${({ theme }) => theme.colors.primary.base};
`;
const StyledCollapse = styled(Collapse)`
margin-left: ${({ theme }) => theme.gridUnit * -4 - 1}px;
margin-right: ${({ theme }) => theme.gridUnit * -4}px;
@ -351,7 +364,8 @@ const FiltersConfigForm = (
forceUpdate();
};
const refreshHandler = useCallback(() => {
const refreshHandler = useCallback(
(force = false) => {
if (!hasDataset || !formFilter?.dataset?.value) {
forceUpdate();
return;
@ -367,7 +381,7 @@ const FiltersConfigForm = (
});
getChartDataRequest({
formData,
force: false,
force,
requestParams: { dashboardId: 0 },
})
.then(response => {
@ -398,7 +412,9 @@ const FiltersConfigForm = (
);
});
});
}, [filterId, forceUpdate, form, formFilter, hasDataset]);
},
[filterId, forceUpdate, form, formFilter, hasDataset],
);
const defaultDatasetSelectOptions = Object.values(loadedDatasets).map(
datasetToSelectOption,
@ -693,6 +709,7 @@ const FiltersConfigForm = (
level="error"
/>
) : showDefaultValue ? (
<DefaultValueContainer>
<DefaultValue
setDataMask={dataMask => {
setNativeFilterFieldValues(form, filterId, {
@ -709,6 +726,10 @@ const FiltersConfigForm = (
formData={newFormData}
enableNoResults={enableNoResults}
/>
<Tooltip title={t('Refresh the default values')}>
<RefreshIcon onClick={() => refreshHandler(true)} />
</Tooltip>
</DefaultValueContainer>
) : (
t('Fill all required fields to enable "Default Value"')
)}