villebro commented on code in PR #21449: URL: https://github.com/apache/superset/pull/21449#discussion_r969558797
########## superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts: ########## @@ -149,8 +148,9 @@ export default function transformProps( const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); const rebasedData = rebaseForecastDatum(data, verboseMap); + // todo: if the both granularity_sqla and x_axis are `null`, should throw an error const xAxisCol = - verboseMap[xAxisOrig] || getColumnLabel(xAxisOrig || DTTM_ALIAS); + verboseMap[xAxisOrig] || getAxis(chartProps.rawFormData) || DTTM_ALIAS; Review Comment: If we make `getAxis` always return a non-undefined value, then we won't need to have the ` || DTTM_ALIAS` here, right? It feels slightly redundant, as it feels like the `getAxis` helper should always return a value (or raise if it can't). ########## superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/getAxis.ts: ########## @@ -0,0 +1,35 @@ +/** + * 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 { + DTTM_ALIAS, + getColumnLabel, + isDefined, + QueryFormData, +} from '@superset-ui/core'; + +export const getAxis = (formData: QueryFormData): string | undefined => { + // The formData should be "raw form_data" -- the snake_case version of formData rather than camelCase. + if (!(formData.granularity_sqla || formData.x_axis)) { + return undefined; + } + + return isDefined(formData.x_axis) + ? getColumnLabel(formData.x_axis) + : DTTM_ALIAS; +}; Review Comment: To future proof this to n dimensions, I think it might make sense to call this helper `getBaseAxes` that returns an array (that way we also wouldn't need to wrap the return value in an array when passing it to the `index` prop). Also, I believe the return type should be based on `QueryFormColumn`, as it may also be an `AdhocColumn`. So maybe the sig should be ```typescript export const getBaseAxes = (formData: QueryFormData): QueryFormColumn[] | undefined => {...} ``` Also, shouldn't we assume that the return value should always be defined, i.e. we always fall back to `DTTM_ALIAS` (at least for now) unless `formData.x_axis` is defined? -- 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]
