Copilot commented on code in PR #37461:
URL: https://github.com/apache/superset/pull/37461#discussion_r2733354325
##########
superset-frontend/src/components/Chart/DrillBy/DrillByModal.tsx:
##########
@@ -205,6 +206,49 @@ export default function DrillByModal({
[dataset.columns, formData, groupbyFieldName],
);
+ const getColumnLabel = useCallback(
+ (colname: string, labelMap: Record<string, string[]>) => {
+ for (const [key, value] of Object.entries(labelMap)) {
+ if (value.includes(colname) && key !== colname) {
+ return key;
+ }
+ }
+
+ return colname;
+ },
+ [],
+ );
+
+ const mapColumnsToLabels = useCallback(
+ (dataResult: QueryData[]) =>
+ dataResult.map(result => {
+ const { colnames, label_map: labelMap, data } = result;
+
+ let newColnames: string[] = colnames;
+ let newData: DataRecord[] = data;
+ colnames.forEach((colname: string) => {
+ const label = getColumnLabel(colname, labelMap);
+ if (label !== colname) {
Review Comment:
`label_map` is declared as optional on `ChartDataResponseResult` and
`QueryData` can also be a legacy payload, but `mapColumnsToLabels` destructures
`label_map` without a default and passes it directly into `getColumnLabel`,
which iterates over `Object.entries(labelMap)`. When the backend omits
`label_map` (or when the result is a legacy `QueryData` without this field),
`labelMap` will be `undefined` and this code will throw at runtime, breaking
Drill By for those queries. Consider updating `getColumnLabel` to accept an
optional `labelMap` and early-return the original `colname` when it is falsy,
and/or add a guard in `mapColumnsToLabels` (for example returning the
unmodified `result` when `!('label_map' in result) || !result.label_map`).
--
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]