From 0d67253853b913776e67be736190d5e171792f57 Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 15:11:01 -0700 Subject: [PATCH 1/8] fix: clean up chart metadata config --- .../src/chart/models/ChartMetadata.ts | 22 +++++++++------ .../superset-ui-core/src/chart/types/Base.ts | 16 +++++++---- .../VizTypeControl/VizTypeGallery.tsx | 27 ++++++++++++------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts b/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts index 1013eeee2d3b3..7a25fe86208d1 100644 --- a/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts +++ b/superset-frontend/packages/superset-ui-core/src/chart/models/ChartMetadata.ts @@ -43,10 +43,11 @@ export interface ChartMetadataConfig { exampleGallery?: ExampleImage[]; tags?: string[]; category?: string | null; - label?: { - name?: ChartLabel; - description?: string; - } | null; + // deprecated: true hides a chart from all viz picker interactions. + deprecated?: boolean; + // label: ChartLabel.DEPRECATED which will display a "deprecated" label on the chart. + label?: ChartLabel | null; + labelExplanation?: string | null; } export default class ChartMetadata { @@ -80,10 +81,11 @@ export default class ChartMetadata { category: string | null; - label?: { - name?: ChartLabel; - description?: string; - } | null; + deprecated?: boolean; + + label?: ChartLabel | null; + + labelExplanation?: string | null; constructor(config: ChartMetadataConfig) { const { @@ -101,7 +103,9 @@ export default class ChartMetadata { exampleGallery = [], tags = [], category = null, + deprecated = false, label = null, + labelExplanation = null, } = config; this.name = name; @@ -127,7 +131,9 @@ export default class ChartMetadata { this.exampleGallery = exampleGallery; this.tags = tags; this.category = category; + this.deprecated = deprecated; this.label = label; + this.labelExplanation = labelExplanation; } canBeAnnotationType(type: string): boolean { diff --git a/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts b/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts index aad547ca2aa5d..8fffe5fbc7831 100644 --- a/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts +++ b/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts @@ -19,6 +19,7 @@ import { ExtraFormData } from '../../query'; import { JsonObject } from '../..'; +import { t } from '../../translation'; export type HandlerFunction = (...args: unknown[]) => void; @@ -53,18 +54,23 @@ export interface PlainObject { } export enum ChartLabel { - VERIFIED = 'VERIFIED', DEPRECATED = 'DEPRECATED', FEATURED = 'FEATURED', } -export const ChartLabelWeight = { +export const chartLabelExplanations: Record = { + [ChartLabel.DEPRECATED]: t( + 'This chart uses features or modules which are no longer actively maintained. It will eventually be replaced or removed.', + ), + [ChartLabel.FEATURED]: t( + 'This chart was tested and verified, so the overall experience should be stable.', + ), +}; + +export const chartLabelWeight: Record = { [ChartLabel.DEPRECATED]: { weight: -0.1, }, - [ChartLabel.VERIFIED]: { - weight: 0.2, - }, [ChartLabel.FEATURED]: { weight: 0.1, }, diff --git a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx index dc7afacb6c082..baf624b49458b 100644 --- a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx +++ b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx @@ -34,7 +34,8 @@ import { SupersetTheme, useTheme, ChartLabel, - ChartLabelWeight, + chartLabelWeight, + chartLabelExplanations, } from '@superset-ui/core'; import { AntdCollapse } from 'src/components'; import { Tooltip } from 'src/components/Tooltip'; @@ -503,8 +504,7 @@ export default function VizTypeGallery(props: VizTypeGalleryProps) { .map(([key, value]) => ({ key, value })) .filter( ({ value }) => - nativeFilterGate(value.behaviors || []) && - value.label?.name !== ChartLabel.DEPRECATED, + nativeFilterGate(value.behaviors || []) && !value.deprecated, ); result.sort((a, b) => vizSortFactor(a) - vizSortFactor(b)); return result; @@ -593,12 +593,16 @@ export default function VizTypeGallery(props: VizTypeGalleryProps) { .search(searchInputValue) .map(result => result.item) .sort((a, b) => { - const aName = a.value?.label?.name; - const bName = b.value?.label?.name; + const aLabel = a.value?.label; + const bLabel = b.value?.label; const aOrder = - aName && ChartLabelWeight[aName] ? ChartLabelWeight[aName].weight : 0; + aLabel && chartLabelWeight[aLabel] + ? chartLabelWeight[aLabel].weight + : 0; const bOrder = - bName && ChartLabelWeight[bName] ? ChartLabelWeight[bName].weight : 0; + bLabel && chartLabelWeight[bLabel] + ? chartLabelWeight[bLabel].weight + : 0; return bOrder - aOrder; }); }, [searchInputValue, fuse]); @@ -798,15 +802,18 @@ export default function VizTypeGallery(props: VizTypeGalleryProps) { `} > {selectedVizMetadata?.name} - {selectedVizMetadata?.label?.name && ( + {selectedVizMetadata?.label && ( -
{t(selectedVizMetadata.label?.name)}
+
{t(selectedVizMetadata.label)}
From 5bd0d414bf7366e016b3d3b75c59575f05684cd0 Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 15:31:05 -0700 Subject: [PATCH 2/8] missed a spot --- .../components/controls/VizTypeControl/VizTypeGallery.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx index baf624b49458b..44c98675ce7c7 100644 --- a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx +++ b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx @@ -415,10 +415,10 @@ const Thumbnail: React.FC = ({ > {type.name} - {type.label?.name && ( + {type.label && ( -
{t(type.label?.name)}
+
{t(type.label)}
)} From bb14f866649e7becc28de2f774249db383f190bb Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 15:38:39 -0700 Subject: [PATCH 3/8] missed another spot --- .../components/controls/VizTypeControl/VizTypeGallery.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx index 44c98675ce7c7..b0861a759058f 100644 --- a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx +++ b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx @@ -33,7 +33,6 @@ import { ChartMetadata, SupersetTheme, useTheme, - ChartLabel, chartLabelWeight, chartLabelExplanations, } from '@superset-ui/core'; From 3eeb8ab9cc5db155a30d08b81fd697af1fcaf6ea Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 16:34:38 -0700 Subject: [PATCH 4/8] fix failing time-specific test --- .../TimezoneSelector/TimezoneSelector.test.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx index 035cff842c9e2..27f05ce49604c 100644 --- a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx +++ b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx @@ -22,6 +22,9 @@ import { render, screen, waitFor } from 'spec/helpers/testing-library'; import userEvent from '@testing-library/user-event'; import TimezoneSelector from './index'; +jest.useFakeTimers('modern'); +jest.setSystemTime(new Date('2022-01-01')); + jest.spyOn(moment.tz, 'guess').mockReturnValue('America/New_York'); const getSelectOptions = () => @@ -69,15 +72,10 @@ it('can select a timezone values and returns canonical value', async () => { }); expect(searchInput).toBeInTheDocument(); userEvent.click(searchInput); - const isDaylight = moment(moment.now()).isDST(); - - const selectedTimezone = isDaylight - ? 'GMT -04:00 (Eastern Daylight Time)' - : 'GMT -05:00 (Eastern Standard Time)'; // selected option ranks first const options = await getSelectOptions(); - expect(options[0]).toHaveTextContent(selectedTimezone); + expect(options[0]).toHaveTextContent('GMT -05:00 (Eastern Standard Time)'); // others are ranked by offset expect(options[1]).toHaveTextContent('GMT -11:00 (Pacific/Pago_Pago)'); @@ -87,10 +85,9 @@ it('can select a timezone values and returns canonical value', async () => { // search for mountain time await userEvent.type(searchInput, 'mou', { delay: 10 }); - const findTitle = isDaylight - ? 'GMT -06:00 (Mountain Daylight Time)' - : 'GMT -07:00 (Mountain Standard Time)'; - const selectOption = await screen.findByTitle(findTitle); + const selectOption = await screen.findByTitle( + 'GMT -07:00 (Mountain Standard Time)', + ); expect(selectOption).toBeInTheDocument(); userEvent.click(selectOption); expect(onTimezoneChange).toHaveBeenCalledTimes(1); From 15c16234ef4038d7858e89b5aa57c7722d6b2554 Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 16:56:03 -0700 Subject: [PATCH 5/8] can't call translation functions here --- .../packages/superset-ui-core/src/chart/types/Base.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts b/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts index 8fffe5fbc7831..39cc6fdf36354 100644 --- a/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts +++ b/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts @@ -59,12 +59,10 @@ export enum ChartLabel { } export const chartLabelExplanations: Record = { - [ChartLabel.DEPRECATED]: t( + [ChartLabel.DEPRECATED]: 'This chart uses features or modules which are no longer actively maintained. It will eventually be replaced or removed.', - ), - [ChartLabel.FEATURED]: t( + [ChartLabel.FEATURED]: 'This chart was tested and verified, so the overall experience should be stable.', - ), }; export const chartLabelWeight: Record = { From a174d544f2de65329dfc60cf8b7a3abb37b9211e Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 17:19:18 -0700 Subject: [PATCH 6/8] Revert "fix failing time-specific test" This reverts commit 3eeb8ab9cc5db155a30d08b81fd697af1fcaf6ea. --- .../TimezoneSelector/TimezoneSelector.test.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx index 27f05ce49604c..035cff842c9e2 100644 --- a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx +++ b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx @@ -22,9 +22,6 @@ import { render, screen, waitFor } from 'spec/helpers/testing-library'; import userEvent from '@testing-library/user-event'; import TimezoneSelector from './index'; -jest.useFakeTimers('modern'); -jest.setSystemTime(new Date('2022-01-01')); - jest.spyOn(moment.tz, 'guess').mockReturnValue('America/New_York'); const getSelectOptions = () => @@ -72,10 +69,15 @@ it('can select a timezone values and returns canonical value', async () => { }); expect(searchInput).toBeInTheDocument(); userEvent.click(searchInput); + const isDaylight = moment(moment.now()).isDST(); + + const selectedTimezone = isDaylight + ? 'GMT -04:00 (Eastern Daylight Time)' + : 'GMT -05:00 (Eastern Standard Time)'; // selected option ranks first const options = await getSelectOptions(); - expect(options[0]).toHaveTextContent('GMT -05:00 (Eastern Standard Time)'); + expect(options[0]).toHaveTextContent(selectedTimezone); // others are ranked by offset expect(options[1]).toHaveTextContent('GMT -11:00 (Pacific/Pago_Pago)'); @@ -85,9 +87,10 @@ it('can select a timezone values and returns canonical value', async () => { // search for mountain time await userEvent.type(searchInput, 'mou', { delay: 10 }); - const selectOption = await screen.findByTitle( - 'GMT -07:00 (Mountain Standard Time)', - ); + const findTitle = isDaylight + ? 'GMT -06:00 (Mountain Daylight Time)' + : 'GMT -07:00 (Mountain Standard Time)'; + const selectOption = await screen.findByTitle(findTitle); expect(selectOption).toBeInTheDocument(); userEvent.click(selectOption); expect(onTimezoneChange).toHaveBeenCalledTimes(1); From 21e6329f25e2b003540da379e67860e097c0f51c Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Mon, 14 Mar 2022 18:36:58 -0700 Subject: [PATCH 7/8] skip problematic test --- .../src/components/TimezoneSelector/TimezoneSelector.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx index 035cff842c9e2..79830fd820921 100644 --- a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx +++ b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx @@ -55,7 +55,7 @@ it('use the default timezone when an invalid timezone is provided', async () => expect(onTimezoneChange).toHaveBeenLastCalledWith('Africa/Abidjan'); }); -it('can select a timezone values and returns canonical value', async () => { +it.skip('can select a timezone values and returns canonical value', async () => { const onTimezoneChange = jest.fn(); render( Date: Tue, 15 Mar 2022 11:51:08 -0700 Subject: [PATCH 8/8] extra import --- .../packages/superset-ui-core/src/chart/types/Base.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts b/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts index 39cc6fdf36354..0bfae7777e7df 100644 --- a/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts +++ b/superset-frontend/packages/superset-ui-core/src/chart/types/Base.ts @@ -19,7 +19,6 @@ import { ExtraFormData } from '../../query'; import { JsonObject } from '../..'; -import { t } from '../../translation'; export type HandlerFunction = (...args: unknown[]) => void;