Fix issue with changing servers and tabs (#2126)

This commit is contained in:
Devin Binnie 2022-05-26 14:17:44 -04:00 committed by GitHub
parent 581e1fd2e0
commit 37fe523e8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 9 deletions

View file

@ -17,7 +17,7 @@ export default abstract class BaseTabView implements TabView {
return getTabViewName(this.server.name, this.type);
}
get urlTypeTuple(): TabTuple {
return tuple(this.url.href, this.type) as TabTuple;
return tuple(this.server.url.href, this.type) as TabTuple;
}
get url(): URL {
throw new Error('Not implemented');

View file

@ -21,7 +21,7 @@ import {
SET_VIEW_OPTIONS,
LOADSCREEN_END,
} from 'common/communication';
import {MattermostServer} from 'common/servers/MattermostServer';
import {TabView, TabTuple} from 'common/tabs/TabView';
import {ServerInfo} from 'main/server/serverInfo';
@ -140,6 +140,12 @@ export class MattermostView extends EventEmitter {
return this.tab.urlTypeTuple;
}
updateServerInfo = (srv: MattermostServer) => {
this.tab.server = srv;
this.serverInfo = new ServerInfo(srv);
this.view.webContents.send(SET_VIEW_OPTIONS, this.tab.name, this.tab.shouldNotify);
}
resetLoadingStatus = () => {
if (this.status !== Status.LOADING) { // if it's already loading, don't touch anything
delete this.retryLoad;

View file

@ -199,6 +199,7 @@ describe('main/views/viewManager', () => {
destroy: destroyFn,
name: tab.name,
urlTypeTuple: tab.urlTypeTuple,
updateServerInfo: jest.fn(),
tab,
}));
});
@ -288,11 +289,15 @@ describe('main/views/viewManager', () => {
const view = {
name: 'server1-tab1',
tab: {
server: {
name: 'server-1',
},
name: 'server1-tab1',
url: new URL('http://server1.com'),
},
urlTypeTuple: tuple('http://server1.com/', 'tab1'),
destroy: jest.fn(),
updateServerInfo: jest.fn(),
};
viewManager.currentView = 'server1-tab1';
viewManager.views.set('server1-tab1', view);
@ -310,7 +315,6 @@ describe('main/views/viewManager', () => {
},
]);
expect(viewManager.showByName).toHaveBeenCalledWith('server1-tab1');
expect(viewManager.mainWindow.webContents.send).not.toHaveBeenCalled();
});
it('should show initial if currentView has been removed', () => {
@ -322,6 +326,7 @@ describe('main/views/viewManager', () => {
},
urlTypeTuple: ['http://server.com/', 'tab1'],
destroy: jest.fn(),
updateServerInfo: jest.fn(),
};
viewManager.currentView = 'server1-tab1';
viewManager.views.set('server1-tab1', view);
@ -338,7 +343,6 @@ describe('main/views/viewManager', () => {
],
},
]);
expect(viewManager.currentView).toBeUndefined();
expect(viewManager.showInitial).toBeCalled();
});

View file

@ -150,8 +150,7 @@ export class ViewManager {
if (!tab.isOpen) {
closed.set(tabTuple, {srv, tab, name: view.name});
} else if (recycle) {
recycle.serverInfo = info;
recycle.tab.server = srv;
recycle.updateServerInfo(srv);
views.set(tabTuple, recycle);
} else {
views.set(tabTuple, this.makeView(srv, info, tab, tabTuple[0]));
@ -177,7 +176,7 @@ export class ViewManager {
this.closedViews.set(x.name, {srv: x.srv, tab: x.tab});
}
if (focusedTuple && (current.has(focusedTuple) || closed.has(focusedTuple))) {
if ((focusedTuple && closed.has(focusedTuple)) || (this.currentView && this.closedViews.has(this.currentView))) {
if (configServers.length) {
delete this.currentView;
this.showInitial();
@ -189,8 +188,11 @@ export class ViewManager {
// show the focused tab (or initial)
if (focusedTuple && views.has(focusedTuple)) {
const view = views.get(focusedTuple);
this.currentView = view!.name;
this.showByName(view!.name);
if (view) {
this.currentView = view.name;
this.showByName(view.name);
this.mainWindow.webContents.send(SET_ACTIVE_VIEW, view.tab.server.name, view.tab.type);
}
} else {
this.showInitial();
}