Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSF-tools: Allow type checking in storySort #25265

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions code/lib/csf-tools/src/getStorySortParameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,31 @@ export default {
]
`);
});

it('storysort satisfies inline', () => {
expect(
getStorySortParameter(dedent`
enum ComponentGroups {
General = 'General'
}
export default {
parameters: {
options: {
storySort: {
order: ['General'] satisfies ComponentGroups[]
}
}
}
};
`)
).toMatchInlineSnapshot(`
{
"order": [
"General",
],
}
`);
});
});
describe('unsupported', () => {
it('bad default export', () => {
Expand Down
4 changes: 3 additions & 1 deletion code/lib/csf-tools/src/getStorySortParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const getValue = (obj: t.ObjectExpression, key: string) => {
return value;
};

const parseValue = (expr: t.Expression): any => {
const parseValue = (value: t.Expression): any => {
const expr = stripTSModifiers(value);

if (t.isArrayExpression(expr)) {
return (expr.elements as t.Expression[]).map((o) => {
return parseValue(o);
Expand Down