diff --git a/plugin.json b/plugin.json index 21a51f382..03f25bb7d 100644 --- a/plugin.json +++ b/plugin.json @@ -63,6 +63,13 @@ "type": "text", "help_text": "(Optional) The upload URL for using the plugin with a GitHub Enterprise installation. This is often the same as your Base URL." }, + { + "key": "EnableLeftSidebar", + "display_name": "Display Notification Counters in Left Sidebar", + "type": "bool", + "help_text": "When false, the counters showing the user how many open/assigned issues they have in Github will not be shown in the Left Hand Sidebar on desktop browsers.", + "default": true + }, { "key": "EnablePrivateRepo", "display_name": "Enable Private Repositories", diff --git a/server/plugin/api.go b/server/plugin/api.go index 78fa07ffb..50c149260 100644 --- a/server/plugin/api.go +++ b/server/plugin/api.go @@ -56,6 +56,10 @@ type HTTPHandlerFuncWithUser func(w http.ResponseWriter, r *http.Request, userID // ResponseType indicates type of response returned by api type ResponseType string +type Settings struct { + LeftSidebarEnabled bool `json:"left_sidebar_enabled"` +} + const ( // ResponseTypeJSON indicates that response type is json ResponseTypeJSON ResponseType = "JSON_RESPONSE" @@ -109,6 +113,7 @@ func (p *Plugin) initializeAPI() { oauthRouter.HandleFunc("/complete", p.extractUserMiddleWare(p.completeConnectUserToGitHub, ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/connected", p.getConnected).Methods(http.MethodGet) + apiRouter.HandleFunc("/settings", p.getSettings).Methods(http.MethodGet) apiRouter.HandleFunc("/todo", p.extractUserMiddleWare(p.postToDo, ResponseTypeJSON)).Methods(http.MethodPost) apiRouter.HandleFunc("/reviews", p.extractUserMiddleWare(p.getReviews, ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/yourprs", p.extractUserMiddleWare(p.getYourPrs, ResponseTypePlain)).Methods(http.MethodGet) @@ -1367,3 +1372,11 @@ func parseRepo(repoParam string) (owner, repo string, err error) { return splitted[0], splitted[1], nil } + +func (p *Plugin) getSettings(w http.ResponseWriter, _ *http.Request) { + resp := Settings{ + LeftSidebarEnabled: p.getConfiguration().EnableLeftSidebar, + } + + p.writeJSON(w, resp) +} diff --git a/server/plugin/configuration.go b/server/plugin/configuration.go index 8384648ab..60a97b952 100644 --- a/server/plugin/configuration.go +++ b/server/plugin/configuration.go @@ -22,6 +22,7 @@ type Configuration struct { GitHubOAuthClientID string GitHubOAuthClientSecret string WebhookSecret string + EnableLeftSidebar bool EnablePrivateRepo bool EncryptionKey string EnterpriseBaseURL string diff --git a/server/plugin/manifest.go b/server/plugin/manifest.go index 27a6ca050..c6d6034a6 100644 --- a/server/plugin/manifest.go +++ b/server/plugin/manifest.go @@ -36,6 +36,14 @@ const manifestStr = ` "header": "The GitHub plugin for Mattermost allows users to Subscribe to notifications, stay up-to-date with reviews, see the status of your pull requests at a glance, and other common GitHub actions - directly from Mattermost. \n \n Instructions for setup are [available here](https://www.mattermost.com/pl/default-github-plugin#configuration)", "footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/mattermost/mattermost-plugin-github).", "settings": [ + { + "key": "EnableLeftSidebar", + "display_name": "Display Notification Counters in Left Sidebar", + "type": "bool", + "help_text": "When false, the counters showing the user how many open/assigned issues they have in Github will not be shown in the Left Hand Sidebar on desktop browsers.", + "placeholder": "", + "default": true + }, { "key": "GitHubOAuthClientID", "display_name": "GitHub OAuth Client ID", diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index 96b967ee3..6650fb963 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -418,3 +418,13 @@ export function attachCommentToIssue(payload) { return {data}; }; } + +export async function getSettings() { + let data; + try { + data = await Client.getSettings(); + } catch (error) { + return {error}; + } + return {data}; +} diff --git a/webapp/src/client/client.js b/webapp/src/client/client.js index 33966c6bf..622f2925b 100644 --- a/webapp/src/client/client.js +++ b/webapp/src/client/client.js @@ -79,6 +79,10 @@ export default class Client { return this.doGet(`${this.url}/pr?owner=${owner}&repo=${repo}&number=${prNumber}`); } + getSettings = async () => { + return this.doGet(`${this.url}/settings`); + } + doGet = async (url, body, headers = {}) => { headers['X-Timezone-Offset'] = new Date().getTimezoneOffset(); diff --git a/webapp/src/index.js b/webapp/src/index.js index df12eaef0..702338bd3 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -11,7 +11,7 @@ import UserAttribute from './components/user_attribute'; import SidebarRight from './components/sidebar_right'; import LinkTooltip from './components/link_tooltip'; import Reducer from './reducers'; -import {getConnected, setShowRHSAction} from './actions'; +import {getConnected, setShowRHSAction, getSettings} from './actions'; import {handleConnect, handleDisconnect, handleOpenCreateIssueModal, handleReconnect, handleRefresh} from './websocket'; import {id as pluginId} from './manifest'; @@ -24,10 +24,13 @@ class PluginClass { async initialize(registry, store) { registry.registerReducer(Reducer); + const {data: settings} = await getSettings(store.getState); await getConnected(true)(store.dispatch, store.getState); - registry.registerLeftSidebarHeaderComponent(SidebarHeader); - registry.registerBottomTeamSidebarComponent(TeamSidebar); + if (settings && settings.left_sidebar_enabled) { + registry.registerLeftSidebarHeaderComponent(SidebarHeader); + registry.registerBottomTeamSidebarComponent(TeamSidebar); + } registry.registerPopoverUserAttributesComponent(UserAttribute); registry.registerRootComponent(CreateIssueModal); registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction); diff --git a/webapp/src/manifest.ts b/webapp/src/manifest.ts index 28e6cd10f..8f06c4fe1 100644 --- a/webapp/src/manifest.ts +++ b/webapp/src/manifest.ts @@ -26,6 +26,14 @@ const manifest = JSON.parse(` "header": "The GitHub plugin for Mattermost allows users to Subscribe to notifications, stay up-to-date with reviews, see the status of your pull requests at a glance, and other common GitHub actions - directly from Mattermost. \\n \\n Instructions for setup are [available here](https://www.mattermost.com/pl/default-github-plugin#configuration)", "footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/mattermost/mattermost-plugin-github).", "settings": [ + { + "key": "EnableLeftSidebar", + "display_name": "Display Notification Counters in Left Sidebar", + "type": "bool", + "help_text": "When false, the counters showing the user how many open/assigned issues they have in Github will not be shown in the Left Hand Sidebar on desktop browsers.", + "placeholder": "", + "default": true + }, { "key": "GitHubOAuthClientID", "display_name": "GitHub OAuth Client ID",