Ensure workspace ID is available in path (#1594)

* WIP: Testing a fix

* Moved to workspace ID path if workspace ID is available

* Remived debug logs

* added personal server check

* Removed an awesome class name

* Use replace instead of push
This commit is contained in:
Harshil Sharma 2021-10-22 14:37:46 +05:30 committed by GitHub
parent 0e6fab45eb
commit 2415c9f28b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 25 deletions

View File

@ -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 (
<IntlProvider
locale={language.split(/[_]/)[0]}
@ -190,7 +168,7 @@ const App = React.memo((): JSX.Element => {
}
if (continueToWelcomeScreen()) {
const originalPath = `/board/${buildOriginalPath('', boardId, viewId, cardId)}`
const originalPath = `/board/${Utils.buildOriginalPath('', boardId, viewId, cardId)}`
return <Redirect to={`/welcome?r=${originalPath}`}/>
}
@ -207,7 +185,7 @@ const App = React.memo((): JSX.Element => {
<Route
path='/workspace/:workspaceId/:boardId?/:viewId?/:cardId?'
render={({match: {params: {workspaceId, boardId, viewId, cardId}}}) => {
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 <Redirect to={`/welcome?${queryString}`}/>
}

View File

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

View File

@ -585,6 +585,28 @@ class Utils {
static generateClassName(conditions: Record<string, boolean>): 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}