Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Change Sort by and Sort descending controls for Time-series Bar Chart #18950

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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