bito-code-review[bot] commented on code in PR #40683:
URL: https://github.com/apache/superset/pull/40683#discussion_r3364685671
##########
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:
<!-- Bito Reply -->
The addition of test coverage for the JSON parsing and contribution-suffix
logic is a positive step. Addressing the reviewer's concern regarding test
coverage ensures that the new logic is verified for various scenarios,
including plain columns, contribution suffixes, and JSON-encoded metric keys.
Regarding the implementation details discussed in the review threads, the
reviewer provided several constructive suggestions to improve the robustness of
the code:
* **Suffix Removal:** Using `.slice()` instead of `.replace()` is
recommended to avoid issues with keys containing multiple occurrences of the
suffix.
* **Metric Labeling:** Utilizing `getMetricLabel` from `@superset-ui/core`
is suggested to better handle ad-hoc metrics that lack an explicit `.label`
property.
* **Logic Separation:** Separating the contribution suffix cleanup from
the JSON parsing logic ensures that plain columns with a `__contribution`
suffix are handled correctly.
* **Code Clarity:** Adding comments to the `catch` block is advised to
clarify that the failure to parse JSON is an expected scenario for non-JSON
headers.
--
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]