ocket8888 commented on code in PR #7362:
URL: https://github.com/apache/trafficcontrol/pull/7362#discussion_r1121919728
##########
experimental/traffic-portal/src/app/api/testing/cache-group.service.ts:
##########
@@ -584,4 +593,39 @@ export class CacheGroupService {
}
return this.regions.splice(index, 1)[0];
}
+
+ public async getASNs(): Promise<Array<ResponseASN>>;
+ public async getASNs(id: number): Promise<ResponseASN>;
+
+ /**
+ * Gets an array of ASNs from Traffic Ops.
+ *
+ * @param id If given, returns only the asn with the given id (number).
+ * @returns An Array of ASNs objects - or a single ASN object if 'id'
+ * was given.
+ */
+ public async getASNs(id?: number): Promise<Array<ResponseASN> |
ResponseASN> {
+ if(id) {
+ const asn = this.asns.find(a=>a.asn === id);
Review Comment:
This gets the ASN with the `asn` that equals the given ID, not the ASN with
the `id` that matches the given ID, which I believe is incorrect.
##########
experimental/traffic-portal/src/app/core/cache-groups/asns/table/asns-table.component.ts:
##########
@@ -0,0 +1,134 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import { Component, type OnInit } from "@angular/core";
+import { FormControl } from "@angular/forms";
+import { MatDialog } from "@angular/material/dialog";
+import { ActivatedRoute, type Params } from "@angular/router";
+import { BehaviorSubject } from "rxjs";
+import type { ResponseASN } from "trafficops-types";
+
+import { CacheGroupService } from "src/app/api";
+import { CurrentUserService } from
"src/app/shared/currentUser/current-user.service";
+import { DecisionDialogComponent } from
"src/app/shared/dialogs/decision-dialog/decision-dialog.component";
+import type { ContextMenuActionEvent, ContextMenuItem } from
"src/app/shared/generic-table/generic-table.component";
+import { NavigationService } from
"src/app/shared/navigation/navigation.service";
+
+/**
+ * AsnsTableComponent is the controller for the "Asns" table.
+ */
+@Component({
+ selector: "tp-asns",
+ styleUrls: ["./asns-table.component.scss"],
+ templateUrl: "./asns-table.component.html"
+})
+export class AsnsTableComponent implements OnInit {
+ /** List of asns */
+ public asns: Promise<Array<ResponseASN>>;
+
+ constructor(private readonly route: ActivatedRoute, private readonly
headerSvc: NavigationService,
+ private readonly api: CacheGroupService, private readonly
dialog: MatDialog, public readonly auth: CurrentUserService) {
+ this.fuzzySubject = new BehaviorSubject<string>("");
+ this.asns = this.api.getASNs();
+ this.headerSvc.headerTitle.next("ASNs");
+ }
+
+ /** Initializes table data, loading it from Traffic Ops. */
+ public ngOnInit(): void {
+ this.route.queryParamMap.subscribe(
+ m => {
+ const search = m.get("search");
+ if (search) {
+
this.fuzzControl.setValue(decodeURIComponent(search));
+ this.updateURL();
+ }
+ },
+ e => {
+ console.error("Failed to get query
parameters:", e);
+ }
+ );
+ }
+
+ /** Definitions of the table's columns according to the ag-grid API */
+ public columnDefs = [
+ {
+ field: "asn",
+ headerName: "ASN"
+ },
+ {
+ field: "cachegroup",
+ headerName: "Cache Group",
+ valueGetter: ({data}: {data: ResponseASN}): string =>
`${data.cachegroup}`
+ },
+ {
+ field: "lastUpdated",
+ headerName: "Last Updated"
+ }
+ ];
+
+ /** Definitions for the context menu items (which act on augmented asn
data). */
+ public contextMenuItems: Array<ContextMenuItem<ResponseASN>> = [
+ {
+ href: (selectedRow: ResponseASN): string =>
`${selectedRow.asn}`,
+ name: "Edit"
+ },
+ {
+ href: (selectedRow: ResponseASN): string =>
`${selectedRow.asn}`,
Review Comment:
Shouldn't these use the ASN's `id`, not `asn`?
##########
experimental/traffic-portal/src/app/core/cache-groups/asns/table/asns-table.component.ts:
##########
@@ -0,0 +1,134 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import { Component, type OnInit } from "@angular/core";
+import { FormControl } from "@angular/forms";
+import { MatDialog } from "@angular/material/dialog";
+import { ActivatedRoute, type Params } from "@angular/router";
+import { BehaviorSubject } from "rxjs";
+import type { ResponseASN } from "trafficops-types";
+
+import { CacheGroupService } from "src/app/api";
+import { CurrentUserService } from
"src/app/shared/currentUser/current-user.service";
+import { DecisionDialogComponent } from
"src/app/shared/dialogs/decision-dialog/decision-dialog.component";
+import type { ContextMenuActionEvent, ContextMenuItem } from
"src/app/shared/generic-table/generic-table.component";
+import { NavigationService } from
"src/app/shared/navigation/navigation.service";
+
+/**
+ * AsnsTableComponent is the controller for the "Asns" table.
+ */
+@Component({
+ selector: "tp-asns",
+ styleUrls: ["./asns-table.component.scss"],
+ templateUrl: "./asns-table.component.html"
+})
+export class AsnsTableComponent implements OnInit {
+ /** List of asns */
+ public asns: Promise<Array<ResponseASN>>;
+
+ constructor(private readonly route: ActivatedRoute, private readonly
headerSvc: NavigationService,
+ private readonly api: CacheGroupService, private readonly
dialog: MatDialog, public readonly auth: CurrentUserService) {
+ this.fuzzySubject = new BehaviorSubject<string>("");
+ this.asns = this.api.getASNs();
+ this.headerSvc.headerTitle.next("ASNs");
+ }
+
+ /** Initializes table data, loading it from Traffic Ops. */
+ public ngOnInit(): void {
+ this.route.queryParamMap.subscribe(
+ m => {
+ const search = m.get("search");
+ if (search) {
+
this.fuzzControl.setValue(decodeURIComponent(search));
+ this.updateURL();
+ }
+ },
+ e => {
+ console.error("Failed to get query
parameters:", e);
+ }
+ );
+ }
+
+ /** Definitions of the table's columns according to the ag-grid API */
+ public columnDefs = [
+ {
+ field: "asn",
+ headerName: "ASN"
+ },
+ {
+ field: "cachegroup",
+ headerName: "Cache Group",
+ valueGetter: ({data}: {data: ResponseASN}): string =>
`${data.cachegroup}`
+ },
+ {
+ field: "lastUpdated",
+ headerName: "Last Updated"
+ }
+ ];
+
+ /** Definitions for the context menu items (which act on augmented asn
data). */
+ public contextMenuItems: Array<ContextMenuItem<ResponseASN>> = [
+ {
+ href: (selectedRow: ResponseASN): string =>
`${selectedRow.asn}`,
+ name: "Edit"
+ },
+ {
+ href: (selectedRow: ResponseASN): string =>
`${selectedRow.asn}`,
+ name: "Open in New Tab",
+ newTab: true
+ },
+ {
+ action: "delete",
+ multiRow: false,
+ name: "Delete"
+ },
+ {
+ href: "/core/cache-groups",
+ name: "View Cache Group",
+ queryParams: (selectedRow: ResponseASN): Params =>
({name: selectedRow.cachegroup}),
+ }
+ ];
+
+ /** A subject that child components can subscribe to for access to the
fuzzy search query text */
+ public fuzzySubject: BehaviorSubject<string>;
+
+ /** Form controller for the user search input. */
+ public fuzzControl = new FormControl<string>("");
+
+ /** Update the URL's 'search' query parameter for the user's search
input. */
+ public updateURL(): void {
+ this.fuzzySubject.next(this.fuzzControl.value ?? "");
+ }
+
+ /**
+ * Handles a context menu event.
+ *
+ * @param evt The action selected from the context menu.
+ */
+ public async handleContextMenu(evt:
ContextMenuActionEvent<ResponseASN>): Promise<void> {
+ const data = evt.data as ResponseASN;
+ switch(evt.action) {
+ case "delete":
+ const ref =
this.dialog.open(DecisionDialogComponent, {
+ data: {message: `Are you sure you want
to delete asn ${data.asn}`, title: "Confirm Delete"}
Review Comment:
Nit: missing <kbd>?</kbd>
##########
experimental/traffic-portal/src/app/core/cache-groups/cache-group-table/cache-group-table.component.ts:
##########
@@ -286,6 +286,15 @@ export class CacheGroupTableComponent implements OnInit {
case "dequeue":
this.queueUpdates(Array.isArray(a.data) ?
a.data : [a.data], false);
break;
+ case "asns":
+ let cg: ResponseCacheGroup;
+ if (Array.isArray(a.data)) {
+ cg = a.data[0];
+ } else {
+ cg = a.data;
+ }
+ this.router.navigate(["/core/asns"],
{queryParams: {cachegroup: cg.name}});
+ break;
Review Comment:
This is only doing navigation, so it should be a link, not a button handling
a click event
##########
experimental/traffic-portal/src/app/core/cache-groups/asns/table/asns-table.component.ts:
##########
@@ -0,0 +1,134 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import { Component, type OnInit } from "@angular/core";
+import { FormControl } from "@angular/forms";
+import { MatDialog } from "@angular/material/dialog";
+import { ActivatedRoute, type Params } from "@angular/router";
+import { BehaviorSubject } from "rxjs";
+import type { ResponseASN } from "trafficops-types";
+
+import { CacheGroupService } from "src/app/api";
+import { CurrentUserService } from
"src/app/shared/currentUser/current-user.service";
+import { DecisionDialogComponent } from
"src/app/shared/dialogs/decision-dialog/decision-dialog.component";
+import type { ContextMenuActionEvent, ContextMenuItem } from
"src/app/shared/generic-table/generic-table.component";
+import { NavigationService } from
"src/app/shared/navigation/navigation.service";
+
+/**
+ * AsnsTableComponent is the controller for the "Asns" table.
+ */
+@Component({
+ selector: "tp-asns",
+ styleUrls: ["./asns-table.component.scss"],
+ templateUrl: "./asns-table.component.html"
+})
+export class AsnsTableComponent implements OnInit {
+ /** List of asns */
+ public asns: Promise<Array<ResponseASN>>;
+
+ constructor(private readonly route: ActivatedRoute, private readonly
headerSvc: NavigationService,
+ private readonly api: CacheGroupService, private readonly
dialog: MatDialog, public readonly auth: CurrentUserService) {
+ this.fuzzySubject = new BehaviorSubject<string>("");
+ this.asns = this.api.getASNs();
+ this.headerSvc.headerTitle.next("ASNs");
+ }
+
+ /** Initializes table data, loading it from Traffic Ops. */
+ public ngOnInit(): void {
+ this.route.queryParamMap.subscribe(
+ m => {
+ const search = m.get("search");
+ if (search) {
+
this.fuzzControl.setValue(decodeURIComponent(search));
+ this.updateURL();
+ }
+ },
+ e => {
+ console.error("Failed to get query
parameters:", e);
+ }
+ );
+ }
+
+ /** Definitions of the table's columns according to the ag-grid API */
+ public columnDefs = [
+ {
+ field: "asn",
+ headerName: "ASN"
+ },
+ {
+ field: "cachegroup",
+ headerName: "Cache Group",
+ valueGetter: ({data}: {data: ResponseASN}): string =>
`${data.cachegroup}`
Review Comment:
This `valueGetter` implements the default behavior of the column; so it's
entirely unnecessary.
##########
experimental/traffic-portal/src/app/core/cache-groups/cache-group-table/cache-group-table.component.spec.ts:
##########
@@ -185,23 +185,7 @@ describe("CacheGroupTableComponent", () => {
expect(menuItem.href({...sampleCG, id:
5})).toBe("core/cache-groups/5");
});
it("doesn't allow selection of unimplemented context menu items", () =>
{
- let menuItem = component.contextMenuItems.find(i => i.name ===
"Manage ASNs");
- if (!menuItem) {
- return fail("'Manage ASNs' context menu item not
found");
- }
- if (!isAction(menuItem)) {
- return fail(`Invalid 'Manage ASNs' context menu item;
not an action: ${menuItem}`);
- }
- if (typeof(menuItem.disabled) !== "function") {
- return fail("'Manage ASNs' context menu item should be
disabled, but no disabled function is defined");
- }
- if (menuItem.multiRow) {
- expect(menuItem.disabled([sampleCG])).toBeTrue();
- } else {
- expect(menuItem.disabled(sampleCG)).toBeTrue();
- }
-
- menuItem = component.contextMenuItems.find(i => i.name ===
"Manage Servers");
Review Comment:
Now that this is working, this spec should include a test for it instead of
a test that checks that it's always disabled - which you are correctly deleting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]