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

Bug: version switcher of compositions #21621

Merged
merged 5 commits into from
Mar 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions code/lib/manager-api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const transformStoryIndexV3toV4 = (index: StoryIndexV3): API_PreparedStor
};

export const transformStoryIndexToStoriesHash = (
index: API_PreparedStoryIndex,
input: API_PreparedStoryIndex | StoryIndexV2 | StoryIndexV3,
{
provider,
docsOptions,
Expand All @@ -146,13 +146,16 @@ export const transformStoryIndexToStoriesHash = (
docsOptions: DocsOptions;
}
): API_IndexHash => {
if (!index.v) throw new Error('Composition: Missing stories.json version');
let v4Index;
if (!input.v) {
throw new Error('Composition: Missing stories.json version');
}

v4Index = index.v === 2 ? transformStoryIndexV2toV3(index as any) : index;
v4Index = index.v === 3 ? transformStoryIndexV3toV4(index as any) : index;
let index = input;
index = index.v === 2 ? transformStoryIndexV2toV3(index as any) : index;
index = index.v === 3 ? transformStoryIndexV3toV4(index as any) : index;
index = index as API_PreparedStoryIndex;

const entryValues = Object.values(v4Index.entries);
const entryValues = Object.values(index.entries);
const { sidebar = {} } = provider.getConfig();
const { showRoots, collapsedRoots = [], renderLabel } = sidebar;

Expand Down
3 changes: 2 additions & 1 deletion code/lib/manager-api/src/modules/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ export const init: ModuleFn<SubAPI, SubState, void> = (
},
changeRefVersion: (id, url) => {
const { versions, title } = api.getRefs()[id];
const ref = { id, url, versions, title, stories: {} } as API_SetRefData;
const ref: API_SetRefData = { id, url, versions, title, index: {}, expanded: true };

api.setRef(id, { ...ref, type: 'unknown' }, false);
api.checkRef(ref);
},
changeRefState: (id, previewInitialized) => {
Expand Down
22 changes: 11 additions & 11 deletions code/ui/manager/src/components/sidebar/RefIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,12 @@ export const RefIndicator = React.memo(
[list]
);

const changeVersion = useCallback(
((event, item) => {
event.preventDefault();
api.changeRefVersion(ref.id, item.href);
}) as ClickHandler,
[]
);

return (
<IndicatorPlacement ref={forwardedRef}>
<WithTooltip
placement="bottom-start"
trigger="click"
closeOnOutsideClick
tooltip={
<MessageWrapper>
<Spaced row={0}>
Expand Down Expand Up @@ -217,17 +211,23 @@ export const RefIndicator = React.memo(
{ref.versions && Object.keys(ref.versions).length ? (
<WithTooltip
placement="bottom-start"
tooltip={
trigger="click"
closeOnOutsideClick
tooltip={(tooltip) => (
<TooltipLinkList
links={Object.entries(ref.versions).map(([id, href]) => ({
icon: href === ref.url ? 'check' : undefined,
id,
title: id,
href,
onClick: changeVersion,
onClick: (event, item) => {
event.preventDefault();
api.changeRefVersion(ref.id, item.href);
tooltip.onHide();
},
}))}
/>
}
)}
>
<CurrentVersion url={ref.url} versions={ref.versions} />
</WithTooltip>
Expand Down
1 change: 1 addition & 0 deletions code/ui/manager/src/components/sidebar/Refs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const Ref: FC<RefType & RefProps> = React.memo(function Ref(props) {
(storyId: string) => api && api.selectStory(storyId, undefined, { ref: !isMain && refId }),
[api, isMain, refId]
);

return (
<>
{isMain || (
Expand Down