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

Composition: Allow refs versions in config #11294

Merged
merged 8 commits into from
Jun 24, 2020
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
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