Skip to content

Commit eba17b6

Browse files
committed
fix(ContactsList): Revert moving locales inside ContactsList attribute
helpers are both used inside cozy-ui and inside app too, so changing anything will be a BC. it's not worth the cost.
1 parent dc9d3ce commit eba17b6

File tree

7 files changed

+24
-44
lines changed

7 files changed

+24
-44
lines changed

react/ContactsList/ContactCell.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Cell = ({ row, column, cell, actions }) => {
2929
<ListItemIcon>
3030
<IconButton
3131
ref={actionsRef}
32-
arial-label={t('ContactsList.menu')}
32+
arial-label={t('menu')}
3333
onClick={() => setShowActions(true)}
3434
>
3535
<Icon icon={DotsIcon} />

react/ContactsList/Contacts/ContactIdentity.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ const MyselfMarker = () => {
1414
useExtendI18n(locales)
1515
const { t } = useI18n()
1616

17-
return (
18-
<span className={`${styles['contact-myself']}`}>
19-
({t('ContactsList.me')})
20-
</span>
21-
)
17+
return <span className={`${styles['contact-myself']}`}>({t('me')})</span>
2218
}
2319

2420
const ContactIdentity = ({ contact }) => {

react/ContactsList/ContactsList.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import React from 'react'
44
import ContactRow from './ContactRow'
55
import { sortContacts, categorizeContacts, sortHeaders } from './helpers'
66
import withContactsListLocales from './locales/withContactsListLocales'
7-
import { locales } from './locales/withContactsListLocales'
87
import List from '../List'
98
import ListSubheader from '../ListSubheader'
109
import { Table } from '../deprecated/Table'
1110
import useBreakpoints from '../providers/Breakpoints'
12-
import { useI18n, useExtendI18n } from '../providers/I18n'
11+
import { useI18n } from '../providers/I18n'
1312

1413
const ContactsList = ({ contacts, onItemClick, ...rest }) => {
15-
useExtendI18n(locales)
1614
const { t } = useI18n()
1715
const sortedContacts = sortContacts(contacts)
1816
const categorizedContacts = categorizeContacts(sortedContacts, t)

react/ContactsList/helpers.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export const sortContacts = contacts => contacts.sort(sortLastNameFirst)
3232
* @returns {string} header
3333
*/
3434
const makeHeader = (contact, t) => {
35-
if (contact.me) return t('ContactsList.me')
35+
if (contact.me) return t('me')
3636

3737
const name = buildLastNameFirst(contact)
38-
return name[0] || t('ContactsList.empty')
38+
return name[0] || t('empty')
3939
}
4040

4141
/**
@@ -45,8 +45,8 @@ const makeHeader = (contact, t) => {
4545
* @returns {string} header
4646
*/
4747
const makeHeaderForIndexedContacts = (contact, t) => {
48-
if (contact.me) return t('ContactsList.me')
49-
if (contact.cozyMetadata?.favorite) return t('ContactsList.favorite')
48+
if (contact.me) return t('me')
49+
if (contact.cozyMetadata?.favorite) return t('favorite')
5050

5151
const index = get(contact, 'indexes.byFamilyNameGivenNameEmailCozyUrl', '')
5252
const hasIndex = index !== null && index.length > 0
@@ -58,7 +58,7 @@ const makeHeaderForIndexedContacts = (contact, t) => {
5858
return firstLetterWithoutAccent
5959
}
6060

61-
return t('ContactsList.empty')
61+
return t('empty')
6262
}
6363

6464
/**
@@ -89,8 +89,7 @@ export const categorizeContacts = (contacts, t) =>
8989
export const sortHeaders = (categorized, t) => {
9090
const headers = Object.keys(categorized)
9191
const notEmptyAndMyselfHeaders = headers.filter(
92-
header =>
93-
header !== t('ContactsList.empty') && header !== t('ContactsList.me')
92+
header => header !== t('empty') && header !== t('me')
9493
)
9594
const notEmptyAndMyselfSorted = notEmptyAndMyselfHeaders.slice().sort()
9695

@@ -99,11 +98,11 @@ export const sortHeaders = (categorized, t) => {
9998
}
10099

101100
const headersSorted = []
102-
if (headers.includes(t('ContactsList.me'))) {
103-
headersSorted.push(t('ContactsList.me'))
101+
if (headers.includes(t('me'))) {
102+
headersSorted.push(t('me'))
104103
}
105-
if (headers.includes(t('ContactsList.empty'))) {
106-
headersSorted.push(t('ContactsList.empty'))
104+
if (headers.includes(t('empty'))) {
105+
headersSorted.push(t('empty'))
107106
}
108107

109108
return headersSorted.concat(notEmptyAndMyselfSorted)

react/ContactsList/helpers.spec.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('sortHeaders', () => {
103103

104104
const sortedHeaders = sortHeaders(contacts, t)
105105

106-
expect(sortedHeaders).toEqual(['B', 'F', 'H', 'empty', 'me'])
106+
expect(sortedHeaders).toEqual(['me', 'empty', 'B', 'F', 'H'])
107107
})
108108
})
109109

@@ -143,16 +143,7 @@ describe('makeGroupLabelsAndCounts', () => {
143143
const res = makeGroupLabelsAndCounts(contacts, t)
144144

145145
expect(res).toStrictEqual({
146-
groupLabels: [
147-
'A',
148-
'C',
149-
'B',
150-
'X',
151-
'Z',
152-
'ContactsList.empty',
153-
'ContactsList.me',
154-
'E'
155-
],
146+
groupLabels: ['A', 'C', 'B', 'X', 'Z', 'empty', 'me', 'E'],
156147
groupCounts: [3, 5, 2, 1, 1, 4, 1, 1]
157148
})
158149
})

react/ContactsList/locales/en.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"ContactsList": {
3-
"empty": "EMPTY",
4-
"me": "me",
5-
"favorite": "favorites",
6-
"menu": "Menu"
7-
}
2+
"empty": "EMPTY",
3+
"me": "me",
4+
"favorite": "favorites",
5+
"menu": "Menu"
86
}

react/ContactsList/locales/fr.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"ContactsList": {
3-
"empty": "VIDE",
4-
"me": "moi",
5-
"favorite": "favoris",
6-
"menu": "Menu"
7-
}
8-
}
2+
"empty": "VIDE",
3+
"me": "moi",
4+
"favorite": "favoris",
5+
"menu": "Menu"
6+
}

0 commit comments

Comments
 (0)