From 311974c0c06820219923ed7f1571d20724ca2b6b Mon Sep 17 00:00:00 2001 From: smileydev <47900232+prosdev0107@users.noreply.github.com> Date: Wed, 27 Apr 2022 16:07:59 -0400 Subject: [PATCH] feature(filter): make to hide sort filter when time range (#19871) --- .../FiltersConfigForm/FiltersConfigForm.tsx | 438 +++++++++--------- 1 file changed, 222 insertions(+), 216 deletions(-) diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx index ff04e0ebe593c..542277f6a6dbc 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx @@ -846,245 +846,251 @@ const FiltersConfigForm = ( expandIconPosition="right" key={`native-filter-config-${filterId}`} > - - {canDependOnOtherFilters && hasAvailableFilters && ( - - { - setNativeFilterFieldValues(form, filterId, { - dependencies, - }); - forceUpdate(); - validateDependencies(); - formChanged(); - }} - getDependencySuggestion={() => - getDependencySuggestion(filterId) - } - /> - - )} - {hasDataset && hasAdditionalFilters && ( - - { - formChanged(); - if (checked) { - validatePreFilter(); - } - }} + {formFilter?.filterType !== 'filter_time' && ( + + {canDependOnOtherFilters && hasAvailableFilters && ( + - - c.filterable, - ) || [] - } - savedMetrics={datasetDetails?.metrics || []} - datasource={datasetDetails} - onChange={(filters: AdhocFilter[]) => { - setNativeFilterFieldValues(form, filterId, { - adhoc_filters: filters, - }); - forceUpdate(); + { + setNativeFilterFieldValues(form, filterId, { + dependencies, + }); + forceUpdate(); + validateDependencies(); + formChanged(); + }} + getDependencySuggestion={() => + getDependencySuggestion(filterId) + } + /> + + )} + {hasDataset && hasAdditionalFilters && ( + + { + formChanged(); + if (checked) { validatePreFilter(); - }} - label={ - - {t('Pre-filter')} - {!hasTimeRange && } - } - /> - - {showTimeRangePicker && ( - {t('Time range')}} - initialValue={filterToEdit?.time_range || 'No filter'} - required={!hasAdhoc} + }} + > + - { + c.filterable, + ) || [] + } + savedMetrics={datasetDetails?.metrics || []} + datasource={datasetDetails} + onChange={(filters: AdhocFilter[]) => { setNativeFilterFieldValues(form, filterId, { - time_range: timeRange, + adhoc_filters: filters, }); forceUpdate(); validatePreFilter(); }} + label={ + + {t('Pre-filter')} + {!hasTimeRange && } + + } /> - - )} - {hasTimeRange && ( + + {showTimeRangePicker && ( + {t('Time range')}} + initialValue={filterToEdit?.time_range || 'No filter'} + required={!hasAdhoc} + rules={[ + { + validator: preFilterValidator, + }, + ]} + > + { + setNativeFilterFieldValues(form, filterId, { + time_range: timeRange, + }); + forceUpdate(); + validatePreFilter(); + }} + /> + + )} + {hasTimeRange && ( + + {t('Time column')}  + + + } + initialValue={filterToEdit?.granularity_sqla} + > + !!column.is_dttm} + datasetId={datasetId} + onChange={column => { + // We need reset default value when when column changed + setNativeFilterFieldValues(form, filterId, { + granularity_sqla: column, + }); + forceUpdate(); + }} + /> + + )} + + + )} + {formFilter?.filterType !== 'filter_range' ? ( + + { + onSortChanged(checked || undefined); + formChanged(); + }} + > - {t('Time column')}  - - - } - initialValue={filterToEdit?.granularity_sqla} + name={[ + 'filters', + filterId, + 'controlValues', + 'sortAscending', + ]} + initialValue={sort} + label={{t('Sort type')}} > - !!column.is_dttm} - datasetId={datasetId} - onChange={column => { - // We need reset default value when when column changed - setNativeFilterFieldValues(form, filterId, { - granularity_sqla: column, - }); - forceUpdate(); + { + onSortChanged(value.target.value); }} - /> + > + {t('Sort ascending')} + {t('Sort descending')} + - )} - - - )} - {formFilter?.filterType !== 'filter_range' ? ( - - { - onSortChanged(checked || undefined); - formChanged(); - }} - > - {t('Sort type')}} + {hasMetrics && ( + + {t('Sort Metric')}  + + + } + data-test="field-input" + > + ({ - value: metric.metric_name, - label: metric.verbose_name ?? metric.metric_name, - }))} - onChange={value => { - if (value !== undefined) { - setNativeFilterFieldValues(form, filterId, { - sortMetric: value, - }); - forceUpdate(); - } - }} - /> - - )} - - - ) : ( - - { - onEnableSingleValueChanged( - checked ? SingleValueType.Exact : undefined, - ); - formChanged(); - }} - > - {t('Single value type')}} - > - - onEnableSingleValueChanged(value.target.value) - } - > - - {t('Minimum')} - - {t('Exact')} - - {t('Maximum')} - - - - - - )} - + + onEnableSingleValueChanged(value.target.value) + } + > + + {t('Minimum')} + + + {t('Exact')} + + + {t('Maximum')} + + + + + + )} + + )}