diff --git a/webapp/src/app.tsx b/webapp/src/app.tsx index f92099c64..27595154c 100644 --- a/webapp/src/app.tsx +++ b/webapp/src/app.tsx @@ -131,28 +131,6 @@ const App = React.memo((): JSX.Element => { return Utils.isFocalboardPlugin() && loggedIn === true && !UserSettings.welcomePageViewed } - const buildOriginalPath = (workspaceId = '', boardId = '', viewId = '', cardId = '') => { - let originalPath = '' - - if (workspaceId) { - originalPath += `${workspaceId}/` - } - - if (boardId) { - originalPath += `${boardId}/` - } - - if (viewId) { - originalPath += `${viewId}/` - } - - if (cardId) { - originalPath += `${cardId}/` - } - - return originalPath - } - return ( { } if (continueToWelcomeScreen()) { - const originalPath = `/board/${buildOriginalPath('', boardId, viewId, cardId)}` + const originalPath = `/board/${Utils.buildOriginalPath('', boardId, viewId, cardId)}` return } @@ -207,7 +185,7 @@ const App = React.memo((): JSX.Element => { { - const originalPath = `/workspace/${buildOriginalPath(workspaceId, boardId, viewId, cardId)}` + const originalPath = `/workspace/${Utils.buildOriginalPath(workspaceId, boardId, viewId, cardId)}` if (loggedIn === false) { let redirectUrl = '/' + Utils.buildURL(originalPath) if (redirectUrl.indexOf('//') === 0) { @@ -253,7 +231,7 @@ const App = React.memo((): JSX.Element => { } if (continueToWelcomeScreen()) { - const originalPath = `/${buildOriginalPath('', boardId, viewId, cardId)}` + const originalPath = `/${Utils.buildOriginalPath('', boardId, viewId, cardId)}` const queryString = boardIdIsValidUUIDV4 ? `r=${originalPath}` : '' return } diff --git a/webapp/src/pages/boardPage.tsx b/webapp/src/pages/boardPage.tsx index 91aa34609..2c70a6bc0 100644 --- a/webapp/src/pages/boardPage.tsx +++ b/webapp/src/pages/boardPage.tsx @@ -65,6 +65,23 @@ const BoardPage = (props: Props): JSX.Element => { useEffect(() => { }, []) + useEffect(() => { + // don't do anything if- + // 1. the URL already has a workspace ID, or + // 2. the workspace ID is unavailable. + // This also ensures once the workspace id is + // set in the URL, we don't update the history anymore. + if (props.readonly || match.params.workspaceId || !workspaceId || workspaceId === '0') { + return + } + + // we can pick workspace ID from board if it's not available anywhere, + const workspaceIDToUse = workspaceId || board.workspaceId + + const newPath = Utils.buildOriginalPath(workspaceIDToUse, match.params.boardId, match.params.viewId, match.params.cardId) + history.replace(`/workspace/${newPath}`) + }, [workspaceId, match.params.boardId, match.params.viewId, match.params.cardId]) + useEffect(() => { // Backward compatibility: This can be removed in the future, this is for // transform the old query params into routes diff --git a/webapp/src/utils.ts b/webapp/src/utils.ts index e8a61edc3..02c008157 100644 --- a/webapp/src/utils.ts +++ b/webapp/src/utils.ts @@ -585,6 +585,28 @@ class Utils { static generateClassName(conditions: Record): string { return Object.entries(conditions).map(([className, condition]) => (condition ? className : '')).filter((className) => className !== '').join(' ') } + + static buildOriginalPath(workspaceId = '', boardId = '', viewId = '', cardId = ''): string { + let originalPath = '' + + if (workspaceId) { + originalPath += `${workspaceId}/` + } + + if (boardId) { + originalPath += `${boardId}/` + } + + if (viewId) { + originalPath += `${viewId}/` + } + + if (cardId) { + originalPath += `${cardId}/` + } + + return originalPath + } } export {Utils, IDType}