Skip to content

Commit

Permalink
fix(table-facet): 修复过滤多列时,删除一列过滤将同时清空后续过滤列 (#2323)
Browse files Browse the repository at this point in the history
  • Loading branch information
LUUUAN authored Sep 9, 2023
1 parent 5320fbf commit 3ad35b1
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 1 deletion.
45 changes: 45 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-2322-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @description spec for issue #2322
* https://github.com/antvis/S2/issues/2322
* 明细表: 多列筛选后清空其中一列筛选,导致其他筛选也清空
*/
import { getContainer } from 'tests/util/helpers';
import dataCfg from '../data/data-issue-2322.json';
import { TableSheet } from '@/sheet-type';
import type { S2Options } from '@/common/interface';
import { S2Event } from '@/common';

const s2Options: S2Options = {
width: 300,
height: 480,
showSeriesNumber: true,
frozenColCount: 1,
};

describe('Table Sheet Filter Test', () => {
test('should filter correctly when part of the filter is cleaned', () => {
const s2 = new TableSheet(getContainer(), dataCfg, s2Options);
s2.render();

// 为两个不同的列设定过滤
s2.emit(S2Event.RANGE_FILTER, {
filterKey: 'province',
filteredValues: ['吉林'],
});
s2.emit(S2Event.RANGE_FILTER, {
filterKey: 'city',
filteredValues: ['杭州'],
});

// 删除一列过滤
s2.emit(S2Event.RANGE_FILTER, {
filterKey: 'province',
filteredValues: [],
});

// 应过滤掉 city = 杭州 的值,共4行
expect(s2.dataSet.getDisplayDataSet().length).toBe(
s2.dataSet.originData.length - 4,
);
});
});
147 changes: 147 additions & 0 deletions packages/s2-core/__tests__/data/data-issue-2322.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"fields": {
"columns": [
{
"key": "area",
"children": ["province", "city"]
},
"type",
{
"key": "money",
"children": [
{
"key": "price"
}
]
}
]
},
"meta": [
{
"field": "province",
"name": "省份"
},
{
"field": "city",
"name": "城市"
},
{
"field": "type",
"name": "商品类别"
},
{
"field": "price",
"name": "价格"
},
{
"field": "cost",
"name": "成本"
},
{
"field": "area",
"name": "位置"
},
{
"field": "money",
"name": "金额"
}
],
"data": [
{
"province": "浙江",
"city": "杭州",
"type": "",
"price": 1
},
{
"province": "浙江",
"city": "杭州",
"type": "纸张",
"price": 2
},
{
"province": "浙江",
"city": "舟山",
"type": "",
"price": 17
},
{
"province": "浙江",
"city": "舟山",
"type": "纸张",
"price": 6
},
{
"province": "吉林",
"city": "长春",
"type": "",
"price": 8
},
{
"province": "吉林",
"city": "白山",
"type": "",
"price": 12
},
{
"province": "吉林",
"city": "长春",
"type": "纸张",
"price": 3
},
{
"province": "吉林",
"city": "白山",
"type": "纸张",
"price": 25
},
{
"province": "浙江",
"city": "杭州",
"type": "",
"price": 20
},
{
"province": "浙江",
"city": "杭州",
"type": "纸张",
"price": 10
},
{
"province": "浙江",
"city": "舟山",
"type": "",
"price": 15
},
{
"province": "浙江",
"city": "舟山",
"type": "纸张",
"price": 2
},
{
"province": "吉林",
"city": "长春",
"type": "",
"price": 15
},
{
"province": "吉林",
"city": "白山",
"type": "",
"price": 30
},
{
"province": "吉林",
"city": "长春",
"type": "纸张",
"price": 40
},
{
"province": "吉林",
"city": "白山",
"type": "纸张",
"price": 50
}
]
}
2 changes: 1 addition & 1 deletion packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class TableFacet extends BaseFacet {
if (oldIndex !== -1) {
if (unFilter) {
// remove filter params on current key if passed an empty filterValues field
oldConfig.splice(oldIndex);
oldConfig.splice(oldIndex, 1);
} else {
// if filter with same key already exists, replace it
oldConfig[oldIndex] = params;
Expand Down

0 comments on commit 3ad35b1

Please sign in to comment.