11import { html , signal , useEffect } from '../../../deps/htm-preact.js' ;
2- import { STATUS , STRUCTURE_TITLES } from '../checks/constants.js' ;
2+ import { STATUS_TO_ICON_MAP , STRUCTURE_TITLES } from '../checks/constants.js' ;
33import { runChecks as runStructureChecks } from '../checks/structure.js' ;
44import userCanPublishPage from '../../../tools/utils/publish.js' ;
5+ import { runChecks as runLocalizationChecks } from '../checks/localization.js' ;
56
67const DEF_NOT_FOUND = 'Not found' ;
78const DEF_NEVER = 'Never' ;
@@ -20,6 +21,9 @@ const footerResult = signal({ icon: 'purple', title: STRUCTURE_TITLES.footer, de
2021const regionSelectorResult = signal ( { icon : 'purple' , title : STRUCTURE_TITLES . regionSelector , description : 'Checking...' } ) ;
2122const georoutingResult = signal ( { icon : 'purple' , title : STRUCTURE_TITLES . georouting , description : 'Checking...' } ) ;
2223const breadcrumbsResult = signal ( { icon : 'purple' , title : STRUCTURE_TITLES . breadcrumbs , description : 'Checking...' } ) ;
24+ const localizationResult = signal ( { icon : 'purple' , title : 'Links' , description : 'Checking...' } ) ;
25+ const localizationIssues = signal ( [ ] ) ;
26+ const localizationClosed = signal ( false ) ;
2327
2428async function getStructureResults ( ) {
2529 const signals = [
@@ -31,16 +35,9 @@ async function getStructureResults() {
3135 ] ;
3236 const checks = runStructureChecks ( { area : document } ) ;
3337
34- const statusToIconMap = {
35- [ STATUS . PASS ] : 'green' ,
36- [ STATUS . FAIL ] : 'red' ,
37- [ STATUS . LIMBO ] : 'orange' ,
38- [ STATUS . EMPTY ] : 'empty' ,
39- } ;
40-
4138 await Promise . all ( checks . map ( ( result , index ) => Promise . resolve ( result )
4239 . then ( ( res ) => {
43- const icon = statusToIconMap [ res . status ] || 'orange' ;
40+ const icon = STATUS_TO_ICON_MAP [ res . status ] || 'orange' ;
4441 signals [ index ] . value = {
4542 icon,
4643 title : res . title ,
@@ -56,6 +53,24 @@ async function getStructureResults() {
5653 } ) ) ) ;
5754}
5855
56+ async function getLocalizationResults ( ) {
57+ try {
58+ const [ res ] = await runLocalizationChecks ( { area : document } ) ;
59+ localizationResult . value = {
60+ icon : STATUS_TO_ICON_MAP [ res . status ] || 'orange' ,
61+ title : res . title ,
62+ description : res . description ,
63+ } ;
64+ localizationIssues . value = res . details ?. violations || [ ] ;
65+ } catch ( error ) {
66+ localizationResult . value = {
67+ icon : 'red' ,
68+ title : 'Links' ,
69+ description : `Error: ${ error . message } ` ,
70+ } ;
71+ }
72+ }
73+
5974function getAdminUrl ( url , type ) {
6075 if ( ! ( / a d o b e c o m \. ( h l x | a e m ) ./ . test ( url . hostname ) ) ) return false ;
6176 const project = url . hostname === 'localhost' ? 'main--milo--adobecom' : url . hostname . split ( '.' ) [ 0 ] ;
@@ -275,17 +290,45 @@ function ContentGroup({ name, group }) {
275290 </ div > ` ;
276291}
277292
278- export default function General ( ) {
279- useEffect ( ( ) => { setContent ( ) ; getStructureResults ( ) ; } , [ ] ) ;
280-
281- const StructureItem = ( { icon, title, description } ) => html `
293+ function StructureItem ( { icon, title, description } ) {
294+ return html `
282295 < div class ="preflight-item ">
283296 < div class ="result-icon ${ icon } "> </ div >
284297 < div class ="preflight-item-text ">
285298 < p class ="preflight-item-title "> ${ title } </ p >
286299 < p class ="preflight-item-description "> ${ description } </ p >
287300 </ div >
288301 </ div > ` ;
302+ }
303+
304+ function LocalizationIssuesList ( { issues } ) {
305+ return html `
306+ ${ issues . length > 0 && html `
307+ < div class ="preflight-content-group ${ localizationClosed . value ? ' is-closed' : '' } ">
308+ < div class ="preflight-group-row preflight-group-heading " onClick =${ ( ) => { localizationClosed . value = ! localizationClosed . value ; } } >
309+ < div class ="preflight-group-expand "> </ div >
310+ < p class =preflight-content-heading > Faulty links</ p >
311+ < p class ="preflight-content-heading "> Loc</ p >
312+ < p class ="preflight-content-heading "> US status</ p >
313+ < p class ="preflight-content-heading "> Loc status</ p >
314+ </ div >
315+ < div class =preflight-group-items >
316+ ${ issues . map ( ( v ) => html `
317+ < div class ="preflight-group-row preflight-group-detail ">
318+ < p > < a href =${ v . url } target =_blank> ${ v . url } </ a > </ p >
319+ < p > ${ v . isLocalized ? 'Yes' : 'No' } </ p >
320+ < p > ${ v . usStatus } </ p >
321+ < p > ${ v . localizedStatus } </ p >
322+ </ div >
323+ ` ) }
324+ </ div >
325+ </ div >
326+ ` }
327+ ` ;
328+ }
329+
330+ export default function General ( ) {
331+ useEffect ( ( ) => { setContent ( ) ; getStructureResults ( ) ; getLocalizationResults ( ) ; } , [ ] ) ;
289332
290333 const allChecked = Object . values ( content . value )
291334 . flatMap ( ( item ) => item . items ) . filter ( ( item ) => item . checked ) ;
@@ -313,6 +356,14 @@ export default function General() {
313356 < ${ StructureItem } ...${ breadcrumbsResult . value } />
314357 </ div >
315358 </ div >
359+ < p class ="preflight-structure-title "> Localization</ p >
360+ < div class =preflight-structure-columns >
361+ < div class =preflight-column >
362+ < ${ StructureItem } ...${ localizationResult . value } />
363+ </ div >
364+ </ div >
365+ < ${ LocalizationIssuesList } issues =${ localizationIssues . value } />
366+ < p class ="preflight-structure-title "> Content</ p >
316367 ${ Object . keys ( content . value ) . map ( ( key ) => html `< ${ ContentGroup } name =${ key } group=${ content . value [ key ] } /> ` ) }
317368 </ div >
318369
0 commit comments