// Issues & Warnings view — surfaces all validation problems before migration import { state } from './state.js'; import { escHtml, formatDate, renderFieldIssues, bindFieldIssueToggles } from './utils.js'; import { navigate } from './router.js'; export function renderIssues() { const outlet = document.getElementById('router-outlet'); const templates = state.templates || []; const blocked = templates.filter(t => hasBlockers(t)); const warnings = templates.filter(t => !hasBlockers(t) && (hasWarnings(t) || hasFieldIssues(t)) ); if (!state.auth.adobe || !state.auth.docusign) { outlet.innerHTML = `
â„šī¸Connect both platforms to see validation results.
`; return; } if (!blocked.length && !warnings.length) { outlet.innerHTML = `
🎉
All templates are ready!
No validation blockers, warnings, or field mapping caveats found across ${templates.length} template${templates.length !== 1 ? 's' : ''}.
`; return; } outlet.innerHTML = ` ${blocked.length ? `
đŸšĢ Blockers — ${blocked.length} template${blocked.length > 1 ? 's' : ''} will fail migration
${blocked.map(t => _blockerItem(t)).join('')}
` : ''} ${warnings.length ? `
⚠ Caveats — ${warnings.length} template${warnings.length > 1 ? 's' : ''} should be reviewed
${warnings.map(t => _warningItem(t)).join('')}
` : ''} `; // Migrate Anyway buttons document.querySelectorAll('.btn-migrate-anyway').forEach(btn => { btn.addEventListener('click', () => { import('./migration.js').then(m => m.showOptionsModal([btn.dataset.id])); }); }); // View Template links document.querySelectorAll('.btn-view-template').forEach(btn => { btn.addEventListener('click', () => navigate(`#/templates/${btn.dataset.id}`)); }); bindFieldIssueToggles(outlet); } function _blockerItem(t) { const blockers = t.blockers || []; return `
đŸšĢ
${escHtml(t.name)}
${blockers.map(b => `
â€ĸ ${escHtml(b)}
`).join('')}
Modified ${formatDate(t.adobe_modified)}
`; } function _warningItem(t) { const warnings = t.warnings || []; const fieldIssues = t.field_issues || []; return `
âš ī¸
${escHtml(t.name)}
${warnings.slice(0, 3).map(w => `
â€ĸ ${escHtml(w)}
`).join('')} ${warnings.length > 3 ? `
â€Ļ +${warnings.length - 3} more
` : ''} ${fieldIssues.length ? renderFieldIssues(fieldIssues) : ''}
Modified ${formatDate(t.adobe_modified)}
`; } function hasBlockers(t) { return (t.blockers || []).length > 0; } function hasWarnings(t) { return (t.warnings || []).length > 0; } function hasFieldIssues(t) { return (t.field_issues || []).length > 0; }