rebenitez1802 commented on code in PR #45540:
URL: https://github.com/apache/superset/pull/45540#discussion_r4341671012
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/filterValueGetter.ts:
##########
@@ -19,16 +19,20 @@
*/
import { ValueGetterParams } from
'@superset-ui/core/components/ThemedAgGridReact';
-const filterValueGetter = (params: ValueGetterParams) => {
- const raw = params.data[params.colDef.field as string];
- const formatter = params.colDef.valueFormatter as Function;
- if (!raw || !formatter) return null;
- const formatted = formatter({
- value: raw,
- });
-
- const numeric = parseFloat(String(formatted).replace('%', '').trim());
- return Number.isNaN(numeric) ? null : numeric;
+// Reads the raw value rather than parsing the formatted text back, which
+// carries the locale's separators and SI suffixes. A percent format shows the
+// value scaled by 100, so the filter compares against that scaled number,
+// shifted in decimal notation to avoid binary noise (0.07 * 100).
+const filterValueGetter = (params: ValueGetterParams, percent: boolean) => {
+ const raw = params.data?.[params.colDef.field as string];
Review Comment:
🟡 Medium: filtering a percent metric's "Main" column hides every row when
time comparison is on
When time comparison is on, `useColDefs` sets `field` to the key with the
`Main ` prefix removed (`colId`). Row data, however, is stored under `` `Main
${key}` `` (see `transformProps.ts`, around line 241), and the original key is
dropped. So `params.data?.[params.colDef.field]` is always `undefined` for the
Main column: any number filter on a percent metric's Main column hides every
row, and "Blank" matches every row.
This already happens on `master`, so it isn't a regression. Since this PR
rewrites this line, it's an easy fix to include here. `useColDefs` already
exposes the unstripped key as `context.dataKey` for this mismatch (the "Export
Current View" snapshot uses it the same way):
```suggestion
const key = params.colDef.context?.dataKey ?? params.colDef.field;
const raw = params.data?.[key as string];
```
A `useColDefs` test with a `Main %x` comparison column would cover it.
--
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]