Skip to content

Commit

Permalink
fix: panel on change remove referesgh
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 10, 2020
1 parent 3672ade commit 4e38c6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions ui/app-components/src/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const Sidebar: FC<SidebarProps & BoxProps> = ({
width,
minWidth,
position: 'relative',
flexShrink: 0,
};
const style: SxStyleProp = !responsive
? defaultStyle
Expand Down
4 changes: 2 additions & 2 deletions ui/app/src/DocPage/DocPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const BasePage: FC<DocPageProps> = ({ pagesFn }) => {
0,
);
return (
<Box sx={{ flex: '1 0 auto' }}>
<Flex sx={{ flex: '1 0 auto' }}>
<Sidebar />
<Box sx={{ flexGrow: 1 }} id="content">
<Tabs
Expand Down Expand Up @@ -67,7 +67,7 @@ export const BasePage: FC<DocPageProps> = ({ pagesFn }) => {
</Tabs>
</Box>
<SideContext pageRef={pageRef} />
</Box>
</Flex>
);
};

Expand Down
17 changes: 12 additions & 5 deletions ui/components/src/PanelContainer/PanelContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, MouseEvent } from 'react';
import React, { FC, MouseEvent, useCallback } from 'react';
import { Button, ButtonProps, useThemeUI } from 'theme-ui';
import { Collapsible } from '../Collapsible';
import { Tab, Tabs, TabList, TabPanel } from '../Tabs';
Expand Down Expand Up @@ -52,16 +52,23 @@ export const PanelContainer: FC<PanelContainerProps> = ({
const [tabsIndex, setTabsIndex] = React.useState<number | undefined>(
undefined,
);

const { theme } = useThemeUI();

const panels: ActionItems = getSortedPanels(actions);

const findPanel = useCallback(
(id: PanelContainerOwnProps['openTab']) => {
return panels.findIndex((p: ActionItem) => p.id === id || p.title === id);
},
// do not update on each panel change
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
React.useEffect(() => {
const index = panels.findIndex(
(p: ActionItem) => p.id === openTab || p.title === openTab,
);
const index = findPanel(openTab);
setTabsIndex(index > -1 ? index : undefined);
}, [openTab, actions, panels]);
}, [openTab, findPanel]);
const panelActions = React.useMemo(
() =>
actions.map((panel: ActionItem) => {
Expand Down

0 comments on commit 4e38c6c

Please sign in to comment.