aminghadersohi commented on code in PR #40683:
URL: https://github.com/apache/superset/pull/40683#discussion_r3343377895
##########
superset-frontend/src/explore/components/DataTablesPane/components/useGridResultTable.tsx:
##########
@@ -37,10 +37,28 @@ export function useGridColumns(
.filter((column: string) => Object.keys(data[0]).includes(column))
.map((key, index) => {
const colType = coltypes?.[index];
- const headerLabel = columnDisplayNames?.[key] ?? key;
+
+ const rawHeader = columnDisplayNames?.[key] ?? key;
+ let cleanHeader = rawHeader;
+
+ try {
+ let jsonToParse = rawHeader;
+ let suffix = '';
+
+ if (rawHeader.endsWith('__contribution')) {
+ jsonToParse = rawHeader.replace('__contribution', '');
+ suffix = ' (contribution)';
Review Comment:
`String.replace()` removes the **first** occurrence, not the confirmed
suffix. `.endsWith` already proves `__contribution` is at the end, but for a
key like `__contribution_total__contribution`, `.replace` strips the leading
one and produces the wrong JSON key.
Use `.slice()` to remove exactly the suffix:
```ts
jsonToParse = rawHeader.slice(0, rawHeader.length - '__contribution'.length);
```
##########
superset-frontend/src/explore/components/DataTablesPane/components/useGridResultTable.tsx:
##########
@@ -37,10 +37,28 @@ export function useGridColumns(
.filter((column: string) => Object.keys(data[0]).includes(column))
.map((key, index) => {
const colType = coltypes?.[index];
- const headerLabel = columnDisplayNames?.[key] ?? key;
+
+ const rawHeader = columnDisplayNames?.[key] ?? key;
+ let cleanHeader = rawHeader;
+
+ try {
+ let jsonToParse = rawHeader;
+ let suffix = '';
+
+ if (rawHeader.endsWith('__contribution')) {
+ jsonToParse = rawHeader.replace('__contribution', '');
+ suffix = ' (contribution)';
+ }
+
+ const parsed = JSON.parse(jsonToParse);
+ if (parsed && typeof parsed === 'object' && parsed.label) {
+ cleanHeader = `${parsed.label}${suffix}`;
Review Comment:
`@superset-ui/core` already exports `getMetricLabel(metric:
QueryFormMetric)` for this. The current check only handles metrics with an
explicit `.label`, but adhoc simple metrics (e.g.,
`{"aggregate":"SUM","column":{...}}` with no custom label) still show raw JSON
— `getMetricLabel` would return `SUM(revenue)` for those.
```ts
import { getMetricLabel, QueryFormMetric, getTimeFormatter, ... } from
'@superset-ui/core';
// inside the try block:
const parsed = JSON.parse(jsonToParse);
if (parsed && typeof parsed === 'object') {
cleanHeader = `${getMetricLabel(parsed as QueryFormMetric)}${suffix}`;
}
```
--
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]