Skip to content

Commit

Permalink
fix: 修复手动排序在单行头且维值相似的场景不生效
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Dec 9, 2024
1 parent f172409 commit 5c86145
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 24 additions & 0 deletions packages/s2-core/__tests__/unit/utils/sort-action-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,30 @@ describe('Sort By Custom', () => {
'Wednesday[&]afternoon',
]);
});

test('sort by custom with semblable value', () => {
const params = {
originValues: [
'我也是测1试',
'我是测试',
'我也是测试',
'我也是测试1',
'我也是1测试',
'测试',
],
sortByValues: ['测试', '我是测试'],
};

// 原来的处理是 endsWith 去模糊匹配维值, 导致其他维值会排序到最上方
expect(sortByCustom(params)).toEqual([
'测试',
'我是测试',
'我也是测1试',
'我也是测试',
'我也是测试1',
'我也是1测试',
]);
});
});

describe('Sort By Func Tests', () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/s2-core/src/utils/sort-action.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
compact,
endsWith,
flatMap,
includes,
indexOf,
isEmpty,
isNaN,
isNil,
keys,
last,
map,
sortBy,
split,
Expand Down Expand Up @@ -99,8 +99,10 @@ export const sortByCustom = (params: SortActionParams): string[] => {
const { sortByValues, originValues } = params;

// 从 originValues 中过滤出所有包含 sortByValue 的 id
const idWithPre = originValues.filter((originItem) =>
sortByValues.find((value) => endsWith(originItem, value)),
const idWithPre = originValues.filter((originValue) =>
sortByValues.find((value) => {
return last(split(originValue, ID_SEPARATOR)) === value;
}),
);
// 将 id 拆分为父节点和目标节点
const idListWithPre = idWithPre.map((idStr) => {
Expand Down

0 comments on commit 5c86145

Please sign in to comment.