Skip to content

Commit

Permalink
Merge pull request #11294 from storybookjs/fix/allow-refs-versions-in…
Browse files Browse the repository at this point in the history
…-config

Composition: Allow refs versions in config
  • Loading branch information
shilman authored Jun 24, 2020
2 parents 1f01a01 + 43a2d32 commit 826f328
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions examples/dev-kits/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = {
id: 'ember',
title: 'Ember',
url: 'https://next--storybookjs.netlify.app/ember-cli',
versions: {
next: 'https://next--storybookjs.netlify.app/ember-cli',
master: 'https://master--storybookjs.netlify.app/ember-cli',
},
},
cra: 'https://next--storybookjs.netlify.app/cra-ts-kitchen-sink',
},
Expand Down
5 changes: 3 additions & 2 deletions lib/api/src/modules/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export const init: ModuleFn = ({ store, provider, fullAPI }, { runCheck = true }
return Object.values(refs).find(({ url }) => url.match(source));
},
changeRefVersion: (id, url) => {
const previous = api.getRefs()[id];
const ref = { ...previous, stories: {}, url } as SetRefData;
const { versions, title } = api.getRefs()[id];
const ref = { id, url, versions, title, stories: {} } as SetRefData;

api.checkRef(ref);
},
Expand Down Expand Up @@ -192,6 +192,7 @@ export const init: ModuleFn = ({ store, provider, fullAPI }, { runCheck = true }
id,
url,
...loadedData,
error: loadedData.error,
type: !loadedData.stories ? 'auto-inject' : 'lazy',
});
},
Expand Down
4 changes: 4 additions & 0 deletions lib/api/src/tests/refs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ describe('Refs API', () => {
Object {
"refs": Object {
"fake": Object {
"error": undefined,
"id": "fake",
"ready": false,
"stories": Object {},
Expand Down Expand Up @@ -423,6 +424,7 @@ describe('Refs API', () => {
Object {
"refs": Object {
"fake": Object {
"error": undefined,
"id": "fake",
"loginUrl": "https://example.com/login",
"ready": false,
Expand Down Expand Up @@ -516,6 +518,7 @@ describe('Refs API', () => {
Object {
"refs": Object {
"fake": Object {
"error": undefined,
"id": "fake",
"ready": false,
"stories": Object {},
Expand Down Expand Up @@ -603,6 +606,7 @@ describe('Refs API', () => {
Object {
"refs": Object {
"fake": Object {
"error": undefined,
"id": "fake",
"ready": false,
"stories": undefined,
Expand Down
7 changes: 5 additions & 2 deletions lib/core/src/server/manager/manager-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ async function getManagerWebpackConfig(options, presets) {
if (definedRefs) {
Object.entries(definedRefs).forEach(([key, value]) => {
const url = typeof value === 'string' ? value : value.url;
const title = typeof value === 'string' ? toTitle(key) : value.title || toTitle(value.key);
const rest =
typeof value === 'string'
? { title: toTitle(key) }
: { ...value, title: value.title || toTitle(value.key) };

refs[key] = {
id: key,
title,
...rest,
url: stripTrailingSlash(url),
};
});
Expand Down

0 comments on commit 826f328

Please sign in to comment.