kgabryje commented on code in PR #35343:
URL: https://github.com/apache/superset/pull/35343#discussion_r2465307686


##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts:
##########
@@ -211,22 +213,137 @@ const buildQuery: BuildQuery<TableChartFormData> = (
       moreProps.row_offset = currentPage * pageSize;
     }
 
-    // getting sort by in case of server pagination from own state
     let sortByFromOwnState: QueryFormOrderBy[] | undefined;
-    if (Array.isArray(ownState?.sortBy) && ownState?.sortBy.length > 0) {
-      const sortByItem = ownState?.sortBy[0];
-      sortByFromOwnState = [[sortByItem?.key, !sortByItem?.desc]];
+
+    const sortSource =
+      isDownloadQuery && ownState?.sortModel
+        ? ownState.sortModel
+        : ownState?.sortBy;
+
+    if (Array.isArray(sortSource) && sortSource.length > 0) {
+      const mapColIdToIdentifier = (colId: string): string | undefined => {
+        const matchingColumn = columns.find((col: QueryFormColumn) => {
+          if (typeof col === 'string') return col === colId;
+          return col?.sqlExpression === colId || col?.label === colId;
+        });
+
+        if (matchingColumn) {
+          return typeof matchingColumn === 'string'
+            ? matchingColumn
+            : matchingColumn.sqlExpression || matchingColumn.label;
+        }
+
+        const matchingMetric = (metrics || []).find((met: QueryFormMetric) => {
+          if (typeof met === 'string')
+            return met === colId || `%${met}` === colId;
+          const metLabel = getMetricLabel(met);
+          return (
+            metLabel === colId ||
+            met?.label === colId ||
+            `%${metLabel}` === colId
+          );
+        });
+
+        if (matchingMetric) {
+          return typeof matchingMetric === 'string'
+            ? matchingMetric
+            : getMetricLabel(matchingMetric);

Review Comment:
   just getMetricLabel is enough - see above



-- 
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]

Reply via email to