Skip to content

Commit

Permalink
feat(plugin-chart-pivot-table): add sort by result to data pane (apac…
Browse files Browse the repository at this point in the history
…he#1243)

* feat(plugin-chart-pivot-table): add sort by result to data pane

* Use getMetricLabel helper function
  • Loading branch information
kgabryje authored and zhaoyongjie committed Nov 17, 2021
1 parent d2700d4 commit 2b1ab10
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@
* specific language governing permissions and limitations
* under the License.
*/
import { buildQueryContext, ensureIsArray, normalizeOrderBy } from '@superset-ui/core';
import {
buildQueryContext,
ensureIsArray,
getMetricLabel,
normalizeOrderBy,
} from '@superset-ui/core';
import { PivotTableQueryFormData } from '../types';

export default function buildQuery(formData: PivotTableQueryFormData) {
const { groupbyColumns = [], groupbyRows = [], order_desc = true } = formData;
const {
groupbyColumns = [],
groupbyRows = [],
order_desc = true,
timeseries_limit_metric,
} = formData;
const groupbySet = new Set([
...ensureIsArray<string>(groupbyColumns),
...ensureIsArray<string>(groupbyRows),
]);
return buildQueryContext(formData, baseQueryObject => {
const queryObject = normalizeOrderBy({ ...baseQueryObject, order_desc });
const { metrics } = queryObject;
const orderBy = ensureIsArray(timeseries_limit_metric);
if (
orderBy.length &&
!metrics?.find(metric => getMetricLabel(metric) === getMetricLabel(orderBy[0]))
) {
metrics?.push(orderBy[0]);
}
return [
{
...queryObject,
columns: [...groupbySet],
metrics,
},
];
});
Expand Down

0 comments on commit 2b1ab10

Please sign in to comment.