ocket8888 commented on code in PR #7615:
URL: https://github.com/apache/trafficcontrol/pull/7615#discussion_r1279934257


##########
experimental/traffic-portal/src/app/core/topologies/topology-details/topology-details.component.html:
##########
@@ -0,0 +1,44 @@
+<!--
+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.
+-->
+<mat-card appearance="outlined" class="page-content single-column">
+       <tp-loading *ngIf="loading"></tp-loading>
+       <form ngNativeValidate (ngSubmit)="submit($event)">
+               <mat-card-content class="container">
+                       <mat-form-field>
+                               <mat-label>Name</mat-label>
+                               <input matInput type="text" name="name" 
required [readonly]="!new" [disabled]="!new" [value]="topology.name">

Review Comment:
   Why aren't we letting people change Topology names? They aren't immutable:
   ```shellsession
   $ topost -kp topologies '{"name": "dev", "nodes": [{"cachegroup": "dev"}]}'
   {
        "alerts": [
                {
                        "text": "topology was created.",
                        "level": "success"
                }
        ],
        "response": {
                "description": "",
                "name": "dev",
                "nodes": [
                        {
                                "cachegroup": "dev",
                                "parents": null
                        }
                ],
                "lastUpdated": "2023-07-31 22:12:18+00"
        }
   }
   $ toput -kp 'topologies?name=dev' '{"name": "dev-1", "nodes": 
[{"cachegroup": "dev"}]}'
   {
        "alerts": [
                {
                        "text": "topology was updated.",
                        "level": "success"
                }
        ],
        "response": {
                "description": "",
                "name": "dev-1",
                "nodes": [
                        {
                                "cachegroup": "dev",
                                "parents": null
                        }
                ],
                "lastUpdated": "2023-07-31 22:13:11+00"
        }
   }
   ```



##########
experimental/traffic-portal/src/app/api/testing/topology.service.ts:
##########
@@ -0,0 +1,155 @@
+/*
+* 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 { Injectable } from "@angular/core";
+import {
+       RequestTopology,
+       ResponseTopology,
+       ResponseTopologyNode
+} from "trafficops-types";
+
+import { TopologyService as ConcreteService, TopTreeNode } from "src/app/api";
+
+/**
+ * TopologyService expose API functionality relating to Topologies.
+ */
+@Injectable()
+export class TopologyService {
+       private readonly topologies: ResponseTopology[] = [
+               {
+                       description: "",
+                       lastUpdated: new Date(),
+                       name: "test",
+                       nodes: [
+                               {
+                                       cachegroup: "Edge",
+                                       parents: [1],
+                               },
+                               {
+                                       cachegroup: "Mid",
+                                       parents: [2],
+                               },
+                               {
+                                       cachegroup: "Origin",
+                                       parents: [],
+                               },
+                       ],
+               },
+       ];
+
+       /**
+        * Gets one or all Topologies from Traffic Ops
+        *
+        * @param name The unique name of a single Topology to be returned
+        * @returns Either an Array of Topologies or a single Topology, 
depending on whether `name` was
+        * passed.
+        */
+       public async getTopologies(name?: string): 
Promise<Array<ResponseTopology> | ResponseTopology> {
+               if (name !== undefined) {
+                       const topology = this.topologies.find(t => t.name === 
name);
+                       if (!topology) {
+                               throw new Error(`no such Topology ${name}`);
+                       }
+                       return topology;
+               }
+               return this.topologies;
+       }

Review Comment:
   The type of this testing service method doesn't match the type of the method 
by the same name on the concrete service. That method can only return arrays of 
Topologies, which means that if you drop this service in as a replacement for 
that concrete service, things calling `getTopologies` with a specified `name` 
argument will expect to get an Array back, but actually you've given them a 
single Topology object.
   
   I'd suggest fixing this not by modifying the testing service, but by 
changing the concrete service to have an overload signature wherein it returns 
a single Topology if asked for it by name, i.e. `(name: string) => 
Promise<ResponseTopology>`



-- 
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: issues-unsubscr...@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to