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 134d7df commit bebaadf
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 @@ -211,6 +211,30 @@ describe('Sort By Custom Test', () => {
'Wednesday[&]afternoon',
]);
});

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

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

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,12 +1,12 @@
import {
compact,
endsWith,
flatMap,
includes,
indexOf,
isEmpty,
isNil,
keys,
last,
map,
sortBy,
split,
Expand Down Expand Up @@ -108,8 +108,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, NODE_ID_SEPARATOR)) === value;
}),
);
// 将 id 拆分为父节点和目标节点
const idListWithPre = idWithPre.map((idStr) => {
Expand Down

0 comments on commit bebaadf

Please sign in to comment.