Skip to content

Commit

Permalink
[MM-54979] Stop auto opening Boards/Playbooks tabs, close existing op…
Browse files Browse the repository at this point in the history
…en tabs once for users that might have them open (#2886)
  • Loading branch information
devinbinnie authored Oct 25, 2023
1 parent 932eff2 commit 8a52a94
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/common/config/migrationPreferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('common/config/migrationPreferences', () => {
getValue: () => false,
setValue: jest.fn(),
}));
expect(migrateConfigItems({})).toBe(true);
expect(migrateConfigItems({teams: []})).toBe(true);
Object.defineProperty(process, 'platform', {
value: originalPlatform,
});
Expand Down
11 changes: 11 additions & 0 deletions src/common/config/migrationPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {Config, MigrationInfo} from 'types/config';

import JsonFileManager from 'common/JsonFileManager';
import {TAB_MESSAGING} from 'common/views/View';

import {migrationInfoPath} from 'main/constants';

Expand All @@ -17,5 +18,15 @@ export default function migrateConfigItems(config: Config) {
didMigrate = true;
}

if (!migrationPrefs.getValue('closeExtraTabs')) {
config.teams.forEach((team) => {
team.tabs.filter((tab) => tab.name !== TAB_MESSAGING).forEach((tab) => {
tab.isOpen = false;
});
});
migrationPrefs.setValue('closeExtraTabs', true);
didMigrate = true;
}

return didMigrate;
}
36 changes: 0 additions & 36 deletions src/common/servers/serverManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,6 @@ describe('common/servers/serverManager', () => {
expect(serverManager.persistServers).not.toHaveBeenCalled();
});

it('should open all views', async () => {
serverManager.updateRemoteInfos(new Map([['server-1', {
siteURL: 'http://server-1.com',
serverVersion: '6.0.0',
hasPlaybooks: true,
hasFocalboard: true,
}]]));

expect(serverManager.views.get('view-2').isOpen).toBe(true);
expect(serverManager.views.get('view-3').isOpen).toBe(true);
});

it('should open only playbooks', async () => {
serverManager.updateRemoteInfos(new Map([['server-1', {
siteURL: 'http://server-1.com',
serverVersion: '6.0.0',
hasPlaybooks: true,
hasFocalboard: false,
}]]));

expect(serverManager.views.get('view-2').isOpen).toBe(true);
expect(serverManager.views.get('view-3').isOpen).toBeUndefined();
});

it('should open none when server version is too old', async () => {
serverManager.updateRemoteInfos(new Map([['server-1', {
siteURL: 'http://server-1.com',
serverVersion: '5.0.0',
hasPlaybooks: true,
hasFocalboard: true,
}]]));

expect(serverManager.views.get('view-2').isOpen).toBeUndefined();
expect(serverManager.views.get('view-3').isOpen).toBeUndefined();
});

it('should update server URL using site URL', async () => {
serverManager.updateRemoteInfos(new Map([['server-1', {
siteURL: 'http://server-2.com',
Expand Down
38 changes: 0 additions & 38 deletions src/common/servers/serverManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import MessagingView from 'common/views/MessagingView';
import FocalboardView from 'common/views/FocalboardView';
import PlaybooksView from 'common/views/PlaybooksView';
import {getFormattedPathName, isInternalURL, parseURL} from 'common/utils/url';
import Utils from 'common/utils/util';

const log = new Logger('ServerManager');

Expand Down Expand Up @@ -108,7 +107,6 @@ export class ServerManager extends EventEmitter {
remoteInfos.forEach((remoteInfo, serverId) => {
this.remoteInfo.set(serverId, remoteInfo);
hasUpdates = this.updateServerURL(serverId) || hasUpdates;
hasUpdates = this.openExtraViews(serverId) || hasUpdates;
});

if (hasUpdates) {
Expand Down Expand Up @@ -379,42 +377,6 @@ export class ServerManager extends EventEmitter {
return false;
}

private openExtraViews = (serverId: string) => {
const server = this.servers.get(serverId);
const remoteInfo = this.remoteInfo.get(serverId);

if (!(server && remoteInfo)) {
return false;
}

if (!(remoteInfo.serverVersion && Utils.isVersionGreaterThanOrEqualTo(remoteInfo.serverVersion, '6.0.0'))) {
return false;
}

let hasUpdates = false;
const viewOrder = this.viewOrder.get(serverId);
if (viewOrder) {
viewOrder.forEach((viewId) => {
const view = this.views.get(viewId);
if (view) {
if (view.type === TAB_PLAYBOOKS && remoteInfo.hasPlaybooks && typeof view.isOpen === 'undefined') {
log.withPrefix(view.id).verbose('opening Playbooks');
view.isOpen = true;
this.views.set(viewId, view);
hasUpdates = true;
}
if (view.type === TAB_FOCALBOARD && remoteInfo.hasFocalboard && typeof view.isOpen === 'undefined') {
log.withPrefix(view.id).verbose('opening Boards');
view.isOpen = true;
this.views.set(viewId, view);
hasUpdates = true;
}
}
});
}
return hasUpdates;
}

private includeId = (id: string, ...prefixes: string[]) => {
const shouldInclude = ['debug', 'silly'].includes(getLevel());
return shouldInclude ? [id, ...prefixes] : prefixes;
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ export type LocalConfiguration = Config & {
export type MigrationInfo = {
updateTrayIconWin32: boolean;
masConfigs: boolean;
closeExtraTabs: boolean;
}

0 comments on commit 8a52a94

Please sign in to comment.