villebro commented on code in PR #21993:
URL: https://github.com/apache/superset/pull/21993#discussion_r1032760934


##########
superset-frontend/packages/superset-ui-chart-controls/src/operators/sortOperator.ts:
##########
@@ -17,25 +16,50 @@
  * specific language governing permissions and limitationsxw
  * under the License.
  */
-import { DTTM_ALIAS, PostProcessingSort, RollingType } from 
'@superset-ui/core';
+import { isEmpty } from 'lodash';
+import {
+  ensureIsArray,
+  getMetricLabel,
+  getXAxisLabel,
+  hasGenericChartAxes,
+  isDefined,
+  PostProcessingSort,
+} from '@superset-ui/core';
 import { PostProcessingFactory } from './types';
 
 export const sortOperator: PostProcessingFactory<PostProcessingSort> = (
   formData,
   queryObject,
 ) => {
-  const { x_axis: xAxis } = formData;
+  // the sortOperator only used in the barchart v2
+  const labelsInMetricsAndXAxis = [
+    getXAxisLabel(formData),
+    ...ensureIsArray(formData.metrics).map(metric => getMetricLabel(metric)),
+  ].filter(Boolean);
+
   if (
-    (xAxis || queryObject.is_timeseries) &&
-    Object.values(RollingType).includes(formData.rolling_type)
+    hasGenericChartAxes &&
+    isDefined(formData?.x_axis_sort) &&
+    isDefined(formData?.x_axis_sort_asc) &&
+    labelsInMetricsAndXAxis.includes(formData.x_axis_sort) &&
+    // the sort operator doesn't support sort-by multiple series.
+    isEmpty(formData.groupby)

Review Comment:
   Thought for the future: As `formData` will always be unstandardized (can 
contain more or less any property names), it will be difficult to harmonize 
functionality based on `formData`. So at some point we should move to using a 
base `queryObject`, which has already been converted to specific format 
(`columns` for dimensional grouping).



##########
superset/utils/pandas_postprocessing/utils.py:
##########
@@ -101,6 +101,14 @@ def _is_multi_index_on_columns(df: DataFrame) -> bool:
     return isinstance(df.columns, pd.MultiIndex)
 
 
+def scalar_to_list(val: Any) -> Sequence[str]:

Review Comment:
   nit: as we're calling this `scalar_to_list`, the return type should probably 
be `List[...]`:
   ```suggestion
   def scalar_to_list(val: Any) -> List[str]:
   ```
   Alternatively call it `scalar_to_sequence`.



##########
superset-frontend/packages/superset-ui-chart-controls/src/operators/sortOperator.ts:
##########
@@ -17,25 +16,50 @@
  * specific language governing permissions and limitationsxw
  * under the License.
  */
-import { DTTM_ALIAS, PostProcessingSort, RollingType } from 
'@superset-ui/core';
+import { isEmpty } from 'lodash';
+import {
+  ensureIsArray,
+  getMetricLabel,
+  getXAxisLabel,
+  hasGenericChartAxes,
+  isDefined,
+  PostProcessingSort,
+} from '@superset-ui/core';
 import { PostProcessingFactory } from './types';
 
 export const sortOperator: PostProcessingFactory<PostProcessingSort> = (
   formData,
   queryObject,
 ) => {
-  const { x_axis: xAxis } = formData;
+  // the sortOperator only used in the barchart v2
+  const labelsInMetricsAndXAxis = [

Review Comment:
   To generalize and make this more specific to it's use case, could we call 
this `sortableLabels`?



-- 
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-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to