Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep session cards inside narrow screens

Yudhi Armyndharisa316221f1b0e
diff --git a/dashboard/src/pages/Sessions.css b/dashboard/src/pages/Sessions.css
index b50854ea9..d152aa6c6 100644
--- a/dashboard/src/pages/Sessions.css
+++ b/dashboard/src/pages/Sessions.css
@@ -71,7 +71,7 @@
.sessions-page .sessions-grid {
display: grid;
- grid-template-columns: repeat(4, 1fr);
+ grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 1.5rem;
width: 100%;
}
@@ -222,19 +222,19 @@
@media (max-width: 1400px) {
.sessions-page .sessions-grid {
- grid-template-columns: repeat(3, 1fr);
+ grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
@media (max-width: 1000px) {
.sessions-page .sessions-grid {
- grid-template-columns: repeat(2, 1fr);
+ grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 600px) {
.sessions-page .sessions-grid {
- grid-template-columns: 1fr;
+ grid-template-columns: minmax(0, 1fr);
}
.sessions-page {
diff --git a/dashboard/src/pages/Sessions.responsive.test.ts b/dashboard/src/pages/Sessions.responsive.test.ts
new file mode 100644
index 000000000..18cd94f81
--- /dev/null
+++ b/dashboard/src/pages/Sessions.responsive.test.ts
@@ -0,0 +1,17 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { decl, readRules } from '../test-helpers/css-rules.ts';
+
+// A 1fr track is minmax(auto, 1fr): it never shrinks below the min-content of the card in it. The error and
+// restriction lines of a card do not wrap, so one long value widened its track past the page and pushed the
+// other columns (every card on a phone) out of the viewport.
+const rules = readRules(new URL('./Sessions.css', import.meta.url));
+
+test('every sessions grid track can shrink below the width of its content', () => {
+ const grids = rules.filter(r => r.selectors.includes('.sessions-page .sessions-grid'));
+ assert.ok(grids.length > 0, 'no .sessions-grid rule found');
+ for (const grid of grids) {
+ const columns = decl(grid.body, 'grid-template-columns') ?? '';
+ assert.match(columns, /minmax\(0, 1fr\)/, `${grid.media || 'default'}: grid-template-columns: ${columns}`);
+ }
+});
diff --git a/dashboard/src/test-helpers/css-rules.ts b/dashboard/src/test-helpers/css-rules.ts
new file mode 100644
index 000000000..7af54f06e
--- /dev/null
+++ b/dashboard/src/test-helpers/css-rules.ts
@@ -0,0 +1,42 @@
+/// <reference types="node" />
+// A stylesheet read into its style rules, for tests that guard a layout. Each rule carries the @media
+// condition it sits under ('' at the top level), so a test can ask what a selector declares at one width
+// and not at another. At-rules other than @media (keyframes, font-face) are left out.
+import { readFileSync } from 'node:fs';
+
+export interface Rule {
+ media: string;
+ selectors: string[];
+ body: string;
+}
+
+export function readRules(sheet: URL): Rule[] {
+ return parse(readFileSync(sheet, 'utf8').replace(/\/\*[\s\S]*?\*\//g, ''));
+}
+
+function parse(text: string, media = ''): Rule[] {
+ const out: Rule[] = [];
+ let i = 0;
+ while (i < text.length) {
+ const open = text.indexOf('{', i);
+ if (open < 0) break;
+ const header = text.slice(i, open).trim();
+ let depth = 1;
+ let k = open + 1;
+ while (k < text.length && depth) {
+ if (text[k] === '{') depth++;
+ else if (text[k] === '}') depth--;
+ k++;
+ }
+ const body = text.slice(open + 1, k - 1);
+ if (header.startsWith('@media')) out.push(...parse(body, header));
+ else if (!header.startsWith('@')) out.push({ media, selectors: header.split(',').map(s => s.trim()), body });
+ i = k;
+ }
+ return out;
+}
+
+/** What a rule body gives `prop`, or undefined when it does not set it. */
+export function decl(body: string, prop: string): string | undefined {
+ return new RegExp(`(?:^|;)\\s*${prop}\\s*:\\s*([^;]+)`).exec(body)?.[1].trim();
+}