rimashah25 commented on code in PR #7362:
URL: https://github.com/apache/trafficcontrol/pull/7362#discussion_r1124806883


##########
experimental/traffic-portal/src/app/core/cache-groups/asns/table/asns-table.component.ts:
##########
@@ -0,0 +1,133 @@
+/*
+* 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",
+               },
+               {
+                       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.id}`,
+                       name: "Edit"
+               },
+               {
+                       href: (selectedRow: ResponseASN): string => 
`${selectedRow.id}`,
+                       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;

Review Comment:
   Ok, checking to see if it is an array.



-- 
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]

Reply via email to