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 @@ -21,6 +21,13 @@
"settings_schema": {
"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)",
"settings": [
{
"key": "EnableLeftSidebar",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"display_name": "Enable Left Sidebar",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"type": "bool",
"help_text": "When false, the left sidebar github buttons will not be visible.",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"default": true
},
{
"key": "GitHubOAuthClientID",
"display_name": "GitHub OAuth Client ID",
Expand Down
11 changes: 11 additions & 0 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (p *Plugin) initializeAPI() {

apiRouter.HandleFunc("/config", checkPluginRequest(p.getConfig)).Methods(http.MethodGet)
apiRouter.HandleFunc("/token", checkPluginRequest(p.getToken)).Methods(http.MethodGet)
apiRouter.HandleFunc("/settings", p.getSettings).Methods(http.MethodGet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this after apiRouter.HandleFunc("/connected", p.getConnected).Methods(http.MethodGet) to keep the list sorted by middle ware type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like that change wasn't pushed. Could you please double check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @hanzei for late reply. I have fixed the ordering.

}

func (p *Plugin) withRecovery(next http.Handler) http.Handler {
Expand Down Expand Up @@ -558,6 +559,16 @@ func (p *Plugin) getUnreads(w http.ResponseWriter, r *http.Request, userID strin
p.writeJSON(w, filteredNotifications)
}

func (p *Plugin) getSettings(w http.ResponseWriter, _ *http.Request) {
resp := struct {
LeftSidebarEnabled bool `json:"left_sidebar_enabled"`
hanzei marked this conversation as resolved.
Show resolved Hide resolved
}{
LeftSidebarEnabled: p.getConfiguration().EnableLeftSidebar,
}

p.writeJSON(w, resp)
}

func (p *Plugin) getReviews(w http.ResponseWriter, r *http.Request, userID string) {
config := p.getConfiguration()

Expand Down
1 change: 1 addition & 0 deletions server/plugin/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Configuration struct {
EnterpriseBaseURL string
EnterpriseUploadURL string
EnableCodePreview string
EnableLeftSidebar bool
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
}

// Clone shallow copies the configuration. Your implementation may require a deep copy if
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": "Enable Left Sidebar",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"type": "bool",
"help_text": "When false, the left sidebar github buttons will not be visible.",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -408,3 +408,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, 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": "Enable Left Sidebar",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"type": "bool",
"help_text": "When false, the left sidebar github buttons will not be visible.",
jatinkksharma marked this conversation as resolved.
Show resolved Hide resolved
"placeholder": "",
"default": true
},
{
"key": "GitHubOAuthClientID",
"display_name": "GitHub OAuth Client ID",
Expand Down