[MM-44932] Fixed issue where deleting a server doesn't switch to another server (or show the new server modal) (#2174)
This commit is contained in:
@@ -4,10 +4,10 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import {dialog} from 'electron';
|
import {dialog, ipcMain} from 'electron';
|
||||||
import {Tuple as tuple} from '@bloomberg/record-tuple-polyfill';
|
import {Tuple as tuple} from '@bloomberg/record-tuple-polyfill';
|
||||||
|
|
||||||
import {BROWSER_HISTORY_PUSH, LOAD_SUCCESS} from 'common/communication';
|
import {BROWSER_HISTORY_PUSH, LOAD_SUCCESS, SHOW_NEW_SERVER_MODAL} from 'common/communication';
|
||||||
import {MattermostServer} from 'common/servers/MattermostServer';
|
import {MattermostServer} from 'common/servers/MattermostServer';
|
||||||
import {getServerView, getTabViewName} from 'common/tabs/TabView';
|
import {getServerView, getTabViewName} from 'common/tabs/TabView';
|
||||||
import urlUtils from 'common/utils/url';
|
import urlUtils from 'common/utils/url';
|
||||||
@@ -417,7 +417,7 @@ describe('main/views/viewManager', () => {
|
|||||||
],
|
],
|
||||||
}];
|
}];
|
||||||
const viewManager = new ViewManager({});
|
const viewManager = new ViewManager({});
|
||||||
viewManager.configServers = teams.concat();
|
viewManager.getServers = () => teams.concat();
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
viewManager.showByName = jest.fn();
|
viewManager.showByName = jest.fn();
|
||||||
@@ -426,7 +426,7 @@ describe('main/views/viewManager', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
viewManager.configServers = teams;
|
viewManager.getServers = () => teams;
|
||||||
delete viewManager.lastActiveServer;
|
delete viewManager.lastActiveServer;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -442,7 +442,7 @@ describe('main/views/viewManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show last active tab of first server', () => {
|
it('should show last active tab of first server', () => {
|
||||||
viewManager.configServers = [{
|
viewManager.getServers = () => [{
|
||||||
name: 'server-1',
|
name: 'server-1',
|
||||||
order: 1,
|
order: 1,
|
||||||
tabs: [
|
tabs: [
|
||||||
@@ -489,7 +489,7 @@ describe('main/views/viewManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show next tab when last active tab is closed', () => {
|
it('should show next tab when last active tab is closed', () => {
|
||||||
viewManager.configServers = [{
|
viewManager.getServers = () => [{
|
||||||
name: 'server-1',
|
name: 'server-1',
|
||||||
order: 1,
|
order: 1,
|
||||||
tabs: [
|
tabs: [
|
||||||
@@ -534,6 +534,17 @@ describe('main/views/viewManager', () => {
|
|||||||
viewManager.showInitial();
|
viewManager.showInitial();
|
||||||
expect(viewManager.showByName).toHaveBeenCalledWith('server-2_tab-1');
|
expect(viewManager.showByName).toHaveBeenCalledWith('server-2_tab-1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should open new server modal when no servers exist', () => {
|
||||||
|
viewManager.mainWindow = {
|
||||||
|
webContents: {
|
||||||
|
send: jest.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
viewManager.getServers = () => [];
|
||||||
|
viewManager.showInitial();
|
||||||
|
expect(ipcMain.emit).toHaveBeenCalledWith(SHOW_NEW_SERVER_MODAL);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('showByName', () => {
|
describe('showByName', () => {
|
||||||
|
@@ -20,6 +20,7 @@ import {
|
|||||||
BROWSER_HISTORY_PUSH,
|
BROWSER_HISTORY_PUSH,
|
||||||
UPDATE_LAST_ACTIVE,
|
UPDATE_LAST_ACTIVE,
|
||||||
UPDATE_URL_VIEW_WIDTH,
|
UPDATE_URL_VIEW_WIDTH,
|
||||||
|
SHOW_NEW_SERVER_MODAL,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
import Config from 'common/config';
|
import Config from 'common/config';
|
||||||
import urlUtils from 'common/utils/url';
|
import urlUtils from 'common/utils/url';
|
||||||
@@ -45,7 +46,6 @@ enum LoadingScreenState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ViewManager {
|
export class ViewManager {
|
||||||
configServers: TeamWithTabs[];
|
|
||||||
lastActiveServer?: number;
|
lastActiveServer?: number;
|
||||||
viewOptions: BrowserViewConstructorOptions;
|
viewOptions: BrowserViewConstructorOptions;
|
||||||
closedViews: Map<string, {srv: MattermostServer; tab: Tab}>;
|
closedViews: Map<string, {srv: MattermostServer; tab: Tab}>;
|
||||||
@@ -58,7 +58,6 @@ export class ViewManager {
|
|||||||
loadingScreenState: LoadingScreenState;
|
loadingScreenState: LoadingScreenState;
|
||||||
|
|
||||||
constructor(mainWindow: BrowserWindow) {
|
constructor(mainWindow: BrowserWindow) {
|
||||||
this.configServers = Config.teams.concat();
|
|
||||||
this.lastActiveServer = Config.lastActiveTeam;
|
this.lastActiveServer = Config.lastActiveTeam;
|
||||||
this.viewOptions = {webPreferences: {spellcheck: Config.useSpellChecker}};
|
this.viewOptions = {webPreferences: {spellcheck: Config.useSpellChecker}};
|
||||||
this.views = new Map(); // keep in mind that this doesn't need to hold server order, only tabs on the renderer need that.
|
this.views = new Map(); // keep in mind that this doesn't need to hold server order, only tabs on the renderer need that.
|
||||||
@@ -72,7 +71,7 @@ export class ViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getServers = () => {
|
getServers = () => {
|
||||||
return this.configServers;
|
return Config.teams.concat();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadServer = (server: TeamWithTabs) => {
|
loadServer = (server: TeamWithTabs) => {
|
||||||
@@ -119,7 +118,7 @@ export class ViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
load = () => {
|
load = () => {
|
||||||
this.configServers.forEach((server) => this.loadServer(server));
|
this.getServers().forEach((server) => this.loadServer(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when a new configuration is received
|
/** Called when a new configuration is received
|
||||||
@@ -199,8 +198,9 @@ export class ViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showInitial = () => {
|
showInitial = () => {
|
||||||
if (this.configServers.length) {
|
const servers = this.getServers();
|
||||||
const element = this.configServers.find((e) => e.order === this.lastActiveServer) || this.configServers.find((e) => e.order === 0);
|
if (servers.length) {
|
||||||
|
const element = servers.find((e) => e.order === this.lastActiveServer) || servers.find((e) => e.order === 0);
|
||||||
if (element && element.tabs.length) {
|
if (element && element.tabs.length) {
|
||||||
let tab = element.tabs.find((tab) => tab.order === element.lastActiveTab) || element.tabs.find((tab) => tab.order === 0);
|
let tab = element.tabs.find((tab) => tab.order === element.lastActiveTab) || element.tabs.find((tab) => tab.order === 0);
|
||||||
if (!tab?.isOpen) {
|
if (!tab?.isOpen) {
|
||||||
@@ -212,6 +212,9 @@ export class ViewManager {
|
|||||||
this.showByName(tabView);
|
this.showByName(tabView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.mainWindow.webContents.send(SET_ACTIVE_VIEW, null, null);
|
||||||
|
ipcMain.emit(SHOW_NEW_SERVER_MODAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,7 +506,7 @@ export class ViewManager {
|
|||||||
// TODO: fix for new tabs
|
// TODO: fix for new tabs
|
||||||
if (url) {
|
if (url) {
|
||||||
const parsedURL = urlUtils.parseURL(url)!;
|
const parsedURL = urlUtils.parseURL(url)!;
|
||||||
const tabView = urlUtils.getView(parsedURL, this.configServers, true);
|
const tabView = urlUtils.getView(parsedURL, this.getServers(), true);
|
||||||
if (tabView) {
|
if (tabView) {
|
||||||
const urlWithSchema = `${urlUtils.parseURL(tabView.url)?.origin}${parsedURL.pathname}${parsedURL.search}`;
|
const urlWithSchema = `${urlUtils.parseURL(tabView.url)?.origin}${parsedURL.pathname}${parsedURL.search}`;
|
||||||
if (this.closedViews.has(tabView.name)) {
|
if (this.closedViews.has(tabView.name)) {
|
||||||
|
Reference in New Issue
Block a user