cozy-ui-plus 12.3.14 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/package.json +3 -3
- package/dist/ListItem/ExpandedAttributes/ExpandedAttribute.js +0 -62
- package/dist/ListItem/ExpandedAttributes/helpers.js +0 -263
- package/dist/ListItem/ExpandedAttributes/index.js +0 -90
- package/dist/ListItem/ListItemBase/Renaming/RenameDialog.js +0 -52
- package/dist/ListItem/ListItemBase/Renaming/RenameInput.js +0 -319
- package/dist/ListItem/ListItemBase/Renaming/helpers.js +0 -73
- package/dist/ListItem/ListItemBase/index.js +0 -151
- package/dist/ListItem/ListItemByDoc/index.js +0 -109
- package/dist/ListItem/ListItemContact/helpers.js +0 -39
- package/dist/ListItem/ListItemContact/index.js +0 -85
- package/dist/ListItem/ListItemContact/useActions.js +0 -28
- package/dist/ListItem/ListItemFile/ExpirationAnnotation.js +0 -54
- package/dist/ListItem/ListItemFile/ItemIcon.js +0 -64
- package/dist/ListItem/ListItemFile/PrimaryText.js +0 -47
- package/dist/ListItem/ListItemFile/SecondaryText.js +0 -41
- package/dist/ListItem/ListItemFile/index.js +0 -96
- package/dist/ListItem/hoc/withListItemLocales.js +0 -320
- package/dist/Qualification/QualificationGrid/helpers.js +0 -16
- package/dist/Qualification/QualificationGrid/index.js +0 -118
- package/dist/Qualification/QualificationGrid/locales/withLocales.js +0 -80
- package/dist/Qualification/QualificationItem/index.js +0 -76
- package/dist/providers/Intent/index.js +0 -130
- package/dist/src/ListItem/ExpandedAttributes/ExpandedAttribute.d.ts +0 -14
- package/dist/src/ListItem/ExpandedAttributes/helpers.d.ts +0 -43
- package/dist/src/ListItem/ExpandedAttributes/helpers.spec.d.ts +0 -1
- package/dist/src/ListItem/ExpandedAttributes/index.d.ts +0 -2
- package/dist/src/ListItem/ListItemBase/Renaming/RenameDialog.d.ts +0 -2
- package/dist/src/ListItem/ListItemBase/Renaming/RenameInput.d.ts +0 -12
- package/dist/src/ListItem/ListItemBase/Renaming/helpers.d.ts +0 -1
- package/dist/src/ListItem/ListItemBase/index.d.ts +0 -2
- package/dist/src/ListItem/ListItemByDoc/index.d.ts +0 -46
- package/dist/src/ListItem/ListItemContact/helpers.d.ts +0 -1
- package/dist/src/ListItem/ListItemContact/helpers.spec.d.ts +0 -1
- package/dist/src/ListItem/ListItemContact/index.d.ts +0 -35
- package/dist/src/ListItem/ListItemContact/useActions.d.ts +0 -2
- package/dist/src/ListItem/ListItemFile/ExpirationAnnotation.d.ts +0 -2
- package/dist/src/ListItem/ListItemFile/ItemIcon.d.ts +0 -12
- package/dist/src/ListItem/ListItemFile/PrimaryText.d.ts +0 -12
- package/dist/src/ListItem/ListItemFile/SecondaryText.d.ts +0 -12
- package/dist/src/ListItem/ListItemFile/index.d.ts +0 -37
- package/dist/src/ListItem/hoc/withListItemLocales.d.ts +0 -12
- package/dist/src/Qualification/QualificationGrid/helpers.d.ts +0 -1
- package/dist/src/Qualification/QualificationGrid/index.d.ts +0 -2
- package/dist/src/Qualification/QualificationGrid/locales/withLocales.d.ts +0 -12
- package/dist/src/Qualification/QualificationItem/index.d.ts +0 -17
- package/dist/src/providers/Intent/index.d.ts +0 -9
- package/src/ListItem/ExpandedAttributes/ExpandedAttribute.jsx +0 -39
- package/src/ListItem/ExpandedAttributes/helpers.js +0 -214
- package/src/ListItem/ExpandedAttributes/helpers.spec.js +0 -175
- package/src/ListItem/ExpandedAttributes/index.jsx +0 -62
- package/src/ListItem/ListItemBase/Renaming/RenameDialog.jsx +0 -38
- package/src/ListItem/ListItemBase/Renaming/RenameInput.jsx +0 -134
- package/src/ListItem/ListItemBase/Renaming/helpers.js +0 -35
- package/src/ListItem/ListItemBase/index.jsx +0 -115
- package/src/ListItem/ListItemByDoc/index.jsx +0 -103
- package/src/ListItem/ListItemContact/helpers.js +0 -28
- package/src/ListItem/ListItemContact/helpers.spec.js +0 -41
- package/src/ListItem/ListItemContact/index.jsx +0 -67
- package/src/ListItem/ListItemContact/useActions.jsx +0 -22
- package/src/ListItem/ListItemFile/ExpirationAnnotation.jsx +0 -39
- package/src/ListItem/ListItemFile/ItemIcon.jsx +0 -55
- package/src/ListItem/ListItemFile/PrimaryText.jsx +0 -38
- package/src/ListItem/ListItemFile/SecondaryText.jsx +0 -36
- package/src/ListItem/ListItemFile/index.jsx +0 -75
- package/src/ListItem/Readme.md +0 -211
- package/src/ListItem/hoc/withListItemLocales.jsx +0 -15
- package/src/ListItem/locales/en.json +0 -75
- package/src/ListItem/locales/fr.json +0 -75
- package/src/ListItem/locales/ru.json +0 -75
- package/src/ListItem/locales/vi.json +0 -75
- package/src/Qualification/QualificationGrid/Readme.md +0 -26
- package/src/Qualification/QualificationGrid/helpers.js +0 -4
- package/src/Qualification/QualificationGrid/index.jsx +0 -93
- package/src/Qualification/QualificationGrid/locales/en.json +0 -15
- package/src/Qualification/QualificationGrid/locales/fr.json +0 -15
- package/src/Qualification/QualificationGrid/locales/ru.json +0 -15
- package/src/Qualification/QualificationGrid/locales/vi.json +0 -15
- package/src/Qualification/QualificationGrid/locales/withLocales.jsx +0 -15
- package/src/Qualification/QualificationItem/Readme.md +0 -8
- package/src/Qualification/QualificationItem/index.jsx +0 -63
- package/src/providers/Intent/index.jsx +0 -83
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/get'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getTranslatedNameForInformationMetadata,
|
|
5
|
-
KNOWN_INFORMATION_METADATA_NAMES,
|
|
6
|
-
KNOWN_DATE_METADATA_NAMES,
|
|
7
|
-
formatInformationMetadataValue,
|
|
8
|
-
formatDateMetadataValue
|
|
9
|
-
} from 'cozy-client/dist/models/paper'
|
|
10
|
-
|
|
11
|
-
export const normalizeExpandedAttribute = attr =>
|
|
12
|
-
attr
|
|
13
|
-
.replaceAll(':', '.')
|
|
14
|
-
.replace('flexsearchProps.', '')
|
|
15
|
-
.replace('translated.', '')
|
|
16
|
-
|
|
17
|
-
// attributes not considered as specific expanded attributes
|
|
18
|
-
// and then fallback to default expanded attributes
|
|
19
|
-
export const notExpandedAttributes = {
|
|
20
|
-
'io.cozy.contacts': ['fullname', 'civility', 'note'],
|
|
21
|
-
'io.cozy.files': [
|
|
22
|
-
...KNOWN_DATE_METADATA_NAMES.map(x => `metadata.${x}`),
|
|
23
|
-
'metadata.noticePeriod',
|
|
24
|
-
'name',
|
|
25
|
-
'flexsearchProps:translated:qualificationLabel',
|
|
26
|
-
'flexsearchProps:translated:driverLicense',
|
|
27
|
-
'flexsearchProps:translated:paymentProofFamilyAllowance',
|
|
28
|
-
'flexsearchProps:translated:caf',
|
|
29
|
-
'flexsearchProps:translated:vehicleRegistration',
|
|
30
|
-
'flexsearchProps:translated:nationalIdCard',
|
|
31
|
-
'flexsearchProps:translated:bankDetails',
|
|
32
|
-
'flexsearchProps:translated:paySheet',
|
|
33
|
-
'flexsearchProps:translated:passport',
|
|
34
|
-
'flexsearchProps:translated:residencePermit'
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// attributes that we want to display if no attribute of the document is related to the search
|
|
39
|
-
export const defaultExpandedAttributes = {
|
|
40
|
-
'io.cozy.contacts': ['email', 'phone', 'address', 'birthday'],
|
|
41
|
-
'io.cozy.files': [
|
|
42
|
-
...KNOWN_INFORMATION_METADATA_NAMES.map(x => `metadata.${x}`),
|
|
43
|
-
...KNOWN_DATE_METADATA_NAMES.map(x => `metadata.${x}`)
|
|
44
|
-
].filter(x => !notExpandedAttributes['io.cozy.files'].includes(x))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const hasAllElement = (arr1, arr2) => arr1?.every(x => arr2.includes(x))
|
|
48
|
-
|
|
49
|
-
export const makeDefaultExpandedAttributes = (doc, expandedAttributes) => {
|
|
50
|
-
const doctype = doc?._type
|
|
51
|
-
|
|
52
|
-
if (!doc || !doctype) return undefined
|
|
53
|
-
|
|
54
|
-
// checks if there are any expanded attributes.
|
|
55
|
-
// If there are none, the default expanded attributes are returned
|
|
56
|
-
if (
|
|
57
|
-
!expandedAttributes ||
|
|
58
|
-
hasAllElement(expandedAttributes, notExpandedAttributes[doctype])
|
|
59
|
-
) {
|
|
60
|
-
return defaultExpandedAttributes[doctype]
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return expandedAttributes
|
|
64
|
-
.map(expandedAttribute =>
|
|
65
|
-
notExpandedAttributes[doctype].includes(expandedAttribute)
|
|
66
|
-
? undefined
|
|
67
|
-
: normalizeExpandedAttribute(expandedAttribute)
|
|
68
|
-
)
|
|
69
|
-
.filter(x => x)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const copyToClipboard =
|
|
73
|
-
({ value, setAlertProps, t }) =>
|
|
74
|
-
async () => {
|
|
75
|
-
try {
|
|
76
|
-
await navigator.clipboard.writeText(value)
|
|
77
|
-
setAlertProps({
|
|
78
|
-
open: true,
|
|
79
|
-
severity: 'success',
|
|
80
|
-
message: t(`ListItem.snackbar.copyToClipboard.success`)
|
|
81
|
-
})
|
|
82
|
-
} catch (_error) {
|
|
83
|
-
setAlertProps({
|
|
84
|
-
open: true,
|
|
85
|
-
severity: 'error',
|
|
86
|
-
message: t(`ListItem.snackbar.copyToClipboard.error`)
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export const isDate = value => {
|
|
92
|
-
if (!isNaN(value)) return false
|
|
93
|
-
const dateTime = new Date(value).getTime()
|
|
94
|
-
const dateParsedValue = Date.parse(value)
|
|
95
|
-
|
|
96
|
-
return dateTime === dateParsedValue
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const getAttrValue = (doc, attrName) => {
|
|
100
|
-
const attrValue = get(doc, attrName)
|
|
101
|
-
if (!attrValue || attrValue.length === 0) return undefined
|
|
102
|
-
|
|
103
|
-
switch (true) {
|
|
104
|
-
case attrName === 'email':
|
|
105
|
-
return attrValue.find(x => x.primary === true)?.address
|
|
106
|
-
|
|
107
|
-
case attrName === 'address':
|
|
108
|
-
return attrValue.find(x => x.primary === true)?.formattedAddress
|
|
109
|
-
|
|
110
|
-
case attrName === 'phone':
|
|
111
|
-
return attrValue.find(x => x.primary === true)?.number
|
|
112
|
-
|
|
113
|
-
default:
|
|
114
|
-
return attrValue
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export const makeAttrsValues = (doc, expandedAttributes) => {
|
|
119
|
-
const attrsValues = expandedAttributes
|
|
120
|
-
.map(attrName => {
|
|
121
|
-
const attrValue = getAttrValue(doc, attrName)
|
|
122
|
-
|
|
123
|
-
if (!attrValue) return undefined
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
attrName,
|
|
127
|
-
attrValue
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
.filter(x => x)
|
|
131
|
-
.slice(0, 3)
|
|
132
|
-
|
|
133
|
-
return attrsValues
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// could be use in apps
|
|
137
|
-
export const hasExpandedAttributesDisplayed = ({ doc, expandedAttributes }) => {
|
|
138
|
-
const defaultExpandedAttributes = makeDefaultExpandedAttributes(
|
|
139
|
-
doc,
|
|
140
|
-
expandedAttributes
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
const attrsValues = makeAttrsValues(doc, defaultExpandedAttributes)
|
|
144
|
-
|
|
145
|
-
return attrsValues?.length > 0 || false
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export const getFormattedValue = ({
|
|
149
|
-
attrName,
|
|
150
|
-
attrValue,
|
|
151
|
-
qualificationLabel,
|
|
152
|
-
f,
|
|
153
|
-
lang
|
|
154
|
-
}) => {
|
|
155
|
-
if (isDate(attrValue)) {
|
|
156
|
-
return formatDateMetadataValue(attrValue, { f, lang })
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (qualificationLabel) {
|
|
160
|
-
return formatInformationMetadataValue(attrValue, {
|
|
161
|
-
lang,
|
|
162
|
-
name: attrName.split('metadata.')[1],
|
|
163
|
-
qualificationLabel
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return attrValue
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export const makeLabel = ({ attrName, qualificationLabel, t, lang }) => {
|
|
171
|
-
if (qualificationLabel) {
|
|
172
|
-
const name = attrName.split('metadata.')[1]
|
|
173
|
-
const label = getTranslatedNameForInformationMetadata(name, {
|
|
174
|
-
lang,
|
|
175
|
-
qualificationLabel
|
|
176
|
-
})
|
|
177
|
-
return label
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return t(`ListItem.attributes.${attrName}`)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export const makeAttrsLabelAndFormattedValue = ({
|
|
184
|
-
doc,
|
|
185
|
-
expandedAttributes,
|
|
186
|
-
t,
|
|
187
|
-
f,
|
|
188
|
-
lang
|
|
189
|
-
}) => {
|
|
190
|
-
const attrsKeyAndFormattedValue = makeAttrsValues(doc, expandedAttributes)
|
|
191
|
-
|
|
192
|
-
return attrsKeyAndFormattedValue.map(({ attrName, attrValue }) => {
|
|
193
|
-
const _attrName =
|
|
194
|
-
attrName.match(/\[.+\]/g) !== null ? attrName.split('[')[0] : attrName
|
|
195
|
-
const qualificationLabel = doc.metadata?.qualification?.label
|
|
196
|
-
|
|
197
|
-
const label = makeLabel({
|
|
198
|
-
attrName: _attrName,
|
|
199
|
-
qualificationLabel,
|
|
200
|
-
t,
|
|
201
|
-
lang
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
const value = getFormattedValue({
|
|
205
|
-
attrName: _attrName,
|
|
206
|
-
attrValue,
|
|
207
|
-
qualificationLabel,
|
|
208
|
-
f,
|
|
209
|
-
lang
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
return { label, value }
|
|
213
|
-
})
|
|
214
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
makeAttrsValues,
|
|
3
|
-
getAttrValue,
|
|
4
|
-
makeLabel,
|
|
5
|
-
normalizeExpandedAttribute
|
|
6
|
-
} from './helpers'
|
|
7
|
-
|
|
8
|
-
describe('makeAttrsValues', () => {
|
|
9
|
-
it('should return attributes names and values', () => {
|
|
10
|
-
const doc = { metadata: { number: '123', refTaxIncome: '400' } }
|
|
11
|
-
const res = makeAttrsValues(doc, [
|
|
12
|
-
'metadata.number',
|
|
13
|
-
'metadata.refTaxIncome'
|
|
14
|
-
])
|
|
15
|
-
|
|
16
|
-
expect(res).toStrictEqual([
|
|
17
|
-
{
|
|
18
|
-
attrName: 'metadata.number',
|
|
19
|
-
attrValue: '123'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
attrName: 'metadata.refTaxIncome',
|
|
23
|
-
attrValue: '400'
|
|
24
|
-
}
|
|
25
|
-
])
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('getAttrValue', () => {
|
|
30
|
-
it('should return the email value', () => {
|
|
31
|
-
const res = getAttrValue(
|
|
32
|
-
{ email: [{ address: 'xx@yy.zz' }] },
|
|
33
|
-
'email[0].address'
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
expect(res).toBe('xx@yy.zz')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should return the primary email value', () => {
|
|
40
|
-
const res = getAttrValue(
|
|
41
|
-
{
|
|
42
|
-
email: [{ address: 'xx@yy.zz' }, { address: 'zz@yy.xx', primary: true }]
|
|
43
|
-
},
|
|
44
|
-
'email'
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
expect(res).toBe('zz@yy.xx')
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('should return the address value', () => {
|
|
51
|
-
const res = getAttrValue(
|
|
52
|
-
{ address: [{ formattedAddress: 'baker street' }] },
|
|
53
|
-
'address[0].formattedAddress'
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
expect(res).toBe('baker street')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should return the primary address value', () => {
|
|
60
|
-
const res = getAttrValue(
|
|
61
|
-
{
|
|
62
|
-
address: [
|
|
63
|
-
{ formattedAddress: 'baker street' },
|
|
64
|
-
{ formattedAddress: 'street baker', primary: true }
|
|
65
|
-
]
|
|
66
|
-
},
|
|
67
|
-
'address'
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
expect(res).toBe('street baker')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('should return the phone number', () => {
|
|
74
|
-
const res = getAttrValue(
|
|
75
|
-
{ phone: ['', { number: '0102030405' }] },
|
|
76
|
-
'phone[1].number'
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
expect(res).toBe('0102030405')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('should return the primary phone number', () => {
|
|
83
|
-
const res = getAttrValue(
|
|
84
|
-
{
|
|
85
|
-
phone: [
|
|
86
|
-
{ number: '0908070605', primary: true },
|
|
87
|
-
{ number: '0102030405' }
|
|
88
|
-
]
|
|
89
|
-
},
|
|
90
|
-
'phone'
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
expect(res).toBe('0908070605')
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('should return metadata number value', () => {
|
|
97
|
-
const res = getAttrValue({ metadata: { number: '123' } }, 'metadata.number')
|
|
98
|
-
|
|
99
|
-
expect(res).toBe('123')
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('should return an ISO string date', () => {
|
|
103
|
-
const res = getAttrValue(
|
|
104
|
-
{ metadata: { date: '2023-03-08T12:48:18.000Z' } },
|
|
105
|
-
'metadata.date'
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
expect(res).toBe('2023-03-08T12:48:18.000Z')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('should return the civility value', () => {
|
|
112
|
-
const res = getAttrValue({ civility: 'female' }, 'civility')
|
|
113
|
-
|
|
114
|
-
expect(res).toBe('female')
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
describe('normalizeExpandedAttribute', () => {
|
|
119
|
-
it('sould remove flexsearchProps and translated words', () => {
|
|
120
|
-
const res = normalizeExpandedAttribute(
|
|
121
|
-
'flexsearchProps:translated:qualificationLabel'
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
expect(res).toBe('qualificationLabel')
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('should keep metadata.x intact', () => {
|
|
128
|
-
const res = normalizeExpandedAttribute(
|
|
129
|
-
'flexsearchProps:translated:metadata.contractType'
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
expect(res).toBe('metadata.contractType')
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('should keep email[1] intact', () => {
|
|
136
|
-
const res = normalizeExpandedAttribute('flexsearchProps:email[1].address')
|
|
137
|
-
|
|
138
|
-
expect(res).toBe('email[1].address')
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
it('should replace : by .', () => {
|
|
142
|
-
const res = normalizeExpandedAttribute('metadata:number')
|
|
143
|
-
|
|
144
|
-
expect(res).toBe('metadata.number')
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it('should do nothing for simple word', () => {
|
|
148
|
-
const res = normalizeExpandedAttribute('fullname')
|
|
149
|
-
|
|
150
|
-
expect(res).toBe('fullname')
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
describe('makeLabel', () => {
|
|
155
|
-
it('should', () => {
|
|
156
|
-
const res = makeLabel({
|
|
157
|
-
attrName: 'metadata.number',
|
|
158
|
-
qualificationLabel: 'driver_license',
|
|
159
|
-
t: x => x,
|
|
160
|
-
lang: 'fr'
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
expect(res).toBe('Numéro du permis')
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
it('should', () => {
|
|
167
|
-
const res = makeLabel({
|
|
168
|
-
attrName: 'birthday',
|
|
169
|
-
t: x => x,
|
|
170
|
-
lang: 'fr'
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
expect(res).toBe('ListItem.attributes.birthday')
|
|
174
|
-
})
|
|
175
|
-
})
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
|
-
import React, { useState } from 'react'
|
|
3
|
-
|
|
4
|
-
import Alert from 'cozy-ui/transpiled/react/Alert'
|
|
5
|
-
import Snackbar from 'cozy-ui/transpiled/react/Snackbar'
|
|
6
|
-
import { useI18n } from 'twake-i18n'
|
|
7
|
-
|
|
8
|
-
import ExpandedAttribute from './ExpandedAttribute'
|
|
9
|
-
import { makeAttrsLabelAndFormattedValue } from './helpers'
|
|
10
|
-
import withListItemLocales from '../hoc/withListItemLocales'
|
|
11
|
-
|
|
12
|
-
const ExpandedAttributes = ({ doc, expandedAttributes }) => {
|
|
13
|
-
const { t, f, lang } = useI18n()
|
|
14
|
-
const [alertProps, setAlertProps] = useState({
|
|
15
|
-
open: false,
|
|
16
|
-
severity: 'primary',
|
|
17
|
-
message: ''
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const attrsLabelAndFormattedValue = makeAttrsLabelAndFormattedValue({
|
|
21
|
-
doc,
|
|
22
|
-
expandedAttributes,
|
|
23
|
-
t,
|
|
24
|
-
f,
|
|
25
|
-
lang
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const handleClose = () => setAlertProps({ open: false })
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<>
|
|
32
|
-
{attrsLabelAndFormattedValue.map(({ label, value }, index) => {
|
|
33
|
-
return (
|
|
34
|
-
<ExpandedAttribute
|
|
35
|
-
key={index}
|
|
36
|
-
label={label}
|
|
37
|
-
value={value}
|
|
38
|
-
setAlertProps={setAlertProps}
|
|
39
|
-
/>
|
|
40
|
-
)
|
|
41
|
-
})}
|
|
42
|
-
{alertProps.open && (
|
|
43
|
-
<Snackbar open onClose={handleClose}>
|
|
44
|
-
<Alert
|
|
45
|
-
variant="filled"
|
|
46
|
-
severity={alertProps.severity}
|
|
47
|
-
onClose={handleClose}
|
|
48
|
-
>
|
|
49
|
-
{alertProps.message}
|
|
50
|
-
</Alert>
|
|
51
|
-
</Snackbar>
|
|
52
|
-
)}
|
|
53
|
-
</>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
ExpandedAttributes.propTypes = {
|
|
58
|
-
doc: PropTypes.object,
|
|
59
|
-
expandedAttributes: PropTypes.array
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default withListItemLocales(ExpandedAttributes)
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
5
|
-
import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
|
|
6
|
-
import { useI18n } from 'twake-i18n'
|
|
7
|
-
|
|
8
|
-
import withListItemLocales from '../../hoc/withListItemLocales'
|
|
9
|
-
|
|
10
|
-
const RenameDialog = ({ onSubmit, onCancel }) => {
|
|
11
|
-
const { t } = useI18n()
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<ConfirmDialog
|
|
15
|
-
open
|
|
16
|
-
title={t('ListItem.renameModal.title')}
|
|
17
|
-
content={t('ListItem.renameModal.content')}
|
|
18
|
-
actions={
|
|
19
|
-
<>
|
|
20
|
-
<Button
|
|
21
|
-
variant="secondary"
|
|
22
|
-
label={t('ListItem.renameModal.cancel')}
|
|
23
|
-
onClick={onCancel}
|
|
24
|
-
/>
|
|
25
|
-
<Button label={t('ListItem.renameModal.submit')} onClick={onSubmit} />
|
|
26
|
-
</>
|
|
27
|
-
}
|
|
28
|
-
onClose={onCancel}
|
|
29
|
-
/>
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
RenameDialog.propTypes = {
|
|
34
|
-
onSubmit: PropTypes.func,
|
|
35
|
-
onCancel: PropTypes.func
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default withListItemLocales(RenameDialog)
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
|
-
import React, { useEffect, useReducer, useRef, useState } from 'react'
|
|
3
|
-
|
|
4
|
-
import { useClient } from 'cozy-client'
|
|
5
|
-
import { splitFilename } from 'cozy-client/dist/models/file'
|
|
6
|
-
import InputGroup from 'cozy-ui/transpiled/react/InputGroup'
|
|
7
|
-
import Spinner from 'cozy-ui/transpiled/react/Spinner'
|
|
8
|
-
import Input from 'cozy-ui/transpiled/react/legacy/Input'
|
|
9
|
-
import { makeStyles } from 'cozy-ui/transpiled/react/styles'
|
|
10
|
-
|
|
11
|
-
import RenameDialog from './RenameDialog'
|
|
12
|
-
import { renameFile } from './helpers'
|
|
13
|
-
|
|
14
|
-
const KEYS = {
|
|
15
|
-
ESCAPE: 'Escape',
|
|
16
|
-
ENTER: 'Enter'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const useStyles = makeStyles({
|
|
20
|
-
inputGroup: {
|
|
21
|
-
maxWidth: 'none',
|
|
22
|
-
height: '2rem',
|
|
23
|
-
margin: '1rem 1rem 1rem 0',
|
|
24
|
-
'& > div': {
|
|
25
|
-
display: 'flex'
|
|
26
|
-
},
|
|
27
|
-
'& input': {
|
|
28
|
-
maxWidth: 'none',
|
|
29
|
-
padding: '.3125rem'
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
spinner: {
|
|
33
|
-
margin: '.4375rem'
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const RenameInput = ({ file, onClose }) => {
|
|
38
|
-
const client = useClient()
|
|
39
|
-
const styles = useStyles()
|
|
40
|
-
const textInput = useRef()
|
|
41
|
-
const [isBusy, toggleBusy] = useReducer(prev => !prev, false)
|
|
42
|
-
const [isModalOpened, setIsModalOpened] = useState(false)
|
|
43
|
-
const defaultValue = file.name
|
|
44
|
-
|
|
45
|
-
const check = async () => {
|
|
46
|
-
const { value } = textInput.current
|
|
47
|
-
if (value === '' || value === '.' || value === '..') {
|
|
48
|
-
await submit()
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
const oldExtension = splitFilename({
|
|
52
|
-
name: defaultValue,
|
|
53
|
-
type: 'file'
|
|
54
|
-
}).extension
|
|
55
|
-
const newExtension = splitFilename({
|
|
56
|
-
name: value,
|
|
57
|
-
type: 'file'
|
|
58
|
-
}).extension
|
|
59
|
-
if (oldExtension === newExtension) {
|
|
60
|
-
await submit()
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
setIsModalOpened(true)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const submit = async () => {
|
|
67
|
-
const { value } = textInput.current
|
|
68
|
-
await close(value)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const cancel = async () => {
|
|
72
|
-
await close(defaultValue)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const close = async value => {
|
|
76
|
-
toggleBusy()
|
|
77
|
-
if (value !== defaultValue) {
|
|
78
|
-
await renameFile(client, file, value)
|
|
79
|
-
}
|
|
80
|
-
onClose()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const handleKeyDown = async event => {
|
|
84
|
-
if (event.key === KEYS.ENTER) {
|
|
85
|
-
await check()
|
|
86
|
-
} else if (event.key === KEYS.ESCAPE) {
|
|
87
|
-
await cancel()
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const handleBlur = async () => {
|
|
92
|
-
// On top of "normal" blurs, the event happens all the time after a submit or a cancel, because this component is removed from the DOM while having the focus.
|
|
93
|
-
// we want to do things only on "normal" blurs, *not* after a cancel
|
|
94
|
-
if (!isModalOpened && !isBusy) {
|
|
95
|
-
await check()
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const handleFocus = () => {
|
|
100
|
-
const { length } = splitFilename({
|
|
101
|
-
name: defaultValue,
|
|
102
|
-
type: 'file'
|
|
103
|
-
}).filename
|
|
104
|
-
|
|
105
|
-
textInput.current.setSelectionRange(0, length)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
textInput.current.focus()
|
|
110
|
-
}, [])
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<InputGroup className={styles.inputGroup}>
|
|
114
|
-
<Input
|
|
115
|
-
ref={textInput}
|
|
116
|
-
type="text"
|
|
117
|
-
defaultValue={defaultValue}
|
|
118
|
-
disabled={isModalOpened || isBusy}
|
|
119
|
-
onBlur={handleBlur}
|
|
120
|
-
onFocus={handleFocus}
|
|
121
|
-
onKeyDown={handleKeyDown}
|
|
122
|
-
/>
|
|
123
|
-
{(isModalOpened || isBusy) && <Spinner className={styles.spinner} />}
|
|
124
|
-
{isModalOpened && <RenameDialog onSubmit={submit} onCancel={cancel} />}
|
|
125
|
-
</InputGroup>
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
RenameInput.propTypes = {
|
|
130
|
-
file: PropTypes.object.isRequired,
|
|
131
|
-
onClose: PropTypes.func.isRequired
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export default RenameInput
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
|
|
2
|
-
|
|
3
|
-
export const renameFile = async (client, file, name) => {
|
|
4
|
-
try {
|
|
5
|
-
return await client.save({
|
|
6
|
-
...file,
|
|
7
|
-
name
|
|
8
|
-
})
|
|
9
|
-
} catch (error) {
|
|
10
|
-
if (error.message.includes('Missing name argument')) {
|
|
11
|
-
Alerter.error('RenameInput.filenameMissing')
|
|
12
|
-
} else if (error.message.includes('Invalid filename:')) {
|
|
13
|
-
Alerter.error('RenameInput.filenameIllegalName', {
|
|
14
|
-
name
|
|
15
|
-
})
|
|
16
|
-
} else if (
|
|
17
|
-
error.message.includes(
|
|
18
|
-
'Invalid filename containing illegal character(s):'
|
|
19
|
-
)
|
|
20
|
-
) {
|
|
21
|
-
Alerter.error(
|
|
22
|
-
'RenameInput.filenameIllegalCharacters',
|
|
23
|
-
{
|
|
24
|
-
name,
|
|
25
|
-
characters: error.message.split(
|
|
26
|
-
'Invalid filename containing illegal character(s): '
|
|
27
|
-
)[1]
|
|
28
|
-
},
|
|
29
|
-
{ duration: 2000 }
|
|
30
|
-
)
|
|
31
|
-
} else {
|
|
32
|
-
Alerter.error('RenameInput.fileExisting', { name })
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|