zhaoyongjie commented on code in PR #21993: URL: https://github.com/apache/superset/pull/21993#discussion_r1032789640
########## 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: Interestingly, these operators are used to "build" part of `Query Object`. I recently found that we might only use `formData` to generate an operator and don't use the `QueryObject`. However, we need to consider more and more to see how to make an efficient and convenient abstraction on the queryObject generation. -- 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