Skip to content

Commit

Permalink
fix: 修复手动排序在单行头且维值相似的场景不生效 (#3019)
Browse files Browse the repository at this point in the history
* fix: 修复手动排序在单行头且维值相似的场景不生效

* chore: 更新 ci 版本

* chore: 更新 ci 版本

* chore: 更新 ci 版本
  • Loading branch information
lijinke666 authored Dec 9, 2024
1 parent 291c727 commit 6221958
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# runs-on: macos-latest # (目前 macos-latest 对应的是 Big Sur 11, macos-12 对应 Monterey 12)
# macOS 3-core CPU, 其他 2-core CPU
# > macos-14 会导致 CI 的测试卡死, 没有任何报错!!!
runs-on: macos-13
runs-on: macos-14
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
Expand Down
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 6221958

Please sign in to comment.