Skip to content

Commit

Permalink
Merge pull request #1400 from TMBigGroup/local/dev
Browse files Browse the repository at this point in the history
fix: chart sorter
  • Loading branch information
scottsut authored Jun 7, 2022
2 parents 758f3ba + 945b0a6 commit 27e61eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
23 changes: 7 additions & 16 deletions frontend/src/app/models/ChartDataRequestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,13 @@ export class ChartDataRequestBuilder {
aggOperator: aggCol.aggregate,
}));

return originalSorters
.reduce<ChartDataRequest['orders']>((acc, cur) => {
const uniqSorter = sorter =>
`${sorter.column}-${
sorter.aggOperator?.length > 0 ? sorter.aggOperator : ''
}`;
const newSorter = this.extraSorters?.find(
extraSorter => uniqSorter(extraSorter) === uniqSorter(cur),
);
if (newSorter) {
return acc;
}
return acc.concat([cur]);
}, [])
.concat(this.extraSorters as [])
.filter(sorter => Boolean(sorter?.operator));
const _extraSorters = this.extraSorters?.filter(
({ column, operator }) => column && operator,
);
if (!isEmptyArray(_extraSorters)) {
return _extraSorters;
}
return originalSorters.filter(sorter => Boolean(sorter?.operator));
}

private buildPageInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,6 @@ describe('ChartDataRequestBuild Test', () => {
const requestParams = builder.build();

expect(requestParams.orders).toEqual([
{ column: 'first-name', operator: 'ASC', aggOperator: undefined },
{ column: 'last-name', operator: 'DESC', aggOperator: undefined },
{ column: 'address', operator: 'DESC', aggOperator: undefined },
{
column: 'age',
aggOperator: 'AVG',
Expand All @@ -813,9 +810,6 @@ describe('ChartDataRequestBuild Test', () => {
builder.addExtraSorters(extraSorters2);

expect(requestParams.orders).toEqual([
{ column: 'first-name', operator: 'ASC', aggOperator: undefined },
{ column: 'last-name', operator: 'DESC', aggOperator: undefined },
{ column: 'address', operator: 'DESC', aggOperator: undefined },
{
column: 'age',
aggOperator: 'AVG',
Expand Down

0 comments on commit 27e61eb

Please sign in to comment.