MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / showMultiEditPanel

Function showMultiEditPanel

renderer.js:17187–17349  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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';

Callers 3

showModelDetailsFunction · 0.85
renderer.jsFile · 0.85
handleFileClickFunction · 0.85

Calls 7

autoSaveMultipleModelsFunction · 0.85
debounceFunction · 0.85
addTagToModelFunction · 0.85
handleRemoveTagSelectFunction · 0.85
populateRemoveTagSelectFunction · 0.85
initializeListButtonsFunction · 0.85

Tested by

no test coverage detected