From 13e86f1c446154dc010189a5391af3b2a0971053 Mon Sep 17 00:00:00 2001 From: Ludy87 Date: Sat, 29 Nov 2025 16:51:53 +0100 Subject: [PATCH] refactor(frontend): normalize LocalIcon usage and icon scanning --- frontend/scripts/generate-icons.js | 52 ++++++++++++------- .../shared/config/LoginRequiredBanner.tsx | 2 +- .../config/configSections/GeneralSection.tsx | 2 +- .../core/components/toast/ToastRenderer.tsx | 6 +-- .../addAttachments/AddAttachmentsSettings.tsx | 2 +- .../tools/sign/SavedSignaturesSection.tsx | 6 +-- .../components/tools/sign/SignSettings.tsx | 6 +-- .../core/data/useTranslatedToolRegistry.tsx | 2 +- 8 files changed, 45 insertions(+), 33 deletions(-) diff --git a/frontend/scripts/generate-icons.js b/frontend/scripts/generate-icons.js index d99414b66..a536f66c1 100644 --- a/frontend/scripts/generate-icons.js +++ b/frontend/scripts/generate-icons.js @@ -19,39 +19,51 @@ const debug = (message) => { function scanForUsedIcons() { const usedIcons = new Set(); const srcDir = path.join(__dirname, '..', 'src'); - + + const addIcon = (iconName) => { + if (!iconName) return; + + const normalizedName = iconName.startsWith('material-symbols:') + ? iconName.split(':', 2)[1] + : iconName; + + usedIcons.add(normalizedName); + + debug(` Found: ${iconName} -> ${normalizedName}`); + }; + info('🔍 Scanning codebase for LocalIcon usage...'); - + if (!fs.existsSync(srcDir)) { console.error('❌ Source directory not found:', srcDir); process.exit(1); } - + // Recursively scan all .tsx and .ts files function scanDirectory(dir) { const files = fs.readdirSync(dir); - + files.forEach(file => { const filePath = path.join(dir, file); const stat = fs.statSync(filePath); - + if (stat.isDirectory()) { scanDirectory(filePath); } else if (file.endsWith('.tsx') || file.endsWith('.ts')) { const content = fs.readFileSync(filePath, 'utf8'); - + // Match LocalIcon usage: const localIconMatches = content.match(/]*icon="([^"]+)"/g); if (localIconMatches) { localIconMatches.forEach(match => { const iconMatch = match.match(/icon="([^"]+)"/); if (iconMatch) { - usedIcons.add(iconMatch[1]); - debug(` Found: ${iconMatch[1]} in ${path.relative(srcDir, filePath)}`); + addIcon(iconMatch[1]); + debug(` in ${path.relative(srcDir, filePath)}`); } }); } - + // Match old material-symbols-rounded spans: icon-name const spanMatches = content.match(/]*className="[^"]*material-symbols-rounded[^"]*"[^>]*>([^<]+)<\/span>/g); if (spanMatches) { @@ -59,32 +71,32 @@ function scanForUsedIcons() { const iconMatch = match.match(/>([^<]+)<\/span>/); if (iconMatch && iconMatch[1].trim()) { const iconName = iconMatch[1].trim(); - usedIcons.add(iconName); - debug(` Found (legacy): ${iconName} in ${path.relative(srcDir, filePath)}`); + addIcon(iconName); + debug(` in ${path.relative(srcDir, filePath)}`); } }); } - + // Match Icon component usage: const iconMatches = content.match(/]*icon="material-symbols:([^"]+)"/g); if (iconMatches) { iconMatches.forEach(match => { const iconMatch = match.match(/icon="material-symbols:([^"]+)"/); if (iconMatch) { - usedIcons.add(iconMatch[1]); - debug(` Found (Icon): ${iconMatch[1]} in ${path.relative(srcDir, filePath)}`); + addIcon(iconMatch[1]); + debug(` in ${path.relative(srcDir, filePath)}`); } }); } } }); } - + scanDirectory(srcDir); - + const iconArray = Array.from(usedIcons).sort(); info(`📋 Found ${iconArray.length} unique icons across codebase`); - + return iconArray; } @@ -102,7 +114,7 @@ async function main() { const existingSet = JSON.parse(fs.readFileSync(outputPath, 'utf8')); const existingIcons = Object.keys(existingSet.icons || {}).sort(); const currentIcons = [...usedIcons].sort(); - + if (JSON.stringify(existingIcons) === JSON.stringify(currentIcons)) { needsRegeneration = false; info(`✅ Icon set already up-to-date (${usedIcons.length} icons, ${Math.round(fs.statSync(outputPath).size / 1024)}KB)`); @@ -122,7 +134,7 @@ async function main() { // Dynamic import of ES module const { getIcons } = await import('@iconify/utils'); - + // Extract only our used icons from the full set const extractedIcons = getIcons(icons, usedIcons); @@ -183,4 +195,4 @@ export default iconSet; main().catch(error => { console.error('❌ Script failed:', error); process.exit(1); -}); \ No newline at end of file +}); diff --git a/frontend/src/core/components/shared/config/LoginRequiredBanner.tsx b/frontend/src/core/components/shared/config/LoginRequiredBanner.tsx index de611b64b..f16e38f4e 100644 --- a/frontend/src/core/components/shared/config/LoginRequiredBanner.tsx +++ b/frontend/src/core/components/shared/config/LoginRequiredBanner.tsx @@ -17,7 +17,7 @@ export default function LoginRequiredBanner({ show }: LoginRequiredBannerProps) return ( } + icon={} title={t('admin.settings.loginDisabled.title', 'Login Mode Required')} color="blue" variant="light" diff --git a/frontend/src/core/components/shared/config/configSections/GeneralSection.tsx b/frontend/src/core/components/shared/config/configSections/GeneralSection.tsx index e8f37a286..37723abbc 100644 --- a/frontend/src/core/components/shared/config/configSections/GeneralSection.tsx +++ b/frontend/src/core/components/shared/config/configSections/GeneralSection.tsx @@ -193,7 +193,7 @@ const GeneralSection: React.FC = ({ hideTitle = false }) => size="sm" color={updateSummary.max_priority === 'urgent' ? 'red' : 'blue'} onClick={() => setUpdateModalOpened(true)} - leftSection={} + leftSection={} > {t('settings.general.updates.viewDetails', 'View Details')} diff --git a/frontend/src/core/components/toast/ToastRenderer.tsx b/frontend/src/core/components/toast/ToastRenderer.tsx index 09891099f..dc7eb5659 100644 --- a/frontend/src/core/components/toast/ToastRenderer.tsx +++ b/frontend/src/core/components/toast/ToastRenderer.tsx @@ -63,7 +63,7 @@ export default function ToastRenderer() { {/* Icon */}
{t.icon ?? ( - + )}
@@ -86,7 +86,7 @@ export default function ToastRenderer() { }} className={`toast-button toast-expand-button ${t.isExpanded ? 'toast-expand-button--expanded' : ''}`} > - + )} diff --git a/frontend/src/core/components/tools/addAttachments/AddAttachmentsSettings.tsx b/frontend/src/core/components/tools/addAttachments/AddAttachmentsSettings.tsx index 33d9e8b33..70ca9935c 100644 --- a/frontend/src/core/components/tools/addAttachments/AddAttachmentsSettings.tsx +++ b/frontend/src/core/components/tools/addAttachments/AddAttachmentsSettings.tsx @@ -42,7 +42,7 @@ const AddAttachmentsSettings = ({ parameters, onParameterChange, disabled = fals component="label" htmlFor="attachments-input" disabled={disabled} - leftSection={} + leftSection={} > {parameters.attachments?.length > 0 ? t("AddAttachmentsRequest.addMoreFiles", "Add more files...") diff --git a/frontend/src/core/components/tools/sign/SavedSignaturesSection.tsx b/frontend/src/core/components/tools/sign/SavedSignaturesSection.tsx index bdb6c07e5..38e7bc0ab 100644 --- a/frontend/src/core/components/tools/sign/SavedSignaturesSection.tsx +++ b/frontend/src/core/components/tools/sign/SavedSignaturesSection.tsx @@ -249,7 +249,7 @@ export const SavedSignaturesSection = ({ onClick={() => handleNavigate('prev')} disabled={disabled || activeIndex === 0} > - + handleNavigate('next')} disabled={disabled || activeIndex >= signatures.length - 1} > - + @@ -277,7 +277,7 @@ export const SavedSignaturesSection = ({ onClick={() => onDeleteSignature(activeSignature)} disabled={disabled} > - + diff --git a/frontend/src/core/components/tools/sign/SignSettings.tsx b/frontend/src/core/components/tools/sign/SignSettings.tsx index a506eeffb..fb98dd998 100644 --- a/frontend/src/core/components/tools/sign/SignSettings.tsx +++ b/frontend/src/core/components/tools/sign/SignSettings.tsx @@ -314,7 +314,7 @@ const SignSettings = ({ color={isSaved ? 'green' : undefined} onClick={onClick} disabled={!isReady || disabled || isSavedSignatureLimitReached || !hasChanges} - leftSection={} + leftSection={} > {isSaved ? translate('saved.status.saved', 'Saved') : label} @@ -903,7 +903,7 @@ const SignSettings = ({ gap: '0.4rem', }} > - + {translate('mode.pause', 'Pause placement')} @@ -926,7 +926,7 @@ const SignSettings = ({ gap: '0.4rem', }} > - + {translate('mode.resume', 'Resume placement')} diff --git a/frontend/src/core/data/useTranslatedToolRegistry.tsx b/frontend/src/core/data/useTranslatedToolRegistry.tsx index cda99dc40..4cec66eb9 100644 --- a/frontend/src/core/data/useTranslatedToolRegistry.tsx +++ b/frontend/src/core/data/useTranslatedToolRegistry.tsx @@ -203,7 +203,7 @@ export function useTranslatedToolCatalog(): TranslatedToolCatalog { supportsAutomate: false, //TODO make support Sign }, addText: { - icon: , + icon: , name: t('home.addText.title', 'Add Text'), component: AddText, description: t('home.addText.desc', 'Add custom text anywhere in your PDF'),