Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setting to hide/show left sidebar github buttons #396

Merged
merged 12 commits into from
Feb 11, 2021
7 changes: 7 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions server/plugin/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Configuration struct {
GitHubOAuthClientID string
GitHubOAuthClientSecret string
WebhookSecret string
EnableLeftSidebar bool
EnablePrivateRepo bool
EncryptionKey string
EnterpriseBaseURL string
Expand Down
8 changes: 8 additions & 0 deletions server/plugin/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
4 changes: 4 additions & 0 deletions webapp/src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
9 changes: 6 additions & 3 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
registry.registerLeftSidebarHeaderComponent(SidebarHeader);
registry.registerBottomTeamSidebarComponent(TeamSidebar);
}
registry.registerPopoverUserAttributesComponent(UserAttribute);
registry.registerRootComponent(CreateIssueModal);
registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction);
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down