Pass the id of the server to remove to event listeners (#855)

* Pass the id of the server to be removed from the manager to the event listener

* Correctly reset appRoot state after destroying a server

* Rename to forgetServer

* Remove stray logging

* Apply suggestions from code review

Co-authored-by: Vinicius Fortuna <fortuna@users.noreply.github.com>

* Further suggested changes

Co-authored-by: Vinicius Fortuna <fortuna@users.noreply.github.com>
This commit is contained in:
Jonathan Cohen 2021-03-24 15:04:09 -04:00 • committed by GitHub
parent 766c22c9f6
commit 8fdd8d7273
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 14 deletions

View file

@ -162,11 +162,11 @@ export class App {
});
appRoot.addEventListener('DeleteServerRequested', (event: CustomEvent) => {
this.deleteSelectedServer();
this.deleteServer(event.detail.serverId);
});
appRoot.addEventListener('ForgetServerRequested', (event: CustomEvent) => {
this.forgetSelectedServer();
this.forgetServer(event.detail.serverId);
});
appRoot.addEventListener('AddAccessKeyRequested', (event: CustomEvent) => {
@ -1072,9 +1072,8 @@ export class App {
});
}
private deleteSelectedServer() {
const serverToDelete = this.selectedServer;
const serverId = serverToDelete.getId();
private deleteServer(serverId: string) {
const serverToDelete = this.getServerById(serverId);
if (!isManagedServer(serverToDelete)) {
const msg = 'cannot delete non-ManagedServer';
console.error(msg);
@ -1091,8 +1090,6 @@ export class App {
.then(
() => {
this.removeServer(serverId);
this.appRoot.selectedServer = null;
this.selectedServer = null;
this.showIntro();
this.appRoot.showNotification(
this.appRoot.localize('notification-server-destroyed'));
@ -1107,9 +1104,8 @@ export class App {
});
}
private forgetSelectedServer() {
const serverToForget = this.selectedServer;
const serverId = serverToForget.getId();
private forgetServer(serverId: string) {
const serverToForget = this.getServerById(serverId);
if (!isManualServer(serverToForget)) {
const msg = 'cannot forget non-ManualServer';
console.error(msg);
@ -1122,8 +1118,6 @@ export class App {
this.appRoot.getConfirmation(confirmationTitle, confirmationText, confirmationButton, () => {
serverToForget.forget();
this.removeServer(serverId);
this.appRoot.selectedServerId = '';
this.selectedServer = null;
this.showIntro();
this.appRoot.showNotification(this.appRoot.localize('notification-server-removed'));
});

View file

@ -1043,11 +1043,11 @@ export class ServerView extends DirMixin(PolymerElement) {
}
destroyServer() {
this.dispatchEvent(makePublicEvent('DeleteServerRequested'));
this.dispatchEvent(makePublicEvent('DeleteServerRequested', {serverId: this.serverId}));
}
removeServer() {
this.dispatchEvent(makePublicEvent('ForgetServerRequested'));
this.dispatchEvent(makePublicEvent('ForgetServerRequested', {serverId: this.serverId}));
}
/**