Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

fix: correctly select and use user locale and application title text [DHIS2-8525] [DHIS2-8723] #399

Merged
merged 5 commits into from
May 15, 2020

Conversation

amcgee
Copy link
Member

@amcgee amcgee commented May 15, 2020

This does a few things, all related to the two localization issues with the headerbar (DHIS2-8525 and DHIS2-8723

  1. Update all i18n.t calls so that they are called at render time, not at module initialization
  2. Remove the API call to systemInfo since it loads a bunch of security-sensitive information. It was only used for (a) contextPath (which we can retrieve statically from the config context in app-runtime) and (b) systemName which is untranslated and replaced with applicationTitle below
  3. Fetch systemSettings/applicationTitle which is the user-localized title for display in headerBar
  4. Change useEffect to useMemo, to avoid needing a duplicate render (useEffect runs after first paint) and to avoid mutating the API response data (it should be treated as immutable)
  5. Don't propagate contextPath throughout all components, instead loading the baseUrl from the config context in app-runtime wherever the baseUrl is actually needed. Note that this is slightly brittle as-written since it makes the assumption that baseUrl ends in a / character. We should probably change this to joinPath(baseUrl, relativePath) (a utility function we have in app-runtime but don't expose)
  6. Ensure that we always set the locale to the user locale and the i18next namespace to default, even if we end up with a different singleton than the app uses (app-shell does this, so it should be a no-op in that environment).
  7. Add a localization story with franglish strings
  8. Update fixtures and cypress tests

I'd like to merge this to the alpha branch if it looks decent for testing in several apps, to avoid possible local dependency link issues.

@amcgee amcgee requested a review from Mohammer5 May 15, 2020 12:56
@amcgee amcgee requested a review from a team as a code owner May 15, 2020 12:56
@@ -66,7 +69,7 @@ function Search({ value, onChange, onIconClick, contextPath }) {
</span>

<span>
<a href={`${contextPath}/dhis-web-menu-management`}>
<a href={`${baseUrl}dhis-web-menu-management`}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to copy the joinPath helper for now (until exposed by app-runtime).
This seems too brittle and could break instances.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, will do

const baseUrl = useConfig().baseUrl
return (
<a
href={`${baseUrl}/dhis-web-user-profile/#/profile`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Contrary to the Apps.js, this one adds a slash. I think I've seen it in other files also.
We could just copye the joinPath as mentioned above

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, this is incorrect

Comment on lines 1 to 3
import '../common/index.js'
import { Then } from 'cypress-cucumber-preprocessor/steps'
import { baseUrl } from '../common/index.js'
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the import in line 3 should be enough and we can remove the one in line 1

@amcgee amcgee merged commit a7cb026 into alpha May 15, 2020
@amcgee amcgee deleted the fix/correct-locale-selection branch May 15, 2020 14:09
github-actions bot pushed a commit that referenced this pull request May 15, 2020
## [2.1.1-alpha.1](v2.1.0...v2.1.1-alpha.1) (2020-05-15)

### Bug Fixes

* correctly select and use user locale and application title text [DHIS2-8525] [DHIS2-8723] ([#399](#399)) ([a7cb026](a7cb026))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 2.1.1-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@amcgee amcgee mentioned this pull request May 18, 2020
amcgee added a commit that referenced this pull request May 18, 2020
amcgee pushed a commit that referenced this pull request May 18, 2020
## [2.1.1-alpha.1](v2.1.0...v2.1.1-alpha.1) (2020-05-15)

### Bug Fixes

* correctly select and use user locale and application title text [DHIS2-8525] [DHIS2-8723] ([#399](#399)) ([a7cb026](a7cb026))
amcgee added a commit that referenced this pull request May 18, 2020
github-actions bot pushed a commit that referenced this pull request May 19, 2020
## [2.1.1](v2.1.0...v2.1.1) (2020-05-19)

### Bug Fixes

* correctly select and use user locale and application title text [DHIS2-8525] [DHIS2-8723] ([#399](#399)) ([404428a](404428a))
* escape regex special chars in search ([451284a](451284a))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants