Skip to content

Commit

Permalink
feat(ExpandedAttributes): Add some translated attributes as expanded
Browse files Browse the repository at this point in the history
For these attributes, we want to display them as expanded attributes
  • Loading branch information
JF-Cozy committed Apr 5, 2023
1 parent 5848c1d commit 866bb00
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
19 changes: 4 additions & 15 deletions react/MuiCozyTheme/ListItem/ExpandedAttributes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,23 @@ import { formatDate } from '../../../Viewer/helpers'

export const normalizeExpandedAttribute = attr =>
attr
.split('[]')[0]
.replace(':', '.')
.replaceAll(':', '.')
.replace('flexsearchProps.', '')
.replace('translated.', '')

// attributes not considered as expanded attributes
export const notExpandedAttributes = {
'io.cozy.contacts': [
'fullname',
'civility',
'note',
'flexsearchProps:translated:phone',
'flexsearchProps:translated:email',
'flexsearchProps:translated:birthday',
'flexsearchProps:translated:address'
],
'io.cozy.contacts': ['fullname', 'civility', 'note'],
'io.cozy.files': [
'name',
'flexsearchProps:translated:qualificationLabel',
'flexsearchProps:translated:refTaxIncome',
'flexsearchProps:translated:contractType',
'flexsearchProps:translated:driverLicense',
'flexsearchProps:translated:paymentProofFamilyAllowance',
'flexsearchProps:translated:vehicleRegistration',
'flexsearchProps:translated:nationalIdCard',
'flexsearchProps:translated:bankDetails',
'flexsearchProps:translated:passport',
'flexsearchProps:translated:residencePermit',
'flexsearchProps:translated:expirationDate'
'flexsearchProps:translated:residencePermit'
]
}

Expand Down
42 changes: 41 additions & 1 deletion react/MuiCozyTheme/ListItem/ExpandedAttributes/helpers.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { formatAttrValue, makeAttrKey } from './helpers'
import {
formatAttrValue,
makeAttrKey,
normalizeExpandedAttribute
} from './helpers'

const f = () => 'someMockedDate'
const lang = 'en'
Expand Down Expand Up @@ -133,3 +137,39 @@ describe('makeAttrKey', () => {
expect(res).toBe('civility')
})
})

describe('normalizeExpandedAttribute', () => {
it('sould remove flexsearchProps and translated words', () => {
const res = normalizeExpandedAttribute(
'flexsearchProps:translated:qualificationLabel'
)

expect(res).toBe('qualificationLabel')
})

it('should keep metadata.x intact', () => {
const res = normalizeExpandedAttribute(
'flexsearchProps:translated:metadata.contractType'
)

expect(res).toBe('metadata.contractType')
})

it('should keep email[1] intact', () => {
const res = normalizeExpandedAttribute('flexsearchProps:email[1].address')

expect(res).toBe('email[1].address')
})

it('should replace : by .', () => {
const res = normalizeExpandedAttribute('metadata:number')

expect(res).toBe('metadata.number')
})

it('should do nothing for simple word', () => {
const res = normalizeExpandedAttribute('fullname')

expect(res).toBe('fullname')
})
})

0 comments on commit 866bb00

Please sign in to comment.