[MM-36431] Logic to support multiple configurable tabs per server (#1655)
* Updated config, added types and classes for messaging tab * Working app with tabs and servers * Remainder of logic * Make base tab abstract class * Account for new app case * Merge'd * PR feedback
This commit is contained in:
@@ -10,14 +10,14 @@ import os from 'os';
|
||||
* @param {number} version - Scheme version. (Not application version)
|
||||
*/
|
||||
|
||||
import {ConfigV2} from 'types/config';
|
||||
import {ConfigV3} from 'types/config';
|
||||
|
||||
export const getDefaultDownloadLocation = (): string => {
|
||||
return path.join(os.homedir(), 'Downloads');
|
||||
};
|
||||
|
||||
const defaultPreferences: ConfigV2 = {
|
||||
version: 2,
|
||||
const defaultPreferences: ConfigV3 = {
|
||||
version: 3,
|
||||
teams: [],
|
||||
showTrayIcon: true,
|
||||
trayIconTheme: 'light',
|
||||
|
@@ -16,12 +16,13 @@ import {
|
||||
Config as ConfigType,
|
||||
LocalConfiguration,
|
||||
RegistryConfig as RegistryConfigType,
|
||||
Team,
|
||||
TeamWithTabs,
|
||||
} from 'types/config';
|
||||
|
||||
import {UPDATE_TEAMS, GET_CONFIGURATION, UPDATE_CONFIGURATION, GET_LOCAL_CONFIGURATION} from 'common/communication';
|
||||
|
||||
import * as Validator from '../../main/Validator';
|
||||
import * as Validator from 'main/Validator';
|
||||
import {getDefaultTeamWithTabsFromTeam} from 'common/tabs/TabView';
|
||||
|
||||
import defaultPreferences, {getDefaultDownloadLocation} from './defaultPreferences';
|
||||
import upgradeConfigData from './upgradePreferences';
|
||||
@@ -263,6 +264,9 @@ export default class Config extends EventEmitter {
|
||||
|
||||
// validate based on config file version
|
||||
switch (configData.version) {
|
||||
case 3:
|
||||
configData = Validator.validateV3ConfigData(configData)!;
|
||||
break;
|
||||
case 2:
|
||||
configData = Validator.validateV2ConfigData(configData)!;
|
||||
break;
|
||||
@@ -317,16 +321,16 @@ export default class Config extends EventEmitter {
|
||||
delete this.combinedData!.defaultTeams;
|
||||
|
||||
// IMPORTANT: properly combine teams from all sources
|
||||
let combinedTeams = [];
|
||||
let combinedTeams: TeamWithTabs[] = [];
|
||||
|
||||
// - start by adding default teams from buildConfig, if any
|
||||
if (this.buildConfigData?.defaultTeams?.length) {
|
||||
combinedTeams.push(...this.buildConfigData.defaultTeams);
|
||||
combinedTeams.push(...this.buildConfigData.defaultTeams.map((team) => getDefaultTeamWithTabsFromTeam(team)));
|
||||
}
|
||||
|
||||
// - add registry defined teams, if any
|
||||
if (this.registryConfigData?.teams?.length) {
|
||||
combinedTeams.push(...this.registryConfigData.teams);
|
||||
combinedTeams.push(...this.registryConfigData.teams.map((team) => getDefaultTeamWithTabsFromTeam(team)));
|
||||
}
|
||||
|
||||
// - add locally defined teams only if server management is enabled
|
||||
@@ -352,7 +356,7 @@ export default class Config extends EventEmitter {
|
||||
*
|
||||
* @param {array} teams array of teams to check for duplicates
|
||||
*/
|
||||
filterOutDuplicateTeams = (teams: Team[]) => {
|
||||
filterOutDuplicateTeams = (teams: TeamWithTabs[]) => {
|
||||
let newTeams = teams;
|
||||
const uniqueURLs = new Set();
|
||||
newTeams = newTeams.filter((team) => {
|
||||
@@ -365,7 +369,7 @@ export default class Config extends EventEmitter {
|
||||
* Returns the provided array fo teams with existing teams filtered out
|
||||
* @param {array} teams array of teams to check for already defined teams
|
||||
*/
|
||||
filterOutPredefinedTeams = (teams: Team[]) => {
|
||||
filterOutPredefinedTeams = (teams: TeamWithTabs[]) => {
|
||||
let newTeams = teams;
|
||||
|
||||
// filter out predefined teams
|
||||
@@ -380,7 +384,7 @@ export default class Config extends EventEmitter {
|
||||
* Apply a default sort order to the team list, if no order is specified.
|
||||
* @param {array} teams to sort
|
||||
*/
|
||||
sortUnorderedTeams = (teams: Team[]) => {
|
||||
sortUnorderedTeams = (teams: TeamWithTabs[]) => {
|
||||
// We want to preserve the array order of teams in the config, otherwise a lot of bugs will occur
|
||||
const mappedTeams = teams.map((team, index) => ({team, originalOrder: index}));
|
||||
|
||||
@@ -470,7 +474,7 @@ export default class Config extends EventEmitter {
|
||||
return config;
|
||||
}
|
||||
|
||||
handleUpdateTeams = (event: Electron.IpcMainInvokeEvent, newTeams: Team[]) => {
|
||||
handleUpdateTeams = (event: Electron.IpcMainInvokeEvent, newTeams: TeamWithTabs[]) => {
|
||||
this.set('teams', newTeams);
|
||||
return this.combinedData!.teams;
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
// Copyright (c) 2015-2016 Yuya Ochiai
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {ConfigV0, ConfigV1} from 'types/config';
|
||||
import {ConfigV0, ConfigV1, ConfigV2} from 'types/config';
|
||||
|
||||
import defaultPreferences from './defaultPreferences';
|
||||
import defaultPreferences, {getDefaultDownloadLocation} from './defaultPreferences';
|
||||
|
||||
const pastDefaultPreferences = {
|
||||
0: {
|
||||
@@ -26,7 +26,26 @@ const pastDefaultPreferences = {
|
||||
autostart: true,
|
||||
spellCheckerLocale: 'en-US',
|
||||
} as ConfigV1,
|
||||
2: defaultPreferences,
|
||||
2: {
|
||||
version: 2,
|
||||
teams: [],
|
||||
showTrayIcon: true,
|
||||
trayIconTheme: 'light',
|
||||
minimizeToTray: true,
|
||||
notifications: {
|
||||
flashWindow: 2,
|
||||
bounceIcon: true,
|
||||
bounceIconType: 'informational',
|
||||
},
|
||||
showUnreadBadge: true,
|
||||
useSpellChecker: true,
|
||||
enableHardwareAcceleration: true,
|
||||
autostart: true,
|
||||
spellCheckerLocale: 'en-US',
|
||||
darkMode: false,
|
||||
downloadLocation: getDefaultDownloadLocation(),
|
||||
} as ConfigV2,
|
||||
3: defaultPreferences,
|
||||
};
|
||||
|
||||
export default pastDefaultPreferences;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
// Copyright (c) 2015-2016 Yuya Ochiai
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {ConfigV2, ConfigV1, ConfigV0, AnyConfig} from 'types/config';
|
||||
|
||||
import {ConfigV3, ConfigV2, ConfigV1, ConfigV0, AnyConfig} from 'types/config';
|
||||
|
||||
import {getDefaultTeamWithTabsFromTeam} from 'common/tabs/TabView';
|
||||
|
||||
import pastDefaultPreferences from './pastDefaultPreferences';
|
||||
|
||||
@@ -30,10 +33,24 @@ function upgradeV1toV2(configV1: ConfigV1) {
|
||||
return config;
|
||||
}
|
||||
|
||||
export default function upgradeToLatest(config: AnyConfig): ConfigV2 {
|
||||
function upgradeV2toV3(configV2: ConfigV2) {
|
||||
const config: ConfigV3 = Object.assign({}, deepCopy<ConfigV3>(pastDefaultPreferences[3]), configV2);
|
||||
config.version = 3;
|
||||
config.teams = configV2.teams.map((value) => {
|
||||
return {
|
||||
...getDefaultTeamWithTabsFromTeam(value),
|
||||
lastActiveTab: 0,
|
||||
};
|
||||
});
|
||||
return config;
|
||||
}
|
||||
|
||||
export default function upgradeToLatest(config: AnyConfig): ConfigV3 {
|
||||
switch (config.version) {
|
||||
case 3:
|
||||
return config as ConfigV3;
|
||||
case 2:
|
||||
return config as ConfigV2;
|
||||
return upgradeToLatest(upgradeV2toV3(config as ConfigV2));
|
||||
case 1:
|
||||
return upgradeToLatest(upgradeV1toV2(config as ConfigV1));
|
||||
default:
|
||||
|
Reference in New Issue
Block a user