From d744e0af472d699c31439b4dd5c3f1bddcce7856 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Fri, 8 Oct 2021 07:46:05 -0600 Subject: [PATCH] gh-1472 Fix sidebar selection (#1477) * fix sidebar selection * update comments * plugin needs the workspaceID * Update webapp/src/pages/boardPage.tsx Co-authored-by: Miguel de la Cruz Co-authored-by: Mattermod Co-authored-by: Miguel de la Cruz --- webapp/src/components/sidebar/sidebarBoardItem.tsx | 11 +++++++++-- webapp/src/pages/boardPage.tsx | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/sidebar/sidebarBoardItem.tsx b/webapp/src/components/sidebar/sidebarBoardItem.tsx index 4078bdd16..f7fb7c4c6 100644 --- a/webapp/src/components/sidebar/sidebarBoardItem.tsx +++ b/webapp/src/components/sidebar/sidebarBoardItem.tsx @@ -32,10 +32,17 @@ const SidebarBoardItem = React.memo((props: Props) => { const [collapsed, setCollapsed] = useState(false) const intl = useIntl() const history = useHistory() - const match = useRouteMatch() + const match = useRouteMatch<{boardId: string, viewId?: string, cardId?: string, workspaceId?: string}>() const showBoard = useCallback((boardId) => { - const newPath = generatePath(match.path, {...match.params, boardId: boardId || ''}) + // if the same board, reuse the match params + // otherwise remove viewId and cardId, results in first view being selected + const params = {...match.params, boardId: boardId || ''} + if (boardId !== match.params.boardId) { + params.viewId = undefined + params.cardId = undefined + } + const newPath = generatePath(match.path, params) history.push(newPath) }, [match, history]) diff --git a/webapp/src/pages/boardPage.tsx b/webapp/src/pages/boardPage.tsx index 58adc05b3..cd97d3533 100644 --- a/webapp/src/pages/boardPage.tsx +++ b/webapp/src/pages/boardPage.tsx @@ -110,8 +110,10 @@ const BoardPage = (props: Props): JSX.Element => { } Utils.log(`attachToBoard: ${boardId}`) - const viewIsFromBoard = boardViews.some((view) => view.id === viewId) - if ((!viewId || !viewIsFromBoard) && boardViews.length > 0) { + + // Ensure boardViews is for our boardId before redirecting + const isCorrectBoardView = boardViews.length > 0 && boardViews[0].parentId === boardId + if (!viewId && isCorrectBoardView) { const newPath = generatePath(match.path, {...match.params, boardId, viewId: boardViews[0].id}) history.replace(newPath) return