Skip to content

Commit

Permalink
fix: Country metadata qualification wasn't correctly editable
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Dec 18, 2024
1 parent a097683 commit 2d15efc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
15 changes: 8 additions & 7 deletions docs/papersDefinitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The `front` and `back` entries have exactly the same structure and attributes.
- `[multipage]`: {boolean} Allows to add as many files as the user wants.
- `illustration`: {string} Name of the illustration used on the step (with extension).
- `text`: {string} Translation key for the text of the step.
- `[isDisplayed]`: {`ocr`|`all`} Determine if the step should be shown.
- `[isDisplayed]`: {`ocr`|`all`|`none`} Determine if the step should be shown.

<br>

Expand All @@ -76,31 +76,32 @@ The `front` and `back` entries have exactly the same structure and attributes.
- [`radio`](#information-field-attributes): {object} Fields used to enter a radio list.
- [`contact`](#information-field-attributes): {object} Fields used to select a contact.
- `country`: {string} Displays a list of countries with search fields.
- `[isDisplayed]`: {`ocr`|`all`} Determine if the step should be shown.
- `[isDisplayed]`: {`ocr`|`all`|`none`} Determine if the step should be shown.

<br>

- ### Step `contact`:
- `model`: {string} Model used for the step (`contact`).
- `text`: {string} Translation key for the text of the step.
- `[multiple]`: {boolean} Allows you to add multiple contacts.
- `[isDisplayed]`: {`ocr`|`all`} Determine if the step should be shown.
- `[isDisplayed]`: {`ocr`|`all`|`none`} Determine if the step should be shown.

<br>

- ### Step `note`:
- `model`: {string} Model used for the step (`note`)
- `[isDisplayed]`: {`ocr`|`all`} Determine if the step should be shown.
- `[isDisplayed]`: {`ocr`|`all`|`none`} Determine if the step should be shown.

***

## Manage the display of informations

The `isDisplayed` property manages the display of steps. Its different values display the step according to the context:
The `isDisplayed` property manages the display of steps in the paper creation flow. Its different values display the step according to the context:

- `ocr` displayes the step when OCR is activated
- `ocr` displayes the step only when OCR is activated
- `undefined` always shows the step
- `all` displayes the step in any case
- `all` displayes the step in any case (OCR and not OCR)
- `none` never shows the step. Usefull to get the step in the edition process, but not in the creation flow.

## Information field attributes:

Expand Down
7 changes: 5 additions & 2 deletions src/components/ModelSteps/Edit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import set from 'lodash/set'
import { CONTACTS_DOCTYPE, FILES_DOCTYPE } from 'src/constants'

import { getReferencedBy } from 'cozy-client'
import { isForeignPaper } from 'cozy-client/dist/models/paper'

/**
* Checks if the edition of the metadata of type "Information" is permitted
Expand Down Expand Up @@ -117,8 +118,10 @@ export const updateReferencedContact = async ({
export const getPaperDefinitionByFile = (papersDefinitions, file) => {
return papersDefinitions.find(paper => {
const countryCondition =
file.metadata.country && paper.country
? paper.country === 'foreign'
Object.keys(file.metadata).includes('country') && paper.country
? isForeignPaper(file)
? paper.country === 'foreign'
: paper.country === 'fr'
: true

return paper.label === file.metadata.qualification.label && countryCondition
Expand Down
4 changes: 2 additions & 2 deletions src/components/ModelSteps/Edit/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ describe('getPaperDefinitionByFile', () => {

expect(res).toMatchObject({
label: 'driver_license',
country: 'foreign'
country: 'fr'
})
})

Expand All @@ -438,7 +438,7 @@ describe('getPaperDefinitionByFile', () => {

expect(res).toMatchObject({
label: 'driver_license',
country: 'foreign'
country: 'fr'
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/filterSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const filterSteps = async ({
if (isOCR) {
return step.isDisplayed === 'all' || step.isDisplayed === 'ocr'
} else {
return step?.isDisplayed !== 'ocr'
return step?.isDisplayed !== 'ocr' && step?.isDisplayed !== 'none'
}
})

Expand Down
25 changes: 25 additions & 0 deletions src/papersDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@
"text": "PaperJSON.generic.back.text",
"isDisplayed": "all"
},
{
"model": "information",
"illustration": "Planet.svg",
"text": "PaperJSON.generic.foreign.country.text",
"attributes": [
{
"name": "country",
"type": "country",
"inputLabel": "PaperJSON.generic.foreign.country.inputLabel"
}
],
"isDisplayed": "none"
},
{
"model": "information",
"illustration": false,
Expand Down Expand Up @@ -907,6 +920,18 @@
"text": "PaperJSON.card.back.text",
"isDisplayed": "all"
},
{
"model": "information",
"illustration": "Planet.svg",
"text": "PaperJSON.generic.foreign.country.text",
"attributes": [
{
"name": "country",
"type": "country",
"inputLabel": "PaperJSON.generic.foreign.country.inputLabel"
}
]
},
{
"model": "information",
"illustration": false,
Expand Down

0 comments on commit 2d15efc

Please sign in to comment.