diff --git a/superset-frontend/src/addSlice/AddSliceContainer.tsx b/superset-frontend/src/addSlice/AddSliceContainer.tsx index 26a910f907f3..f63c53f3370e 100644 --- a/superset-frontend/src/addSlice/AddSliceContainer.tsx +++ b/superset-frontend/src/addSlice/AddSliceContainer.tsx @@ -19,10 +19,15 @@ import React, { ReactNode } from 'react'; import rison from 'rison'; import querystring from 'query-string'; -import { styled, t, SupersetClient, JsonResponse } from '@superset-ui/core'; +import { + styled, + t, + SupersetClient, + JsonResponse, + isDefined, +} from '@superset-ui/core'; import { getUrlParam } from 'src/utils/urlUtils'; import { URL_PARAMS } from 'src/constants'; -import { isNullish } from 'src/utils/common'; import { Link, withRouter, RouteComponentProps } from 'react-router-dom'; import Button from 'src/components/Button'; import { AsyncSelect, Steps } from 'src/components'; @@ -247,7 +252,7 @@ export class AddSliceContainer extends React.PureComponent< exploreUrl() { const dashboardId = getUrlParam(URL_PARAMS.dashboardId); let url = `/explore/?viz_type=${this.state.vizType}&datasource=${this.state.datasource?.value}`; - if (!isNullish(dashboardId)) { + if (isDefined(dashboardId)) { url += `&dashboard_id=${dashboardId}`; } return url; diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx index b53f49718959..5fca65c3ec6c 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx @@ -23,9 +23,9 @@ import { DataMaskStateWithId, styled, t, + isDefined, } from '@superset-ui/core'; import Button from 'src/components/Button'; -import { isNullish } from 'src/utils/common'; import { OPEN_FILTER_BAR_WIDTH } from 'src/dashboard/constants'; import { rgba } from 'emotion-rgba'; import { getFilterBarTestId } from '../index'; @@ -97,9 +97,9 @@ export const ActionButtons = ({ () => Object.values(dataMaskApplied).some( filter => - !isNullish(dataMaskSelected[filter.id]?.filterState?.value) || + isDefined(dataMaskSelected[filter.id]?.filterState?.value) || (!dataMaskSelected[filter.id] && - !isNullish(filter.filterState?.value)), + isDefined(filter.filterState?.value)), ), [dataMaskApplied, dataMaskSelected], ); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx index d14a94f8d344..871f2b402647 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx @@ -26,7 +26,7 @@ import { testWithId } from 'src/utils/testUtils'; import { FeatureFlag } from 'src/featureFlags'; import { Preset } from '@superset-ui/core'; import { TimeFilterPlugin, SelectFilterPlugin } from 'src/filters/components'; -import { DATE_FILTER_CONTROL_TEST_ID } from 'src/explore/components/controls/DateFilterControl'; +import { DATE_FILTER_TEST_KEY } from 'src/explore/components/controls/DateFilterControl'; import fetchMock from 'fetch-mock'; import { waitFor } from '@testing-library/react'; import FilterBar, { FILTER_BAR_TEST_ID } from '.'; @@ -71,10 +71,6 @@ fetchMock.get('glob:*/api/v1/dataset/7', { const getTestId = testWithId(FILTER_BAR_TEST_ID, true); const getModalTestId = testWithId(FILTERS_CONFIG_MODAL_TEST_ID, true); -const getDateControlTestId = testWithId( - DATE_FILTER_CONTROL_TEST_ID, - true, -); const FILTER_NAME = 'Time filter 1'; const FILTER_SET_NAME = 'New filter set'; @@ -121,7 +117,7 @@ const changeFilterValue = async () => { userEvent.click(screen.getAllByText('No filter')[0]); userEvent.click(screen.getByDisplayValue('Last day')); expect(await screen.findByText(/2021-04-13/)).toBeInTheDocument(); - userEvent.click(screen.getByTestId(getDateControlTestId('apply-button'))); + userEvent.click(screen.getByTestId(DATE_FILTER_TEST_KEY.applyButton)); }; describe('FilterBar', () => { diff --git a/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx b/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx index 1eca21ed1fe9..0f7993f5c174 100644 --- a/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx +++ b/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx @@ -20,7 +20,7 @@ import React, { useState, useEffect, useMemo } from 'react'; import { css, styled, t, useTheme, NO_TIME_RANGE } from '@superset-ui/core'; import Button from 'src/components/Button'; import ControlHeader from 'src/explore/components/ControlHeader'; -import Label, { Type } from 'src/components/Label'; +import Label from 'src/components/Label'; import Modal from 'src/components/Modal'; import { Divider } from 'src/components'; import Icons from 'src/components/Icons'; @@ -36,7 +36,6 @@ import { DATE_FILTER_TEST_KEY, fetchTimeRange, FRAME_OPTIONS, - getDateFilterControlTestId, guessFrame, useDefaultTimeFilter, } from './utils'; @@ -124,7 +123,6 @@ const IconWrapper = styled.span` export default function DateFilterLabel(props: DateFilterControlProps) { const { onChange, - type, onOpenPopover = noOp, onClosePopover = noOp, overlayStyle = 'Popover', @@ -174,11 +172,6 @@ export default function DateFilterLabel(props: DateFilterControlProps) { guessedFrame === 'No filter' ) { setActualTimeRange(value); - setTooltipTitle( - type === ('error' as Type) - ? t('Default value is required') - : actualRange || '', - ); } else { setActualTimeRange(actualRange || ''); setTooltipTitle(value || ''); @@ -302,7 +295,7 @@ export default function DateFilterLabel(props: DateFilterControlProps) { disabled={!validTimeRange} key="apply" onClick={onSave} - {...getDateFilterControlTestId('apply-button')} + data-test={DATE_FILTER_TEST_KEY.applyButton} > {t('APPLY')} diff --git a/superset-frontend/src/explore/components/controls/DateFilterControl/index.ts b/superset-frontend/src/explore/components/controls/DateFilterControl/index.ts index 801b13937adc..d339827629fb 100644 --- a/superset-frontend/src/explore/components/controls/DateFilterControl/index.ts +++ b/superset-frontend/src/explore/components/controls/DateFilterControl/index.ts @@ -17,9 +17,4 @@ * under the License. */ export { default } from './DateFilterLabel'; -export { - DATE_FILTER_CONTROL_TEST_ID, - fetchTimeRange, - guessFrame, - DATE_FILTER_TEST_KEY, -} from './utils'; +export * from './utils'; diff --git a/superset-frontend/src/explore/components/controls/DateFilterControl/types.ts b/superset-frontend/src/explore/components/controls/DateFilterControl/types.ts index c14204919e95..d08a016724e6 100644 --- a/superset-frontend/src/explore/components/controls/DateFilterControl/types.ts +++ b/superset-frontend/src/explore/components/controls/DateFilterControl/types.ts @@ -16,8 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -import { Type } from 'src/components/Label'; - export type SelectOptionType = { value: string; label: string; @@ -96,7 +94,6 @@ export interface DateFilterControlProps { name: string; onChange: (timeRange: string) => void; value?: string; - type?: Type; onOpenPopover?: () => void; onClosePopover?: () => void; overlayStyle?: 'Modal' | 'Popover'; diff --git a/superset-frontend/src/explore/components/controls/DateFilterControl/utils/constants.ts b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/constants.ts index e6ec228cb2ab..dad77fb9cb82 100644 --- a/superset-frontend/src/explore/components/controls/DateFilterControl/utils/constants.ts +++ b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/constants.ts @@ -26,7 +26,6 @@ import { CommonRangeType, CalendarRangeType, } from 'src/explore/components/controls/DateFilterControl/types'; -import { testWithId } from 'src/utils/testUtils'; export const FRAME_OPTIONS: SelectOptionType[] = [ { value: 'Common', label: t('Last') }, @@ -133,15 +132,11 @@ export const LOCALE_MAPPING = { nl: 'nl_NL', }; -export const DATE_FILTER_CONTROL_TEST_ID = 'date-filter-control'; -export const getDateFilterControlTestId = testWithId( - DATE_FILTER_CONTROL_TEST_ID, -); - export enum DATE_FILTER_TEST_KEY { commonFrame = 'common-frame', modalOverlay = 'modal-overlay', popoverOverlay = 'time-range-trigger', noFilter = 'no-filter', cancelButton = 'cancel-button', + applyButton = 'date-filter-control__apply-button', } diff --git a/superset-frontend/src/filters/components/Time/TimeFilterPlugin.tsx b/superset-frontend/src/filters/components/Time/TimeFilterPlugin.tsx index b97ce0bc6cbf..82bfc678f0a7 100644 --- a/superset-frontend/src/filters/components/Time/TimeFilterPlugin.tsx +++ b/superset-frontend/src/filters/components/Time/TimeFilterPlugin.tsx @@ -88,7 +88,6 @@ export default function TimeFilterPlugin(props: PluginFilterTimeProps) { }, [filterState.value]); return props.formData?.inView ? ( - // @ts-ignore setFilterActive(true)} onClosePopover={() => setFilterActive(false)} /> diff --git a/superset-frontend/src/utils/common.js b/superset-frontend/src/utils/common.js index 4283554138c9..4bc702d44758 100644 --- a/superset-frontend/src/utils/common.js +++ b/superset-frontend/src/utils/common.js @@ -36,17 +36,6 @@ export const SHORT_TIME = 'h:m a'; const DATETIME_FORMATTER = getTimeFormatter(TimeFormats.DATABASE_DATETIME); -export function getParamFromQuery(query, param) { - const vars = query.split('&'); - for (let i = 0; i < vars.length; i += 1) { - const pair = vars[i].split('='); - if (decodeURIComponent(pair[0]) === param) { - return decodeURIComponent(pair[1]); - } - } - return null; -} - export function storeQuery(query) { return SupersetClient.post({ endpoint: '/kv/store/', @@ -150,5 +139,3 @@ export const isSafari = () => { return userAgent && /^((?!chrome|android).)*safari/i.test(userAgent); }; - -export const isNullish = value => value === null || value === undefined; diff --git a/superset-frontend/src/visualizations/presets/MainPreset.js b/superset-frontend/src/visualizations/presets/MainPreset.js index 837cd98a7aa5..88c1975d012d 100644 --- a/superset-frontend/src/visualizations/presets/MainPreset.js +++ b/superset-frontend/src/visualizations/presets/MainPreset.js @@ -76,7 +76,7 @@ import { TimeColumnFilterPlugin, TimeGrainFilterPlugin, GroupByFilterPlugin, -} from 'src/filters/components/'; +} from 'src/filters/components'; import { PivotTableChartPlugin as PivotTableChartPluginV2 } from '@superset-ui/plugin-chart-pivot-table'; import { HandlebarsChartPlugin } from '@superset-ui/plugin-chart-handlebars'; import FilterBoxChartPlugin from '../FilterBox/FilterBoxChartPlugin';