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

【WIP】fix: 修复【指标不在最后一级customValueOrder】+ 【分组汇总】+【按汇总值排序】同时使用时,获取排序数据时为空 #2368

Closed
wants to merge 1 commit into from
Closed
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
77 changes: 77 additions & 0 deletions packages/s2-core/__tests__/unit/utils/sort-action-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,80 @@ describe('GetSortByMeasureValues Total Fallback Tests', () => {
]);
});
});
describe('GetSortByMeasureValues Total With Group Fallback Tests', () => {
let sheet: PivotSheet;
let dataSet: PivotDataSet;
const s2Options = {
totals: {
col: {
totalsGroupDimensions: ['city'],
showGrandTotals: true,
},
},
} as S2Options;

const dataConfig = {
...sortData,
data: [
...sortData.data,
{
city: '杭州',
type: '纸张',
price: '999',
},
{
city: '杭州',
type: '笔',
price: '666',
},
],
fields: {
rows: ['type'],
columns: ['province', 'city'],
values: ['price'],
},
};

beforeEach(() => {
sheet = new PivotSheet(getContainer(), dataConfig, s2Options);
dataSet = new PivotDataSet(sheet);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这应该不是 Mock 的 PivotSheet 把, 为什么不直接用 sheet.dataSet, 而要重新赋值

dataSet.setDataCfg(dataConfig);
sheet.dataSet = dataSet;
});

test('should sort by col total whit group', () => {
sheet.render();
// 根据列(类别)的总和排序
const sortParam: SortParam = {
sortFieldId: 'type',
sortByMeasure: TOTAL_VALUE,
sortMethod: 'desc',
query: {
[EXTRA_FIELD]: 'price',
city: '杭州',
},
};

const params: SortActionParams = {
dataSet,
sortParam,
};
const measureValues = getSortByMeasureValues(params);
expect(measureValues).toEqual([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(measureValues).toEqual([
expect(measureValues).toMatchInlineSnapshot()

{
$$extra$$: 'price',
$$value$$: '666',
city: '杭州',
price: '666',
type: '笔',
},
{
$$extra$$: 'price',
$$value$$: '999',
city: '杭州',
price: '999',
type: '纸张',
},
]);
});
});
14 changes: 5 additions & 9 deletions packages/s2-core/src/data-set/pivot-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ export class PivotDataSet extends BaseDataSet {
getTotalGroupQueries(dimensions: string[], originQuery: DataType) {
let queries = [originQuery];
let existDimensionGroupKey = null;
for (let i = dimensions.length; i > 0; i--) {
const key = dimensions[i - 1];
for (let i = dimensions.length - 1; i >= 0; i--) {
const key = dimensions[i];
if (keys(originQuery).includes(key)) {
if (key !== EXTRA_FIELD) {
existDimensionGroupKey = key;
Expand All @@ -587,8 +587,6 @@ export class PivotDataSet extends BaseDataSet {
const allCurrentFieldDimensionValues =
this.sortedDimensionValues[existDimensionGroupKey];
let res = [];
const arrayLength =
allCurrentFieldDimensionValues[0].split(ID_SEPARATOR).length;
for (const query of queries) {
const resKeys = [];
for (const dimValue of allCurrentFieldDimensionValues) {
Expand All @@ -601,14 +599,12 @@ export class PivotDataSet extends BaseDataSet {
})
) {
const arrTypeValue = dimValue.split(ID_SEPARATOR);
const currentKey = arrTypeValue[arrayLength - 2];
if (currentKey !== 'undefined') {
resKeys.push(currentKey);
}
const currentKey = arrTypeValue[i];
resKeys.push(currentKey);
}
}
const queryList = uniq(resKeys).map((v) => {
return { ...query, [key]: v };
return { ...query, [key]: v === 'undefined' ? undefined : v };
});
res = concat(res, queryList);
}
Expand Down
Loading