1- import { Component , Input , OnInit } from '@angular/core'
1+ import { Component , Input , OnChanges , OnInit , SimpleChanges } from '@angular/core'
22import { RecordImportWizard } from '../../../types/record-peer-review-import.endpoint'
33
44@Component ( {
@@ -7,13 +7,64 @@ import { RecordImportWizard } from '../../../types/record-peer-review-import.end
77 styleUrls : [ './search-link-wizard.component.scss' ] ,
88 standalone : false ,
99} )
10- export class SearchLinkWizardComponent implements OnInit {
10+ export class SearchLinkWizardComponent implements OnInit , OnChanges {
1111 @Input ( ) recordImportWizards : RecordImportWizard [ ]
1212
13+ certifiedWizards : RecordImportWizard [ ] = [ ]
14+ featuredWizards : RecordImportWizard [ ] = [ ]
15+ defaultWizards : RecordImportWizard [ ] = [ ]
16+
1317 constructor ( ) { }
1418
1519 ngOnInit ( ) : void { }
1620
21+ ngOnChanges ( changes : SimpleChanges ) : void {
22+ if ( changes . recordImportWizards ) {
23+ this . groupWizards ( )
24+ }
25+ }
26+
27+ displayDescription ( recordImportWizard : RecordImportWizard ) : string {
28+ return (
29+ recordImportWizard ?. redirectUriMetadata ?. defaultDescription ||
30+ recordImportWizard ?. description ||
31+ ''
32+ )
33+ }
34+
35+ private groupWizards ( ) : void {
36+ const wizards = this . recordImportWizards || [ ]
37+
38+ const certified : RecordImportWizard [ ] = [ ]
39+ const featured : RecordImportWizard [ ] = [ ]
40+ const defaults : RecordImportWizard [ ] = [ ]
41+
42+ for ( const w of wizards ) {
43+ const type = w ?. redirectUriMetadata ?. type || 'Default'
44+ if ( type === 'Certified' ) {
45+ certified . push ( w )
46+ } else if ( type === 'Featured' ) {
47+ featured . push ( w )
48+ } else {
49+ defaults . push ( w )
50+ }
51+ }
52+
53+ const sortByIndexThenName = ( a : RecordImportWizard , b : RecordImportWizard ) => {
54+ const ai = a ?. redirectUriMetadata ?. index ?? Number . POSITIVE_INFINITY
55+ const bi = b ?. redirectUriMetadata ?. index ?? Number . POSITIVE_INFINITY
56+ if ( ai !== bi ) return ai - bi
57+ return ( a ?. name || '' ) . localeCompare ( b ?. name || '' )
58+ }
59+
60+ const sortByName = ( a : RecordImportWizard , b : RecordImportWizard ) =>
61+ ( a ?. name || '' ) . localeCompare ( b ?. name || '' )
62+
63+ this . certifiedWizards = certified . sort ( sortByIndexThenName )
64+ this . featuredWizards = featured . sort ( sortByIndexThenName )
65+ this . defaultWizards = defaults . sort ( sortByName )
66+ }
67+
1768 openImportWizardUrlFilter ( client : RecordImportWizard ) : string {
1869 if ( client . status === 'RETIRED' ) {
1970 return client . clientWebsite
0 commit comments