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


##########
experimental/traffic-portal/src/app/core/cache-groups/cache-group-table/cache-group-table.component.ts:
##########
@@ -162,13 +222,78 @@ export class CacheGroupTableComponent implements OnInit {
                this.fuzzySubject.next(this.fuzzControl.value);
        }
 
+       /**
+        * Queues or clears updates on a group of Cache Groups.
+        *
+        * @param cgs The Cache Groups on which to operate.
+        * @param queue Whether updates should be queued (`true`) or cleared
+        * (`false`).
+        */
+       private async queueUpdates(cgs: ResponseCacheGroup[], queue: boolean = 
true): Promise<void> {
+               const title = `${queue ? "Queue" : "Clear"} Updates on 
${cgs.length === 1 ? cgs[0].name : `${cgs.length} Cache Groups`}`;
+               const data = {
+                       collection: (await this.cdns).map(c => ({label: c.name, 
value: c.id})),
+                       hint: "Note that 'ALL' does NOT mean 'all CDNs'!",
+                       label: "CDN",
+                       message: `Select a CDN to which to limit the ${queue ? 
"Queuing" : "Clearing"} of Updates.`,
+                       title,
+               };
+               const ref = this.dialog.open<CollectionChoiceDialogComponent, 
CollectionChoiceDialogData<number>, number | false>(
+                       CollectionChoiceDialogComponent,
+                       {data}
+               );
+               const result = await ref.afterClosed().toPromise();
+               if (typeof(result) === "number") {
+                       const responses = await Promise.all(cgs.map(async cg => 
this.api.queueCacheGroupUpdates(cg, result)));
+                       const serverNum = responses.map(r => 
r.serverNames.length).reduce((n, l) => n+l, 0);
+                       // This endpoint returns no alerts at the time of this 
writing, so
+                       // we gotta do it by hand.
+                       this.alerts.newAlert(
+                               AlertLevel.SUCCESS,
+                               `${queue ? "Queued" : "Cleared"} Updates on 
${serverNum} server${serverNum === 1 ? "" : "s"}`
+                       );
+               }
+       }
+
+       /**
+        * Asks the user for confirmation before deleting a Cache Group.
+        *
+        * @param cg The Cache Group (potentially) being deleted.
+        */
+       private async delete(cg: ResponseCacheGroup): Promise<void> {
+               const ref = this.dialog.open<DecisionDialogComponent, 
DecisionDialogData, boolean>(DecisionDialogComponent, {
+                       data: {
+                               message: `Are you sure you want to delete the 
${cg.name} Cache Group?`,
+                               title: `Delete ${cg.name}`
+                       }
+               });
+               if (await ref.afterClosed().toPromise()) {
+                       this.api.deleteCacheGroup(cg);

Review Comment:
   I can do that if you think it's more clear or whatever, but all this does is 
asynchronously run that API call whenever the cycles can be spared, while 
resolving the Promise in the meantime. To illustrate:
   
   ```javascript
   async function a() {
        new Promise(r => setTimeout(() => {
                console.log("resolving");
                r();
        }, 1000));
        console.log("done")
   }
   
   a().then(() => console.log("resolved"));
   // Prints:
   // done
   // resolved
   // resolving
   ```
   Arguably the method call shouldn't resolve until the Cache Group is actually 
deleted, but freeing up the scheduling is technically slightly faster depending 
on conditions.
   You know what I just talked myself out of it. I changed it to await. Because 
what if deletion fails? You don't wanna navigate away just yet.



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