Skip to content

Commit 18d8083

Browse files
kartbenLingaoM
authored andcommitted
doc: _extensions: make tag handling for supported HW caps more generic
There might be different UI widgets that deal with tags so make sure that we use identifiers and selectors that are not too generic. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 26f000b commit 18d8083

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

doc/_extensions/zephyr/domain/static/js/board-catalog.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,21 @@ function populateFormFromURL() {
4141
const features = hashParams.get("features").split(",");
4242
setTimeout(() => {
4343
features.forEach(feature => {
44-
const tagContainer = document.getElementById('tag-container');
45-
const tagInput = document.getElementById('tag-input');
44+
const tagContainer = document.getElementById('hwcaps-tags');
45+
const tagInput = document.getElementById('hwcaps-input');
4646

4747
const tagElement = document.createElement('span');
4848
tagElement.classList.add('tag');
4949
tagElement.textContent = feature;
5050
tagElement.onclick = () => {
51-
const selectedTags = [...document.querySelectorAll('.tag')].map(tag => tag.textContent);
52-
selectedTags.splice(selectedTags.indexOf(feature), 1);
51+
tagElement.remove();
52+
filterBoards();
53+
};
54+
tagContainer.insertBefore(tagElement, tagInput);
55+
});
56+
filterBoards();
57+
}, 0);
58+
}
5359
tagElement.remove();
5460
filterBoards();
5561
};
@@ -83,8 +89,8 @@ function updateURL() {
8389
});
8490

8591
// Add supported features to URL
86-
const selectedTags = [...document.querySelectorAll('.tag')].map(tag => tag.textContent);
87-
selectedTags.length ? hashParams.set("features", selectedTags.join(",")) : hashParams.delete("features");
92+
const selectedHWTags = [...document.querySelectorAll('#hwcaps-tags .tag')].map(tag => tag.textContent);
93+
selectedHWTags.length ? hashParams.set("features", selectedHWTags.join(",")) : hashParams.delete("features");
8894

8995
window.history.replaceState({}, "", `#${hashParams.toString()}`);
9096
}
@@ -126,8 +132,8 @@ function fillSocSocSelect(families, series = undefined, selectOnFill = false) {
126132
function setupHWCapabilitiesField() {
127133
let selectedTags = [];
128134

129-
const tagContainer = document.getElementById('tag-container');
130-
const tagInput = document.getElementById('tag-input');
135+
const tagContainer = document.getElementById('hwcaps-tags');
136+
const tagInput = document.getElementById('hwcaps-input');
131137
const datalist = document.getElementById('tag-list');
132138

133139
const tagCounts = Array.from(document.querySelectorAll('.board-card')).reduce((acc, board) => {
@@ -272,8 +278,8 @@ function resetForm() {
272278
document.getElementById("show-shields").checked = true;
273279

274280
// Clear supported features
275-
document.querySelectorAll('.tag').forEach(tag => tag.remove());
276-
document.getElementById('tag-input').value = '';
281+
document.querySelectorAll('#hwcaps-tags .tag').forEach(tag => tag.remove());
282+
document.getElementById('hwcaps-input').value = '';
277283

278284
filterBoards();
279285
}
@@ -297,10 +303,11 @@ function filterBoards() {
297303
const showBoards = document.getElementById("show-boards").checked;
298304
const showShields = document.getElementById("show-shields").checked;
299305

300-
const selectedTags = [...document.querySelectorAll('.tag')].map(tag => tag.textContent);
306+
// Get selected hardware capability tags
307+
const selectedHWTags = [...document.querySelectorAll('#hwcaps-tags .tag')].map(tag => tag.textContent);
301308

302309
const resetFiltersBtn = document.getElementById("reset-filters");
303-
if (nameInput || archSelect || vendorSelect || socSocSelect.selectedOptions.length || selectedTags.length || !showBoards || !showShields) {
310+
if (nameInput || archSelect || vendorSelect || socSocSelect.selectedOptions.length || selectedHWTags.length || !showBoards || !showShields) {
304311
resetFiltersBtn.classList.remove("btn-disabled");
305312
} else {
306313
resetFiltersBtn.classList.add("btn-disabled");
@@ -328,7 +335,7 @@ function filterBoards() {
328335
!(archSelect && !boardArchs.includes(archSelect)) &&
329336
!(vendorSelect && boardVendor !== vendorSelect) &&
330337
(selectedSocs.length === 0 || selectedSocs.some((soc) => boardSocs.includes(soc))) &&
331-
(selectedTags.length === 0 || selectedTags.every((tag) => boardSupportedFeatures.includes(tag)));
338+
(selectedHWTags.length === 0 || selectedHWTags.every((tag) => boardSupportedFeatures.includes(tag)));
332339
}
333340

334341
board.classList.toggle("hidden", !matches);

doc/_extensions/zephyr/domain/templates/board-catalog.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@
7676
</div>
7777

7878
<div class="form-group" style="flex-basis: 100%">
79-
<label for="tag-input">Supported Hardware Capabilities</label>
80-
<div class="tag-container" id="tag-container">
81-
<input list="tag-list" class="tag-input" id="tag-input"
79+
<label for="hwcaps-input">Supported Hardware Capabilities</label>
80+
<div class="tag-container" id="hwcaps-tags">
81+
<input list="tag-list" class="tag-input" id="hwcaps-input"
8282
placeholder="{% if hw_features_present -%}
83-
Type a tag...
83+
Type a hardware capability, e.g. &quot;display&quot;, &quot;sensor&quot;, &hellip;
8484
{%- else -%}
8585
List of supported hardware capabilities is not available
8686
{%- endif %}"

0 commit comments

Comments
 (0)