Skip to content

Commit

Permalink
[MM-56795] Improve help options in the Help menu (#3216)
Browse files Browse the repository at this point in the history
* [MM-56795] Improve help options in the Help menu

* Fix i18n

* Remove extra separator
  • Loading branch information
devinbinnie authored Nov 22, 2024
1 parent fad05fd commit 513a7e0
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 18 deletions.
4 changes: 3 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@
"main.menus.app.file.signInToAnotherServer": "Sign in to Another Server",
"main.menus.app.file.unhide": "Show All",
"main.menus.app.help": "Hel&p",
"main.menus.app.help.academy": "Mattermost Academy",
"main.menus.app.help.checkForUpdates": "Check for Updates",
"main.menus.app.help.commitString": " commit: {hashVersion}",
"main.menus.app.help.downloadUpdate": "Download Update",
"main.menus.app.help.learnMore": "Learn More...",
"main.menus.app.help.reportProblem": "Report a problem",
"main.menus.app.help.restartAndUpdate": "Restart and Update",
"main.menus.app.help.RunDiagnostics": "Run diagnostics",
"main.menus.app.help.ShowLogs": "Show logs",
"main.menus.app.help.userGuide": "User guide",
"main.menus.app.help.versionString": "Version {version}{commit}",
"main.menus.app.history": "&History",
"main.menus.app.history.back": "Back",
Expand Down
5 changes: 4 additions & 1 deletion src/common/config/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import type {BuildConfig} from 'types/config';

import {DEFAULT_ACADEMY_LINK, DEFAULT_HELP_LINK} from '../../common/constants';

// For detailed guides, please refer to https://docs.mattermost.com/deployment/desktop-app-deployment.html

/**
Expand All @@ -27,7 +29,8 @@ const buildConfig: BuildConfig = {
url: 'https://example.com'
}
*/],
helpLink: 'https://docs.mattermost.com/messaging/managing-desktop-app-servers.html',
helpLink: DEFAULT_HELP_LINK,
academyLink: DEFAULT_ACADEMY_LINK,
enableServerManagement: true,
enableAutoUpdater: true,
managedResources: ['trusted'],
Expand Down
3 changes: 3 additions & 0 deletions src/common/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export class Config extends EventEmitter {
get helpLink() {
return this.combinedData?.helpLink;
}
get academyLink() {
return this.combinedData?.academyLink;
}
get minimizeToTray() {
return this.combinedData?.minimizeToTray;
}
Expand Down
10 changes: 6 additions & 4 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import type {DownloadItemTypeEnum} from 'main/downloadsManager';

import type {DownloadedItem} from 'types/downloads';
import type {DownloadedItem, DownloadItemTypeEnum} from 'types/downloads';

/**
* This string includes special characters so that it's not confused with
* a file that may have the same filename (eg APP_UPDATE)
*/
export const APP_UPDATE_KEY = '#:(APP_UPDATE):#';

export const UPDATE_DOWNLOAD_ITEM: Omit<DownloadedItem, 'filename' | 'state'> = {
type: 'update' as DownloadItemTypeEnum,
progress: 0,
Expand Down Expand Up @@ -46,3 +43,8 @@ export const IS_ONLINE_ENDPOINT = 'https://community.mattermost.com/api/v4/syste
export const COOKIE_NAME_USER_ID = 'MMUSERID';
export const COOKIE_NAME_CSRF = 'MMCSRF';
export const COOKIE_NAME_AUTH_TOKEN = 'MMAUTHTOKEN';

export const DEFAULT_HELP_LINK = 'https://docs.mattermost.com/guides/collaborate.html';
export const DEFAULT_ACADEMY_LINK = 'https://academy.mattermost.com/';
export const DEFAULT_TE_REPORT_PROBLEM_LINK = 'https://mattermost.com/pl/report-a-bug';
export const DEFAULT_EE_REPORT_PROBLEM_LINK = 'https://support.mattermost.com/hc/en-us/requests/new';
7 changes: 1 addition & 6 deletions src/main/downloadsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ import {doubleSecToMs, getPercentage, isStringWithLength, readFilenameFromConten
import ViewManager from 'main/views/viewManager';
import MainWindow from 'main/windows/mainWindow';

import type {DownloadedItem, DownloadItemDoneEventState, DownloadedItems, DownloadItemState, DownloadItemUpdatedEventState} from 'types/downloads';
import {type DownloadedItem, type DownloadItemDoneEventState, type DownloadedItems, type DownloadItemState, type DownloadItemUpdatedEventState, DownloadItemTypeEnum} from 'types/downloads';

import appVersionManager from './AppVersionManager';
import {downloadsJson} from './constants';

const log = new Logger('DownloadsManager');

export enum DownloadItemTypeEnum {
FILE = 'file',
UPDATE = 'update',
}

export class DownloadsManager extends JsonFileManager<DownloadedItems> {
autoCloseTimeout: NodeJS.Timeout | null;
open: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/main/menus/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jest.mock('common/servers/serverManager', () => ({
hasServers: jest.fn(),
getOrderedServers: jest.fn(),
getOrderedTabsForServer: jest.fn(),
getRemoteInfo: jest.fn(),
}));
jest.mock('app/serverViewState', () => ({
switchServer: jest.fn(),
Expand Down Expand Up @@ -302,6 +303,7 @@ describe('main/menus/app', () => {
}
return id;
});
ServerManager.hasServers.mockReturnValue(true);
ServerViewState.getCurrentServer.mockImplementation(() => ({id: servers[0].id}));

const modifiedViews = [...Array(15).keys()].map((key) => ({
Expand Down
47 changes: 42 additions & 5 deletions src/main/menus/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import log from 'electron-log';
import ServerViewState from 'app/serverViewState';
import {OPEN_SERVERS_DROPDOWN, SHOW_NEW_SERVER_MODAL} from 'common/communication';
import type {Config} from 'common/config';
import {DEFAULT_EE_REPORT_PROBLEM_LINK, DEFAULT_TE_REPORT_PROBLEM_LINK} from 'common/constants';
import ServerManager from 'common/servers/serverManager';
import {t} from 'common/utils/util';
import {getViewDisplayName} from 'common/views/View';
Expand Down Expand Up @@ -312,6 +313,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
});

const servers = ServerManager.getOrderedServers();
const currentServer = ServerManager.hasServers() ? ServerViewState.getCurrentServer() : undefined;
const windowMenu = {
id: 'window',
label: localizeMessage('main.menus.app.window', '&Window'),
Expand Down Expand Up @@ -347,7 +349,7 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
ServerViewState.switchServer(server.id);
},
});
if (ServerViewState.getCurrentServer().id === server.id) {
if (currentServer?.id === server.id) {
ServerManager.getOrderedTabsForServer(server.id).slice(0, 9).forEach((view, i) => {
items.push({
label: ` ${localizeMessage(`common.views.${view.type}`, getViewDisplayName(view.type as ViewType))}`,
Expand Down Expand Up @@ -380,6 +382,8 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
],
};
template.push(windowMenu);

const currentRemoteInfo = currentServer ? ServerManager.getRemoteInfo(currentServer.id) : undefined;
const submenu = [];
if (updateManager && config.canUpgrade) {
if (updateManager.versionDownloaded) {
Expand All @@ -404,16 +408,28 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
},
});
}
submenu.push(separatorItem);
}
if (config.helpLink) {

const helpLink = currentRemoteInfo?.helpLink ?? config.helpLink;
if (helpLink) {
submenu.push({
label: localizeMessage('main.menus.app.help.learnMore', 'Learn More...'),
label: localizeMessage('main.menus.app.help.userGuide', 'User guide'),
click() {
shell.openExternal(config.helpLink!);
shell.openExternal(helpLink);
},
});
}
const academyLink = config.academyLink;
if (academyLink) {
submenu.push({
label: localizeMessage('main.menus.app.help.academy', 'Mattermost Academy'),
click() {
shell.openExternal(academyLink);
},
});
submenu.push(separatorItem);
}
submenu.push(separatorItem);

submenu.push({
id: 'Show logs',
Expand All @@ -430,6 +446,27 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
Diagnostics.run();
},
});

let reportProblemLink = currentRemoteInfo?.reportProblemLink;
if (!reportProblemLink) {
switch (currentRemoteInfo?.licenseSku) {
case 'enterprise':
case 'professional':
reportProblemLink = DEFAULT_EE_REPORT_PROBLEM_LINK;
break;
default:
reportProblemLink = DEFAULT_TE_REPORT_PROBLEM_LINK;
break;
}
}
if (reportProblemLink) {
submenu.push({
label: localizeMessage('main.menus.app.help.reportProblem', 'Report a problem'),
click() {
shell.openExternal(reportProblemLink!);
},
});
}
submenu.push(separatorItem);

const version = localizeMessage('main.menus.app.help.versionString', 'Version {version}{commit}', {
Expand Down
11 changes: 11 additions & 0 deletions src/main/server/serverInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class ServerInfo {
this.onGetPlugins,
parseURL(`${this.server.url}/api/v4/plugins/webapp`),
);
await this.getRemoteInfo<{SkuShortName: string}>(
this.onGetLicense,
parseURL(`${this.server.url}/api/v4/license/client?format=old`),
);

return this.remoteInfo;
};
Expand Down Expand Up @@ -66,10 +70,17 @@ export class ServerInfo {
this.remoteInfo.siteURL = data.SiteURL;
this.remoteInfo.siteName = data.SiteName;
this.remoteInfo.hasFocalboard = this.remoteInfo.hasFocalboard || data.BuildBoards === 'true';
this.remoteInfo.helpLink = data.HelpLink;
this.remoteInfo.reportProblemLink = data.ReportAProblemLink;
};

private onGetLicense = (data: {SkuShortName: string}) => {
this.remoteInfo.licenseSku = data.SkuShortName;
};

private onGetPlugins = (data: Array<{id: string; version: string}>) => {
this.remoteInfo.hasFocalboard = this.remoteInfo.hasFocalboard || data.some((plugin) => plugin.id === 'focalboard');
this.remoteInfo.hasPlaybooks = data.some((plugin) => plugin.id === 'playbooks');
this.remoteInfo.hasUserSurvey = data.some((plugin) => plugin.id === 'com.mattermost.nps');
};
}
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export type AnyConfig = ConfigV3 | ConfigV2 | ConfigV1 | ConfigV0;
export type BuildConfig = {
defaultServers?: Server[];
helpLink: string;
academyLink: string;
enableServerManagement: boolean;
enableAutoUpdater: boolean;
managedResources: string[];
Expand Down
5 changes: 4 additions & 1 deletion src/types/downloads.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import type {DownloadItemTypeEnum} from 'main/downloadsManager';
export enum DownloadItemTypeEnum {
FILE = 'file',
UPDATE = 'update',
}

export type DownloadItemUpdatedEventState = 'interrupted' | 'progressing';
export type DownloadItemDoneEventState = 'completed' | 'cancelled' | 'interrupted';
Expand Down
6 changes: 6 additions & 0 deletions src/types/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ export type RemoteInfo = {
serverVersion?: string;
siteName?: string;
siteURL?: string;
licenseSku?: string;
helpLink?: string;
reportProblemLink?: string;
hasFocalboard?: boolean;
hasPlaybooks?: boolean;
hasUserSurvey?: boolean;
};

export type ClientConfig = {
Version: string;
SiteURL: string;
SiteName: string;
BuildBoards: string;
HelpLink: string;
ReportAProblemLink: string;
}

export type URLValidationResult = {
Expand Down

0 comments on commit 513a7e0

Please sign in to comment.