mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat(plugin-chart-pivot-table): support series limit (#17803)
* feat(plugin-chart-pivot-table): support series limit * Add a migration * Use non-legacy series limit controls * Add a todo comment * Bug fix
This commit is contained in:
committed by
GitHub
parent
19daf65b54
commit
2c3f39f3f2
@@ -19,45 +19,31 @@
|
||||
import {
|
||||
buildQueryContext,
|
||||
ensureIsArray,
|
||||
getMetricLabel,
|
||||
normalizeOrderBy,
|
||||
QueryFormColumn,
|
||||
QueryFormOrderBy,
|
||||
} from '@superset-ui/core';
|
||||
import { PivotTableQueryFormData } from '../types';
|
||||
|
||||
export default function buildQuery(formData: PivotTableQueryFormData) {
|
||||
const {
|
||||
groupbyColumns = [],
|
||||
groupbyRows = [],
|
||||
order_desc = true,
|
||||
legacy_order_by,
|
||||
} = formData;
|
||||
const { groupbyColumns = [], groupbyRows = [] } = formData;
|
||||
// TODO: add deduping of AdhocColumns
|
||||
const groupbySet = new Set([
|
||||
...ensureIsArray<QueryFormColumn>(groupbyColumns),
|
||||
...ensureIsArray<QueryFormColumn>(groupbyRows),
|
||||
]);
|
||||
return buildQueryContext(formData, baseQueryObject => {
|
||||
const queryObject = normalizeOrderBy({
|
||||
...baseQueryObject,
|
||||
order_desc,
|
||||
legacy_order_by,
|
||||
});
|
||||
const { metrics } = queryObject;
|
||||
const orderBy = ensureIsArray(legacy_order_by);
|
||||
if (
|
||||
orderBy.length &&
|
||||
!metrics?.find(
|
||||
metric => getMetricLabel(metric) === getMetricLabel(orderBy[0]),
|
||||
)
|
||||
) {
|
||||
metrics?.push(orderBy[0]);
|
||||
const { series_limit_metric, metrics, order_desc } = baseQueryObject;
|
||||
let orderBy: QueryFormOrderBy[] | undefined;
|
||||
if (series_limit_metric) {
|
||||
orderBy = [[series_limit_metric, !order_desc]];
|
||||
} else if (Array.isArray(metrics) && metrics[0]) {
|
||||
orderBy = [[metrics[0], !order_desc]];
|
||||
}
|
||||
return [
|
||||
{
|
||||
...queryObject,
|
||||
...baseQueryObject,
|
||||
orderby: orderBy,
|
||||
columns: [...groupbySet],
|
||||
metrics,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
sections,
|
||||
sharedControls,
|
||||
emitFilterControl,
|
||||
legacySortBy,
|
||||
} from '@superset-ui/chart-controls';
|
||||
import { MetricsLayoutEnum } from '../types';
|
||||
|
||||
@@ -90,15 +89,41 @@ const config: ControlPanelConfig = {
|
||||
],
|
||||
['adhoc_filters'],
|
||||
emitFilterControl,
|
||||
['series_limit'],
|
||||
[
|
||||
{
|
||||
name: 'row_limit',
|
||||
config: {
|
||||
...sharedControls.row_limit,
|
||||
label: t('Cell limit'),
|
||||
description: t('Limits the number of cells that get retrieved.'),
|
||||
},
|
||||
},
|
||||
],
|
||||
// TODO(kgabryje): add series_columns control after control panel is redesigned to avoid clutter
|
||||
[
|
||||
{
|
||||
name: 'series_limit_metric',
|
||||
config: {
|
||||
...sharedControls.series_limit_metric,
|
||||
description: t(
|
||||
'Metric used to define how the top series are sorted if a series or cell limit is present. ' +
|
||||
'If undefined reverts to the first metric (where appropriate).',
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
name: 'order_desc',
|
||||
config: {
|
||||
type: 'CheckboxControl',
|
||||
label: t('Sort Descending'),
|
||||
default: true,
|
||||
description: t('Whether to sort descending or ascending'),
|
||||
},
|
||||
},
|
||||
],
|
||||
...legacySortBy,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user