rusackas commented on code in PR #41350:
URL: https://github.com/apache/superset/pull/41350#discussion_r3578536295


##########
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts:
##########
@@ -1799,3 +1799,69 @@ describe('Tooltip with long labels', () => {
     expect(result).toContain('599616000000');
   });
 });
+
+describe('Tooltip time grain wiring', () => {
+  test('dashboard-level extraFormData time grain overrides the chart-level 
grain in the tooltip', () => {
+    const ts = Date.UTC(2021, 0, 7);
+    const chartProps = createTestChartProps({
+      formData: {
+        granularity_sqla: 'ds',
+        richTooltip: false,
+        // The chart itself is configured with a Day grain...
+        timeGrainSqla: TimeGranularity.DAY,
+        // ...but a dashboard-level filter/override resolves to Month.
+        extraFormData: { time_grain_sqla: TimeGranularity.MONTH },
+      },
+      queriesData: [
+        createTestQueryData([{ __timestamp: ts, sales: 100 }], {
+          colnames: ['__timestamp', 'sales'],
+          coltypes: [GenericDataType.Temporal, GenericDataType.Numeric],
+        }),
+      ],
+    });
+
+    const transformedProps = transformProps(chartProps);
+    const tooltipFormatter = (transformedProps.echartOptions as any).tooltip
+      .formatter;
+
+    const result = tooltipFormatter({
+      value: [ts, 100],
+      seriesName: 'sales',
+    });
+
+    // Month grain (the dashboard override) should win, so the tooltip title
+    // reads "Jan 2021" rather than the Day-grain "2021-01-07".
+    expect(result).toContain('Jan');
+    expect(result).toContain('2021');
+    expect(result).not.toContain('2021-01-07');
+  });
+
+  test('chart-level time grain drives the tooltip when there is no dashboard 
override', () => {
+    const ts = Date.UTC(2021, 0, 7);
+    const chartProps = createTestChartProps({
+      formData: {
+        granularity_sqla: 'ds',
+        richTooltip: false,
+        timeGrainSqla: TimeGranularity.YEAR,
+      },
+      queriesData: [
+        createTestQueryData([{ __timestamp: ts, sales: 100 }], {
+          colnames: ['__timestamp', 'sales'],
+          coltypes: [GenericDataType.Temporal, GenericDataType.Numeric],
+        }),
+      ],
+    });
+
+    const transformedProps = transformProps(chartProps);
+    const tooltipFormatter = (transformedProps.echartOptions as any).tooltip
+      .formatter;
+
+    const result = tooltipFormatter({
+      value: [ts, 100],
+      seriesName: 'sales',
+    });
+
+    expect(result).toContain('2021');
+    expect(result).not.toContain('2021-01-07');
+  });
+});

Review Comment:
   Flattened this into standalone tests.



##########
superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts:
##########
@@ -821,3 +822,89 @@ test('temporal x coltype wires the time formatter and Time 
axis', () => {
   expect(typeof label).toBe('string');
   expect(label).not.toMatch(/NaN/);
 });
