kdamichie commented on code in PR #7243: URL: https://github.com/apache/trafficcontrol/pull/7243#discussion_r1048960503
########## experimental/traffic-portal/src/app/core/cache-groups/regions/table/regions-table.component.ts: ########## @@ -0,0 +1,139 @@ +/* +* 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, OnInit } from "@angular/core"; +import { FormControl } from "@angular/forms"; +import { MatDialog } from "@angular/material/dialog"; +import { ActivatedRoute, Router } from "@angular/router"; +import { BehaviorSubject } from "rxjs"; +import { Region, ResponseRegion } 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 { ContextMenuActionEvent, ContextMenuItem } from "src/app/shared/generic-table/generic-table.component"; +import { TpHeaderService } from "src/app/shared/tp-header/tp-header.service"; + +/** + * RegionsTableComponent is the controller for the "Regions" table. + */ +@Component({ + selector: "tp-regions", + styleUrls: ["./regions-table.component.scss"], + templateUrl: "./regions-table.component.html" +}) +export class RegionsTableComponent implements OnInit { + /** List of regions */ + public readonly regions: Promise<Array<ResponseRegion>>; + + constructor(private readonly route: ActivatedRoute, private readonly headerSvc: TpHeaderService, private readonly router: Router, + private readonly api: CacheGroupService, private readonly dialog: MatDialog, public readonly auth: CurrentUserService) { + this.fuzzySubject = new BehaviorSubject<string>(""); + this.regions = this.api.getRegions(); + } + + /** 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); + } + ); + this.headerSvc.headerTitle.next("Regions"); + } + + /** Definitions of the table's columns according to the ag-grid API */ + public columnDefs = [ + { + field: "name", + headerName: "Name" + }, + { + field: "divisionName", + headerName: "Division" + }, + { + field: "id", + headerName:" ID", + hide: true + }, + { + field: "lastUpdated", + headerName: "Last Updated" + } + ]; + + /** Definitions for the context menu items (which act on augmented region data). */ + public contextMenuItems: Array<ContextMenuItem<Region>> = [ + { + action: "edit", + multiRow: false, + name: "Edit" + }, + { + action: "delete", + multiRow: false, + name: "Delete" + }, + { + action: "viewRegions", + multiRow: false, + name: "View Regions" + } + ]; + + /** 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: FormControl = new FormControl<string>(""); Review Comment: If type sting is removed, it does complain with `TS1099: Type argument list cannot be empty.` I don't know of another way to remove that inference to `FormControl`, especially if we want to simplify it's expression based on this description of `FormControl`: ```ɵFormControlCtor. <string>( value: FormControlState<string> | string, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<string | null> Various available constructors for FormControl. Do not use this interface directly. Instead, use FormControl: const fc = new FormControl('foo'); This symbol is prefixed with ɵ to make plain that it is an internal symbol. @angular/forms``` -- 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]
