Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): give the filter field a row of its own up to 420px

Yudhi Armyndharis18f26c896ece
diff --git a/dashboard/src/components/FilterBuilder.css b/dashboard/src/components/FilterBuilder.css
index 1899b2c8a..3a0f858a5 100644
--- a/dashboard/src/components/FilterBuilder.css
+++ b/dashboard/src/components/FilterBuilder.css
@@ -53,8 +53,9 @@
width: 100%;
}
-/* Wide enough, with the padding above, for the longest field and operator label in every shipped locale
- except the two or three over-long ones, which end in an ellipsis; the open list shows them whole. */
+/* From 601px wide enough, with the padding above, for the longest field and operator label in every shipped
+ locale except the two or three over-long ones, which end in an ellipsis; the open list shows them whole. The
+ phone rule below replaces these bases. */
.filter-field {
flex: 0 0 10.75rem;
}
@@ -116,9 +117,10 @@
}
}
-/* At 320px the two selects share a row with 89px of text each, which cuts even "Message body"; the field takes
- the first row and the operator the second. */
-@media (max-width: 340px) {
+/* Up to 420px two selects side by side leave the field 100px of text at 341px and 109px at 360px, which cuts
+ "Message body" in German, French, Italian, Spanish and Portuguese; the field takes the first row and the
+ operator the second. From 421px the share is 139px and holds every label the desktop bases hold. */
+@media (max-width: 420px) {
.filter-field {
flex-basis: 100%;
}
diff --git a/dashboard/src/components/FilterBuilder.select.test.ts b/dashboard/src/components/FilterBuilder.select.test.ts
index 6d4a35a5d..e3f37347b 100644
--- a/dashboard/src/components/FilterBuilder.select.test.ts
+++ b/dashboard/src/components/FilterBuilder.select.test.ts
@@ -49,6 +49,33 @@ test('the field and the operator selects leave room for the labels of the shippe
assert.ok(text('.filter-operator') >= 83, `${text('.filter-operator')}px of text in the operator select`);
});
-test('a 320px phone gives the field select a row of its own', () => {
- assert.equal(decl(body(filter, '.filter-field', '@media (max-width: 340px)'), 'flex-basis'), '100%');
+// The flex basis a selector ends up with at a viewport width: the last rule that sets it among those whose
+// max-width media query admits the width. This is where the phone rule's 6rem overrode the bases measured above.
+function flexBasisAt(selector: string, width: number): string | undefined {
+ let basis: string | undefined;
+ for (const rule of filter) {
+ const max = /^@media \(max-width: (\d+)px\)$/.exec(rule.media)?.[1];
+ if (rule.media && !(max && width <= Number(max))) continue;
+ if (!rule.selectors.includes(selector)) continue;
+ basis = decl(rule.body, 'flex-basis') ?? decl(rule.body, 'flex')?.split(/\s+/)[2] ?? basis;
+ }
+ return basis;
+}
+
+// Two selects side by side leave the field select 100px of text at 341px and 109px at 360px, under the 133px the
+// longest label that fits needs (Italian "Corpo del messaggio", German "Nachrichteninhalt" at 341px): in a phone
+// row the field takes a row of its own. From 421px the equal share leaves it 139px, which holds every label that
+// the desktop bases hold, so the two share a row up to 600px, where the 6rem bases still grow to fill it.
+test('the field select has a row of its own on every phone width up to 420px', () => {
+ for (const width of [320, 340, 341, 360, 375, 390, 414, 420]) {
+ assert.equal(flexBasisAt('.filter-field', width), '100%', `${width}px`);
+ }
+});
+
+test('the field and the operator share a row from 421px up to the phone breakpoint', () => {
+ for (const width of [421, 450, 500, 600]) {
+ assert.equal(flexBasisAt('.filter-field', width), '6rem', `${width}px`);
+ assert.equal(flexBasisAt('.filter-operator', width), '6rem', `${width}px`);
+ }
+ assert.equal(flexBasisAt('.filter-field', 601), '10.75rem');
});