mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-31 05:03:21 +08:00
Fix existing behaviour with prefixes
This commit is contained in:
parent
4af0d0d4b4
commit
07c7e47783
@ -748,6 +748,17 @@ describe('preview.story_store', () => {
|
||||
expect(store.getSelection()).toEqual({ storyId: 'g2-a--1', viewMode: 'story' });
|
||||
});
|
||||
|
||||
// Making sure the fix #11571 doesn't break this
|
||||
it('selects the first story if there are two stories in the group of different lengths', () => {
|
||||
const store = new StoryStore({ channel });
|
||||
store.setSelectionSpecifier({ storySpecifier: 'a', viewMode: 'story' });
|
||||
addStoryToStore(store, 'a', 'long-long-long', () => 0);
|
||||
addStoryToStore(store, 'a', 'short', () => 0);
|
||||
store.finishConfiguring();
|
||||
|
||||
expect(store.getSelection()).toEqual({ storyId: 'a--long-long-long', viewMode: 'story' });
|
||||
});
|
||||
|
||||
it('selects nothing if the component or group does not exist', () => {
|
||||
const store = new StoryStore({ channel });
|
||||
store.setSelectionSpecifier({ storySpecifier: 'c', viewMode: 'story' });
|
||||
|
@ -220,9 +220,12 @@ export default class StoryStore {
|
||||
// '*' means select the first story. If there is none, we have no selection.
|
||||
[foundStory] = stories;
|
||||
} else if (typeof storySpecifier === 'string') {
|
||||
// Find the story with the shortest id that matches the specifier (see #11571)
|
||||
const foundStories = Object.values(stories).filter((s) => s.id.startsWith(storySpecifier));
|
||||
[foundStory] = foundStories.sort((a, b) => a.id.length - b.id.length);
|
||||
// Find the story with the exact id that matches the specifier (see #11571)
|
||||
foundStory = Object.values(stories).find((s) => s.id === storySpecifier);
|
||||
if (!foundStory) {
|
||||
// Fallback to the first story that starts with the specifier
|
||||
foundStory = Object.values(stories).find((s) => s.id.startsWith(storySpecifier));
|
||||
}
|
||||
} else {
|
||||
// Try and find a story matching the name/kind, setting no selection if they don't exist.
|
||||
const { name, kind } = storySpecifier;
|
||||
|
Loading…
x
Reference in New Issue
Block a user