diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/isDerivedSeries.ts b/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/isDerivedSeries.ts index ddb3e425df05..b906878129d5 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/isDerivedSeries.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/isDerivedSeries.ts @@ -17,22 +17,14 @@ * specific language governing permissions and limitationsxw * under the License. */ -import { - ensureIsArray, - JsonObject, - QueryFormData, - ComparisonType, -} from '@superset-ui/core'; +import { ensureIsArray } from '@superset-ui/core'; +import type { JsonObject, QueryFormData } from '@superset-ui/core'; import { hasTimeOffset } from './timeOffset'; export const isDerivedSeries = ( series: JsonObject, formData: QueryFormData, ): boolean => { - const comparisonType = formData.comparison_type; - if (comparisonType !== ComparisonType.Values) { - return false; - } - const timeCompare: string[] = ensureIsArray(formData?.time_compare); + const timeCompare = ensureIsArray(formData?.time_compare).filter((v): v is string => typeof v === 'string'); return hasTimeOffset(series, timeCompare); }; diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts b/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts index 852b4eb1ab83..c6f2d0ba6063 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts @@ -36,7 +36,7 @@ export const hasTimeOffset = ( timeCompare: string[], ): boolean => typeof series.name === 'string' - ? !!getTimeOffset(series, timeCompare) + ? !!getTimeOffset(series, timeCompare) || timeCompare.includes(series.name) : false; export const getOriginalSeries = ( diff --git a/superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/isDerivedSeries.test.ts b/superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/isDerivedSeries.test.ts index 472b980be6f2..f752eff27770 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/isDerivedSeries.test.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/isDerivedSeries.test.ts @@ -29,20 +29,19 @@ const series = { data: [100], }; -test('should be false if comparison type is not actual values', () => { +test('should be false if time_compare is not set', () => { expect(isDerivedSeries(series, formData)).toEqual(false); - Object.keys(ComparisonType) - .filter(type => type === ComparisonType.Values) - .forEach(type => { - const formDataWithComparisonType = { - ...formData, - comparison_type: type, - time_compare: ['1 month ago'], - }; - expect(isDerivedSeries(series, formDataWithComparisonType)).toEqual( - false, - ); - }); +}); + +test('should be true if series name matches time_compare regardless of comparison_type', () => { + Object.values(ComparisonType).forEach(type => { + const formDataWithComparisonType = { + ...formData, + comparison_type: type, + time_compare: ['1 month ago'], + }; + expect(isDerivedSeries(series, formDataWithComparisonType)).toEqual(true); + }); }); test('should be true if comparison type is values', () => {