Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

prathamVaidya
Copy link
Contributor

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

image

};

const url = (wiki) => {
const subdomain = wiki.language || 'www';
Copy link
Contributor

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';
}

Comment on lines +89 to +108
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));
};
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants