bito-code-review[bot] commented on code in PR #37229: URL: https://github.com/apache/superset/pull/37229#discussion_r2705753086
########## superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.test.ts: ########## @@ -0,0 +1,199 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { DatasourceType } from '@superset-ui/core'; +import transformProps from './transformProps'; +import { EchartsTimeseriesChartProps } from './types'; + +const mockedProps = { + // Datasource metadata + datasource: { + id: 1, + name: 'test_datasource', + type: DatasourceType.Table, + columnFormats: {}, + currencyFormats: {}, + verboseMap: { + testing_count: 'Testing count', + 'SUM(money_for_learning)': 'SUM(money_for_learning)', + time_start: 'time_start', + }, + }, + + // Query results + queriesData: [ + { + label_map: { + time_start: ['time_start'], + 'SUM(money_for_learning)': ['SUM(money_for_learning)'], + 'SUM(money_for_learning), 1 day ago': [ + 'SUM(money_for_learning)', + '1 day ago', + ], + 'SUM(money_for_learning), 1 week ago': [ + 'SUM(money_for_learning)', + '1 week ago', + ], + 'SUM(money_for_learning), 1 year ago': [ + 'SUM(money_for_learning)', + '1 year ago', + ], + testing_count: ['testing_count'], + 'testing_count, 1 day ago': ['testing_count', '1 day ago'], + 'testing_count, 1 week ago': ['testing_count', '1 week ago'], + 'testing_count, 1 year ago': ['testing_count', '1 year ago'], + 'Testing count': ['testing_count'], + }, + colnames: [ + 'time_start', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'testing_count', + 'testing_count, 1 day ago', + 'testing_count, 1 week ago', + 'testing_count, 1 year ago', + ], + indexnames: [0, 1, 2], + coltypes: [2, 0, 0, 0, 1, 0, 0, 0, 1], + data: [ + { + time_start: 1533081600001, + 'SUM(money_for_learning)': 101, + 'SUM(money_for_learning), 1 day ago': null, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 1, + 'testing_count, 1 day ago': null, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + { + time_start: 1533168000001, + 'SUM(money_for_learning)': 5791, + 'SUM(money_for_learning), 1 day ago': 101, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 131, + 'testing_count, 1 day ago': 11, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + ], + result_format: 'json', + applied_filters: [ + { + column: 'time_start', + }, + ], + rejected_filters: [], + }, + ] as unknown as EchartsTimeseriesChartProps['queriesData'], + + // Filter and legend state + filterState: { + selectedValues: [], + }, + legendState: {}, + + // Form data (chart configuration) + formData: { + metrics: [ + { + aggregate: 'SUM', + column: { + column_name: 'money_for_learning', + filterable: true, + groupby: true, + id: 460, + is_dttm: false, + type: 'DOUBLE PRECISION', + type_generic: 0, + }, + expressionType: 'SIMPLE', + hasCustomLabel: false, + label: 'SUM(money_for_learning)', + optionName: 'metric_olnflt1ak9g_z1vjg3dhmnf', + }, + 'testing_count', + ], + } as unknown as EchartsTimeseriesChartProps['formData'], + + // Hooks + hooks: { + setDataMask: () => {}, + setControlValue: () => {}, + onContextMenu: () => {}, + onLegendStateChanged: () => {}, + onLegendScroll: () => {}, + }, + + // UI state + inContextMenu: false, + emitCrossFilters: true, + legendIndex: 0, + + // Raw form data (needed for additional validation) + rawFormData: { + datasource: '1__table', + viz_type: 'echarts_timeseries', + x_axis: 'ds', + time_compare: [], Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Incorrect test expectations</b></div> <div id="fix"> The test expects 'time_start' in legendData, but transformProps does not include the x-axis in the legend—only series names. With time_compare as an empty array, only 2 series are generated ('SUM(money_for_learning)' and 'Testing count'), but expectedResult has 9 items. Update time_compare to enable time-shifted series and remove 'time_start' to match the actual legend output of 8 items. </div> </div> <small><i>Code Review Run #72a151</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.test.ts: ########## @@ -0,0 +1,295 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { DatasourceType } from '@superset-ui/core'; +import transformProps from './transformProps'; +import { EchartsTimeseriesChartProps } from '../types'; +import { EchartsMixedTimeseriesProps } from './types'; + +const mockedProps = { + // Datasource metadata + datasource: { + id: 1, + name: 'test_datasource', + type: DatasourceType.Table, + columnFormats: {}, + currencyFormats: {}, + verboseMap: { + testing_count: 'Testing count', + 'SUM(money_for_learning)': 'SUM(money_for_learning)', + time_start: 'time_start', + }, + }, + + // Query results + queriesData: [ + { + label_map: { + time_start: ['time_start'], + 'SUM(money_for_learning)': ['SUM(money_for_learning)'], + 'SUM(money_for_learning), 1 day ago': [ + 'SUM(money_for_learning)', + '1 day ago', + ], + 'SUM(money_for_learning), 1 week ago': [ + 'SUM(money_for_learning)', + '1 week ago', + ], + 'SUM(money_for_learning), 1 year ago': [ + 'SUM(money_for_learning)', + '1 year ago', + ], + testing_count: ['testing_count'], + 'testing_count, 1 day ago': ['testing_count', '1 day ago'], + 'testing_count, 1 week ago': ['testing_count', '1 week ago'], + 'testing_count, 1 year ago': ['testing_count', '1 year ago'], + 'Testing count': ['testing_count'], + }, + colnames: [ + 'time_start', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'testing_count', + 'testing_count, 1 day ago', + 'testing_count, 1 week ago', + 'testing_count, 1 year ago', + ], + indexnames: [0, 1, 2], + coltypes: [2, 0, 0, 0, 1, 0, 0, 0, 1], + data: [ + { + time_start: 1533081600001, + 'SUM(money_for_learning)': 101, + 'SUM(money_for_learning), 1 day ago': null, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 1, + 'testing_count, 1 day ago': null, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + { + time_start: 1533168000001, + 'SUM(money_for_learning)': 5791, + 'SUM(money_for_learning), 1 day ago': 101, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 131, + 'testing_count, 1 day ago': 11, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + ], + result_format: 'json', + applied_filters: [ + { + column: 'time_start', + }, + ], + rejected_filters: [], + }, + { + label_map: { + time_start: ['time_start'], + 'SUM(money_for_learning)': ['SUM(money_for_learning)'], + 'SUM(money_for_learning), 1 day ago': [ + 'SUM(money_for_learning)', + '1 day ago', + ], + 'SUM(money_for_learning), 1 week ago': [ + 'SUM(money_for_learning)', + '1 week ago', + ], + 'SUM(money_for_learning), 1 year ago': [ + 'SUM(money_for_learning)', + '1 year ago', + ], + testing_count: ['testing_count'], + 'testing_count, 1 day ago': ['testing_count', '1 day ago'], + 'testing_count, 1 week ago': ['testing_count', '1 week ago'], + 'testing_count, 1 year ago': ['testing_count', '1 year ago'], + 'Testing count': ['testing_count'], + }, + colnames: [ + 'time_start', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'testing_count', + 'testing_count, 1 day ago', + 'testing_count, 1 week ago', + 'testing_count, 1 year ago', + ], + indexnames: [0, 1, 2], + coltypes: [2, 0, 0, 0, 1, 0, 0, 0, 1], + data: [ + { + time_start: 1533081600000, + 'SUM(money_for_learning)': 100, + 'SUM(money_for_learning), 1 day ago': null, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 1, + 'testing_count, 1 day ago': null, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + { + time_start: 1533168000000, + 'SUM(money_for_learning)': 5790, + 'SUM(money_for_learning), 1 day ago': 100, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 13, + 'testing_count, 1 day ago': 1, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + ], + result_format: 'json', + applied_filters: [ + { + column: 'time_start', + }, + ], + rejected_filters: [], + }, + ] as unknown as EchartsTimeseriesChartProps['queriesData'], + + // Filter and legend state + filterState: { + selectedValues: [], + }, + legendState: {}, + + // Form data (chart configuration) + formData: { + metrics: [ + { + aggregate: 'SUM', + column: { + column_name: 'money_for_learning', + filterable: true, + groupby: true, + id: 460, + is_dttm: false, + type: 'DOUBLE PRECISION', + type_generic: 0, + }, + expressionType: 'SIMPLE', + hasCustomLabel: false, + label: 'SUM(money_for_learning)', + optionName: 'metric_olnflt1ak9g_z1vjg3dhmnf', + }, + 'testing_count', + ], + metricsB: [ + { + aggregate: 'SUM', + column: { + column_name: 'money_for_learning', + filterable: true, + groupby: true, + id: 460, + is_dttm: false, + type: 'DOUBLE PRECISION', + type_generic: 0, + }, + expressionType: 'SIMPLE', + hasCustomLabel: false, + label: 'SUM(money_for_learning)', + optionName: 'metric_olnflt1ak9g_z1vjg3dhmnf', + }, + 'testing_count', + ], + } as unknown as EchartsTimeseriesChartProps['formData'], + + // Hooks + hooks: { + setDataMask: () => {}, + setControlValue: () => {}, + onContextMenu: () => {}, + onLegendStateChanged: () => {}, + onLegendScroll: () => {}, + }, + + // UI state + inContextMenu: false, + emitCrossFilters: true, + legendIndex: 0, + + // Raw form data (needed for additional validation) + rawFormData: { + datasource: '1__table', + viz_type: 'echarts_timeseries', + x_axis: 'ds', + time_compare: [], + } as unknown as EchartsTimeseriesChartProps['rawFormData'], + + // Theme + theme: {}, +} as unknown as EchartsMixedTimeseriesProps; + +describe('MixedTimeseries transformProps', () => { + it('Should transform props correctly', () => { + const result = transformProps(mockedProps); + + expect(result.coltypeMapping).toEqual({ + 'SUM(money_for_learning)': 0, + 'SUM(money_for_learning), 1 day ago': 0, + 'SUM(money_for_learning), 1 week ago': 0, + 'SUM(money_for_learning), 1 year ago': 1, + testing_count: 0, + 'testing_count, 1 day ago': 0, + 'testing_count, 1 week ago': 0, + 'testing_count, 1 year ago': 1, + time_start: 2, + }); + + const legendData = (result.echartOptions.legend as { data: string[] }).data; + + const expectedResult = [ + 'SUM(money_for_learning)', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'SUM(money_for_learning), 1 year ago', + 'Testing count', + 'Testing count', + 'Testing count, 1 day ago', + 'Testing count, 1 day ago', + 'Testing count, 1 week ago', + 'Testing count, 1 week ago', + 'Testing count, 1 year ago', + 'Testing count, 1 year ago', + 'time_start', + 'time_start', Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Unexpected x-axis in expected legend</b></div> <div id="fix"> The expected legend includes 'time_start', but transformProps legend data only includes series names from metrics, not the x-axis. </div> </div> <small><i>Code Review Run #72a151</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
