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

Feature/deseng623 Add language selector UI based roughly on ISO 639 codes #2540

Merged
merged 9 commits into from
Jun 19, 2024

Conversation

Baelx
Copy link
Collaborator

@Baelx Baelx commented Jun 17, 2024

Issue #: https://github.com/bcgov/met-public/issues/

Description of changes:

  • Add admin UI for tenant language selection, allows user to add/remove language mappings
  • Add API routes for tenant-language mappings
  • Restrict some Language API routes and store languages directly in the DB
  • Add tests, merge migrations, clean up code

Note for reviewer Most of this work has already been reviewed. This PR merges that previous work into main and introduces new code for:

  • language-tenant API routes
  • fixing migrations
  • tests (frontend and backend)

Baelx and others added 7 commits June 4, 2024 15:33
* DESENG-632 Add DB tables & API routes

* DESENG-623 fix linting

* DESENG-623 Move language to migration file, remove delete crud language route

* DESENG-623 Remove ability to delete language

---------

Co-authored-by: Alex <[email protected]>
… short name (#2538)

* DESENG-623 Add frontend, update backend routes

* DESENG-623 Add api route updates, correct linting

* DESENG-623 Correctly invoke autocomplete api to disable claering

---------

Co-authored-by: Alex <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 59.01639% with 25 lines in your changes missing coverage. Please review.

Project coverage is 75.93%. Comparing base (8512584) to head (47a99b8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2540      +/-   ##
==========================================
- Coverage   75.98%   75.93%   -0.05%     
==========================================
  Files         603      604       +1     
  Lines       21800    21807       +7     
  Branches     1678     1689      +11     
==========================================
- Hits        16564    16559       -5     
- Misses       4974     4985      +11     
- Partials      262      263       +1     
Flag Coverage Δ
metweb 64.52% <59.01%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
met-api/src/met_api/models/__init__.py 100.00% <ø> (ø)
met-api/src/met_api/models/language.py 94.73% <ø> (-2.41%) ⬇️
met-api/src/met_api/resources/language.py 79.24% <ø> (+5.82%) ⬆️
met-api/src/met_api/services/language_service.py 94.44% <ø> (+7.77%) ⬆️
met-api/src/met_api/utils/roles.py 100.00% <ø> (ø)
met-web/src/apiManager/endpoints/index.ts 100.00% <ø> (ø)
met-web/src/components/language/index.tsx 59.01% <59.01%> (ø)

Copy link
Contributor

@NatSquared NatSquared left a comment

Choose a reason for hiding this comment

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

Looks good! A few things to review but all in all this seems like a robust start to the language system!

## Languages

The list of languages in `versions/c656f3f82334_add_languages_and_tenant_mapping.py` has been taken from [https://www.w3schools.com/tags/ref_language_codes.asp](https://www.w3schools.com/tags/ref_language_codes.asp) and modified slightly to remove duplicate or multiple language codes per language.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you starting a pattern of documenting large data dumps with their migration IDs? I see promise in that approach!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I kinda thought it would be nice to have transparency with this migration anyway! Just to let future devs know we didn't pull this list out of nowhere

@@ -8,6 +8,9 @@
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# Enables albemic CLI commands like 'history,' 'branches,' etc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this shortcut! Just double-check the spelling of "alembic":

Suggested change
# Enables albemic CLI commands like 'history,' 'branches,' etc.
# Enables Alembic CLI commands like 'history,' 'branches,' etc.

@@ -0,0 +1,27 @@
"""
Merge albembic revisions that:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Merge albembic revisions that:
Merge Alembic revisions that:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lol, I'm getting creative with the spelling a few different ways

"iso_code": "ce"
},
{
"language": "Chichewa, Chewa, Nyanja",
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we are intentionally remaining neutral in the cases where languages have multiple names

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind; this is specified in the ticket

const mockSecondLanguage = {
id: 90,
code: 'tlh',
name: 'Klingon',
Copy link
Contributor

Choose a reason for hiding this comment

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

I like these test languages! 😉

test('Language selection updates', async () => {
await addOrRemoveLanguage('gdx', [mockLanguage, mockSecondLanguage], [mockLanguage]);
expect(languageService.postTenantLanguage).toHaveBeenCalledWith('gdx', mockSecondLanguage.id);
await addOrRemoveLanguage('gdx', [mockLanguage], [mockLanguage, mockSecondLanguage]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding high-quality tests for your components! If it's not too much work, consider also using fired events to replicate actual user keystrokes and clicks on the DOM.


def upgrade():
for index, value in enumerate(language_data):
op.execute("INSERT INTO language (created_date, updated_date, id, name, code) VALUES ('{0}', '{0}', '{1}', '{2}', '{3}')".format(sa.func.now(), index, value['language'], value['iso_code']))
Copy link
Contributor

Choose a reason for hiding this comment

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

to avoid ID collisions, you may want to drop the existing languages in the table, unless this table is known to be empty

@@ -876,8 +869,7 @@ def factory_enagement_content_model(
def engagement_content_model_with_language():
"""Produce a engagement content model instance with language."""
content_model = factory_enagement_content_model()
language_model = factory_language_model({'code': 'en', 'name': 'English'})
return content_model, language_model
return content_model
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is now just a wrapper for factory_enagement_content_model() and should be replaced with such to avoid redundancy.

Copy link

sonarcloud bot commented Jun 19, 2024

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Baelx Baelx merged commit 502fece into main Jun 19, 2024
15 checks passed
@Baelx Baelx deleted the feature/deseng623 branch June 19, 2024 00:29
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.

3 participants