@@ -25,7 +25,7 @@ export default class ApiClientRegistrationFormComponent extends Component {
2525 @tracked rorUseError = null ;
2626 @tracked selectedInstitution = null ;
2727
28- ROR_API_URL = 'https://api.ror.org/organizations' ;
28+ ROR_API_URL = 'https://api.ror.org/v2/ organizations' ;
2929 countries = countries ;
3030
3131 get isFormInvalid ( ) {
@@ -96,6 +96,16 @@ export default class ApiClientRegistrationFormComponent extends Component {
9696 return text ? this . sanitizer . sanitize ( text ) . substring ( 0 , 500 ) : null ;
9797 }
9898
99+ _getDisplayOrganizationName ( item ) {
100+ if ( item . names && item . names . length > 0 ) {
101+ const displayName = item . names . find ( nameObj =>
102+ nameObj . types && nameObj . types . includes ( 'ror_display' )
103+ ) ;
104+ return displayName ? displayName . value : item . names [ 0 ] . value ;
105+ }
106+ return item . name || '' ;
107+ }
108+
99109 @action
100110 async searchOrganizations ( searchTerm ) {
101111 if ( ! searchTerm || searchTerm . length < 2 ) {
@@ -106,17 +116,22 @@ export default class ApiClientRegistrationFormComponent extends Component {
106116 `${ this . ROR_API_URL } ?query=${ encodeURIComponent ( searchTerm ) } `
107117 ) ;
108118 const data = await response . json ( ) ;
109- let results = data . items || [ ] ;
110- const exactMatch = results . some (
111- item => item . name . toLowerCase ( ) === searchTerm . toLowerCase ( )
119+ let results = data . items . map ( item => ( {
120+ id : item . id ,
121+ name : this . _getDisplayOrganizationName ( item ) ,
122+ original_item : item
123+ } ) ) ;
124+ const exactMatch = results . some ( item =>
125+ item . original_item . names . some ( nameObj => nameObj . value . toLowerCase ( ) === searchTerm . toLowerCase ( ) )
112126 ) ;
113127 if ( ! exactMatch ) {
114128 const sanitizedInput = this . sanitizeInput ( searchTerm ) ;
115129 results = [
116130 {
117131 name : sanitizedInput ,
118132 id : null ,
119- isManualEntry : true
133+ isManualEntry : true ,
134+ original_item : null
120135 } ,
121136 ...results
122137 ]
@@ -127,7 +142,8 @@ export default class ApiClientRegistrationFormComponent extends Component {
127142 return [ {
128143 name : this . sanitizeInput ( searchTerm ) ,
129144 id : null ,
130- isManualEntry : true
145+ isManualEntry : true ,
146+ original_item : null
131147 } ] ;
132148 }
133149 }
0 commit comments