Skip to content

Commit

Permalink
fix(ui): #1544 Agent Policy Duplicate does not redirect to newly crea…
Browse files Browse the repository at this point in the history
…ted policy (#2095)
  • Loading branch information
gpazuch authored Dec 19, 2022
1 parent 478d318 commit 988b2c2
Showing 1 changed file with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import {
ChangeDetectorRef,
Component,
OnChanges,
OnDestroy,
OnInit,
ViewChild,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import {
ActivatedRoute,
NavigationEnd,
Router,
RouterEvent,
} from '@angular/router';
import { AgentPolicy } from 'app/common/interfaces/orb/agent.policy.interface';
import { Dataset } from 'app/common/interfaces/orb/dataset.policy.interface';
import { PolicyConfig } from 'app/common/interfaces/orb/policy/config/policy.config.interface';
Expand All @@ -18,13 +24,14 @@ import { STRINGS } from 'assets/text/strings';
import { Subscription } from 'rxjs';
import yaml from 'js-yaml';
import { AgentGroup } from 'app/common/interfaces/orb/agent.group.interface';
import { filter } from 'rxjs/operators';

@Component({
selector: 'ngx-agent-view',
templateUrl: './agent.policy.view.component.html',
styleUrls: ['./agent.policy.view.component.scss'],
})
export class AgentPolicyViewComponent implements OnInit, OnDestroy {
export class AgentPolicyViewComponent implements OnInit, OnDestroy, OnChanges {
strings = STRINGS.agents;

isLoading: boolean;
Expand Down Expand Up @@ -54,14 +61,28 @@ export class AgentPolicyViewComponent implements OnInit, OnDestroy {
private orb: OrbService,
private cdr: ChangeDetectorRef,
private notifications: NotificationsService,
private router: Router,
) {}

ngOnInit() {
this.router.events
.pipe(filter((event: RouterEvent) => event instanceof NavigationEnd))
.subscribe(() => {
this.fetchData();
});
this.fetchData();
}

fetchData() {
this.isLoading = true;
this.policyId = this.route.snapshot.paramMap.get('id');
this.retrievePolicy();
}

ngOnChanges(): void {
this.fetchData();
}

isEditMode() {
return Object.values(this.editMode).reduce(
(prev, cur) => prev || cur,
Expand All @@ -87,14 +108,7 @@ export class AgentPolicyViewComponent implements OnInit, OnDestroy {
}

save() {
const {
format,
version,
name,
description,
id,
backend,
} = this.policy;
const { format, version, name, description, id, backend } = this.policy;

// get values from all modified sections' forms and submit through service.
const policyDetails = this.detailsComponent.formGroup?.value;
Expand Down Expand Up @@ -125,19 +139,19 @@ export class AgentPolicyViewComponent implements OnInit, OnDestroy {
const payload = {
...detailsPartial,
...interfacePartial,
version, id, tags, backend,
version,
id,
tags,
backend,
} as AgentPolicy;

this.policiesService.editAgentPolicy(payload)
.subscribe(resp => {
this.discard();
this.policy = resp;
this.cdr.markForCheck();
});
this.policiesService.editAgentPolicy(payload).subscribe((resp) => {
this.discard();
this.policy = resp;
this.cdr.markForCheck();
});

this.notifications.success(
'Agent Policy updated successfully', '',
);
this.notifications.success('Agent Policy updated successfully', '');
} catch (err) {
this.notifications.error(
'Failed to edit Agent Policy',
Expand Down Expand Up @@ -167,6 +181,9 @@ export class AgentPolicyViewComponent implements OnInit, OnDestroy {
'Agent Policy Duplicated',
`New Agent Policy Name: ${resp?.name}`,
);
this.router.navigate([`view/${resp.id}`], {
relativeTo: this.route.parent,
});
}
});
}
Expand Down

0 comments on commit 988b2c2

Please sign in to comment.