From 24da7396f353316d55874326bd32ab138142604d Mon Sep 17 00:00:00 2001 From: justinpark Date: Thu, 2 May 2024 10:15:53 -0700 Subject: [PATCH] rename function name --- .../src/sections/advancedAnalytics.tsx | 4 +- .../src/sections/forecastInterval.tsx | 4 +- .../src/shared-controls/sharedControls.tsx | 4 +- ...eries.ts => displayTimeRelatedControls.ts} | 2 +- .../src/utils/index.ts | 2 +- ....ts => displayTimeRelatedControls.test.ts} | 88 +++++++++---------- .../ControlPanelsContainer.test.tsx | 4 +- 7 files changed, 53 insertions(+), 55 deletions(-) rename superset-frontend/packages/superset-ui-chart-controls/src/utils/{showIfTimeSeries.ts => displayTimeRelatedControls.ts} (96%) rename superset-frontend/packages/superset-ui-chart-controls/test/utils/{showIfTimeSeries.test.ts => displayTimeRelatedControls.test.ts} (52%) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/sections/advancedAnalytics.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/sections/advancedAnalytics.tsx index bc8b52c31a637..926488f51e09c 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/sections/advancedAnalytics.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/sections/advancedAnalytics.tsx @@ -21,7 +21,7 @@ import { t, RollingType, ComparisonType } from '@superset-ui/core'; import { ControlSubSectionHeader } from '../components/ControlSubSectionHeader'; import { ControlPanelSectionConfig } from '../types'; -import { formatSelectOptions, showIfTimeSeries } from '../utils'; +import { formatSelectOptions, displayTimeRelatedControls } from '../utils'; export const advancedAnalyticsControls: ControlPanelSectionConfig = { label: t('Advanced analytics'), @@ -31,7 +31,7 @@ export const advancedAnalyticsControls: ControlPanelSectionConfig = { 'that allow for advanced analytical post processing ' + 'of query results', ), - visibility: showIfTimeSeries, + visibility: displayTimeRelatedControls, controlSetRows: [ [{t('Rolling window')}], [ diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/sections/forecastInterval.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/sections/forecastInterval.tsx index afae40b3aec9f..67c64725c0a9e 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/sections/forecastInterval.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/sections/forecastInterval.tsx @@ -22,7 +22,7 @@ import { t, } from '@superset-ui/core'; import { ControlPanelSectionConfig } from '../types'; -import { showIfTimeSeries } from '../utils'; +import { displayTimeRelatedControls } from '../utils'; export const FORECAST_DEFAULT_DATA = { forecastEnabled: false, @@ -36,7 +36,7 @@ export const FORECAST_DEFAULT_DATA = { export const forecastIntervalControls: ControlPanelSectionConfig = { label: t('Predictive Analytics'), expanded: false, - visibility: showIfTimeSeries, + visibility: displayTimeRelatedControls, controlSetRows: [ [ { diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index e1e71cb870d8c..c01b4052d1242 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -49,7 +49,7 @@ import { import { formatSelectOptions, - showIfTimeSeries, + displayTimeRelatedControls, D3_FORMAT_OPTIONS, D3_FORMAT_DOCS, D3_TIME_FORMAT_OPTIONS, @@ -201,7 +201,7 @@ const time_grain_sqla: SharedControlConfig<'SelectControl'> = { mapStateToProps: ({ datasource }) => ({ choices: (datasource as Dataset)?.time_grain_sqla || [], }), - visibility: showIfTimeSeries, + visibility: displayTimeRelatedControls, }; const time_range: SharedControlConfig<'DateFilterControl'> = { diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/showIfTimeSeries.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/displayTimeRelatedControls.ts similarity index 96% rename from superset-frontend/packages/superset-ui-chart-controls/src/utils/showIfTimeSeries.ts rename to superset-frontend/packages/superset-ui-chart-controls/src/utils/displayTimeRelatedControls.ts index 0b8100e422fbf..e5e430d158919 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/showIfTimeSeries.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/displayTimeRelatedControls.ts @@ -19,7 +19,7 @@ import { isAdhocColumn, isPhysicalColumn } from '@superset-ui/core'; import type { ColumnMeta, ControlPanelsContainerProps } from '../types'; -export default function showIfTimeSeries({ +export default function displayTimeRelatedControls({ controls, }: ControlPanelsContainerProps) { if (!controls?.x_axis) { diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts index 0c60e935bff2f..fb829ea057389 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts @@ -26,4 +26,4 @@ export { default as columnChoices } from './columnChoices'; export * from './defineSavedMetrics'; export * from './getStandardizedControls'; export * from './getTemporalColumns'; -export { default as showIfTimeSeries } from './showIfTimeSeries'; +export { default as displayTimeRelatedControls } from './displayTimeRelatedControls'; diff --git a/superset-frontend/packages/superset-ui-chart-controls/test/utils/showIfTimeSeries.test.ts b/superset-frontend/packages/superset-ui-chart-controls/test/utils/displayTimeRelatedControls.test.ts similarity index 52% rename from superset-frontend/packages/superset-ui-chart-controls/test/utils/showIfTimeSeries.test.ts rename to superset-frontend/packages/superset-ui-chart-controls/test/utils/displayTimeRelatedControls.test.ts index faa4c70398d28..4997e90e703dd 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/test/utils/showIfTimeSeries.test.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/test/utils/displayTimeRelatedControls.test.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { showIfTimeSeries } from '../../src'; +import { displayTimeRelatedControls } from '../../src'; const mockData = { actions: { @@ -39,55 +39,53 @@ const mockData = { }, }; -describe('showIfTimeSeries', () => { - it('returns true when no x-axis exists', () => { - expect( - showIfTimeSeries({ - ...mockData, - controls: { - control_options: { - type: 'SelectControl', - value: 'not_temporal', - options: [], - }, +test('returns true when no x-axis exists', () => { + expect( + displayTimeRelatedControls({ + ...mockData, + controls: { + control_options: { + type: 'SelectControl', + value: 'not_temporal', + options: [], }, - }), - ).toBeTruthy(); - }); + }, + }), + ).toBeTruthy(); +}); - it('returns false when x-axis value is not temporal', () => { - expect(showIfTimeSeries(mockData)).toBeFalsy(); - }); +test('returns false when x-axis value is not temporal', () => { + expect(displayTimeRelatedControls(mockData)).toBeFalsy(); +}); - it('returns true when x-axis value is temporal', () => { - expect( - showIfTimeSeries({ - ...mockData, - controls: { - x_axis: { - ...mockData.controls.x_axis, - value: 'ds', - }, +test('returns true when x-axis value is temporal', () => { + expect( + displayTimeRelatedControls({ + ...mockData, + controls: { + x_axis: { + ...mockData.controls.x_axis, + value: 'ds', }, - }), - ).toBeTruthy(); - }); + }, + }), + ).toBeTruthy(); +}); - it('returns true when x-axis is ad-hoc column', () => { - expect( - showIfTimeSeries({ - ...mockData, - controls: { - x_axis: { - ...mockData.controls.x_axis, - value: { - sqlExpression: 'ds', - label: 'ds', - expressionType: 'SQL', - }, +test('returns true when x-axis is ad-hoc column', () => { + expect( + displayTimeRelatedControls({ + ...mockData, + controls: { + x_axis: { + ...mockData.controls.x_axis, + value: { + sqlExpression: 'ds', + label: 'ds', + expressionType: 'SQL', }, }, - }), - ).toBeTruthy(); - }); + }, + }), + ).toBeTruthy(); }); diff --git a/superset-frontend/src/explore/components/ControlPanelsContainer.test.tsx b/superset-frontend/src/explore/components/ControlPanelsContainer.test.tsx index 81e62b0e851f1..a7d68047f8d6e 100644 --- a/superset-frontend/src/explore/components/ControlPanelsContainer.test.tsx +++ b/superset-frontend/src/explore/components/ControlPanelsContainer.test.tsx @@ -145,12 +145,12 @@ describe('ControlPanelsContainer', () => { ).toHaveLength(2); }); - test('hide ControlPanelSections when its visibility is false', async () => { + test('visibility of panels is correctly applied', async () => { getChartControlPanelRegistry().registerValue('table', { controlPanelSections: [ { label: t('Advanced analytics'), - description: t('Advanced analytical post processin'), + description: t('Advanced analytics post processing'), expanded: true, controlSetRows: [['groupby'], ['metrics'], ['percent_metrics']], visibility: () => false,