Skip to content

Commit

Permalink
Merge pull request #18243 from EloB/feature/wildcard-parent-sortorder
Browse files Browse the repository at this point in the history
Added parent wildcard sortOrder
  • Loading branch information
kylegach authored Jun 28, 2022
2 parents 8519d51 + c8fc501 commit 57af527
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/store/src/storySort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,19 @@ describe('preview.storySort', () => {
expect(sortFn(fixture.a_c, fixture.a_b)).toBeLessThan(0);
expect(sortFn(fixture.a_b, fixture.a_c)).toBeGreaterThan(0);
});

it('sorts according to the nested order array with parent wildcard', () => {
const sortFn = storySort({
order: ['*', ['*', 'b', 'a']],
includeNames: true,
});

expect(sortFn(fixture.a_a, fixture.a_b)).toBeGreaterThan(0);
expect(sortFn(fixture.a_b, fixture.a_a)).toBeLessThan(0);
expect(sortFn(fixture.a_c, fixture.a_a)).toBeLessThan(0);
expect(sortFn(fixture.a_c, fixture.a_b)).toBeLessThan(0);
expect(sortFn(fixture.a_a, fixture.a_c)).toBeGreaterThan(0);
expect(sortFn(fixture.a_b, fixture.a_c)).toBeGreaterThan(0);
expect(sortFn(fixture.a_a, fixture.a_a)).toBe(0);
});
});
3 changes: 2 additions & 1 deletion lib/store/src/storySort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export const storySort =
}

// If a nested array is provided for a name, use it for ordering.
const index = order.indexOf(nameA);
let index = order.indexOf(nameA);
if (index === -1) index = order.indexOf('*');
order = index !== -1 && Array.isArray(order[index + 1]) ? order[index + 1] : [];

// We'll need to look at the next part of the name.
Expand Down

0 comments on commit 57af527

Please sign in to comment.