cozy-ui 128.10.0 → 129.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 +21 -0
- package/package.json +1 -1
- package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +5 -2
- package/react/Contacts/AddModal/ContactForm/FieldInputAccordion.jsx +2 -2
- package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +2 -1
- package/react/Table/Readme.md +46 -53
- package/react/Table/Virtualized/FixedHeaderContent.jsx +2 -2
- package/react/Table/Virtualized/HeadCell.jsx +12 -4
- package/react/Table/Virtualized/helpers.js +6 -6
- package/react/Table/Virtualized/index.jsx +14 -10
- package/react/providers/Selection/Readme.md +2 -2
- package/react/providers/Selection/index.jsx +17 -18
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +3 -1
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +8 -1
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputAccordion.js +2 -4
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +2 -1
- package/transpiled/react/Table/Virtualized/FixedHeaderContent.d.ts +2 -2
- package/transpiled/react/Table/Virtualized/FixedHeaderContent.js +2 -2
- package/transpiled/react/Table/Virtualized/HeadCell.d.ts +2 -2
- package/transpiled/react/Table/Virtualized/HeadCell.js +4 -4
- package/transpiled/react/Table/Virtualized/helpers.d.ts +1 -1
- package/transpiled/react/Table/Virtualized/helpers.js +6 -6
- package/transpiled/react/Table/Virtualized/index.js +15 -11
- package/transpiled/react/providers/Selection/index.js +17 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [129.0.0](https://github.com/cozy/cozy-ui/compare/v128.10.1...v129.0.0) (2025-09-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **SelectionProvider:** Replace `item`by `itemId` and don't rely on `._id` anymore ([f6086d3](https://github.com/cozy/cozy-ui/commit/f6086d3))
|
|
7
|
+
* **VirtualizedTable:** Now don't sort anything if no `defaultOrder` set ([707d62d](https://github.com/cozy/cozy-ui/commit/707d62d))
|
|
8
|
+
* **VirtualizedTable:** Prop `onSortChange` is now longer required ([31188a6](https://github.com/cozy/cozy-ui/commit/31188a6))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### BREAKING CHANGES
|
|
12
|
+
|
|
13
|
+
* **SelectionProvider:** If you use `cozy-ui/transpiled/react/providers/Selection` you have to replace prop object by its `id` value. For example replace `isSelectedItem(item)` by `isSelectedItem(item.id)` or `toggleSelectAllItems(items)` by `toggleSelectAllItems(items.map(item => item.id))`
|
|
14
|
+
|
|
15
|
+
## [128.10.1](https://github.com/cozy/cozy-ui/compare/v128.10.0...v128.10.1) (2025-09-16)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **AddModal/ContactForm:** Secondary input wasn't hide correctly ([b1fd6b0](https://github.com/cozy/cozy-ui/commit/b1fd6b0))
|
|
21
|
+
|
|
1
22
|
# [128.10.0](https://github.com/cozy/cozy-ui/compare/v128.9.0...v128.10.0) (2025-09-16)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@ const FieldInput = ({
|
|
|
22
22
|
error,
|
|
23
23
|
helperText,
|
|
24
24
|
label,
|
|
25
|
+
isInvisible,
|
|
25
26
|
required
|
|
26
27
|
}) => {
|
|
27
28
|
const [id] = useState(uniqueId('field_')) // state only use to generate id once and not at each render
|
|
@@ -51,8 +52,8 @@ const FieldInput = ({
|
|
|
51
52
|
className={cx(
|
|
52
53
|
className,
|
|
53
54
|
styles['contact-form-field__wrapper'],
|
|
54
|
-
'u-flex',
|
|
55
|
-
'u-flex-
|
|
55
|
+
'u-flex-column-s',
|
|
56
|
+
{ 'u-flex': !isInvisible, 'u-dn': isInvisible }
|
|
56
57
|
)}
|
|
57
58
|
>
|
|
58
59
|
<Field
|
|
@@ -103,6 +104,8 @@ FieldInput.propTypes = {
|
|
|
103
104
|
className: PropTypes.string,
|
|
104
105
|
labelProps: labelPropTypes,
|
|
105
106
|
attributes: fieldInputAttributesTypes,
|
|
107
|
+
/** Whether the field is visible by the user or not (still in the DOM anyway) */
|
|
108
|
+
isInvisible: PropTypes.bool,
|
|
106
109
|
contacts: PropTypes.shape({
|
|
107
110
|
data: PropTypes.arrayOf(PropTypes.object)
|
|
108
111
|
}),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import cx from 'classnames'
|
|
2
1
|
import React, { useState } from 'react'
|
|
3
2
|
|
|
4
3
|
import FieldInput from './FieldInput'
|
|
@@ -43,9 +42,10 @@ const FieldInputAccordion = ({
|
|
|
43
42
|
return (
|
|
44
43
|
<FieldInput
|
|
45
44
|
key={index}
|
|
46
|
-
className=
|
|
45
|
+
className="u-mt-1"
|
|
47
46
|
attributes={attributes}
|
|
48
47
|
name={name}
|
|
48
|
+
isInvisible={!showExtended}
|
|
49
49
|
label={t(`Contacts.AddModal.ContactForm.fields.${name}`)}
|
|
50
50
|
/>
|
|
51
51
|
)
|
|
@@ -25,9 +25,10 @@ const FieldInputLayout = ({
|
|
|
25
25
|
|
|
26
26
|
return (
|
|
27
27
|
<div
|
|
28
|
-
className={cx('u-
|
|
28
|
+
className={cx('u-mt-1', {
|
|
29
29
|
'u-flex-items-center': !layout,
|
|
30
30
|
'u-flex-items-baseline': !!layout,
|
|
31
|
+
'u-flex': !isSecondary || showSecondaryFields,
|
|
31
32
|
'u-dn': isSecondary && !showSecondaryFields
|
|
32
33
|
})}
|
|
33
34
|
>
|
package/react/Table/Readme.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
### React-Virtuoso
|
|
2
2
|
|
|
3
3
|
```jsx
|
|
4
|
+
import { useState } from 'react'
|
|
4
5
|
import VirtualizedTable from 'cozy-ui/transpiled/react/Table/Virtualized'
|
|
5
6
|
import Variants from 'cozy-ui/docs/components/Variants'
|
|
7
|
+
import Typography from 'cozy-ui/transpiled/react/Typography'
|
|
8
|
+
import SelectionProvider, { useSelection } from 'cozy-ui/transpiled/react/providers/Selection'
|
|
6
9
|
|
|
7
10
|
const createData = (id, name, calories, fat, carbs, protein) => {
|
|
8
11
|
return { id, name, calories, fat, carbs, protein }
|
|
@@ -10,18 +13,18 @@ const createData = (id, name, calories, fat, carbs, protein) => {
|
|
|
10
13
|
|
|
11
14
|
const rows = [
|
|
12
15
|
createData(0, 'Cupcake', 305, 3.7, 67, 4.3),
|
|
13
|
-
createData(1, '
|
|
14
|
-
createData(2, '
|
|
15
|
-
createData(3, '
|
|
16
|
-
createData(4, '
|
|
17
|
-
createData(5, '
|
|
18
|
-
createData(6, '
|
|
16
|
+
createData(1, 'Frozen yoghurt', 159, 6.0, 24, 4.0),
|
|
17
|
+
createData(2, 'Donut', 452, 25.0, 51, 4.9),
|
|
18
|
+
createData(3, 'Eclair', 262, 16.0, 24, 6.0),
|
|
19
|
+
createData(4, 'Ice cream sandwich', 237, 9.0, 37, 4.3),
|
|
20
|
+
createData(5, 'Gingerbread', 356, 16.0, 49, 3.9),
|
|
21
|
+
createData(6, 'Honeycomb', 408, 3.2, 87, 6.5),
|
|
19
22
|
createData(7, 'Jelly Bean', 375, 0.0, 94, 0.0),
|
|
20
23
|
createData(8, 'KitKat', 518, 26.0, 65, 7.0),
|
|
21
|
-
createData(9, '
|
|
24
|
+
createData(9, 'Oreo', 437, 18.0, 63, 4.0),
|
|
22
25
|
createData(10, 'Marshmallow', 318, 0, 81, 2.0),
|
|
23
|
-
createData(11, '
|
|
24
|
-
createData(12, '
|
|
26
|
+
createData(11, 'Lollipop', 392, 0.2, 98, 0.0),
|
|
27
|
+
createData(12, 'Nougat', 360, 19.0, 9, 37.0),
|
|
25
28
|
createData(
|
|
26
29
|
13,
|
|
27
30
|
'Ice cream with a very long list of ingredient to see how the table can handle this kind of item, and this is the end',
|
|
@@ -70,59 +73,30 @@ const columns = [
|
|
|
70
73
|
}
|
|
71
74
|
]
|
|
72
75
|
|
|
73
|
-
initialState = { selectedItemsId: [] }
|
|
74
|
-
|
|
75
|
-
const isSelectedItem = row => state.selectedItemsId.some(selectedItem => selectedItem === row.id)
|
|
76
|
-
const addSelected = row => setState(prev => {
|
|
77
|
-
const arr = prev.selectedItemsId
|
|
78
|
-
arr.push(row.id)
|
|
79
|
-
return { selectedItemsId: arr }
|
|
80
|
-
})
|
|
81
|
-
const removeSelected = (row) => setState(prev => {
|
|
82
|
-
const arr = prev.selectedItemsId
|
|
83
|
-
arr.splice(arr.indexOf(row.id), 1)
|
|
84
|
-
return { selectedItemsId: arr }
|
|
85
|
-
})
|
|
86
|
-
const onSelect = row => {
|
|
87
|
-
if (isSelectedItem(row)) {
|
|
88
|
-
removeSelected(row)
|
|
89
|
-
} else {
|
|
90
|
-
addSelected(row)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const onSelectAll = rows => {
|
|
94
|
-
const ids = rows.map(row => row.id)
|
|
95
|
-
if (state.selectedItemsId.length === ids.length) {
|
|
96
|
-
setState({ selectedItemsId: [] })
|
|
97
|
-
} else {
|
|
98
|
-
setState({ selectedItemsId: ids })
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
76
|
const initialVariants = [{ grouped: false }]
|
|
103
77
|
|
|
104
|
-
|
|
78
|
+
// Very basic usage only works when Dessert is sorted "asc"
|
|
79
|
+
// Ideally you have to create a logic to create groups with sorted data
|
|
80
|
+
const makeGroups = () => ({ groupLabels: ['C', 'D', 'E', 'Others'], groupCounts: [1,1,1,11] })
|
|
105
81
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* @param orderBy
|
|
109
|
-
*/
|
|
110
|
-
const onSortChange = ({ order, orderBy }) => {
|
|
111
|
-
setState({ order, orderBy })
|
|
112
|
-
}
|
|
82
|
+
const ExampleTable = ({ variant, ...props }) => {
|
|
83
|
+
const { selectedItemsId, isSelectedItem, toggleSelectedItem, toggleSelectAllItems } = useSelection()
|
|
113
84
|
|
|
114
|
-
|
|
115
|
-
|
|
85
|
+
const onSortChange = ({ order, orderBy }) => {
|
|
86
|
+
console.info('order:', order, 'oderBy:', orderBy)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
116
90
|
<div style={{ border: "1px solid var(--borderMainColor)", height: 400, width: "100%" }}>
|
|
117
91
|
<VirtualizedTable
|
|
92
|
+
{...props}
|
|
118
93
|
rows={rows}
|
|
119
94
|
columns={columns}
|
|
120
95
|
groups={variant.grouped ? makeGroups : undefined}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
onSelectAll={onSelectAll}
|
|
96
|
+
selectedItems={selectedItemsId}
|
|
97
|
+
isSelectedItem={row => isSelectedItem(row.id)}
|
|
98
|
+
onSelect={(row, event, index) => toggleSelectedItem(row.id)}
|
|
99
|
+
onSelectAll={rows => toggleSelectAllItems(rows.map(item => item.id))}
|
|
126
100
|
onSortChange={onSortChange}
|
|
127
101
|
componentsProps={{
|
|
128
102
|
rowContent: {
|
|
@@ -132,6 +106,25 @@ const onSortChange = ({ order, orderBy }) => {
|
|
|
132
106
|
}}
|
|
133
107
|
/>
|
|
134
108
|
</div>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
<Variants initialVariants={initialVariants} screenshotAllVariants>
|
|
113
|
+
{variant => (
|
|
114
|
+
<>
|
|
115
|
+
<Typography variant="h4">Not sorted table</Typography>
|
|
116
|
+
<div className="u-mt-half" style={{ border: "1px solid var(--borderMainColor)", height: 400, width: "100%" }}>
|
|
117
|
+
<SelectionProvider>
|
|
118
|
+
<ExampleTable variant={variant} />
|
|
119
|
+
</SelectionProvider>
|
|
120
|
+
</div>
|
|
121
|
+
<Typography className="u-mt-1" variant="h4">Sorted table</Typography>
|
|
122
|
+
<div className="u-mt-half" style={{ border: "1px solid var(--borderMainColor)", height: 400, width: "100%" }}>
|
|
123
|
+
<SelectionProvider>
|
|
124
|
+
<ExampleTable variant={variant} defaultOrder={columns[0].id} />
|
|
125
|
+
</SelectionProvider>
|
|
126
|
+
</div>
|
|
127
|
+
</>
|
|
135
128
|
)}
|
|
136
129
|
</Variants>
|
|
137
130
|
```
|
|
@@ -23,7 +23,7 @@ const useStyles = makeStyles({
|
|
|
23
23
|
|
|
24
24
|
const FixedHeaderContent = ({
|
|
25
25
|
columns,
|
|
26
|
-
|
|
26
|
+
orderDirection,
|
|
27
27
|
orderBy,
|
|
28
28
|
rowCount,
|
|
29
29
|
context,
|
|
@@ -52,7 +52,7 @@ const FixedHeaderContent = ({
|
|
|
52
52
|
key={column.id}
|
|
53
53
|
className={classes.visuallyHidden}
|
|
54
54
|
column={column}
|
|
55
|
-
|
|
55
|
+
orderDirection={orderDirection}
|
|
56
56
|
orderBy={orderBy}
|
|
57
57
|
onClick={() => onClick(column.id)}
|
|
58
58
|
/>
|
|
@@ -11,7 +11,13 @@ const useStyles = makeStyles({
|
|
|
11
11
|
}
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
const TableHeadCell = ({
|
|
14
|
+
const TableHeadCell = ({
|
|
15
|
+
className,
|
|
16
|
+
column,
|
|
17
|
+
orderBy,
|
|
18
|
+
orderDirection,
|
|
19
|
+
onClick
|
|
20
|
+
}) => {
|
|
15
21
|
const classes = useStyles({ column })
|
|
16
22
|
|
|
17
23
|
return (
|
|
@@ -20,18 +26,20 @@ const TableHeadCell = ({ className, column, orderBy, order, onClick }) => {
|
|
|
20
26
|
classes={classes}
|
|
21
27
|
align={column.textAlign ?? 'left'}
|
|
22
28
|
padding={column.disablePadding ? 'none' : 'normal'}
|
|
23
|
-
sortDirection={orderBy === column.id ?
|
|
29
|
+
sortDirection={orderBy === column.id ? orderDirection : false}
|
|
24
30
|
>
|
|
25
31
|
{column.sortable !== false ? (
|
|
26
32
|
<TableSortLabel
|
|
27
33
|
active={orderBy === column.id}
|
|
28
|
-
direction={orderBy === column.id ?
|
|
34
|
+
direction={orderBy === column.id ? orderDirection : 'asc'}
|
|
29
35
|
onClick={onClick}
|
|
30
36
|
>
|
|
31
37
|
{column.label}
|
|
32
38
|
{orderBy === column.id && (
|
|
33
39
|
<span className={className}>
|
|
34
|
-
{
|
|
40
|
+
{orderDirection === 'desc'
|
|
41
|
+
? 'sorted descending'
|
|
42
|
+
: 'sorted ascending'}
|
|
35
43
|
</span>
|
|
36
44
|
)}
|
|
37
45
|
</TableSortLabel>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import get from 'lodash/get'
|
|
2
2
|
|
|
3
|
-
const descendingComparator = ({ a, b,
|
|
3
|
+
const descendingComparator = ({ a, b, orderDirection, orderBy, lang }) => {
|
|
4
4
|
const aValue = get(a, orderBy, '')
|
|
5
5
|
const bValue = get(b, orderBy, '')
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ const descendingComparator = ({ a, b, order, orderBy, lang }) => {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const { compare } = Intl.Collator(lang || 'en', {
|
|
20
|
-
caseFirst:
|
|
20
|
+
caseFirst: orderDirection === 'asc' ? 'upper' : 'lower'
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
return compare(bValue, aValue)
|
|
@@ -26,10 +26,10 @@ const descendingComparator = ({ a, b, order, orderBy, lang }) => {
|
|
|
26
26
|
return bValue - aValue
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export const getComparator = (
|
|
30
|
-
return
|
|
31
|
-
? (a, b) => descendingComparator({ a, b,
|
|
32
|
-
: (a, b) => -descendingComparator({ a, b,
|
|
29
|
+
export const getComparator = (orderDirection, orderBy, lang) => {
|
|
30
|
+
return orderDirection === 'desc'
|
|
31
|
+
? (a, b) => descendingComparator({ a, b, orderDirection, orderBy, lang })
|
|
32
|
+
: (a, b) => -descendingComparator({ a, b, orderDirection, orderBy, lang })
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export const stableSort = (array, comparator) => {
|
|
@@ -28,10 +28,12 @@ const VirtualizedTable = forwardRef(
|
|
|
28
28
|
},
|
|
29
29
|
ref
|
|
30
30
|
) => {
|
|
31
|
-
const [
|
|
31
|
+
const [orderDirection, setOrderDirection] = useState('asc')
|
|
32
32
|
const [orderBy, setOrderBy] = useState(defaultOrder)
|
|
33
33
|
|
|
34
|
-
const sortedData =
|
|
34
|
+
const sortedData = orderBy
|
|
35
|
+
? stableSort(rows, getComparator(orderDirection, orderBy))
|
|
36
|
+
: rows
|
|
35
37
|
const data = secondarySort ? secondarySort(sortedData) : sortedData
|
|
36
38
|
const { groupLabels, groupCounts } = groups?.(data) || {}
|
|
37
39
|
const isGroupedTable = !!groupCounts
|
|
@@ -43,11 +45,11 @@ const VirtualizedTable = forwardRef(
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
const handleSort = property => {
|
|
46
|
-
const isAsc = orderBy === property &&
|
|
48
|
+
const isAsc = orderBy === property && orderDirection === 'asc'
|
|
47
49
|
const newOrder = isAsc ? 'desc' : 'asc'
|
|
48
|
-
|
|
50
|
+
setOrderDirection(newOrder)
|
|
49
51
|
setOrderBy(property)
|
|
50
|
-
onSortChange({ order: newOrder, orderBy: property })
|
|
52
|
+
onSortChange?.({ order: newOrder, orderBy: property })
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
const handleSelectAll = event => {
|
|
@@ -74,7 +76,7 @@ const VirtualizedTable = forwardRef(
|
|
|
74
76
|
columns={columns}
|
|
75
77
|
rowCount={rows.length}
|
|
76
78
|
context={_context}
|
|
77
|
-
|
|
79
|
+
orderDirection={orderDirection}
|
|
78
80
|
orderBy={orderBy}
|
|
79
81
|
onClick={handleSort}
|
|
80
82
|
onSelectAllClick={handleSelectAll}
|
|
@@ -115,10 +117,12 @@ VirtualizedTable.defaultProps = {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
VirtualizedTable.propTypes = {
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
groups: PropTypes.func
|
|
120
|
+
/** Column ID to be used for initiating the sort */
|
|
121
|
+
defaultOrder: PropTypes.string,
|
|
122
|
+
/** Returned object is: PropTypes.shape({ groupLabels: PropTypes.array, groupCounts: PropTypes.array }) */
|
|
123
|
+
groups: PropTypes.func,
|
|
124
|
+
/** Callback called after the sort */
|
|
125
|
+
onSortChange: PropTypes.func
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
export default VirtualizedTable
|
|
@@ -12,8 +12,8 @@ const Component = () => {
|
|
|
12
12
|
return (
|
|
13
13
|
<>
|
|
14
14
|
<Typography>selectedItemsId : {JSON.stringify(selectedItemsId)}</Typography>
|
|
15
|
-
<Button label="Add Item" onClick={() => addSelectedItem(
|
|
16
|
-
<Button label="Remove Item" onClick={() => removeSelectedItem(
|
|
15
|
+
<Button label="Add Item" onClick={() => addSelectedItem('01')} />
|
|
16
|
+
<Button label="Remove Item" onClick={() => removeSelectedItem('01')} />
|
|
17
17
|
</>
|
|
18
18
|
)
|
|
19
19
|
}
|
|
@@ -18,48 +18,47 @@ export const useSelection = () => {
|
|
|
18
18
|
const SelectionProvider = ({ children }) => {
|
|
19
19
|
const [selectedItemsId, setSelectedItemsId] = useState([])
|
|
20
20
|
|
|
21
|
-
const isSelectedItem =
|
|
22
|
-
return selectedItemsId.some(selectedItemId => selectedItemId ===
|
|
21
|
+
const isSelectedItem = itemId => {
|
|
22
|
+
return selectedItemsId.some(selectedItemId => selectedItemId === itemId)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const isSelectionEnabled = selectedItemsId.length > 0
|
|
26
26
|
|
|
27
|
-
const addSelectedItem =
|
|
28
|
-
setSelectedItemsId(prev => [...prev,
|
|
27
|
+
const addSelectedItem = itemId => {
|
|
28
|
+
setSelectedItemsId(prev => [...prev, itemId])
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const removeSelectedItem =
|
|
32
|
-
setSelectedItemsId(prev => prev.filter(el => el !==
|
|
31
|
+
const removeSelectedItem = itemId => {
|
|
32
|
+
setSelectedItemsId(prev => prev.filter(el => el !== itemId))
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const toggleSelectedItem =
|
|
36
|
-
if (isSelectedItem(
|
|
37
|
-
removeSelectedItem(
|
|
35
|
+
const toggleSelectedItem = itemId => {
|
|
36
|
+
if (isSelectedItem(itemId)) {
|
|
37
|
+
removeSelectedItem(itemId)
|
|
38
38
|
} else {
|
|
39
|
-
addSelectedItem(
|
|
39
|
+
addSelectedItem(itemId)
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
const selectAll =
|
|
44
|
-
|
|
45
|
-
setSelectedItemsId(ids)
|
|
43
|
+
const selectAll = itemsId => {
|
|
44
|
+
setSelectedItemsId(itemsId)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
const unselectAll = () => {
|
|
49
48
|
setSelectedItemsId([])
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
const isSelectedAllItems =
|
|
51
|
+
const isSelectedAllItems = itemsId => {
|
|
53
52
|
const a = selectedItemsId.sort()
|
|
54
|
-
const b =
|
|
53
|
+
const b = itemsId.sort()
|
|
55
54
|
return isEqual(a, b)
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
const toggleSelectAllItems =
|
|
59
|
-
if (isSelectedAllItems(
|
|
57
|
+
const toggleSelectAllItems = itemsId => {
|
|
58
|
+
if (isSelectedAllItems(itemsId)) {
|
|
60
59
|
unselectAll()
|
|
61
60
|
} else {
|
|
62
|
-
selectAll(
|
|
61
|
+
selectAll(itemsId)
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default FieldInput;
|
|
2
|
-
declare function FieldInput({ name, labelProps, className, attributes: { subFields, ...restAttributes }, contacts, error, helperText, label, required }: {
|
|
2
|
+
declare function FieldInput({ name, labelProps, className, attributes: { subFields, ...restAttributes }, contacts, error, helperText, label, isInvisible, required }: {
|
|
3
3
|
name: any;
|
|
4
4
|
labelProps: any;
|
|
5
5
|
className: any;
|
|
@@ -11,6 +11,7 @@ declare function FieldInput({ name, labelProps, className, attributes: { subFiel
|
|
|
11
11
|
error: any;
|
|
12
12
|
helperText: any;
|
|
13
13
|
label: any;
|
|
14
|
+
isInvisible: any;
|
|
14
15
|
required: any;
|
|
15
16
|
}): JSX.Element;
|
|
16
17
|
declare namespace FieldInput {
|
|
@@ -19,6 +20,7 @@ declare namespace FieldInput {
|
|
|
19
20
|
export const className: PropTypes.Requireable<string>;
|
|
20
21
|
export { labelPropTypes as labelProps };
|
|
21
22
|
export { fieldInputAttributesTypes as attributes };
|
|
23
|
+
export const isInvisible: PropTypes.Requireable<boolean>;
|
|
22
24
|
export const contacts: PropTypes.Requireable<PropTypes.InferProps<{
|
|
23
25
|
data: PropTypes.Requireable<(object | null)[]>;
|
|
24
26
|
}>>;
|
|
@@ -28,6 +28,7 @@ var FieldInput = function FieldInput(_ref) {
|
|
|
28
28
|
error = _ref.error,
|
|
29
29
|
helperText = _ref.helperText,
|
|
30
30
|
label = _ref.label,
|
|
31
|
+
isInvisible = _ref.isInvisible,
|
|
31
32
|
required = _ref.required;
|
|
32
33
|
|
|
33
34
|
var _useState = useState(uniqueId('field_')),
|
|
@@ -70,7 +71,10 @@ var FieldInput = function FieldInput(_ref) {
|
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
return /*#__PURE__*/React.createElement("div", {
|
|
73
|
-
className: cx(className, styles['contact-form-field__wrapper'], 'u-flex
|
|
74
|
+
className: cx(className, styles['contact-form-field__wrapper'], 'u-flex-column-s', {
|
|
75
|
+
'u-flex': !isInvisible,
|
|
76
|
+
'u-dn': isInvisible
|
|
77
|
+
})
|
|
74
78
|
}, /*#__PURE__*/React.createElement(Field, {
|
|
75
79
|
required: required,
|
|
76
80
|
error: error,
|
|
@@ -113,6 +117,9 @@ FieldInput.propTypes = {
|
|
|
113
117
|
className: PropTypes.string,
|
|
114
118
|
labelProps: labelPropTypes,
|
|
115
119
|
attributes: fieldInputAttributesTypes,
|
|
120
|
+
|
|
121
|
+
/** Whether the field is visible by the user or not (still in the DOM anyway) */
|
|
122
|
+
isInvisible: PropTypes.bool,
|
|
116
123
|
contacts: PropTypes.shape({
|
|
117
124
|
data: PropTypes.arrayOf(PropTypes.object)
|
|
118
125
|
}),
|
|
@@ -2,7 +2,6 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["name", "label", "subFields"],
|
|
4
4
|
_excluded2 = ["name"];
|
|
5
|
-
import cx from 'classnames';
|
|
6
5
|
import React, { useState } from 'react';
|
|
7
6
|
import FieldInput from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInput";
|
|
8
7
|
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
|
|
@@ -58,11 +57,10 @@ var FieldInputAccordion = function FieldInputAccordion(_ref) {
|
|
|
58
57
|
|
|
59
58
|
return /*#__PURE__*/React.createElement(FieldInput, {
|
|
60
59
|
key: index,
|
|
61
|
-
className:
|
|
62
|
-
'u-dn': !showExtended
|
|
63
|
-
}),
|
|
60
|
+
className: "u-mt-1",
|
|
64
61
|
attributes: attributes,
|
|
65
62
|
name: name,
|
|
63
|
+
isInvisible: !showExtended,
|
|
66
64
|
label: t("Contacts.AddModal.ContactForm.fields.".concat(name))
|
|
67
65
|
});
|
|
68
66
|
}));
|
|
@@ -37,9 +37,10 @@ var FieldInputLayout = function FieldInputLayout(_ref) {
|
|
|
37
37
|
|
|
38
38
|
var isError = fieldsRequired.includes(name) && !valid && submitFailed;
|
|
39
39
|
return /*#__PURE__*/React.createElement("div", {
|
|
40
|
-
className: cx('u-
|
|
40
|
+
className: cx('u-mt-1', {
|
|
41
41
|
'u-flex-items-center': !layout,
|
|
42
42
|
'u-flex-items-baseline': !!layout,
|
|
43
|
+
'u-flex': !isSecondary || showSecondaryFields,
|
|
43
44
|
'u-dn': isSecondary && !showSecondaryFields
|
|
44
45
|
})
|
|
45
46
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default FixedHeaderContent;
|
|
2
|
-
declare function FixedHeaderContent({ columns,
|
|
2
|
+
declare function FixedHeaderContent({ columns, orderDirection, orderBy, rowCount, context, onClick, onSelectAllClick }: {
|
|
3
3
|
columns: any;
|
|
4
|
-
|
|
4
|
+
orderDirection: any;
|
|
5
5
|
orderBy: any;
|
|
6
6
|
rowCount: any;
|
|
7
7
|
context: any;
|
|
@@ -21,7 +21,7 @@ var useStyles = makeStyles({
|
|
|
21
21
|
|
|
22
22
|
var FixedHeaderContent = function FixedHeaderContent(_ref) {
|
|
23
23
|
var columns = _ref.columns,
|
|
24
|
-
|
|
24
|
+
orderDirection = _ref.orderDirection,
|
|
25
25
|
orderBy = _ref.orderBy,
|
|
26
26
|
rowCount = _ref.rowCount,
|
|
27
27
|
context = _ref.context,
|
|
@@ -48,7 +48,7 @@ var FixedHeaderContent = function FixedHeaderContent(_ref) {
|
|
|
48
48
|
key: column.id,
|
|
49
49
|
className: classes.visuallyHidden,
|
|
50
50
|
column: column,
|
|
51
|
-
|
|
51
|
+
orderDirection: orderDirection,
|
|
52
52
|
orderBy: orderBy,
|
|
53
53
|
onClick: function onClick() {
|
|
54
54
|
return _onClick(column.id);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export default TableHeadCell;
|
|
2
|
-
declare function TableHeadCell({ className, column, orderBy,
|
|
2
|
+
declare function TableHeadCell({ className, column, orderBy, orderDirection, onClick }: {
|
|
3
3
|
className: any;
|
|
4
4
|
column: any;
|
|
5
5
|
orderBy: any;
|
|
6
|
-
|
|
6
|
+
orderDirection: any;
|
|
7
7
|
onClick: any;
|
|
8
8
|
}): JSX.Element;
|
|
@@ -21,7 +21,7 @@ var TableHeadCell = function TableHeadCell(_ref3) {
|
|
|
21
21
|
var className = _ref3.className,
|
|
22
22
|
column = _ref3.column,
|
|
23
23
|
orderBy = _ref3.orderBy,
|
|
24
|
-
|
|
24
|
+
orderDirection = _ref3.orderDirection,
|
|
25
25
|
onClick = _ref3.onClick;
|
|
26
26
|
var classes = useStyles({
|
|
27
27
|
column: column
|
|
@@ -31,14 +31,14 @@ var TableHeadCell = function TableHeadCell(_ref3) {
|
|
|
31
31
|
classes: classes,
|
|
32
32
|
align: (_column$textAlign = column.textAlign) !== null && _column$textAlign !== void 0 ? _column$textAlign : 'left',
|
|
33
33
|
padding: column.disablePadding ? 'none' : 'normal',
|
|
34
|
-
sortDirection: orderBy === column.id ?
|
|
34
|
+
sortDirection: orderBy === column.id ? orderDirection : false
|
|
35
35
|
}, column.sortable !== false ? /*#__PURE__*/React.createElement(TableSortLabel, {
|
|
36
36
|
active: orderBy === column.id,
|
|
37
|
-
direction: orderBy === column.id ?
|
|
37
|
+
direction: orderBy === column.id ? orderDirection : 'asc',
|
|
38
38
|
onClick: onClick
|
|
39
39
|
}, column.label, orderBy === column.id && /*#__PURE__*/React.createElement("span", {
|
|
40
40
|
className: className
|
|
41
|
-
},
|
|
41
|
+
}, orderDirection === 'desc' ? 'sorted descending' : 'sorted ascending')) : column.label);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export default TableHeadCell;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function getComparator(
|
|
1
|
+
export function getComparator(orderDirection: any, orderBy: any, lang: any): (a: any, b: any) => number;
|
|
2
2
|
export function stableSort(array: any, comparator: any): any;
|
|
@@ -3,7 +3,7 @@ import get from 'lodash/get';
|
|
|
3
3
|
var descendingComparator = function descendingComparator(_ref) {
|
|
4
4
|
var a = _ref.a,
|
|
5
5
|
b = _ref.b,
|
|
6
|
-
|
|
6
|
+
orderDirection = _ref.orderDirection,
|
|
7
7
|
orderBy = _ref.orderBy,
|
|
8
8
|
lang = _ref.lang;
|
|
9
9
|
var aValue = get(a, orderBy, '');
|
|
@@ -22,7 +22,7 @@ var descendingComparator = function descendingComparator(_ref) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
var _Intl$Collator = Intl.Collator(lang || 'en', {
|
|
25
|
-
caseFirst:
|
|
25
|
+
caseFirst: orderDirection === 'asc' ? 'upper' : 'lower'
|
|
26
26
|
}),
|
|
27
27
|
compare = _Intl$Collator.compare;
|
|
28
28
|
|
|
@@ -32,12 +32,12 @@ var descendingComparator = function descendingComparator(_ref) {
|
|
|
32
32
|
return bValue - aValue;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
export var getComparator = function getComparator(
|
|
36
|
-
return
|
|
35
|
+
export var getComparator = function getComparator(orderDirection, orderBy, lang) {
|
|
36
|
+
return orderDirection === 'desc' ? function (a, b) {
|
|
37
37
|
return descendingComparator({
|
|
38
38
|
a: a,
|
|
39
39
|
b: b,
|
|
40
|
-
|
|
40
|
+
orderDirection: orderDirection,
|
|
41
41
|
orderBy: orderBy,
|
|
42
42
|
lang: lang
|
|
43
43
|
});
|
|
@@ -45,7 +45,7 @@ export var getComparator = function getComparator(order, orderBy, lang) {
|
|
|
45
45
|
return -descendingComparator({
|
|
46
46
|
a: a,
|
|
47
47
|
b: b,
|
|
48
|
-
|
|
48
|
+
orderDirection: orderDirection,
|
|
49
49
|
orderBy: orderBy,
|
|
50
50
|
lang: lang
|
|
51
51
|
});
|
|
@@ -34,15 +34,15 @@ var VirtualizedTable = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
34
34
|
|
|
35
35
|
var _useState = useState('asc'),
|
|
36
36
|
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
orderDirection = _useState2[0],
|
|
38
|
+
setOrderDirection = _useState2[1];
|
|
39
39
|
|
|
40
40
|
var _useState3 = useState(defaultOrder),
|
|
41
41
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
42
|
orderBy = _useState4[0],
|
|
43
43
|
setOrderBy = _useState4[1];
|
|
44
44
|
|
|
45
|
-
var sortedData = stableSort(rows, getComparator(
|
|
45
|
+
var sortedData = orderBy ? stableSort(rows, getComparator(orderDirection, orderBy)) : rows;
|
|
46
46
|
var data = secondarySort ? secondarySort(sortedData) : sortedData;
|
|
47
47
|
|
|
48
48
|
var _ref2 = (groups === null || groups === void 0 ? void 0 : groups(data)) || {},
|
|
@@ -60,11 +60,11 @@ var VirtualizedTable = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
var handleSort = function handleSort(property) {
|
|
63
|
-
var isAsc = orderBy === property &&
|
|
63
|
+
var isAsc = orderBy === property && orderDirection === 'asc';
|
|
64
64
|
var newOrder = isAsc ? 'desc' : 'asc';
|
|
65
|
-
|
|
65
|
+
setOrderDirection(newOrder);
|
|
66
66
|
setOrderBy(property);
|
|
67
|
-
onSortChange({
|
|
67
|
+
onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange({
|
|
68
68
|
order: newOrder,
|
|
69
69
|
orderBy: property
|
|
70
70
|
});
|
|
@@ -93,7 +93,7 @@ var VirtualizedTable = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
93
93
|
columns: columns,
|
|
94
94
|
rowCount: rows.length,
|
|
95
95
|
context: _context,
|
|
96
|
-
|
|
96
|
+
orderDirection: orderDirection,
|
|
97
97
|
orderBy: orderBy,
|
|
98
98
|
onClick: handleSort,
|
|
99
99
|
onSelectAllClick: handleSelectAll
|
|
@@ -129,9 +129,13 @@ VirtualizedTable.defaultProps = {
|
|
|
129
129
|
onSelectAll: function onSelectAll() {}
|
|
130
130
|
};
|
|
131
131
|
VirtualizedTable.propTypes = {
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
/** Column ID to be used for initiating the sort */
|
|
133
|
+
defaultOrder: PropTypes.string,
|
|
134
|
+
|
|
135
|
+
/** Returned object is: PropTypes.shape({ groupLabels: PropTypes.array, groupCounts: PropTypes.array }) */
|
|
136
|
+
groups: PropTypes.func,
|
|
137
|
+
|
|
138
|
+
/** Callback called after the sort */
|
|
139
|
+
onSortChange: PropTypes.func
|
|
136
140
|
};
|
|
137
141
|
export default VirtualizedTable;
|
|
@@ -24,60 +24,55 @@ var SelectionProvider = function SelectionProvider(_ref) {
|
|
|
24
24
|
selectedItemsId = _useState2[0],
|
|
25
25
|
setSelectedItemsId = _useState2[1];
|
|
26
26
|
|
|
27
|
-
var isSelectedItem = function isSelectedItem(
|
|
27
|
+
var isSelectedItem = function isSelectedItem(itemId) {
|
|
28
28
|
return selectedItemsId.some(function (selectedItemId) {
|
|
29
|
-
return selectedItemId ===
|
|
29
|
+
return selectedItemId === itemId;
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
var isSelectionEnabled = selectedItemsId.length > 0;
|
|
34
34
|
|
|
35
|
-
var addSelectedItem = function addSelectedItem(
|
|
35
|
+
var addSelectedItem = function addSelectedItem(itemId) {
|
|
36
36
|
setSelectedItemsId(function (prev) {
|
|
37
|
-
return [].concat(_toConsumableArray(prev), [
|
|
37
|
+
return [].concat(_toConsumableArray(prev), [itemId]);
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
var removeSelectedItem = function removeSelectedItem(
|
|
41
|
+
var removeSelectedItem = function removeSelectedItem(itemId) {
|
|
42
42
|
setSelectedItemsId(function (prev) {
|
|
43
43
|
return prev.filter(function (el) {
|
|
44
|
-
return el !==
|
|
44
|
+
return el !== itemId;
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
var toggleSelectedItem = function toggleSelectedItem(
|
|
50
|
-
if (isSelectedItem(
|
|
51
|
-
removeSelectedItem(
|
|
49
|
+
var toggleSelectedItem = function toggleSelectedItem(itemId) {
|
|
50
|
+
if (isSelectedItem(itemId)) {
|
|
51
|
+
removeSelectedItem(itemId);
|
|
52
52
|
} else {
|
|
53
|
-
addSelectedItem(
|
|
53
|
+
addSelectedItem(itemId);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
var selectAll = function selectAll(
|
|
58
|
-
|
|
59
|
-
return item._id;
|
|
60
|
-
});
|
|
61
|
-
setSelectedItemsId(ids);
|
|
57
|
+
var selectAll = function selectAll(itemsId) {
|
|
58
|
+
setSelectedItemsId(itemsId);
|
|
62
59
|
};
|
|
63
60
|
|
|
64
61
|
var unselectAll = function unselectAll() {
|
|
65
62
|
setSelectedItemsId([]);
|
|
66
63
|
};
|
|
67
64
|
|
|
68
|
-
var isSelectedAllItems = function isSelectedAllItems(
|
|
65
|
+
var isSelectedAllItems = function isSelectedAllItems(itemsId) {
|
|
69
66
|
var a = selectedItemsId.sort();
|
|
70
|
-
var b =
|
|
71
|
-
return item._id;
|
|
72
|
-
}).sort();
|
|
67
|
+
var b = itemsId.sort();
|
|
73
68
|
return isEqual(a, b);
|
|
74
69
|
};
|
|
75
70
|
|
|
76
|
-
var toggleSelectAllItems = function toggleSelectAllItems(
|
|
77
|
-
if (isSelectedAllItems(
|
|
71
|
+
var toggleSelectAllItems = function toggleSelectAllItems(itemsId) {
|
|
72
|
+
if (isSelectedAllItems(itemsId)) {
|
|
78
73
|
unselectAll();
|
|
79
74
|
} else {
|
|
80
|
-
selectAll(
|
|
75
|
+
selectAll(itemsId);
|
|
81
76
|
}
|
|
82
77
|
};
|
|
83
78
|
|