Skip to content

Commit 4b775cd

Browse files
authored
Fix formatting of client and numbers (#1108)
1 parent b6c6219 commit 4b775cd

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

src/js/techreport/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class TechReport {
201201

202202
// Update labels
203203
document.querySelectorAll('[data-slot="client"]').forEach(component => {
204-
component.innerHTML = client;
204+
component.innerText = client;
205205
});
206206
}
207207

src/js/techreport/table.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ function updateTable(id, config, appConfig, apps, data) {
139139
let text = '';
140140
let className = column.className;
141141

142-
const value = column.value;
142+
const value =
143+
typeof column.value === 'string' ? UIUtils.capitalizeFirstLetter(column.value) :
144+
typeof column.value === 'number' ? column.value.toLocaleString() :
145+
column.value;
143146

144147
// Fill in the data if it exists
145148
if(value && value !== '') {
@@ -152,7 +155,7 @@ function updateTable(id, config, appConfig, apps, data) {
152155

153156
// Wrap the text in a span for styling
154157
const wrapper = document.createElement('span');
155-
wrapper.innerHTML = text;
158+
wrapper.innerText = text;
156159
cell.append(wrapper);
157160

158161
// Stylized column groups (eg format `<column 1> / <column 2>`)
@@ -167,7 +170,7 @@ function updateTable(id, config, appConfig, apps, data) {
167170
hiddenSuffix.innerHTML = column.hiddenSuffix;
168171

169172
const textWrapper = document.createElement('span');
170-
textWrapper.innerHTML = text;
173+
textWrapper.innerText = text;
171174

172175
const cellWrapper = document.createElement(cellType);
173176
cellWrapper.appendChild(textWrapper);

src/js/techreport/tableLinked.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ class TableLinked {
116116
const formattedApp = DataUtils.formatAppName(app);
117117
const link = document.createElement('a');
118118
link.setAttribute('href', `/reports/techreport/tech?tech=${app}&geo=${geo}&rank=${rank}`);
119-
link.innerHTML = formattedApp;
119+
link.innerText = formattedApp;
120120
wrapper.append(link);
121121
cell.append(wrapper);
122122
} else if (column.type === 'checkbox') {
123123
cell = this.addColumnCheckbox(app);
124124
} else if(column.key === 'client') {
125125
cell = document.createElement('td');
126-
cell.innerHTML = component.dataset.client;
126+
cell.innerText = UIUtils.capitalizeFirstLetter(component.dataset.client);
127127
} else {
128128
const cellContent = document.createElement('span');
129129
cell = document.createElement('td');
@@ -132,9 +132,9 @@ class TableLinked {
132132
const changeStyle = UIUtils.getChangeStatus(value?.[component.dataset.client]?.momPerc);
133133
value = value?.[component.dataset.client]?.[column?.metric];
134134
if(column.suffix) {
135-
cellContent.innerHTML = `${value?.toLocaleString()}${column.suffix}`;
135+
cellContent.innerText = `${value?.toLocaleString()}${column.suffix}`;
136136
} else {
137-
cellContent.innerHTML = `${value?.toLocaleString()}`;
137+
cellContent.innerText = `${value?.toLocaleString()}`;
138138
}
139139

140140
if(column.viz === 'progress') {
@@ -265,7 +265,7 @@ class TableLinked {
265265
}
266266

267267
appLinkEl.setAttribute('href', href);
268-
appLinkEl.innerHTML = label;
268+
appLinkEl.innerText = label;
269269
});
270270

271271
if(this.selectedTechs.length > 0) {
@@ -320,7 +320,7 @@ class TableLinked {
320320
this.data = result.data;
321321
this.updateContent();
322322
const rowsAnnouncement = document.getElementById('rows-announcement');
323-
rowsAnnouncement.innerHTML = `Showing ${this.rows} rows.`;
323+
rowsAnnouncement.innerText = `Showing ${this.rows} rows.`;
324324
}
325325
}
326326

src/js/techreport/timeseries.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Table } from "./table";
44
import { DataUtils } from "./utils/data";
55
import { UIUtils } from "./utils/ui";
6+
67
class Timeseries {
78
// Create the component
89
constructor(id, pageConfig, config, filters, data) {
@@ -150,7 +151,7 @@ class Timeseries {
150151

151152
/* Add a text label to the wrapper */
152153
const breakdownLabel = document.createElement('p');
153-
breakdownLabel.textContent = breakdown.name;
154+
breakdownLabel.textContent = UIUtils.capitalizeFirstLetter(breakdown.name);
154155
breakdownLabel.classList.add('breakdown-label');
155156
itemWrapper.appendChild(breakdownLabel);
156157

@@ -377,7 +378,7 @@ class Timeseries {
377378

378379
document.getElementsByTagName('main')[0].append(pointSvg);
379380

380-
pointSeries.innerHTML = point.series.name;
381+
pointSeries.innerHTML = UIUtils.capitalizeFirstLetter(point.series.name);
381382
pointItem.innerHTML = `${pointSvg.outerHTML} ${pointSeries.outerHTML}: ${point.y.toLocaleString()}`;
382383

383384
pointList.appendChild(pointItem);
@@ -389,6 +390,13 @@ class Timeseries {
389390
}
390391
}
391392

393+
timeseries.legend = {
394+
labelFormatter: function () {
395+
const name = this.name || "";
396+
return UIUtils.capitalizeFirstLetter(name);
397+
}
398+
}
399+
392400
// Render the chart
393401
Highcharts.chart(`${this.id}-timeseries`, timeseries);
394402
}

src/js/techreport/utils/ui.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ const getChangeStatus = (percentage, meaning) => {
5757
}
5858
}
5959

60+
function capitalizeFirstLetter(theString) {
61+
return theString && typeof theString === 'string' ? theString.charAt(0)?.toUpperCase() + theString.slice(1) : theString;
62+
}
63+
6064
export const UIUtils = {
6165
getAppColor,
6266
updateReportComponents,
6367
getChangeStatus,
68+
capitalizeFirstLetter,
6469
}

templates/techreport/components/filter_meta.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ul class="meta">
22
<li>
3-
Client: <span data-slot="client">{{ request.args.get('client', '') or 'mobile' }}</span>
3+
Client: <span data-slot="client">{{ request.args.get('client', '') | capitalize or 'Mobile' }}</span>
44
</li>
55
<li>
66
Geo: <span data-slot="geo">{{ request.args.get('geo', '') or 'ALL' }}</span>

0 commit comments

Comments
 (0)