Skip to content

Commit

Permalink
Control sortby based on series limit (#18950)
Browse files Browse the repository at this point in the history
(cherry picked from commit f53f86f)
  • Loading branch information
geido authored and villebro committed Apr 3, 2022
1 parent 3729df2 commit 4bff8fe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ const row_limit: SharedControlConfig<'SelectControl'> = {
description: t('Limits the number of rows that get displayed.'),
};

const order_desc: SharedControlConfig<'CheckboxControl'> = {
type: 'CheckboxControl',
label: t('Sort Descending'),
default: true,
description: t('Whether to sort descending or ascending'),
visibility: ({ controls }) =>
Boolean(controls?.timeseries_limit_metric.value),
};

const limit: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
freeForm: true,
Expand Down Expand Up @@ -508,6 +517,7 @@ const sharedControls = {
limit,
timeseries_limit_metric: enableExploreDnd ? dnd_sort_by : sort_by,
orderby: enableExploreDnd ? dnd_sort_by : sort_by,
order_desc,
series: enableExploreDnd ? dndSeries : series,
entity: enableExploreDnd ? dndEntity : entity,
x: enableExploreDnd ? dnd_x : x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* under the License.
*/
import { t } from '@superset-ui/core';
import { ControlPanelConfig, sections } from '@superset-ui/chart-controls';
import {
ControlPanelConfig,
sections,
sharedControls,
} from '@superset-ui/chart-controls';
import {
lineInterpolation,
showBrush,
Expand All @@ -41,6 +45,38 @@ import {
} from '../NVD3Controls';

const config: ControlPanelConfig = {
controlOverrides: {
limit: {
rerender: ['timeseries_limit_metric', 'order_desc'],
},
timeseries_limit_metric: {
label: t('Series Limit Sort By'),
description: t(
'Metric used to order the limit if a series limit is present. ' +
'If undefined reverts to the first metric (where appropriate).',
),
visibility: ({ controls }) => Boolean(controls?.limit.value),
mapStateToProps: (state, controlState) => {
const timeserieslimitProps =
sharedControls.timeseries_limit_metric.mapStateToProps?.(
state,
controlState,
) || {};
timeserieslimitProps.value = state.controls?.limit?.value
? controlState.value
: [];
return timeserieslimitProps;
},
},
order_desc: {
label: t('Series Limit Sort Descending'),
default: false,
description: t(
'Whether to sort descending or ascending if a series limit is present',
),
visibility: ({ controls }) => Boolean(controls?.limit.value),
},
},
controlPanelSections: [
sections.legacyTimeseriesTime,
timeSeriesSection[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,7 @@ export const timeSeriesSection: ControlPanelSectionConfig[] = [
['groupby'],
['limit'],
['timeseries_limit_metric'],
[
{
name: 'order_desc',
config: {
type: 'CheckboxControl',
label: t('Sort Descending'),
default: true,
description: t('Whether to sort descending or ascending'),
visibility: ({ controls }) =>
Boolean(controls?.timeseries_limit_metric.value),
},
},
],
['order_desc'],
[
{
name: 'contribution',
Expand Down

0 comments on commit 4bff8fe

Please sign in to comment.