Skip to content

Commit

Permalink
fix(plugin-chart-handlebars): order by control not work (apache#21005)
Browse files Browse the repository at this point in the history
(cherry picked from commit e70699f)
  • Loading branch information
stephenLYZ authored and Fahrenheit35 committed Nov 11, 2022
1 parent 8430c36 commit c1e82da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
import { buildQueryContext, QueryFormData } from '@superset-ui/core';
import {
buildQueryContext,
normalizeOrderBy,
QueryFormData,
} from '@superset-ui/core';

export default function buildQuery(formData: QueryFormData) {
const { metric, sort_by_metric, groupby } = formData;
const { groupby } = formData;

return buildQueryContext(formData, baseQueryObject => [
{
...baseQueryObject,
...(sort_by_metric && { orderby: [[metric, false]] }),
orderby: normalizeOrderBy(baseQueryObject).orderby,
...(groupby && { groupby }),
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ const config: ControlPanelConfig = {
[metricsControlSetItem, allColumnsControlSetItem],
[percentMetricsControlSetItem],
[timeSeriesLimitMetricControlSetItem, orderByControlSetItem],
[orderDescendingControlSetItem],
serverPaginationControlSetRow,
[rowLimitControlSetItem, serverPageLengthControlSetItem],
[includeTimeControlSetItem, orderDescendingControlSetItem],
[includeTimeControlSetItem],
[showTotalsControlSetItem],
['adhoc_filters'],
emitFilterControl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { ControlSetItem, Dataset } from '@superset-ui/chart-controls';
import { t } from '@superset-ui/core';
import { isEmpty } from 'lodash';
import { isAggMode, isRawMode } from './shared';

export const orderByControlSetItem: ControlSetItem = {
Expand Down Expand Up @@ -45,7 +46,12 @@ export const orderDescendingControlSetItem: ControlSetItem = {
label: t('Sort descending'),
default: true,
description: t('Whether to sort descending or ascending'),
visibility: isAggMode,
visibility: ({ controls }) =>
!!(
isAggMode({ controls }) &&
controls?.timeseries_limit_metric.value &&
!isEmpty(controls?.timeseries_limit_metric.value)
),
resetOnHide: false,
},
};

0 comments on commit c1e82da

Please sign in to comment.