LevisNgigi commented on code in PR #34175: URL: https://github.com/apache/superset/pull/34175#discussion_r2241123912
########## superset-frontend/packages/superset-ui-chart-controls/src/utils/metricColumnFilter.ts: ########## @@ -0,0 +1,102 @@ +/** + * 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 { + QueryFormMetric, + getMetricLabel, + SqlaFormData, +} from '@superset-ui/core'; + +export interface MetricColumnFilterParams { + colname: string; + colnames: string[]; + formData: SqlaFormData; +} + +/** + * Determines if a column should be skipped based on metric filtering logic. + * + * This function implements the logic to skip unprefixed percent metric columns + * if a prefixed version exists, but doesn't skip if it's also a regular metric. + * + * @param params - The parameters for metric column filtering + * @returns true if the column should be skipped, false otherwise + */ +export function shouldSkipMetricColumn({ + colname, + colnames, + formData, +}: MetricColumnFilterParams): boolean { + // Skip unprefixed percent metric columns if a prefixed version exists + // But don't skip if it's also a regular metric + return !!( + colname && + !colname.startsWith('%') && + colnames.includes(`%${colname}`) && + formData.percent_metrics?.some( + (metric: QueryFormMetric) => getMetricLabel(metric) === colname, + ) && + !formData.metrics?.some( + (metric: QueryFormMetric) => getMetricLabel(metric) === colname, + ) + ); Review Comment: Using form data is definitely the better approach.I have updated it based on the above feedback. -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org