Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 1cad456

Browse files
authored
TPv2 Cache Groups table minor updates (#7487)
* TPv2 Cache Group Table minor updates * Add tests * Fix invalid context menu links
1 parent b514a3b commit 1cad456

File tree

2 files changed

+24
-44
lines changed

2 files changed

+24
-44
lines changed

experimental/traffic-portal/src/app/core/cache-groups/cache-group-table/cache-group-table.component.spec.ts

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe("CacheGroupTableComponent", () => {
172172
return fail(`invalid 'Open in New Tab' context menu item; either not a link or has a static href: ${menuItem}`);
173173
}
174174
expect(menuItem.newTab).toBeTrue();
175-
expect(menuItem.href({...sampleCG, id: 5})).toBe("core/cache-groups/5");
175+
expect(menuItem.href({...sampleCG, id: 5})).toBe("5");
176176

177177
menuItem = component.contextMenuItems.find(i => i.name === "Edit");
178178
if (!menuItem) {
@@ -182,13 +182,13 @@ describe("CacheGroupTableComponent", () => {
182182
return fail(`invalid 'Edit' context menu item; either not a link or has a static href: ${menuItem}`);
183183
}
184184
expect(menuItem.newTab).toBeFalsy();
185-
expect(menuItem.href({...sampleCG, id: 5})).toBe("core/cache-groups/5");
185+
expect(menuItem.href({...sampleCG, id: 5})).toBe("5");
186186
});
187187

188-
it("generates 'Manage ASNs' context menu item href", () => {
189-
const item = component.contextMenuItems.find(i => i.name === "Manage ASNs");
188+
it("generates 'View ASNs' context menu item href", () => {
189+
const item = component.contextMenuItems.find(i => i.name === "View ASNs");
190190
if (!item) {
191-
return fail("missing 'Manage ASNs' context menu item");
191+
return fail("missing 'View ASNs' context menu item");
192192
}
193193
if (isAction(item)) {
194194
return fail("expected an action, not a link");
@@ -197,7 +197,7 @@ describe("CacheGroupTableComponent", () => {
197197
return fail("missing 'href' property");
198198
}
199199
if (typeof(item.href) !== "string") {
200-
return fail("'Manage ASNs' context menu item should use a static string to determine href, instead uses a function");
200+
return fail("'View ASNs' context menu item should use a static string to determine href, instead uses a function");
201201
}
202202
expect(item.href).toBe("/core/asns");
203203
if (typeof(item.queryParams) !== "function") {
@@ -210,38 +210,23 @@ describe("CacheGroupTableComponent", () => {
210210
expect(item.newTab).toBeFalsy();
211211
});
212212

213-
it("doesn't allow selection of unimplemented context menu items", () => {
214-
let menuItem = component.contextMenuItems.find(i => i.name === "Manage Servers");
213+
it("builds links to the servers in a Cache Group", () => {
214+
const menuItem = component.contextMenuItems.find(i => i.name === "View Servers");
215215
if (!menuItem) {
216-
return fail("'Manage Servers' context menu item not found");
216+
return fail("'View Servers' context menu item not found");
217217
}
218-
if (!isAction(menuItem)) {
219-
return fail(`Invalid 'Manage Servers' context menu item; not an action: ${menuItem}`);
220-
}
221-
if (typeof(menuItem.disabled) !== "function") {
222-
return fail("'Manage Servers' context menu item should be disabled, but no disabled function is defined");
223-
}
224-
if (menuItem.multiRow) {
225-
expect(menuItem.disabled([sampleCG])).toBeTrue();
226-
} else {
227-
expect(menuItem.disabled(sampleCG)).toBeTrue();
218+
if (isAction(menuItem)) {
219+
return fail("Invalid 'View Servers' context menu item; not a link");
228220
}
229221

230-
menuItem = component.contextMenuItems.find(i => i.name === "Manage Parameters");
231-
if (!menuItem) {
232-
return fail("'Manage Parameters' context menu item not found");
233-
}
234-
if (!isAction(menuItem)) {
235-
return fail(`Invalid 'Manage Parameters' context menu item; not an action: ${menuItem}`);
236-
}
237-
if (typeof(menuItem.disabled) !== "function") {
238-
return fail("'Manage Parameters' context menu item should be disabled, but no disabled function is defined");
239-
}
240-
if (menuItem.multiRow) {
241-
expect(menuItem.disabled([sampleCG])).toBeTrue();
242-
} else {
243-
expect(menuItem.disabled(sampleCG)).toBeTrue();
222+
expect(menuItem.href).toBe("/core/servers");
223+
expect(menuItem.newTab).toBeFalsy();
224+
expect(menuItem.fragment).not.toBeDefined();
225+
expect(menuItem.queryParams).toBeDefined();
226+
if (typeof(menuItem.queryParams) !== "function") {
227+
return fail("invalid 'View Servers' context menu item; query params not a function");
244228
}
229+
expect(menuItem.queryParams(sampleCG)).toEqual({cachegroup: sampleCG.name});
245230
});
246231

247232
it("initializes from query string parameters", fakeAsync(() => {

experimental/traffic-portal/src/app/core/cache-groups/cache-group-table/cache-group-table.component.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ export class CacheGroupTableComponent implements OnInit {
141141
*/
142142
public contextMenuItems: Array<ContextMenuItem<ResponseCacheGroup>> = [
143143
{
144-
href: (selectedRow): string => `core/cache-groups/${selectedRow.id}`,
144+
href: (selectedRow): string => String(selectedRow.id),
145145
name: "Open in New Tab",
146146
newTab: true
147147
},
148148
{
149-
href: (selectedRow): string => `core/cache-groups/${selectedRow.id}` ,
149+
href: (selectedRow): string => String(selectedRow.id),
150150
name: "Edit"
151151
},
152152
{
@@ -165,18 +165,13 @@ export class CacheGroupTableComponent implements OnInit {
165165
},
166166
{
167167
href: "/core/asns",
168-
name: "Manage ASNs",
168+
name: "View ASNs",
169169
queryParams: (selectedRow): Params => ({cachegroup: selectedRow.name})
170170
},
171171
{
172-
action: "parameters",
173-
disabled: (): true => true,
174-
name: "Manage Parameters"
175-
},
176-
{
177-
action: "servers",
178-
disabled: (): true => true,
179-
name: "Manage Servers"
172+
href: "/core/servers",
173+
name: "View Servers",
174+
queryParams: (selectedRow): Params => ({cachegroup: selectedRow.name})
180175
}
181176
];
182177

0 commit comments

Comments
 (0)