diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTabs.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTabs.tsx index ccb0e009fb..3d687961ea 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTabs.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTabs.tsx @@ -24,7 +24,7 @@ import Icon from 'src/components/Icon'; import { FilterRemoval } from './types'; import { REMOVAL_DELAY_SECS } from './utils'; -export const FILTER_WIDTH = 200; +export const FILTER_WIDTH = 180; export const StyledSpan = styled.span` cursor: pointer; @@ -115,6 +115,7 @@ const FilterTabsContainer = styled(LineEditableTabs)` padding-right: ${theme.gridUnit}px; padding-bottom: ${theme.gridUnit * 3}px; padding-left: ${theme.gridUnit * 3}px; + width: 270px; } // extra selector specificity: @@ -185,6 +186,8 @@ const FilterTabs: FC = ({ children, }) => ( = ({ tabBarExtraContent={{ left: {t('Filters')}, right: ( - onEdit('', 'add')}> + { + onEdit('', 'add'); + setTimeout(() => { + const element = document.getElementById('native-filters-tabs'); + if (element) { + const navList = element.getElementsByClassName( + 'ant-tabs-nav-list', + )[0]; + navList.scrollTop = navList.scrollHeight; + } + }, 0); + }} + > {' '} {t('Add filter')} 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 90768e8ee8..76fa33bdc7 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx @@ -229,6 +229,7 @@ const FILTERS_WITH_ADHOC_FILTERS = ['filter_select', 'filter_range']; const BASIC_CONTROL_ITEMS = ['enableEmptyFilter', 'multiSelect']; +// TODO: Rename the filter plugins and remove this mapping const FILTER_TYPE_NAME_MAPPING = { [t('Select filter')]: t('Value'), [t('Range filter')]: t('Numerical range'), @@ -254,7 +255,12 @@ const FiltersConfigForm = ( ref: React.RefObject, ) => { const [metrics, setMetrics] = useState([]); - const [activeTabKey, setActiveTabKey] = useState(); + const [activeTabKey, setActiveTabKey] = useState( + FilterTabs.configuration.key, + ); + const [activeFilterPanelKey, setActiveFilterPanelKey] = useState< + string | string[] + >(FilterPanels.basic.key); const [hasDefaultValue, setHasDefaultValue] = useState( !!filterToEdit?.defaultDataMask?.filterState?.value, ); @@ -410,10 +416,6 @@ const FiltersConfigForm = ( [], ); - if (removed) { - return restoreFilter(filterId)} />; - } - const parentFilterOptions = parentFilters.map(filter => ({ value: filter.id, label: filter.title, @@ -423,6 +425,14 @@ const FiltersConfigForm = ( ({ value }) => value === filterToEdit?.cascadeParentIds[0], ); + const hasParentFilter = !!parentFilter; + + const hasPreFilter = + !!filterToEdit?.adhoc_filters || !!filterToEdit?.time_range; + + const hasSorting = + typeof filterToEdit?.controlValues?.sortAscending === 'boolean'; + const showDefaultValue = !hasDataset || (!isDataDirty && hasFilledDataset); const controlItems = formFilter @@ -447,9 +457,27 @@ const FiltersConfigForm = ( forceUpdate(); }; + let hasCheckedAdvancedControl = hasParentFilter || hasPreFilter || hasSorting; + if (!hasCheckedAdvancedControl) { + hasCheckedAdvancedControl = Object.keys(controlItems) + .filter(key => !BASIC_CONTROL_ITEMS.includes(key)) + .some(key => controlItems[key].checked); + } + + useEffect(() => { + const activeFilterPanelKey = [FilterPanels.basic.key]; + if (hasCheckedAdvancedControl) { + activeFilterPanelKey.push(FilterPanels.advanced.key); + } + setActiveFilterPanelKey(activeFilterPanelKey); + }, [hasCheckedAdvancedControl]); + + if (removed) { + return restoreFilter(filterId)} />; + } + return ( setActiveTabKey(activeKey)} centered @@ -559,7 +587,8 @@ const FiltersConfigForm = ( )} setActiveFilterPanelKey(key)} expandIconPosition="right" > {Object.keys(controlItems) .filter(key => BASIC_CONTROL_ITEMS.includes(key)) - .map(key => controlItems[key])} + .map(key => controlItems[key].element)} { if (checked) { // execute after render @@ -687,13 +716,11 @@ const FiltersConfigForm = ( )} {Object.keys(controlItems) .filter(key => !BASIC_CONTROL_ITEMS.includes(key)) - .map(key => controlItems[key])} + .map(key => controlItems[key].element)} {hasDataset && hasAdditionalFilters && ( { if (checked) { // execute after render @@ -757,72 +784,71 @@ const FiltersConfigForm = ( )} - onSortChanged(checked || undefined)} - checked={ - typeof filterToEdit?.controlValues?.sortAscending === - 'boolean' - } - > - - {t('Sort type')}} - > -