+
+describe('Tooltip time grain wiring', () => {

Review Comment:
   Flattened these into standalone tests.



##########
superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts:
##########
@@ -821,3 +822,89 @@ test('temporal x coltype wires the time formatter and Time 
axis', () => {
   expect(typeof label).toBe('string');
   expect(label).not.toMatch(/NaN/);
 });
+
+describe('Tooltip time grain wiring', () => {
+  test('dashboard-level extraFormData time grain overrides the chart-level 
grain in the tooltip', () => {
+    const ts = Date.UTC(2021, 0, 7);
+    const temporalRows = [{ __timestamp: ts, metric: 100 }];
+    const temporalQueryData = createTestQueryData(temporalRows, {
+      colnames: ['__timestamp', 'metric'],
+      coltypes: [GenericDataType.Temporal, GenericDataType.Numeric],
+      label_map: { __timestamp: ['__timestamp'], metric: ['metric'] },
+    });
+
+    const chartProps = createEchartsTimeseriesTestChartProps<
+      EchartsMixedTimeseriesFormData,
+      EchartsMixedTimeseriesProps
+    >({
+      ...MIXED_TIMESERIES_CHART_PROPS_DEFAULTS,
+      defaultQueriesData: [temporalQueryData, temporalQueryData],
+      formData: {
+        ...formData,
+        x_axis: '__timestamp',
+        metrics: ['metric'],
+        metricsB: ['metric'],
+        groupby: [],
+        groupbyB: [],
+        // The chart itself is configured with a Day grain...
+        timeGrainSqla: TimeGranularity.DAY,
+        // ...but a dashboard-level filter/override resolves to Month.
+        extraFormData: { time_grain_sqla: TimeGranularity.MONTH },
+      },
+      queriesData: [temporalQueryData, temporalQueryData],
+    });
+
+    const { echartOptions } = transformProps(chartProps);
+    const tooltipFormatter = (echartOptions as any).tooltip.formatter;

Review Comment:
   Typed this instead of casting to any.



##########
superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts:
##########
@@ -821,3 +822,89 @@ test('temporal x coltype wires the time formatter and Time 
axis', () => {
   expect(typeof label).toBe('string');
   expect(label).not.toMatch(/NaN/);
 });
+
+describe('Tooltip time grain wiring', () => {
+  test('dashboard-level extraFormData time grain overrides the chart-level 
grain in the tooltip', () => {
+    const ts = Date.UTC(2021, 0, 7);
+    const temporalRows = [{ __timestamp: ts, metric: 100 }];
+    const temporalQueryData = createTestQueryData(temporalRows, {
+      colnames: ['__timestamp', 'metric'],
+      coltypes: [GenericDataType.Temporal, GenericDataType.Numeric],
+      label_map: { __timestamp: ['__timestamp'], metric: ['metric'] },
+    });
+
+    const chartProps = createEchartsTimeseriesTestChartProps<
+      EchartsMixedTimeseriesFormData,
+      EchartsMixedTimeseriesProps
+    >({
+      ...MIXED_TIMESERIES_CHART_PROPS_DEFAULTS,
+      defaultQueriesData: [temporalQueryData, temporalQueryData],
+      formData: {
+        ...formData,
+        x_axis: '__timestamp',
+        metrics: ['metric'],
+        metricsB: ['metric'],
+        groupby: [],
+        groupbyB: [],
+        // The chart itself is configured with a Day grain...
+        timeGrainSqla: TimeGranularity.DAY,
+        // ...but a dashboard-level filter/override resolves to Month.
+        extraFormData: { time_grain_sqla: TimeGranularity.MONTH },
+      },
+      queriesData: [temporalQueryData, temporalQueryData],
+    });
+
+    const { echartOptions } = transformProps(chartProps);
+    const tooltipFormatter = (echartOptions as any).tooltip.formatter;
+
+    const result = tooltipFormatter({
+      value: [ts, 100],
+      seriesName: 'metric',
+    });
+
+    // Month grain (the dashboard override) should win, so the tooltip title
+    // reads "Jan 2021" rather than the Day-grain "2021-01-07".
+    expect(result).toContain('Jan');
+    expect(result).toContain('2021');
+    expect(result).not.toContain('2021-01-07');
+  });
+
+  test('chart-level time grain drives the tooltip when there is no dashboard 
override', () => {
+    const ts = Date.UTC(2021, 0, 7);
+    const temporalRows = [{ __timestamp: ts, metric: 100 }];
+    const temporalQueryData = createTestQueryData(temporalRows, {
+      colnames: ['__timestamp', 'metric'],
+      coltypes: [GenericDataType.Temporal, GenericDataType.Numeric],
+      label_map: { __timestamp: ['__timestamp'], metric: ['metric'] },
+    });
+
+    const chartProps = createEchartsTimeseriesTestChartProps<
+      EchartsMixedTimeseriesFormData,
+      EchartsMixedTimeseriesProps
+    >({
+      ...MIXED_TIMESERIES_CHART_PROPS_DEFAULTS,
+      defaultQueriesData: [temporalQueryData, temporalQueryData],
+      formData: {
+        ...formData,
+        x_axis: '__timestamp',
+        metrics: ['metric'],
+        metricsB: ['metric'],
+        groupby: [],
+        groupbyB: [],
+        timeGrainSqla: TimeGranularity.YEAR,
+      },
+      queriesData: [temporalQueryData, temporalQueryData],
+    });
+
+    const { echartOptions } = transformProps(chartProps);
+    const tooltipFormatter = (echartOptions as any).tooltip.formatter;

Review Comment:
   Same fix here, typed instead of any.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to