Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

fix(ssh-keys-sidebar): SSH keys sidebar loads invalid key if there ar… #653

Merged
merged 4 commits into from
Nov 13, 2017

Conversation

HeyRoach
Copy link
Contributor

@HeyRoach HeyRoach commented Nov 7, 2017

…e duplicate names for different accounts

@HeyRoach HeyRoach requested a review from zolotyx November 7, 2017 01:51
@@ -40,7 +40,7 @@ export class SshKeyListComponent {
public selectSshKeyPair(sshKeyPair: SSHKeyPair): void {
this.router.navigate(['view', sshKeyPair.name], {
relativeTo: this.route,
queryParamsHandling: 'preserve'
queryParams: {account: sshKeyPair.account}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add queryParamsHandling: 'preserve'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if queryParams and queryParamsHandling: 'preserve' are used together, the query parameters are not adding to the routerLink

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HeyRoach , is there any other way to pass params to route with queryParamsHandling: 'preserve'?

}

public getByName(name: string): Observable<SSHKeyPair> {
return this.getList({ name }).map(sshKeys => sshKeys[0]);
return this.getList({ name }).map(sshKeys => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to fetch only one key by account and name? there will be no need to do subscription in constructor and store it locally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also have to handle the situation when account is not present in the query string

}

public getByName(name: string): Observable<SSHKeyPair> {
return this.getList({ name }).map(sshKeys => sshKeys[0]);
return this.getList({ name }).map(sshKeys => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also have to handle the situation when account is not present in the query string

…e duplicate names for different accounts - review fixes
@@ -40,7 +40,7 @@ export class SshKeyListComponent {
public selectSshKeyPair(sshKeyPair: SSHKeyPair): void {
this.router.navigate(['view', sshKeyPair.name], {
relativeTo: this.route,
queryParamsHandling: 'preserve'
queryParams: {account: sshKeyPair.account}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HeyRoach , is there any other way to pass params to route with queryParamsHandling: 'preserve'?

}

public getByName(name: string): Observable<SSHKeyPair> {
return this.getList({ name }).map(sshKeys => sshKeys[0]);
public getByName(name: string, account?: string): Observable<SSHKeyPair> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor this method to accept params object, rename the method

private asyncJobService: AsyncJobService,
protected http: HttpClient
) {
protected account: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to store the account? service should not store any data

super(http);

this.activatedRoute.queryParams.subscribe((params: Params) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

super(entityService, notificationService, route, router);
}

public ngOnInit() {
this.getEntityAccount();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this, use RXJS power not to store the data in the component

public onDescriptionChange(description: string): void {
this.description = description;
this.userTagService.setSshKeyDescription(this.entity, this.description).subscribe();
}

protected loadEntity(name: string): Observable<SSHKeyPair> {
return this.entityService.getByName(name)
protected loadEntity(name: string, account?: string): Observable<SSHKeyPair> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we leave this method with a single parameter and fetch account from stateParams here?

@HeyRoach HeyRoach force-pushed the 651-ssh-sidebar-load-invalid-key branch 2 times, most recently from 2b74a78 to feff524 Compare November 8, 2017 05:41
…e duplicate names for different accounts - review fixes 1
@HeyRoach HeyRoach force-pushed the 651-ssh-sidebar-load-invalid-key branch from feff524 to 9110eec Compare November 8, 2017 05:43
@@ -1,5 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

private asyncJobService: AsyncJobService,
protected http: HttpClient
) {
constructor(private asyncJobService: AsyncJobService,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert the indent

protected router: Router,
protected userTagService: UserTagService
) {
constructor(protected entityService: SSHKeyPairService,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use correct styling for constructor

public description: string;
public account: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not store account

@@ -32,7 +31,10 @@ export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> impleme
}

protected loadEntity(name: string): Observable<SSHKeyPair> {
return this.entityService.getByName(name)
const account = this.route.snapshot.queryParams['account'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use snapshot, use switchMap with this.entityService.getByParams

…e duplicate names for different accounts - review fixes 2
@HeyRoach HeyRoach merged commit 7227296 into master Nov 13, 2017
@dariashka dariashka deleted the 651-ssh-sidebar-load-invalid-key branch November 28, 2017 08:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants