-
Notifications
You must be signed in to change notification settings - Fork 78
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: add settings tab and toggle for multi lang feature #7561
base: feat/multi-lang-feature
Are you sure you want to change the base?
Conversation
03ab01d
to
ca7584a
Compare
0ab3e87
to
52c66fa
Compare
frontend/src/features/admin-form/settings/SettingsMultiLangPage.tsx
Outdated
Show resolved
Hide resolved
...src/features/admin-form/settings/components/MultiLanguageSection/FormMultiLanguageToggle.tsx
Outdated
Show resolved
Hide resolved
...src/features/admin-form/settings/components/MultiLanguageSection/FormMultiLanguageToggle.tsx
Outdated
Show resolved
Hide resolved
(language: Language) => { | ||
if (supportedLanguages == null) return | ||
|
||
// Remove support for this language if it exists in supportedLanguages |
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.
Suggestion: instead of using comments to describe what
the code is doing, the code should probably be able to explain itself (i prefer reserving comments to describe why
something is done)
The following code block (to line 76) could be replaced with something like this:
// Remove support for this language if it exists in supportedLanguages | |
const isLanguageSupportedPreviously = !!supportedLanguages.find(language) | |
const isAddSupport = !isLanguageSupportedPreviously | |
const updatedSupportedLanguages = isAddSupport | |
? supportedLanguage.concat(language) | |
: supportedLanguages.filter(l => l !== language) | |
setIsLanguageSupported(isAddSupport) | |
return mutateFormSupportedLanguages.mutate({ | |
nextSupportedLanguages: updatedSupportedLanguages, | |
selectedLanguage: language, | |
}) |
</HStack> | ||
)} | ||
</Flex> | ||
{!isLast && <Divider />} |
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.
formsg has a convention to use
{!!isLast ? <Divider /> : null}
instead of using &&
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.
I understand. Just out of curiosity is there any reason why the convention is preferred over using &&
?
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.
I'm not sure, I think it was a practice that has been applied before throughout the codebase (due to the belief that it is more readable) and hence just maintained for overall consistency in the codebase
...src/features/admin-form/settings/components/MultiLanguageSection/FormMultiLanguageToggle.tsx
Outdated
Show resolved
Hide resolved
|
||
mutateFormSupportedLanguages.mutate({ nextSupportedLanguages }) | ||
|
||
return mutateFormHasMultiLang.mutate(nextHasMultiLang) |
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.
not sure but would this cause an inconsistency error if error occurs for this but previous mutation has succeeded?
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.
Thanks for bringing up this scenario. I changed the implementation to only add the array of supported languages in the first instance that the user turns on the toggle for this feature. I also updated the model to have a default false value for the hasMultiLang
attribute. Hence now if the mutation to update the hasMultiLang
attribute fail, the data is not in an inconsistent state because the intended implementation was to still keep the list of supported languages even if the hasMultiLang
value has not been updated. This is to be able to retrieve back the list of supported languages when the user turns the toggle back on.
I hope this clarifies your question.
...src/features/admin-form/settings/components/MultiLanguageSection/FormMultiLanguageToggle.tsx
Outdated
Show resolved
Hide resolved
hi @siddarth2824, In order for us to ensure there are no regressions and everything is working as expected, could you add in the PR description the following:
This also helps me as a reviewer who may not have much context of this feature to avoid missing anything out You may refer to the following PR as reference: PR 7566 |
I have added the screenshots and manual tests that can be run to ensure the functionality works as it should as suggested. Do let me know if anything else is required from my side as I am still getting to used to the team's practices for making PRs. Thanks! |
Hi @siddarth2824, could we add some Chromatic Visual tests for the new settings page tab (& other UI components) as well? the rationale is to provide UI snapshots and prevent future regressions |
Thanks for adding the chromatic tests! |
52c66fa
to
a7de23e
Compare
ddf4eea
to
8e7e0c5
Compare
Context
Changes
hasMultiLang
to indicate if a form supports the multiple languagessupportedLanguages
field, that the a form supportsBefore & After Screenshots
Tests
TC 1: Turning on toggle adds support for default supported languages and sets the
hasMultiLang
attribute to be truesupportedLanguages
field is populated with the default supported languages ([en-SG, zh-SG, ms-SG, ta-SG]
) and thehasMultiLang
value is trueTC 2: Disable and then enable support for a specific language
supportedLanguages
field now contains[en-SG, ms-SG, ta-SG]
supportedLanguages
field now contains[en-SG, ms-SG, ta-SG]