aminghadersohi commented on code in PR #40683:
URL: https://github.com/apache/superset/pull/40683#discussion_r3343379920
##########
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', '');
Review Comment:
The `__contribution` suffix cleanup only fires when `JSON.parse` also
succeeds. For a plain column like `revenue__contribution` (non-JSON key), the
`catch` swallows the error and `cleanHeader` stays as `revenue__contribution` —
the ` (contribution)` suffix is never applied.
If the fix is intentionally scoped to JSON-encoded metric keys, add a
comment saying so. If plain `__contribution` columns should also be cleaned,
separate the two concerns:
```ts
let cleaned = rawHeader;
let suffix = '';
if (rawHeader.endsWith('__contribution')) {
cleaned = rawHeader.slice(0, rawHeader.length - '__contribution'.length);
suffix = ' (contribution)';
}
try {
const parsed = JSON.parse(cleaned);
if (parsed && typeof parsed === 'object') {
cleaned = getMetricLabel(parsed as QueryFormMetric);
}
} catch { /* not a JSON-encoded metric */ }
cleanHeader = `${cleaned}${suffix}`;
```
##########
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}`;
+ }
+ } catch (_) {}
+
Review Comment:
Empty catch block should have a comment so a reader knows this is
intentional:
```ts
} catch {
// rawHeader is not a JSON-encoded metric — keep original display name
}
```
TypeScript 4.0+ supports omitting the binding variable.
--
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]