You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "michael-s-molina (via GitHub)" <gi...@apache.org> on 2025/01/08 14:08:21 UTC
[PR] fix: Heatmap sorting [superset]
michael-s-molina opened a new pull request, #31752:
URL: https://github.com/apache/superset/pull/31752
### SUMMARY
Fixes https://github.com/apache/superset/issues/31318 by giving users the flexibility to sort a Heatmap chart by only one axis.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
https://github.com/user-attachments/assets/931d0a18-dd04-418d-a23d-5c3cbf9781f5
### TESTING INSTRUCTIONS
Check the original issue for instructions.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: Heatmap sorting [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on PR #31752:
URL: https://github.com/apache/superset/pull/31752#issuecomment-2577763171
@nicholaslimck
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: Heatmap sorting [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina merged PR #31752:
URL: https://github.com/apache/superset/pull/31752
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: Heatmap sorting [superset]
Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #31752:
URL: https://github.com/apache/superset/pull/31752#discussion_r1907248723
##########
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/buildQuery.ts:
##########
@@ -26,26 +27,28 @@ import {
getXAxisColumn,
} from '@superset-ui/core';
import { rankOperator } from '@superset-ui/chart-controls';
-import { HeatmapFormData } from './types';
-export default function buildQuery(formData: HeatmapFormData) {
+export default function buildQuery(formData: QueryFormData) {
const { groupby, normalize_across, sort_x_axis, sort_y_axis, x_axis } =
formData;
const metric = getMetricLabel(formData.metric);
const columns = [
...ensureIsArray(getXAxisColumn(formData)),
...ensureIsArray(groupby),
];
- const orderby: QueryFormOrderBy[] = [
- [
+ const orderby: QueryFormOrderBy[] = [];
+ if (sort_x_axis) {
+ orderby.push([
sort_x_axis.includes('value') ? metric : columns[0],
sort_x_axis.includes('asc'),
- ],
- [
+ ]);
+ }
+ if (sort_y_axis) {
+ orderby.push([
sort_y_axis.includes('value') ? metric : columns[1],
Review Comment:
### Array index access without bounds check <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
No validation that columns[1] exists before accessing it
###### Why this matters
If groupby is empty array, columns[1] will be undefined, potentially causing incorrect sorting behavior or runtime errors
###### Suggested change
Add validation: sort_y_axis.includes('value') ? metric : (columns[1] ?? columns[0])
</details>
###### Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
<!--- korbi internal id:99dde114-afa7-4f5e-bde4-3a27c2c35baa -->
##########
superset-frontend/plugins/plugin-chart-echarts/src/Heatmap/transformProps.ts:
##########
@@ -156,8 +156,10 @@ export default function transformProps(
),
label: {
show: showValues,
- formatter: (params: CallbackDataParams) =>
- valueFormatter(params.value?.[2]),
+ formatter: (params: CallbackDataParams) => {
+ const paramsValue = params.value as (string | number)[];
+ return valueFormatter(paramsValue?.[2] as number | null | undefined);
+ },
Review Comment:
### Unsafe Value Type Assertion in Formatter <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The type assertion of params.value to (string | number)[] may lead to runtime errors if the actual value structure differs from the expected format.
###### Why this matters
If the data structure changes or if params.value is undefined, the code could crash during chart rendering. The current implementation doesn't provide proper runtime validation of the data structure.
###### Suggested change
Add proper runtime validation:
```typescript
formatter: (params: CallbackDataParams) => {
if (!params.value || !Array.isArray(params.value)) {
return '';
}
const value = params.value[2];
return valueFormatter(typeof value === 'number' ? value : null);
}
```
</details>
###### Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
<!--- korbi internal id:dab4afd5-9865-4a44-bf5a-2631546ffabd -->
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org