Skip to content

Commit ce8f9db

Browse files
fix: wrap tables in scrollable containers (#226)
fix ![image](https://github.com/user-attachments/assets/f205f183-84a5-4aae-b3c4-30d16a23f556) --------- Co-authored-by: Tomás Grüner <[email protected]>
1 parent 43a5be4 commit ce8f9db

File tree

7 files changed

+47
-91
lines changed

7 files changed

+47
-91
lines changed

src/graphics/basic_components/table.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface TableOptions {
1515
export class Table {
1616
private table: HTMLTableElement;
1717
private tbody: HTMLTableSectionElement;
18+
private tableWrapper: HTMLDivElement;
1819

1920
constructor(private options: TableOptions) {
2021
this.table = document.createElement("table");
@@ -26,6 +27,13 @@ export class Table {
2627
}
2728

2829
this.initializeTable();
30+
31+
// Create a wrapper for the table
32+
const wrapper = document.createElement("div");
33+
wrapper.classList.add(CSS_CLASSES.TABLE_CONTAINER);
34+
wrapper.appendChild(this.table);
35+
36+
this.tableWrapper = wrapper;
2937
}
3038

3139
private initializeTable(): void {
@@ -187,7 +195,7 @@ export class Table {
187195
this.tbody.innerHTML = ""; // Clear all rows from tbody
188196
}
189197

190-
toHTML(): HTMLTableElement {
191-
return this.table;
198+
toHTML(): HTMLElement {
199+
return this.tableWrapper;
192200
}
193201
}

src/graphics/basic_components/text_info.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ export class TextInfo {
193193
),
194194
fieldsPerRow: Object.keys(flags).length,
195195
rows: [statusRow, valueRow],
196-
tableClasses: [
197-
CSS_CLASSES.TABLE,
198-
CSS_CLASSES.RIGHT_BAR_TABLE,
199-
CSS_CLASSES.TCP_FLAGS_TABLE,
200-
],
196+
tableClasses: [CSS_CLASSES.TABLE, CSS_CLASSES.RIGHT_BAR_TABLE],
201197
});
202198

203199
// Get the table element

src/graphics/renderables/arp_table.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class ArpTable {
2121

2222
constructor(private props: ArpTableProps) {
2323
this.container = document.createElement("div");
24-
this.container.className = CSS_CLASSES.ROUTING_TABLE_CONTAINER;
2524

2625
const { onEdit, onRegenerate, onDelete } = this.setArpTableCallbacks();
2726

@@ -38,14 +37,10 @@ export class ArpTable {
3837
headers: headers,
3938
fieldsPerRow: 2, // IP and MAC
4039
rows: props.rows,
41-
editableColumns: [false, true], // Make all columns non-editable
40+
editableColumns: [false, true], // Make the MAC address column editable
4241
onEdit: onEdit,
4342
onDelete: onDelete,
44-
tableClasses: [
45-
CSS_CLASSES.TABLE,
46-
CSS_CLASSES.RIGHT_BAR_TABLE,
47-
CSS_CLASSES.ARP_TABLE,
48-
],
43+
tableClasses: [CSS_CLASSES.TABLE, CSS_CLASSES.RIGHT_BAR_TABLE],
4944
});
5045

5146
this.toggleButton = new ToggleButton({

src/graphics/renderables/program_runner_info.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { attachTooltip } from "./tooltip_manager";
1313
export class ProgramRunnerInfo implements Renderable {
1414
private runner: ProgramRunner;
1515
private inputFields: Node[] = [];
16-
private runningProgramsTable: HTMLTableElement;
16+
private runningProgramsTable: HTMLElement;
1717

1818
constructor(runner: ProgramRunner, programInfos: ProgramInfo[]) {
1919
this.runner = runner;
@@ -88,7 +88,7 @@ export class ProgramRunnerInfo implements Renderable {
8888
private createProgramsTable(
8989
runner: ProgramRunner,
9090
runningPrograms: RunningProgram[],
91-
): HTMLTableElement {
91+
): HTMLElement {
9292
const onDelete = (row: number) => {
9393
const { pid } = runningPrograms[row];
9494
runner.removeRunningProgram(pid);
@@ -129,7 +129,7 @@ export class ProgramRunnerInfo implements Renderable {
129129
this.runningProgramsTable = newTable;
130130
}
131131

132-
private generateProgramsTable(): HTMLTableElement {
132+
private generateProgramsTable(): HTMLElement {
133133
const runningPrograms = this.runner.getRunningPrograms();
134134
if (runningPrograms.length === 0) {
135135
return document.createElement("table");

src/graphics/renderables/routing_table.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class RoutingTable {
2222

2323
constructor(private props: RoutingTableProps) {
2424
this.container = document.createElement("div");
25-
this.container.className = CSS_CLASSES.ROUTING_TABLE_CONTAINER;
2625

2726
const { onEdit, onDelete, onRegenerate } = this.setRoutingTableCallbacks(
2827
props.viewgraph,
@@ -46,11 +45,7 @@ export class RoutingTable {
4645
editableColumns: [false, true, true, false], // Make the last column non-editable
4746
onEdit: onEdit,
4847
onDelete: onDelete,
49-
tableClasses: [
50-
CSS_CLASSES.TABLE,
51-
CSS_CLASSES.RIGHT_BAR_TABLE,
52-
CSS_CLASSES.ROUTER_TABLE,
53-
],
48+
tableClasses: [CSS_CLASSES.TABLE, CSS_CLASSES.RIGHT_BAR_TABLE],
5449
});
5550

5651
this.toggleButton = new ToggleButton({

src/styles/table.css

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,58 @@
1-
/* Common styles for both tables */
2-
.table-base {
1+
/* CONTAINER that allows horizontal scroll if needed */
2+
.right-bar-table-container {
3+
overflow-x: auto;
4+
display: block;
5+
border-radius: 1rem;
36
width: 100%;
7+
}
8+
9+
/* TABLE that adapts: fills 100% if it fits, but can expand beyond */
10+
.right-bar-table {
11+
min-width: 100%; /* At least fills the container */
12+
width: max-content; /* Expands to fit content if needed */
413
border-collapse: collapse;
514
font-size: 1rem;
615
text-align: center;
716
border-radius: 1rem;
817
box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.1);
918
clip-path: inset(0 round 1rem);
10-
overflow-x: auto;
11-
}
12-
13-
/* Common cell styles */
14-
.table-base th,
15-
.table-base td {
16-
word-wrap: break-word;
17-
overflow-wrap: break-word;
18-
white-space: normal;
19-
padding: 1vh;
20-
border: 0.2vh solid #ddd;
21-
text-align: center;
2219
}
2320

24-
.table-base th {
21+
/* TABLE HEADER */
22+
.right-bar-table th {
2523
background-color: #333;
2624
color: white;
25+
padding: 1vh;
26+
border: 0.2vh solid #ddd;
2727
box-sizing: border-box;
28+
white-space: nowrap; /* Prevents line breaks in headers */
2829
}
2930

30-
.table-base td {
31+
/* TABLE CELLS */
32+
.right-bar-table td {
33+
padding: 1vh;
34+
border: 0.2vh solid #ddd;
35+
overflow-wrap: break-word;
36+
word-wrap: break-word;
37+
white-space: nowrap; /* Prevents breaking key content */
3138
transition: background-color 0.3s ease-in-out;
3239
}
3340

34-
.table-base td:hover {
41+
/* HOVER effect for cells */
42+
.right-bar-table td:hover {
3543
background-color: #f0f0f0;
3644
cursor: pointer;
3745
}
3846

39-
/* TCP FLAGS TABLE specific styles */
40-
.tcp-flags-table {
41-
display: table;
42-
table-layout: auto;
43-
}
44-
45-
.tcp-flags-table tr:nth-child(even) {
47+
/* ALTERNATE ROW COLORS */
48+
.right-bar-table tr:nth-child(even) {
4649
background-color: #f9f9f9;
4750
}
4851

49-
.tcp-flags-table tr:nth-child(odd) {
52+
.right-bar-table tr:nth-child(odd) {
5053
background-color: #fff;
5154
}
5255

53-
/* TCP table container for proper scrolling */
54-
.tcp-flags-table-container {
55-
overflow-x: auto;
56-
border-radius: 1rem;
57-
}
58-
5956
/* ROUTER TABLE specific styles */
6057
.router-table {
6158
display: block;

src/utils/constants/css_constants.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
export const CSS_CLASSES = {
22
// General
3-
HIDDEN: "hidden",
4-
SELECTED: "selected",
5-
DISABLED: "disabled",
63
SHOW: "show",
7-
HIDE: "hide",
8-
ACTIVE: "active",
9-
INACTIVE: "inactive",
104
BLOCK: "block",
115

126
CENTRAL_LABEL: "central-label",
137

148
// Right Bar
15-
RIGHT_BAR: "right-bar",
169
RIGHT_BAR_BUTTON: "right-bar-button",
1710
RIGHT_BAR_TOGGLE_BUTTON: "right-bar-toggle-button",
1811
RIGHT_BAR_DELETE_BUTTON: "right-bar-delete-button",
1912
RIGHT_BAR_CONNECT_BUTTON: "right-bar-connect-button",
2013
RIGHT_BAR_START_BUTTON: "right-bar-start-button",
2114

2215
// Table
23-
TABLE: "table-base",
24-
TCP_FLAGS_TABLE: "tcp-flags-table",
25-
ROUTER_TABLE: "router-table",
26-
ARP_TABLE: "arp-table",
16+
TABLE_CONTAINER: "right-bar-table-container",
17+
TABLE: "table",
2718
RIGHT_BAR_TABLE: "right-bar-table",
28-
TOGGLE_TABLE: "toggle-table",
29-
TABLE_WRAPPER: "table-wrapper",
30-
EDITABLE_CELL: "editable-cell",
31-
32-
// Routing Table
33-
ROUTING_TABLE_CONTAINER: "routing-table-container",
3419

3520
// Dropdown
36-
DROPDOWN_CONTAINER: "dropdown-container",
3721
CUSTOM_DROPDOWN: "custom-dropdown",
3822
SELECTED_OPTION: "selected-option",
3923
OPTIONS_CONTAINER: "options-container",
@@ -45,28 +29,13 @@ export const CSS_CLASSES = {
4529
TRASH_BUTTON: "trash-button",
4630
REGENERATE_BUTTON: "regenerate-button",
4731

48-
// Tooltips
49-
HAS_TOOLTIP: "has-tooltip",
50-
GLOBAL_TOOLTIP: "global-tooltip",
51-
5232
// Parameter Editor
53-
PARAMETER_EDITOR_CONTAINER: "parameter-editor-container",
5433
PARAMETER_EDITOR: "parameter-editor",
5534
PARAMETER_EDITOR_LABEL: "parameter-editor-label",
5635
PARAMETER_EDITOR_INPUT: "parameter-editor-input",
5736
PARAMETER_GROUP: "parameter-group",
58-
PARAMETER_GROUP_TITLE: "parameter-group-title",
59-
60-
// Modal
61-
MODAL_OVERLAY: "modal-overlay",
62-
MODAL_CONTENT: "modal-content",
63-
MODAL_BODY: "modal-body",
64-
SAVE_BUTTON: "save-button",
65-
CLOSE_BUTTON: "close",
6637

6738
// Info
68-
TOGGLE_INFO_CONTAINER: "toggle-info-container",
69-
RIGHT_BAR_INFO: "right-bar-info",
7039
DETAIL_ITEM: "detail-item",
7140
DETAIL_CONTAINER: "detail-container",
7241
DETAIL_KEY: "detail-key",
@@ -82,10 +51,6 @@ export const CSS_CLASSES = {
8251
TCP_FLAG_INACTIVE: "tcp-flag-inactive",
8352
TCP_FLAG_HEADER: "tcp-flag-header",
8453

85-
// Layer Selector
86-
LAYER_SELECTOR_CONTAINER: "layer-selector-container",
87-
LAYER_SELECTOR_DROPDOWN: "layerselectordropdown",
88-
8954
// Speed Wheel
9055
SPEED_WHEEL_CONTAINER: "speed-control-container",
9156
SLIDER_CONTAINER: "slider-container",

0 commit comments

Comments
 (0)