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: add form field list for translation #7778

Open
wants to merge 6 commits into
base: feat/multi-lang-feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/src/app/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ export const AppRouter = (): JSX.Element => {
>
<Route index element={<CreatePage />} />
<Route path={ADMINFORM_SETTINGS_SUBROUTE} element={<SettingsPage />}>
<Route path={':settingsTab'} element={<SettingsPage />} />
<Route path={':settingsTab'} element={<SettingsPage />}>
<Route path={':language'} element={<SettingsPage />} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible to use frontend/src/features/admin-form/settings/SettingsPage.tsx::tabConfig to manage the deeplink for language? -- since language seemed to be a subpath of SettingsPage

</Route>
</Route>
<Route
path={ADMINFORM_RESULTS_SUBROUTE}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Meta, Story } from '@storybook/react'
import { Meta, StoryFn } from '@storybook/react'

import { FormSettings, Language } from '~shared/types'
import {
FormColorTheme,
FormLogoState,
FormSettings,
Language,
} from '~shared/types'

import {
createFormBuilderMocks,
getAdminFormSettings,
MOCK_FORM_FIELDS_WITH_NO_TRANSLATIONS,
MOCK_FORM_FIELDS_WITH_TRANSLATIONS,
patchAdminFormSettings,
} from '~/mocks/msw/handlers/admin-form'

Expand All @@ -29,15 +37,23 @@ const buildMswRoutes = ({
export default {
title: 'Pages/AdminFormPage/Settings/MultiLang',
component: SettingsMultiLangPage,
decorators: [StoryRouter({ initialEntries: ['/12345'], path: '/:formId' })],
decorators: [
StoryRouter({
initialEntries: ['/61540ece3d4a6e50ac0cc6ff'],
path: '/:formId',
}),
],
parameters: {
// Required so skeleton "animation" does not hide content.
chromatic: { pauseAnimationAtEnd: true },
msw: buildMswRoutes(),
},
} as Meta

const Template: Story = () => <SettingsMultiLangPage />
const Template: StoryFn = () => <SettingsMultiLangPage />

// Stories related to toggling multi language translation feature on and off
// and choosing which language to enable translations for
export const MultiLangNotSelected = Template.bind({})
MultiLangNotSelected.parameters = {
msw: buildMswRoutes({
Expand All @@ -62,6 +78,70 @@ MultiLangEnglishChineseMalaySelected.parameters = {
}),
}

// Stories related to displaying list of form fields for translations
export const MultiLangListOfFormFieldsWithNoTranslations = Template.bind({})
MultiLangListOfFormFieldsWithNoTranslations.parameters = {
router: {
initialEntries: ['/61540ece3d4a6e50ac0cc6ff/settings/multi-language/zh-SG'],
path: '/:formId/settings/multi-language/:language',
},
msw: [
...createFormBuilderMocks({
form_fields: MOCK_FORM_FIELDS_WITH_NO_TRANSLATIONS,
startPage: {
colorTheme: FormColorTheme.Blue,
logo: { state: FormLogoState.Default },
paragraph: 'Test start page',
},
}),
getAdminFormSettings(),
patchAdminFormSettings(),
],
}

export const MultiLangListOfFormFieldsWithCompletedTranslations = Template.bind(
{},
)
MultiLangListOfFormFieldsWithCompletedTranslations.parameters = {
router: {
initialEntries: ['/61540ece3d4a6e50ac0cc6ff/settings/multi-language/zh-SG'],
path: '/:formId/settings/multi-language/:language',
},
msw: [
...createFormBuilderMocks({
form_fields: MOCK_FORM_FIELDS_WITH_TRANSLATIONS,
// Completed translations for start page
startPage: {
colorTheme: FormColorTheme.Blue,
logo: { state: FormLogoState.Default },
paragraph: 'Test start page',
paragraphTranslations: [
{ language: Language.CHINESE, translation: 'Fake Translations' },
],
},
// Completed translations for end page
endPage: {
title: 'Thank you for filling out the form.',
titleTranslations: [
{ language: Language.CHINESE, translation: 'Fake Title Translation' },
],
paragraph: 'Test end page paragraph',
paragraphTranslations: [
{
language: Language.CHINESE,
translation: 'Fake Paragraph Translation',
},
],
buttonText: 'Submit another form',
paymentTitle: 'payment title',
paymentParagraph: 'payment paragraph',
},
}),
getAdminFormSettings(),
patchAdminFormSettings(),
],
}

export const Loading = Template.bind({})
Loading.parameters = {
msw: buildMswRoutes({ delay: 'infinite' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { useParams } from 'react-router-dom'

import { MultiLanguageSection } from './components/MultiLanguageSection/MultiLanguageSection'
import { TranslationListSection } from './components/MultiLanguageSection/TranslationListSection'

export const SettingsMultiLangPage = (): JSX.Element => {
return <MultiLanguageSection />
const { language } = useParams()

return (
<>
{!language ? <MultiLanguageSection /> : null}
{language ? <TranslationListSection language={language} /> : null}
Comment on lines +11 to +12
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
{!language ? <MultiLanguageSection /> : null}
{language ? <TranslationListSection language={language} /> : null}
{language ? <TranslationListSection language={language} /> : <MultiLanguageSection />}

</>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useState } from 'react'
import { BiEditAlt } from 'react-icons/bi'
import { GoEye, GoEyeClosed } from 'react-icons/go'
import { useNavigate, useParams } from 'react-router-dom'
import {
Box,
Divider,
Expand All @@ -14,6 +15,7 @@ import _ from 'lodash'

import { Language } from '~shared/types'

import { ADMINFORM_ROUTE } from '~constants/routes'
import {
convertUnicodeLocaleToLanguage,
getDefaultSupportedLanguages,
Expand All @@ -40,7 +42,9 @@ const LanguageTranslationRow = ({
isDefaultLanguage,
isLast,
}: LanguageTranslationRowProps): JSX.Element => {
const { formId } = useParams()
const { data: settings } = useAdminFormSettings()
const navigate = useNavigate()

const supportedLanguages = settings?.supportedLanguages ?? null

Expand Down Expand Up @@ -74,6 +78,15 @@ const LanguageTranslationRow = ({
[mutateFormSupportedLanguages, supportedLanguages],
)

const handleLanguageTranslationEditClick = useCallback(
(language: Language) => {
navigate(
`${ADMINFORM_ROUTE}/${formId}/settings/multi-language/${language.toString()}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Possible to move this to frontend/src/features/public-form/utils/urls.ts since this might be a little complex and we might want to have some type-safety on the language variable.

  2. Looking at the multi-language path again, I feel that we could use /language instead of /multi-language since we're manipulating the "language" settings.

)
},
[formId, navigate],
)

return (
<>
<Flex alignItems="center" w="100%" py={2}>
Expand Down Expand Up @@ -109,7 +122,9 @@ const LanguageTranslationRow = ({
colorScheme="secondary"
aria-label={`Add ${unicodeLocale} translations`}
// TODO: Will add redirection to translation section in next PR
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this comment can now be removed 😆

onClick={() => console.log('Edit translations')}
onClick={() =>
handleLanguageTranslationEditClick(unicodeLocale)
}
/>
</Tooltip>
</HStack>
Expand Down
Loading
Loading