Skip to content

Commit 03b8367

Browse files
author
DanielRyanSmith
committed
update tables for mobile view
1 parent 6c6316a commit 03b8367

File tree

1 file changed

+163
-35
lines changed

1 file changed

+163
-35
lines changed

webapp/components/interop-dashboard.js

Lines changed: 163 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
3838
}
3939
4040
.previous-year-banner {
41-
height: 40px;
4241
background-color: #DEF;
4342
text-align: center;
44-
padding-top: 16px;
43+
padding: 16px 0;
4544
}
4645
4746
.previous-year-banner p {
@@ -224,10 +223,6 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
224223
text-align: right;
225224
}
226225
227-
.score-table tbody > tr:nth-child(odd) {
228-
background: hsl(0 0% 0% / 5%);
229-
}
230-
231226
.subtotal-row {
232227
border-top: 1px solid GrayText;
233228
background: hsl(0 0% 0% / 5%);
@@ -286,10 +281,104 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
286281
}
287282
}
288283
284+
.interop-score-mobile,
285+
.table-title-mobile {
286+
display: none;
287+
}
288+
289289
@media only screen and (max-width: 800px) {
290290
.grid-container {
291291
margin: 0 1em;
292292
}
293+
294+
/* --- RESPONSIVE TABLE STYLES --- */
295+
.table-title-mobile {
296+
display: block;
297+
}
298+
.card-header-mobile {
299+
display: flex;
300+
justify-content: space-between;
301+
align-items: center;
302+
gap: 1em;
303+
}
304+
.interop-score-mobile {
305+
display: flex;
306+
font-size: 0.9em;
307+
font-weight: 500;
308+
color: #333;
309+
background: #e0e0e0;
310+
padding: 0.1em 0.5em;
311+
border-radius: 4px;
312+
white-space: nowrap;
313+
}
314+
.score-table thead {
315+
border: none;
316+
clip: rect(0 0 0 0);
317+
height: 1px;
318+
margin: -1px;
319+
overflow: hidden;
320+
padding: 0;
321+
position: absolute;
322+
width: 1px;
323+
}
324+
.score-table tr {
325+
display: block;
326+
border: 1px solid #ddd;
327+
border-radius: 5px;
328+
margin-bottom: 1em;
329+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
330+
overflow: hidden; /* To contain the floated pseudo-elements */
331+
}
332+
.score-table .subtotal-row,
333+
.score-table tfoot tr {
334+
border-top: 2px solid #aaa;
335+
font-weight: bold;
336+
}
337+
.score-table td {
338+
display: block;
339+
text-align: right;
340+
border-bottom: 1px solid #eee;
341+
padding: 0.75em;
342+
line-height: 1.5;
343+
}
344+
.score-table td[data-label="Interop"] {
345+
/* Hide the separate Interop row in our new layout */
346+
display: none;
347+
}
348+
.score-table td:last-child {
349+
border-bottom: 0;
350+
}
351+
.score-table td:first-child {
352+
text-align: left;
353+
font-weight: bold;
354+
background-color: hsl(0 0% 0% / 5%);
355+
border-bottom: 1px solid #ddd;
356+
padding: 0; /* Padding is now on the inner element */
357+
}
358+
.score-table td:first-child .card-header-mobile {
359+
padding: 0.75em;
360+
}
361+
.score-table td:not(:first-child)::before {
362+
content: attr(data-label);
363+
float: left;
364+
font-weight: 500;
365+
color: #555;
366+
}
367+
.score-table td[colspan="4"] {
368+
background-color: hsl(0 0% 0% / 5%);
369+
font-weight: bold;
370+
text-align: left;
371+
padding: 0.75em;
372+
373+
}
374+
.score-table td[colspan="4"] + td::before {
375+
content: "Progress";
376+
}
377+
}
378+
@media only screen and (min-width: 801px) {
379+
.score-table tbody > tr:nth-child(odd) {
380+
background: hsl(0 0% 0% / 5%);
381+
}
293382
}
294383
</style>
295384
<div class="previous-year-banner" hidden$=[[isCurrentYear]]>
@@ -302,9 +391,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
302391
<div class="grid-item grid-item-header">
303392
<h1>[[dashboardTitle]]</h1>
304393
<div class="channel-area">
305-
<paper-button id="toggleStable" class\$="[[stableButtonClass(stable, isMobileScoresView)]]" on-click="clickStable">Stable</paper-button>
306-
<paper-button id="toggleExperimental" class\$="[[experimentalButtonClass(stable, isMobileScoresView)]]" on-click="clickExperimental">Experimental</paper-button>
307-
<paper-button id="toggleMobile" class\$="[[mobileButtonClass(isMobileScoresView)]]" on-click="clickMobile" hidden$="[[!shouldShowMobileScoresView()]]">Mobile</paper-button>
394+
<paper-button id="toggleStable" class$="[[stableButtonClass(stable, isMobileScoresView)]]" on-click="clickStable">Stable</paper-button>
395+
<paper-button id="toggleExperimental" class$="[[experimentalButtonClass(stable, isMobileScoresView)]]" on-click="clickExperimental">Experimental</paper-button>
396+
<paper-button id="toggleMobile" class$="[[mobileButtonClass(isMobileScoresView)]]" on-click="clickMobile" hidden$="[[!shouldShowMobileScoresView()]]">Mobile</paper-button>
308397
</div>
309398
<div class="text-center" id="mobileWarning" hidden$="[[!isMobileScoresView]]">
310399
<p><i>Mobile browser results and how they are obtained are a work in progress. Scores may not reflect the real level of support for a given feature.</i></p>
@@ -354,19 +443,19 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
354443
<div class="grid-item grid-item-scores">
355444
<div class="table-card">
356445
<template is="dom-repeat" items="{{getYearProp('tableSections')}}" as="section">
446+
<h1 class="table-title-mobile">{{section.name}}</h1>
357447
<table class="score-table">
358448
<thead>
359-
360449
<!-- First score table header with sort functionality -->
361450
<template is="dom-if" if="[[isFirstTable(itemsIndex)]]">
362451
<tr class="section-header">
363-
<th class="sortable-header">
452+
<th class="sortable-header" data-label$="[[section.name]]">
364453
{{section.name}}
365454
<img class="sort-icon-focus-areas" src="[[getFocusAreaSortIcon(sortColumn, isSortedAsc)]]" />
366455
</th>
367456
<template is="dom-repeat" items="{{getYearProp('browserInfo')}}" as="browserInfo">
368457
<template is="dom-if" if="{{isChromeEdgeCombo(browserInfo)}}">
369-
<th class="sortable-header">
458+
<th class="sortable-header" data-label="Chrome/Edge">
370459
<template is="dom-if" if="[[stable]]">
371460
<div class="browser-icons">
372461
<img src="/static/chrome_64x64.png" width="32" alt="Chrome" title="Chrome" />
@@ -383,7 +472,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
383472
</th>
384473
</template>
385474
<template is="dom-if" if="{{!isChromeEdgeCombo(browserInfo)}}">
386-
<th class="sortable-header">
475+
<th class="sortable-header" data-label$="[[browserInfo.tableName]]">
387476
<div class="browser-icons single-browser-icon">
388477
<img src="[[getBrowserIcon(browserInfo, stable)]]" width="32" alt="[[getBrowserIconName(browserInfo, stable)]]" title="[[getBrowserIconName(browserInfo, stable)]]" />
389478
</div>
@@ -392,14 +481,14 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
392481
</template>
393482
</template>
394483
<template is="dom-if" if="{{isMobileScoresView}}">
395-
<th class="sortable-header">
484+
<th class="sortable-header" data-label="Safari iOS">
396485
<div class="browser-icons single-browser-icon">
397486
<img src="/static/wktr_64x64.png" width="32" alt="Safari iOS" title="Safari iOS" />
398487
</div>
399488
<img class="sort-icon" src="[[getSortIcon(2, sortColumn, isSortedAsc)]]" />
400489
</th>
401490
</template>
402-
<th class="sortable-header">
491+
<th class="sortable-header" data-label="Interop">
403492
<div class="interop-header">INTEROP</div>
404493
<img class="sort-icon" src="[[getInteropSortIcon(sortColumn, isSortedAsc)]]" />
405494
</th>
@@ -454,47 +543,54 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
454543
<template is="dom-repeat" items="{{sortRows(section.rows, index, sortColumn, isSortedAsc)}}" as="rowName">
455544
<tr data-feature$="[[rowName]]">
456545
<td>
457-
<a href$="[[getTestsURL(rowName, stable)]]">[[getRowInfo(rowName, 'description')]]</a>
546+
<div class="card-header-mobile">
547+
<a href$="[[getTestsURL(rowName, stable)]]">[[getRowInfo(rowName, 'description')]]</a>
548+
<span class="interop-score-mobile">[[getInteropScoreForFeature(rowName, stable)]]</span>
549+
</div>
458550
</td>
459551
<template is="dom-repeat" items="{{getYearProp('browserInfo')}}" as="browserInfo">
460-
<td>[[getBrowserScoreForFeature(itemsIndex, rowName, stable)]]</td>
552+
<td data-label$="[[browserInfo.tableName]]">[[getBrowserScoreForFeature(itemsIndex, rowName, stable)]]</td>
461553
</template>
462554
<template is="dom-if" if="[[isMobileScoresView]]">
463-
<td>--%</td>
555+
<td data-label="Safari iOS">--%</td>
464556
</template>
465-
<td>[[getInteropScoreForFeature(rowName, stable)]]</td>
557+
<td data-label="Interop">[[getInteropScoreForFeature(rowName, stable)]]</td>
466558
</tr>
467559
</template>
468560
</tbody>
469561
<tfoot>
470562
<tr class="subtotal-row">
471-
<td><strong>TOTAL</strong></td>
563+
<td>
564+
<div class="card-header-mobile">
565+
<strong>TOTAL</strong>
566+
<span class="interop-score-mobile">[[getInteropSubtotalScore(section, stable)]]</span>
567+
</div>
568+
</td>
472569
<template is="dom-repeat" items="{{getYearProp('browserInfo')}}" as="browserInfo">
473-
<td>[[getSubtotalScore(itemsIndex, section, stable)]]</td>
570+
<td data-label$="[[browserInfo.tableName]]">[[getSubtotalScore(itemsIndex, section, stable)]]</td>
474571
</template>
475572
<template is="dom-if" if="[[isMobileScoresView]]">
476-
<td>--%</td>
573+
<td data-label="Safari iOS">--%</td>
477574
</template>
478-
<td>[[getInteropSubtotalScore(section, stable)]]</td>
575+
<td data-label="Interop">[[getInteropSubtotalScore(section, stable)]]</td>
479576
</tr>
480577
</tfoot>
481578
</template>
482579
<template is="dom-if" if="[[section.score_as_group]]">
483580
<tbody>
484581
<template is="dom-repeat" items="{{section.rows}}" as="rowName">
485582
<tr>
486-
<td colspan=4>
583+
<td colspan="4">
487584
<a href$="[[getInvestigationUrl(rowName, section.previous_investigation)]]">[[rowName]]</a>
488585
</td>
489-
<td>[[getInvestigationScore(rowName, section.previous_investigation)]]</td>
586+
<td data-label="Progress">[[getInvestigationScore(rowName, section.previous_investigation)]]</td>
490587
</tr>
491588
</template>
492589
</tbody>
493590
<tfoot>
494591
<tr class="subtotal-row">
495-
<td><strong>TOTAL</strong></td>
496-
<td colspan=3></td>
497-
<td>[[getInvestigationScoreSubtotal(section.previous_investigation)]]</td>
592+
<td colspan="4" class="card-header-mobile"><strong>TOTAL</strong></td>
593+
<td data-label="Total Progress">[[getInvestigationScoreSubtotal(section.previous_investigation)]]</td>
498594
</tr>
499595
</tfoot>
500596
</template>
@@ -534,9 +630,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
534630
</div>
535631
536632
<interop-feature-chart year="[[year]]"
537-
data-manager="[[dataManager]]"
538-
stable="[[stable]]"
539-
feature="{{feature}}">
633+
data-manager="[[dataManager]]"
634+
stable="[[stable]]"
635+
feature="{{feature}}">
540636
</interop-feature-chart>
541637
</section>
542638
</div>
@@ -553,7 +649,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
553649
</template>
554650
</div>
555651
</footer>
556-
`;
652+
`;
557653
}
558654
static get is() {
559655
return 'interop-dashboard';
@@ -563,7 +659,10 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
563659
return {
564660
year: String,
565661
embedded: Boolean,
566-
stable: Boolean,
662+
stable: {
663+
type: Boolean,
664+
observer: '_stableChanged',
665+
},
567666
feature: String,
568667
features: {
569668
type: Array,
@@ -659,7 +758,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
659758
if (this.year === '2021' || this.year === '2022' || this.isMobileScoresView) {
660759
const gridContainerDiv = this.shadowRoot.querySelector('.grid-container');
661760
gridContainerDiv.style.display = 'block';
662-
gridContainerDiv.style.width = '700px';
761+
gridContainerDiv.style.maxWidth = '700px';
663762
gridContainerDiv.style.margin = 'auto';
664763
// Dashboards after 2022 also display a special description,
665764
// which is not displayed in previous years.
@@ -669,6 +768,35 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
669768
afterNextRender(this, this.addSortEvents);
670769
}
671770

771+
_stableChanged() {
772+
this.updateSummaryScores();
773+
}
774+
775+
async updateSummaryScores() {
776+
const scoreElements = this.shadowRoot.querySelectorAll('.interop-score-mobile');
777+
const scores = this.stable ? this.scores.stable : this.scores.experimental;
778+
const summaryFeatureName = this.dataManager.getYearProp('summaryFeatureName');
779+
console.log(this.scores);
780+
// If the elements have not rendered yet, don't update the scores.
781+
if ((!this.isMobileScoresView && scoreElements.length !== scores.length) ||
782+
(this.isMobileScoresView && scoreElements.length !== scores.length + 1)) {
783+
return;
784+
}
785+
// // Update interop summary number first.
786+
// this.updateSummaryScore(scoreElements[0], scores[scores.length - 1][summaryFeatureName]);
787+
// // Update the rest of the browser scores.
788+
// for (let i = 1; i < scores.length; i++) {
789+
// this.updateSummaryScore(scoreElements[i], scores[i - 1][summaryFeatureName]);
790+
// }
791+
792+
// // Update investigation summary separately.
793+
// if (this.shouldDisplayInvestigationNumber()) {
794+
// const investigationNumber = this.shadowRoot.querySelector('#investigationNumber');
795+
// this.updateSummaryScore(
796+
// investigationNumber, this.dataManager.getYearProp('investigationTotalScore'));
797+
// }
798+
}
799+
672800
// Add the on-click handlers for sorting by a specific table header.
673801
addSortEvents() {
674802
const sortableHeaders = this.shadowRoot.querySelectorAll('.sortable-header');
@@ -1067,7 +1195,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
10671195
// Reverse the sort order if the same column is clicked again.
10681196
if (this.sortColumn === i) {
10691197
this.isSortedAsc = !this.isSortedAsc;
1070-
} else {
1198+
} else {
10711199
// Otherwise, sort in descending order.
10721200
this.isSortedAsc = false;
10731201
}

0 commit comments

Comments
 (0)