Skip to content

Commit

Permalink
feat: do not display empty respondents lists
Browse files Browse the repository at this point in the history
  • Loading branch information
chloe-renaud committed Dec 18, 2024
1 parent 7f4d800 commit 43dfa63
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
20 changes: 9 additions & 11 deletions src/components/orchestrator/customPages/WelcomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function renderMetadataContents(contents: Contents[] | undefined) {
}

/** Page displayed when the user first arrives on the orchestrator */
export function WelcomePage(props: { metadata: Metadata }) {
export function WelcomePage(props: Readonly<{ metadata: Metadata }>) {
const { t } = useTranslation({ WelcomePage })
const { metadata } = props
const { resolveLocalizedString } = useResolveLocalizedString({
Expand All @@ -55,16 +55,14 @@ export function WelcomePage(props: { metadata: Metadata }) {
useDocumentTitle(t('document title'))

return (
<>
<div className={fr.cx('fr-my-4w')}>
<h1>{t('title')}</h1>
<p className={fr.cx('fr-text--lead')}>
{resolveLocalizedString(metadata.objectives)}
</p>
{renderMetadataContents(metadata.campaignInfo)}
{renderMetadataContents(metadata.surveyUnitInfo)}
</div>
</>
<div className={fr.cx('fr-my-4w')}>
<h1>{t('title')}</h1>
<p className={fr.cx('fr-text--lead')}>
{resolveLocalizedString(metadata.objectives)}
</p>
{renderMetadataContents(metadata.campaignInfo)}
{renderMetadataContents(metadata.surveyUnitInfo)}
</div>
)
}

Expand Down
43 changes: 43 additions & 0 deletions src/utils/convertOldPersonalization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { convertOldPersonalization } from './convertOldPersonalization'

test.each([
[undefined, undefined],
[[], undefined],
[[{ name: 'invalid-key', value: 'Three-headed monkey' }], undefined],
[
[
{ name: 'whoAnswers1', value: 'Guybrush Threepwood' },
{ name: 'whoAnswers2', value: 'Three-headed monkey' },
],
[
{
title: 'Qui doit répondre à ce questionnaire ?',
contentBlocks: [
{
type: 'list',
textItems: ['Guybrush Threepwood', 'Three-headed monkey'],
},
],
},
],
],
[
[
{ name: 'whoAnswers1', value: 'Guybrush Threepwood' },
{ name: 'invalid-key', value: 'Three-headed monkey' },
],
[
{
title: 'Qui doit répondre à ce questionnaire ?',
contentBlocks: [
{
type: 'list',
textItems: ['Guybrush Threepwood'],
},
],
},
],
],
])('Convert old personalization', (input, res) => {
expect(convertOldPersonalization(input)).toEqual(res)
})
4 changes: 2 additions & 2 deletions src/utils/convertOldPersonalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type { SurveyUnitMetadata } from '@/models/api'

const keysToExtract = ['whoAnswers1', 'whoAnswers2', 'whoAnswers3']

export function convertContent(
function convertContent(
personalization: SurveyUnitMetadata['personalization'],
): Content | undefined {
const textItems = personalization
?.filter((item) => keysToExtract.includes(item.name) && item.value !== '')
.map((item) => item.value)

if (textItems === undefined) return undefined
if (textItems === undefined || textItems.length === 0) return undefined
return {
type: 'list',
textItems,
Expand Down
5 changes: 5 additions & 0 deletions website/src/pages/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 1.3.3

#### QoL
- on n'affiche plus la rubrique "Qui doit répondre" quand elle est vide

### 1.3.2

#### Montée de version Lunatic
Expand Down

0 comments on commit 43dfa63

Please sign in to comment.