diff --git a/mattermost-plugin/webapp/webpack.config.js b/mattermost-plugin/webapp/webpack.config.js index eabbdaa8c..bfe44a94e 100644 --- a/mattermost-plugin/webapp/webpack.config.js +++ b/mattermost-plugin/webapp/webpack.config.js @@ -118,7 +118,7 @@ module.exports = { options: { name: '[name].[ext]', outputPath: 'static', - publicPath: '/plugins/focalboard/static/', + publicPath: '/static/', }, }, { diff --git a/webapp/src/app.tsx b/webapp/src/app.tsx index 34d49e9a1..794584fe3 100644 --- a/webapp/src/app.tsx +++ b/webapp/src/app.tsx @@ -1,6 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {useEffect} from 'react' +import React, {useEffect, useMemo} from 'react' import { Router, Redirect, @@ -40,45 +40,8 @@ import {UserSettings} from './userSettings' declare let window: IAppWindow -export const history = createBrowserHistory({basename: Utils.getFrontendBaseURL()}) - const UUID_REGEX = new RegExp(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/) -if (Utils.isDesktop() && Utils.isFocalboardPlugin()) { - window.addEventListener('message', (event: MessageEvent) => { - if (event.origin !== window.location.origin) { - return - } - - const pathName = event.data.message?.pathName - if (!pathName || !pathName.startsWith(window.frontendBaseURL)) { - return - } - - Utils.log(`Navigating Boards to ${pathName}`) - history.replace(pathName.replace(window.frontendBaseURL, '')) - }) -} - -const browserHistory: typeof history = { - ...history, - push: (path: string, state?: unknown) => { - if (Utils.isDesktop() && Utils.isFocalboardPlugin()) { - window.postMessage( - { - type: 'browser-history-push', - message: { - path: `${window.frontendBaseURL}${path}`, - }, - }, - window.location.origin, - ) - } else { - history.push(path, state) - } - }, -} - const App = React.memo((): JSX.Element => { const language = useAppSelector(getLanguage) const loggedIn = useAppSelector(getLoggedIn) @@ -86,6 +49,44 @@ const App = React.memo((): JSX.Element => { const me = useAppSelector(getMe) const dispatch = useAppDispatch() + const browserHistory: ReturnType = useMemo(() => { + const history = createBrowserHistory({basename: Utils.getFrontendBaseURL()}) + + if (Utils.isDesktop() && Utils.isFocalboardPlugin()) { + window.addEventListener('message', (event: MessageEvent) => { + if (event.origin !== window.location.origin) { + return + } + + const pathName = event.data.message?.pathName + if (!pathName || !pathName.startsWith(window.frontendBaseURL)) { + return + } + + Utils.log(`Navigating Boards to ${pathName}`) + history.replace(pathName.replace(window.frontendBaseURL, '')) + }) + } + return { + ...history, + push: (path: string, state?: unknown) => { + if (Utils.isDesktop() && Utils.isFocalboardPlugin()) { + window.postMessage( + { + type: 'browser-history-push', + message: { + path: `${window.frontendBaseURL}${path}`, + }, + }, + window.location.origin, + ) + } else { + history.push(path, state) + } + }, + } + }, []) + useEffect(() => { dispatch(fetchLanguage()) dispatch(fetchMe()) @@ -95,7 +96,7 @@ const App = React.memo((): JSX.Element => { if (Utils.isFocalboardPlugin()) { useEffect(() => { if (window.frontendBaseURL) { - history.replace(window.location.pathname.replace(window.frontendBaseURL, '')) + browserHistory.replace(window.location.pathname.replace(window.frontendBaseURL, '')) } }, []) } @@ -137,9 +138,7 @@ const App = React.memo((): JSX.Element => { > - +
diff --git a/webapp/src/components/__snapshots__/shareBoardComponent.test.tsx.snap b/webapp/src/components/__snapshots__/shareBoardComponent.test.tsx.snap index 3e206da69..6a47bd23f 100644 --- a/webapp/src/components/__snapshots__/shareBoardComponent.test.tsx.snap +++ b/webapp/src/components/__snapshots__/shareBoardComponent.test.tsx.snap @@ -41,11 +41,11 @@ exports[`src/components/shareBoardComponent return shareBoardComponent and click > - http://localhost/plugins/focalboard/workspace/1/shared/1/1?r=oneToken + http://localhost/workspace/1/shared/1/1?r=oneToken +
+
+ +
+
+ + +`; + +exports[`src/components/shareBoardComponent should match snapshot with sharing and subpath 1`] = ` +
+