alexandrusoare commented on code in PR #35343:
URL: https://github.com/apache/superset/pull/35343#discussion_r2419043832
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts:
##########
@@ -218,15 +218,79 @@ const buildQuery: BuildQuery<TableChartFormData> = (
sortByFromOwnState = [[sortByItem?.key, !sortByItem?.desc]];
}
+ // Note: In Superset, "columns" are dimensions and "metrics" are measures,
+ // but AG Grid treats them all as "columns" in the UI
+ let orderedColumns = columns;
+ let orderedMetrics = metrics;
+
+ if (
+ isDownloadQuery &&
+ ownState.columnOrder &&
+ Array.isArray(ownState.columnOrder)
+ ) {
+ const orderedCols: typeof columns = [];
+ const orderedMets: typeof metrics = [];
+
+ ownState.columnOrder.forEach((colId: string) => {
+ const matchingCol = columns.find(col => {
+ if (typeof col === 'string') {
+ return col === colId;
+ }
+ return col?.sqlExpression === colId || col?.label === colId;
+ });
+
+ if (matchingCol && !orderedCols.includes(matchingCol)) {
+ orderedCols.push(matchingCol);
+ return;
+ }
+
+ const matchingMetric = metrics?.find(met => {
+ if (typeof met === 'string') {
+ return met === colId;
+ }
+ return getMetricLabel(met) === colId || met?.label === colId;
+ });
+
+ if (matchingMetric && !orderedMets.includes(matchingMetric)) {
+ orderedMets.push(matchingMetric);
+ }
+ });
+
+ columns.forEach(col => {
+ if (!orderedCols.includes(col)) {
+ orderedCols.push(col);
+ }
+ });
+
+ metrics?.forEach(met => {
+ if (!orderedMets.includes(met)) {
+ orderedMets.push(met);
+ }
+ });
+
+ orderedColumns = orderedCols;
+ orderedMetrics = orderedMets;
+ }
Review Comment:
Took care of, thanks
--
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]