Skip to content

Commit 4a76015

Browse files
authored
feat: add ifacesDropdown (#257)
1 parent 2209411 commit 4a76015

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

src/graphics/renderables/base_info.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export abstract class BaseInfo implements Renderable {
1111

1212
constructor(title: string) {
1313
this.information = new TextInfo(title);
14-
this.addCommonButtons();
1514
}
1615

1716
protected abstract addCommonInfoFields(): void;

src/graphics/renderables/device_info.ts

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ArpTable } from "./arp_table";
1818
import { Layer } from "../../types/layer";
1919
import { DataNetworkDevice, DataSwitch } from "../../types/data-devices";
2020
import { SwitchingTable } from "./switching_table";
21+
import { ToggleInfo } from "../components/toggle_info";
2122

2223
export class DeviceInfo extends BaseInfo {
2324
readonly device: ViewDevice;
@@ -26,6 +27,7 @@ export class DeviceInfo extends BaseInfo {
2627
super(getTypeName(device) + " Information");
2728
this.device = device;
2829
this.addCommonInfoFields();
30+
this.addCommonButtons();
2931
}
3032

3133
protected addCommonInfoFields(): void {
@@ -38,34 +40,11 @@ export class DeviceInfo extends BaseInfo {
3840
connections,
3941
TOOLTIP_KEYS.CONNECTED_DEVICES,
4042
);
41-
42-
const layer = this.device.viewgraph.getLayer();
43-
const showIp = this.device.getType() !== DeviceType.Switch;
44-
const showMac = layer === Layer.Link;
45-
46-
if (showIp) {
47-
this.device.interfaces.forEach((iface) => {
48-
this.information.addField(
49-
TOOLTIP_KEYS.IP_ADDRESS + (iface.name ? ` (${iface.name})` : ""),
50-
iface.ip.toString(),
51-
TOOLTIP_KEYS.IP_ADDRESS,
52-
);
53-
});
54-
}
55-
56-
if (showMac) {
57-
this.device.interfaces.forEach((iface) => {
58-
this.information.addField(
59-
TOOLTIP_KEYS.MAC_ADDRESS + (iface.name ? ` (${iface.name})` : ""),
60-
iface.mac.toString(),
61-
TOOLTIP_KEYS.MAC_ADDRESS,
62-
);
63-
});
64-
}
6543
}
6644

6745
protected addCommonButtons(): void {
6846
this.addDivider();
47+
6948
const connectButton = new Button({
7049
text: TOOLTIP_KEYS.CONNECT_DEVICE,
7150
onClick: () => this.device.selectToConnect(),
@@ -91,9 +70,47 @@ export class DeviceInfo extends BaseInfo {
9170
});
9271

9372
this.inputFields.push(connectButton.toHTML(), deleteButton.toHTML());
73+
74+
this.addIfacesToggle();
9475
this.addDivider();
9576
}
9677

78+
addIfacesToggle(): void {
79+
const layer = this.device.viewgraph.getLayer();
80+
const showIp = this.device.getType() !== DeviceType.Switch;
81+
const showMac = layer === Layer.Link;
82+
83+
const fields: { key: string; value: string; tooltip: string }[] = [];
84+
85+
if (showIp) {
86+
this.device.interfaces.forEach((iface) => {
87+
fields.push({
88+
key: TOOLTIP_KEYS.IP_ADDRESS + (iface.name ? ` (${iface.name})` : ""),
89+
value: iface.ip.toString(),
90+
tooltip: TOOLTIP_KEYS.IP_ADDRESS,
91+
});
92+
});
93+
}
94+
if (showMac) {
95+
this.device.interfaces.forEach((iface) => {
96+
fields.push({
97+
key:
98+
TOOLTIP_KEYS.MAC_ADDRESS + (iface.name ? ` (${iface.name})` : ""),
99+
value: iface.mac.toString(),
100+
tooltip: TOOLTIP_KEYS.MAC_ADDRESS,
101+
});
102+
});
103+
}
104+
105+
const toggleInfo = new ToggleInfo({
106+
title: "Interfaces",
107+
fields,
108+
toggleButtonText: { on: "Hide Interfaces", off: "Show Interfaces" },
109+
});
110+
111+
this.inputFields.push(toggleInfo.toHTML());
112+
}
113+
97114
addProgramRunner(runner: ProgramRunner, programs: ProgramInfo[]): void {
98115
const programRunnerInfo = new ProgramRunnerInfo(runner, programs);
99116
this.inputFields.push(...programRunnerInfo.toHTML());

src/graphics/renderables/edge_info.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class EdgeInfo extends BaseInfo {
1414
super(TOOLTIP_KEYS.EDGE_INFORMATION);
1515
this.edge = edge;
1616
this.addCommonInfoFields();
17+
this.addCommonButtons();
1718
this.addInterfaceDropdowns();
1819
}
1920

src/graphics/renderables/packet_info.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class PacketInfo extends BaseInfo {
1414
super("Packet Information");
1515
this.packet = packet;
1616
this.addCommonInfoFields();
17+
this.addCommonButtons();
1718
this.addToggleInfo(); // Add the toggle info for packet details
1819
}
1920

src/styles/divider.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Style for the divider */
22
.divider {
3-
border-bottom: 1px solid #d6d6d6; /* Separator line */
3+
border-bottom: 1px solid #bcbcbc; /* Separator line */
44
margin: 10px 0; /* Spacing above and below */
55
width: 100%; /* Takes up the full width of the container */
66
box-sizing: border-box; /* Includes padding and border in the total width */

0 commit comments

Comments
 (0)