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

feat: added autocomplete for language codes #117

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

shubham-1806
Copy link
Contributor

What

Added Autocomplete for selecting language code wherever necessary using autocomplete component of MUI.

Screenshot

image

Fixes bug(s)

Fixes #107

Copy link
Collaborator

@aadarsh-ram aadarsh-ram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubham-1806 Thank you for the good work! There are some changes that I have requested, which can be easily rectified. The autocomplete component's usage is very good and clean!

taxonomy-editor-frontend/src/constants.js Outdated Show resolved Hide resolved
taxonomy-editor-frontend/src/pages/allentries/index.jsx Outdated Show resolved Hide resolved
taxonomy-editor-frontend/src/pages/allentries/index.jsx Outdated Show resolved Hide resolved
@shubham-1806
Copy link
Contributor Author

@aadarsh-ram Please review the changes

Copy link
Collaborator

@aadarsh-ram aadarsh-ram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @shubham-1806! I'd like @nobeeakon to review this as well.

@@ -17,3 +17,189 @@ function taxonomyApiUrlFromUi(location) {
}
export const API_URL = taxonomyApiUrlFromUi(window.location);
export const ENTER_KEYCODE = 13;
export const ISO_CODES ={
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get this from the library? I think it is going to be difficult to maintain this

options={Object.keys(ISO_CODES)}
onChange={(e,language) => {
setNewLanguageCode(ISO_CODES[language]);
setIsValidLanguageCode(ISO6391.validate(ISO_CODES[language]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess this could be a derived state:

const isValidLanguageCode  = ISO6391.validate(newLanguageCode)

instead of a useState

onChange={(e,language) => {
setNewLanguageCode(ISO_CODES[language]);
const validateBool = ISO6391.validate(ISO_CODES[language])
const ifDuplicateBool = renderedTranslations.some(el => (el.languageCode === ISO_CODES[language])) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's rename these two: isValidLanguage and isDuplicateLanguage?

Copy link
Collaborator

@nobeeakon nobeeakon Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess this could be a derived state:

const isValidLanguageCode  = ISO6391.validate(newLanguageCode)
...

instead of a useState

options={Object.keys(ISO_CODES)}
onChange={(e,language) => {
setNewLanguageCode(ISO_CODES[language]);
setIsValidLanguageCode(ISO6391.validate(ISO_CODES[language]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess this could be a derived state:

const isValidLanguageCode  = ISO6391.validate(newLanguageCode)

instead of a useState

setNewLanguageCode(e.target.value);
setIsValidLanguageCode(ISO6391.validate(e.target.value));
<Autocomplete
options={Object.keys(ISO_CODES)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we don't need to have the ISO_CODES const. Please check the iso-639-1 package docs, we can obtain the names and extract the codes with it.

}}
label="Language Code"
error={!isValidLanguageCode}
renderInput={(params) => <TextField error={!isValidLanguageCode} {...params} label="Languages" />}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does it needs a helper text as the other one?

Copy link
Collaborator

@nobeeakon nobeeakon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR , nice work, just please replace the ISO_CODES , think we can use the features that the iso-639-1 package already gives us

@nobeeakon nobeeakon changed the title feat: added autocomplete for language codes frontend: feat: added autocomplete for language codes Oct 23, 2022
@nobeeakon nobeeakon changed the title frontend: feat: added autocomplete for language codes feat: added autocomplete for language codes Oct 23, 2022
@shubham-1806 shubham-1806 reopened this Nov 14, 2022
Copy link
Collaborator

@nobeeakon nobeeakon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work !!

@aadarsh-ram aadarsh-ram merged commit 7d8863a into openfoodfacts:main Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Add autocomplete for language codes in frontend
3 participants