diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2905791ec2..f7ab65d367 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts b/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts index ca1afcb811..59ef2ac5ce 100644 --- a/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts @@ -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测试', + ]); + }); }); }); diff --git a/packages/s2-core/src/utils/sort-action.ts b/packages/s2-core/src/utils/sort-action.ts index 171b00ceec..da5ccf36b0 100644 --- a/packages/s2-core/src/utils/sort-action.ts +++ b/packages/s2-core/src/utils/sort-action.ts @@ -1,12 +1,12 @@ import { compact, - endsWith, flatMap, includes, indexOf, isEmpty, isNil, keys, + last, map, sortBy, split, @@ -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) => {