Skip to content

Commit

Permalink
Adding backward compatibility for 5.38 (#922)
Browse files Browse the repository at this point in the history
* Adding backward compatibility for 5.38

* Fixing problem with urls
  • Loading branch information
jespino committed Aug 11, 2021
1 parent 75e9930 commit 4296b7d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
42 changes: 28 additions & 14 deletions mattermost-plugin/webapp/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useEffect, useState} from 'react'
import React, {useEffect} from 'react'
import {Store, Action} from 'redux'
import {Provider as ReduxProvider} from 'react-redux'
import {useHistory} from 'react-router-dom'
import {useHistory} from 'mm-react-router-dom'

import {GlobalState} from 'mattermost-redux/types/store'

Expand Down Expand Up @@ -80,21 +80,35 @@ export default class Plugin {
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
public async initialize(registry: PluginRegistry, store: Store<GlobalState, Action<Record<string, unknown>>>) {
this.registry = registry
const goToFocalboardWorkspace = () => {
const currentChannel = store.getState().entities.channels.currentChannelId
window.open(`${window.location.origin}/boards/workspace/${currentChannel}`)
}
this.channelHeaderButtonId = registry.registerChannelHeaderButtonAction(<FocalboardIcon/>, goToFocalboardWorkspace, '', 'Focalboard Workspace')

this.registry.registerCustomRoute('go-to-current-workspace', () => {
const history = useHistory()
const currentChannel = store.getState().entities.channels.currentChannelId
history.push(`/boards/workspace/${currentChannel}`)
return <></>
})

if (this.registry.registerProduct) {
windowAny.frontendBaseURL = '/boards'
const goToFocalboardWorkspace = () => {
const currentChannel = store.getState().entities.channels.currentChannelId
window.open(`${window.location.origin}/boards/workspace/${currentChannel}`)
}
this.channelHeaderButtonId = registry.registerChannelHeaderButtonAction(<FocalboardIcon/>, goToFocalboardWorkspace, '', 'Focalboard Workspace')

this.registry.registerCustomRoute('go-to-current-workspace', () => {
const history = useHistory()
useEffect(() => {
const currentChannel = store.getState().entities.channels.currentChannelId
if (currentChannel) {
history.push(`/boards/workspace/${currentChannel}`)
} else {
history.goBack()
}
}, [])
return <></>
})
this.registry.registerProduct('/boards', GlobalHeaderIcon, 'Boards', '/plug/focalboard/go-to-current-workspace', MainApp, HeaderComponent)
} else {
windowAny.frontendBaseURL = '/plug/focalboard'
this.channelHeaderButtonId = registry.registerChannelHeaderButtonAction(<FocalboardIcon/>, () => {
const currentChannel = store.getState().entities.channels.currentChannelId
window.open(`${window.location.origin}/plug/focalboard/workspace/${currentChannel}`)
}, '', 'Focalboard Workspace')
this.registry.registerCustomRoute('/', MainApp)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "mm-react-router-dom"
1 change: 1 addition & 0 deletions mattermost-plugin/webapp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ module.exports = {
react: 'React',
redux: 'Redux',
'react-redux': 'ReactRedux',
'mm-react-router-dom': 'ReactRouterDom',
'prop-types': 'PropTypes',
'react-bootstrap': 'ReactBootstrap',
},
Expand Down

0 comments on commit 4296b7d

Please sign in to comment.