Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): #1544 Agent Policy Duplicate Redirect #2095

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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