diff --git a/ui/app/src/Sidebar/Sidebar.tsx b/ui/app/src/Sidebar/Sidebar.tsx index 7a20bf6a7..5a40181e8 100644 --- a/ui/app/src/Sidebar/Sidebar.tsx +++ b/ui/app/src/Sidebar/Sidebar.tsx @@ -172,17 +172,15 @@ export const Sidebar: FC = ({ const story = useCurrentStory(); const activeId = story ? story.id : docId; const config = useConfig() || {}; - const { pages, menu, sidebar = [] } = config; - const page: PageConfiguration = useMemo(() => pages?.[type] || {}, [ - pages, - type, - ]); - const { label = '' } = page; const docs: Pages = useDocByType(type); - const menuItems = useMemo(() => { - const staticMenus = Array.isArray(menu) ? staticMenusToMenuItems(menu) : []; + const [search, setSearch] = useState(undefined); + const node = useMemo(() => { + const { pages, menu, sidebar = [] } = config; + const page: PageConfiguration = pages?.[type] || {}; + const { label = '' } = page; + let menuItems = Array.isArray(menu) ? staticMenusToMenuItems(menu) : []; if (store) { - const menuItems = docs.reduce((acc: TreeItems, doc: Document) => { + menuItems = docs.reduce((acc: TreeItems, doc: Document) => { const { title, menu } = doc; if (menu) { const item = findMenuItem(acc, menu); @@ -205,58 +203,65 @@ export const Sidebar: FC = ({ const levels = title.split('/'); createMenuItem(store, doc, type, levels, page, activeTab, acc); return acc; - }, staticMenus); - return menuItems; + }, menuItems); + } + const actions: ActionItems = [...sidebar]; + if (propsTitle || label) { + actions.push({ + node: ( + + {propsTitle || label} + + ), + id: 'title', + }); } - return staticMenus; - }, [type, activeTab, store, page, docs, menu]); - const [search, setSearch] = useState(undefined); - const actions: ActionItems = [...sidebar]; - - if (propsTitle || label) { actions.push({ node: ( - - {propsTitle || label} - + + setSearch(e.target.value)} + onClick={e => e.stopPropagation()} + /> + ), - id: 'title', + id: 'filter', }); - } - actions.push({ - node: ( - - setSearch(e.target.value)} - onClick={e => e.stopPropagation()} - /> - - ), - id: 'filter', - }); - return ( - - {responsive && ( -
- - -
- )} - - - - -
- ); + return ( + + {responsive && ( +
+ + +
+ )} + + + + +
+ ); + }, [ + activeId, + activeTab, + config, + docs, + propsTitle, + responsive, + search, + store, + type, + ]); + return node; };