Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions app/components/organizations/api-client-registration-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class ApiClientRegistrationFormComponent extends Component {
@tracked rorUseError = null;
@tracked selectedInstitution = null;

ROR_API_URL = 'https://api.ror.org/organizations';
ROR_API_URL = 'https://api.ror.org/v2/organizations';
countries = countries;

get isFormInvalid() {
Expand Down Expand Up @@ -96,6 +96,16 @@ export default class ApiClientRegistrationFormComponent extends Component {
return text ? this.sanitizer.sanitize(text).substring(0, 500) : null;
}

_getDisplayOrganizationName(item) {
if (item.names && item.names.length > 0) {
const displayName = item.names.find(nameObj =>
nameObj.types && nameObj.types.includes('ror_display')
);
return displayName ? displayName.value : item.names[0].value;
}
return item.name || '';
}

@action
async searchOrganizations(searchTerm) {
if (!searchTerm || searchTerm.length < 2) {
Expand All @@ -106,17 +116,22 @@ export default class ApiClientRegistrationFormComponent extends Component {
`${this.ROR_API_URL}?query=${encodeURIComponent(searchTerm)}`
);
const data = await response.json();
let results = data.items || [];
const exactMatch = results.some(
item => item.name.toLowerCase() === searchTerm.toLowerCase()
let results = data.items.map(item => ({
id: item.id,
name: this._getDisplayOrganizationName(item),
original_item: item
}));
const exactMatch = results.some(item =>
item.original_item.names.some(nameObj => nameObj.value.toLowerCase() === searchTerm.toLowerCase())
);
if (!exactMatch) {
const sanitizedInput = this.sanitizeInput(searchTerm);
results = [
{
name: sanitizedInput,
id: null,
isManualEntry: true
isManualEntry: true,
original_item: null
},
...results
]
Expand All @@ -127,7 +142,8 @@ export default class ApiClientRegistrationFormComponent extends Component {
return [{
name: this.sanitizeInput(searchTerm),
id: null,
isManualEntry: true
isManualEntry: true,
original_item: null
}];
}
}
Expand Down
Loading