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 <miguel@mcrx.me>

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
This commit is contained in:
Scott Bishel 2021-10-08 07:46:05 -06:00 committed by GitHub
parent 708b736e8f
commit d744e0af47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -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])

View file

@ -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