-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: wiki_select.jsx to functional component #5784
base: master
Are you sure you want to change the base?
refactor: wiki_select.jsx to functional component #5784
Conversation
}; | ||
|
||
const url = (wiki) => { | ||
const subdomain = wiki.language || 'www'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This language || 'www'
is duplicated here and is used in other places of the codebase. Maybe a good idea to refactor this into a function and use it everywhere
function getWikiSubdomain(wiki) {
return wiki.language || 'www';
}
const filterOptionsLong = function (val) { | ||
return availableOptions.filter(wiki => | ||
wiki.label.toLowerCase().includes(val.toLowerCase()) | ||
).slice(0, 10); // limit the options for better performance | ||
}; | ||
|
||
// If the input is at least three characters, it will be matched anywhere in the string | ||
|
||
const filterOptionsShort = function (val) { | ||
return availableOptions.filter(wiki => | ||
wiki.label.toLowerCase().includes(val.toLowerCase()) | ||
).slice(0, 10); | ||
}; | ||
|
||
const loadOptions = function (inputValue, callback) { | ||
if (inputValue.length < 3) { | ||
callback(filterOptionsShort(inputValue)); | ||
} | ||
callback(filterOptionsLong(inputValue)); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like filterOptionsLong
and filterOptionsShort
are doing the same thing. Futher more in loadOptions, we are checking for less than 3 but we are not returning within it and calling the callback again outside which does not look right.
What this PR does
Part of #5393 (Component refactor for React class components)
Refactors Class component to a function component for
wiki_select.jsx
Screenshots