From f566a7d7c064e57ced68afecb3491efbba443599 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 4 Nov 2021 18:24:57 +0100 Subject: [PATCH] Redirect to new routes when visiting a board with the legacy ones (#1746) --- webapp/src/app.tsx | 14 ++++++-------- webapp/src/pages/boardPage.tsx | 6 ++++++ webapp/src/utils.ts | 7 +++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/webapp/src/app.tsx b/webapp/src/app.tsx index 27595154c..989bf1db3 100644 --- a/webapp/src/app.tsx +++ b/webapp/src/app.tsx @@ -85,13 +85,6 @@ const App = React.memo((): JSX.Element => { const me = useAppSelector(getMe) const dispatch = useAppDispatch() - // this is a temporary solution while we're using legacy routes - // for shared boards as a way to disable websockets, and should be - // removed when anonymous plugin routes are implemented. This - // check is used to detect if we're running inside the plugin but - // in a legacy route - const inPluginLegacy = window.location.pathname.includes('/plugins/focalboard/') - useEffect(() => { dispatch(fetchLanguage()) dispatch(fetchMe()) @@ -106,7 +99,12 @@ const App = React.memo((): JSX.Element => { }, []) } - if (!inPluginLegacy) { + // this is a temporary solution while we're using legacy routes + // for shared boards as a way to disable websockets, and should be + // removed when anonymous plugin routes are implemented. This + // check is used to detect if we're running inside the plugin but + // in a legacy route + if (!Utils.isFocalboardLegacy()) { useEffect(() => { wsClient.open() return () => { diff --git a/webapp/src/pages/boardPage.tsx b/webapp/src/pages/boardPage.tsx index 4792a8d9d..f83fdcc66 100644 --- a/webapp/src/pages/boardPage.tsx +++ b/webapp/src/pages/boardPage.tsx @@ -53,6 +53,12 @@ const BoardPage = (props: Props): JSX.Element => { let workspaceId = match.params.workspaceId || UserSettings.lastWorkspaceId || '0' + // if we're in a legacy route and not showing a shared board, + // redirect to the new URL schema equivalent + if (Utils.isFocalboardLegacy() && !props.readonly) { + window.location.href = window.location.href.replace('/plugins/focalboard', '/boards') + } + // TODO: Make this less brittle. This only works because this is the root render function useEffect(() => { workspaceId = match.params.workspaceId || workspaceId diff --git a/webapp/src/utils.ts b/webapp/src/utils.ts index 4caf7576c..26fad7279 100644 --- a/webapp/src/utils.ts +++ b/webapp/src/utils.ts @@ -508,6 +508,13 @@ class Utils { return Boolean(window.isFocalboardPlugin) } + // this is a temporary solution while we're using legacy routes + // for shared boards as a way to check if we're accessing the + // legacy routes inside the plugin + static isFocalboardLegacy(): boolean { + return window.location.pathname.includes('/plugins/focalboard') + } + static fixBlock(block: Block): Block { switch (block.type) { case 'board':