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

UI: Fix custom tabs not showing in the manager #25792

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6216569
un-memoize getTabs to always get up-to-date tabs from addons registry
JReinhold Jan 25, 2024
d6d9583
add tab=<ID> query parameter
JReinhold Jan 26, 2024
1d84cd9
make tabs work with a queryParam
ndelangen Jan 26, 2024
a7baa7a
cleanup types, remove showPanel
JReinhold Jan 29, 2024
c8c19f9
fix consistency when refresh browser an tabs/canvas hiding
ndelangen Jan 29, 2024
f4ca800
make (out) tools not show on tabs
ndelangen Jan 29, 2024
4f22662
cleanup
ndelangen Jan 29, 2024
73c9fd3
remove story, because it's not valuable, and the component now depend…
ndelangen Jan 29, 2024
0c42662
fix
ndelangen Jan 29, 2024
1057948
fix review comments and add migration notes
ndelangen Jan 31, 2024
fea21eb
Merge branch 'next' into jeppe/25322-bug-main-section-disappears-when…
ndelangen Jan 31, 2024
33fef12
Merge branch 'next' into jeppe/25322-bug-main-section-disappears-when…
ndelangen Jan 31, 2024
be19e9e
upgrade playwright
ndelangen Jan 31, 2024
1ccab20
Merge branch 'jeppe/25322-bug-main-section-disappears-when-navigating…
ndelangen Jan 31, 2024
cdbfaf5
Merge branch 'next' into jeppe/25322-bug-main-section-disappears-when…
ndelangen Jan 31, 2024
002754f
change to focal
ndelangen Jan 31, 2024
c4a7d4c
Merge branch 'jeppe/25322-bug-main-section-disappears-when-navigating…
ndelangen Jan 31, 2024
dfa1f88
yolo
ndelangen Jan 31, 2024
62d5aac
...
ndelangen Jan 31, 2024
b6aa557
!!!
ndelangen Jan 31, 2024
658ce8f
???
ndelangen Jan 31, 2024
8b63181
,,,,
ndelangen Jan 31, 2024
b3ddedf
oooo
ndelangen Jan 31, 2024
d6df2a1
aaaaaa
ndelangen Jan 31, 2024
688682a
oof
ndelangen Jan 31, 2024
01647d0
Merge branch 'next' into jeppe/25322-bug-main-section-disappears-when…
ndelangen Jan 31, 2024
24e6213
Merge branch 'next' into jeppe/25322-bug-main-section-disappears-when…
ndelangen Jan 31, 2024
56470f2
move the migration notes
ndelangen Feb 1, 2024
fe286a8
Merge branch 'jeppe/25322-bug-main-section-disappears-when-navigating…
ndelangen Feb 1, 2024
3b950a7
Merge branch 'next' into jeppe/25322-bug-main-section-disappears-when…
ndelangen Feb 1, 2024
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
2 changes: 1 addition & 1 deletion code/addons/a11y/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ addons.register(ADDON_ID, (api) => {
addons.add(PANEL_ID, {
title: '',
type: types.TOOL,
match: ({ viewMode }) => viewMode === 'story',
match: ({ viewMode, tabId }) => viewMode === 'story' && !tabId,
render: () => <VisionSimulator />,
});

Expand Down
2 changes: 1 addition & 1 deletion code/addons/backgrounds/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ addons.register(ADDON_ID, () => {
addons.add(ADDON_ID, {
title: 'Backgrounds',
type: types.TOOL,
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
match: ({ viewMode, tabId }) => !!(viewMode && viewMode.match(/^(story|docs)$/)) && !tabId,
render: () => (
<Fragment>
<BackgroundSelector />
Expand Down
2 changes: 1 addition & 1 deletion code/addons/measure/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ addons.register(ADDON_ID, () => {
addons.add(TOOL_ID, {
type: types.TOOL,
title: 'Measure',
match: ({ viewMode }) => viewMode === 'story',
match: ({ viewMode, tabId }) => viewMode === 'story' && !tabId,
render: () => <Tool />,
});
});
2 changes: 1 addition & 1 deletion code/addons/outline/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ addons.register(ADDON_ID, () => {
addons.add(ADDON_ID, {
title: 'Outline',
type: types.TOOL,
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
match: ({ viewMode, tabId }) => !!(viewMode && viewMode.match(/^(story|docs)$/)) && !tabId,
render: () => <OutlineSelector />,
});
});
2 changes: 1 addition & 1 deletion code/addons/themes/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addons.register(ADDON_ID, () => {
addons.add(THEME_SWITCHER_ID, {
title: 'Themes',
type: types.TOOL,
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
match: ({ viewMode, tabId }) => !!(viewMode && viewMode.match(/^(story|docs)$/)) && !tabId,
render: ThemeSwitcher,
paramKey: PARAM_KEY,
});
Expand Down
2 changes: 1 addition & 1 deletion code/addons/toolbars/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addons.register(ADDON_ID, () =>
addons.add(ADDON_ID, {
title: ADDON_ID,
type: types.TOOL,
match: () => true,
match: ({ tabId }) => !tabId,
render: () => <ToolbarManager />,
})
);
2 changes: 1 addition & 1 deletion code/addons/viewport/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ addons.register(ADDON_ID, () => {
addons.add(ADDON_ID, {
title: 'viewport / media-queries',
type: types.TOOL,
match: ({ viewMode }) => viewMode === 'story',
match: ({ viewMode, tabId }) => viewMode === 'story' && !tabId,
render: () => <ViewportTool />,
});
});
12 changes: 12 additions & 0 deletions code/lib/manager-api/src/modules/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export interface SubAPI {
* @returns {void}
*/
setQueryParams: (input: QueryParams) => void;
/**
* Set the query parameters for the current URL & navigates.
* @param {QueryParams} input - An object containing the query parameters to set.
* @returns {void}
*/
applyQueryParams: (input: QueryParams) => void;
}

export const init: ModuleFn<SubAPI, SubState> = (moduleArgs) => {
Expand Down Expand Up @@ -188,6 +194,12 @@ export const init: ModuleFn<SubAPI, SubState> = (moduleArgs) => {
provider.channel?.emit(UPDATE_QUERY_PARAMS, update);
}
},
applyQueryParams(input) {
const { path, queryParams } = api.getUrlState();

navigateTo(path, { ...queryParams, ...input } as any);
api.setQueryParams(input);
},
navigateUrl(url, options) {
navigate(url, { plain: true, ...options });
},
Expand Down
3 changes: 1 addition & 2 deletions code/lib/types/src/modules/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export interface Addon_BaseType {
/**
* This will determine the value of `active` prop of your render function.
*/
match?: (matchOptions: RouterData) => boolean;
match?: (matchOptions: RouterData & { tabId?: string }) => boolean;
/**
* The actual contents of your addon.
*
Expand Down Expand Up @@ -423,7 +423,6 @@ export interface Addon_WrapperType {
children: ReactNode;
id: string;
storyId: StoryId;
active: boolean;
}>
>;
}
Expand Down
4 changes: 3 additions & 1 deletion code/ui/manager/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type Props = {
managerLayoutState: ComponentProps<typeof Layout>['managerLayoutState'];
setManagerLayoutState: ComponentProps<typeof Layout>['setManagerLayoutState'];
pages: Addon_PageType[];
hasTab: boolean;
};

export const App = ({ managerLayoutState, setManagerLayoutState, pages }: Props) => {
export const App = ({ managerLayoutState, setManagerLayoutState, pages, hasTab }: Props) => {
const { setMobileAboutOpen } = useLayout();

return (
<>
<Global styles={createGlobal} />
<Layout
hasTab={hasTab}
managerLayoutState={managerLayoutState}
setManagerLayoutState={setManagerLayoutState}
slotMain={
Expand Down
1 change: 1 addition & 0 deletions code/ui/manager/src/components/layout/Layout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const meta = {
slotPanel: <MockPanel />,
slotPages: <MockPage />,
setManagerLayoutState: fn(),
hasTab: false,
},
parameters: {
theme: 'light',
Expand Down
16 changes: 10 additions & 6 deletions code/ui/manager/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Props {
slotSidebar?: React.ReactNode;
slotPanel?: React.ReactNode;
slotPages?: React.ReactNode;
hasTab: boolean;
}
const MINIMUM_CONTENT_WIDTH_PX = 100;

Expand All @@ -44,10 +45,12 @@ const useLayoutSyncingState = ({
managerLayoutState,
setManagerLayoutState,
isDesktop,
hasTab,
}: {
managerLayoutState: Props['managerLayoutState'];
setManagerLayoutState: Props['setManagerLayoutState'];
isDesktop: boolean;
hasTab: boolean;
}) => {
// ref to keep track of previous managerLayoutState, to check if the props change
const prevManagerLayoutStateRef = React.useRef<ManagerLayoutState>(managerLayoutState);
Expand Down Expand Up @@ -95,7 +98,7 @@ const useLayoutSyncingState = ({

const isPagesShown =
managerLayoutState.viewMode !== 'story' && managerLayoutState.viewMode !== 'docs';
const isPanelShown = managerLayoutState.viewMode === 'story';
const isPanelShown = managerLayoutState.viewMode === 'story' && !hasTab;

const { panelResizerRef, sidebarResizerRef } = useDragging({
setState: setInternalDraggingSizeState,
Expand All @@ -119,7 +122,7 @@ const useLayoutSyncingState = ({
};
};

export const Layout = ({ managerLayoutState, setManagerLayoutState, ...slots }: Props) => {
export const Layout = ({ managerLayoutState, setManagerLayoutState, hasTab, ...slots }: Props) => {
const { isDesktop, isMobile } = useLayout();

const {
Expand All @@ -132,7 +135,7 @@ export const Layout = ({ managerLayoutState, setManagerLayoutState, ...slots }:
showPages,
showPanel,
isDragging,
} = useLayoutSyncingState({ managerLayoutState, setManagerLayoutState, isDesktop });
} = useLayoutSyncingState({ managerLayoutState, setManagerLayoutState, isDesktop, hasTab });

return (
<LayoutContainer
Expand All @@ -142,6 +145,7 @@ export const Layout = ({ managerLayoutState, setManagerLayoutState, ...slots }:
panelPosition={managerLayoutState.panelPosition}
isDragging={isDragging}
viewMode={managerLayoutState.viewMode}
showPanel={showPanel}
>
<Notifications />
{showPages && <PagesContainer>{slots.slotPages}</PagesContainer>}
Expand Down Expand Up @@ -171,8 +175,8 @@ export const Layout = ({ managerLayoutState, setManagerLayoutState, ...slots }:
);
};

const LayoutContainer = styled.div<LayoutState>(
({ navSize, rightPanelWidth, bottomPanelHeight, viewMode, panelPosition }) => {
const LayoutContainer = styled.div<LayoutState & { showPanel: boolean }>(
({ navSize, rightPanelWidth, bottomPanelHeight, viewMode, panelPosition, showPanel }) => {
return {
width: '100%',
height: ['100vh', '100dvh'], // This array is a special Emotion syntax to set a fallback if 100dvh is not supported
Expand All @@ -186,7 +190,7 @@ const LayoutContainer = styled.div<LayoutState>(
gridTemplateColumns: `minmax(0, ${navSize}px) minmax(${MINIMUM_CONTENT_WIDTH_PX}px, 1fr) minmax(0, ${rightPanelWidth}px)`,
gridTemplateRows: `1fr minmax(0, ${bottomPanelHeight}px)`,
gridTemplateAreas: (() => {
if (viewMode === 'docs') {
if (viewMode === 'docs' || !showPanel) {
// remove panel in docs viewMode
return `"sidebar content content"
"sidebar content content"`;
Expand Down
55 changes: 0 additions & 55 deletions code/ui/manager/src/components/preview/Preview.mockdata.tsx

This file was deleted.

Loading
Loading