()
| 17185 | |
| 17186 | // Collect unique tags across all selected files |
| 17187 | // Use Set to automatically ensure uniqueness |
| 17188 | const uniqueTags = new Set(); |
| 17189 | allTagsArrays.forEach(tags => { |
| 17190 | if (Array.isArray(tags)) { |
| 17191 | // First deduplicate tags within each model (in case a model has duplicate tags) |
| 17192 | const modelUniqueTags = new Set(); |
| 17193 | tags.forEach(tag => { |
| 17194 | // Normalize tag: trim whitespace and ensure it's a non-empty string |
| 17195 | if (tag && typeof tag === 'string') { |
| 17196 | const normalizedTag = tag.trim(); |
| 17197 | if (normalizedTag) { |
| 17198 | modelUniqueTags.add(normalizedTag); |
| 17199 | } |
| 17200 | } |
| 17201 | }); |
| 17202 | // Add all unique tags from this model to the overall set |
| 17203 | modelUniqueTags.forEach(tag => uniqueTags.add(tag)); |
| 17204 | } |
| 17205 | }); |
| 17206 | |
| 17207 | // Convert Set to array and sort alphabetically |
| 17208 | // Set already ensures uniqueness, so no need for additional deduplication |
| 17209 | const sortedTags = Array.from(uniqueTags).sort((a, b) => a.localeCompare(b)); |
| 17210 | |
| 17211 | // Double-check for duplicates (defensive programming) |
| 17212 | const finalUniqueTags = []; |
| 17213 | const seenTags = new Set(); |
| 17214 | sortedTags.forEach(tag => { |
| 17215 | if (!seenTags.has(tag)) { |
| 17216 | seenTags.add(tag); |
| 17217 | finalUniqueTags.push(tag); |
| 17218 | } |
| 17219 | }); |
| 17220 | |
| 17221 | // Populate dropdown |
| 17222 | if (finalUniqueTags.length === 0) { |
| 17223 | const noTagsOption = document.createElement('option'); |
| 17224 | noTagsOption.value = ''; |
| 17225 | noTagsOption.textContent = 'No tags to remove'; |
| 17226 | noTagsOption.disabled = true; |
| 17227 | removeTagSelect.appendChild(noTagsOption); |
| 17228 | } else { |
| 17229 | finalUniqueTags.forEach(tagName => { |
| 17230 | // Additional check to prevent duplicate options in the DOM |
| 17231 | const existingOption = Array.from(removeTagSelect.options).find(opt => opt.value === tagName); |
| 17232 | if (!existingOption) { |
| 17233 | const option = document.createElement('option'); |
| 17234 | option.value = tagName; |
| 17235 | option.textContent = tagName; |
| 17236 | removeTagSelect.appendChild(option); |
| 17237 | } |
| 17238 | }); |
| 17239 | } |
| 17240 | } catch (error) { |
| 17241 | console.error('Error populating remove tag select:', error); |
| 17242 | const errorOption = document.createElement('option'); |
| 17243 | errorOption.value = ''; |
| 17244 | errorOption.textContent = 'Error loading tags'; |
no test coverage detected