cozy-ui 74.6.1 → 75.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 +33 -0
- package/package.json +1 -1
- package/react/DropdownButton/Readme.md +62 -14
- package/react/DropdownButton/index.jsx +80 -21
- package/react/DropdownText/Readme.md +25 -12
- package/react/DropdownText/index.jsx +2 -1
- package/react/Viewer/Panel/ActionMenuDesktop.jsx +68 -0
- package/react/Viewer/Panel/ActionMenuMobile.jsx +75 -0
- package/react/Viewer/Panel/ActionMenuProvider.jsx +35 -0
- package/react/Viewer/Panel/ActionMenuWrapper.jsx +58 -30
- package/react/Viewer/Panel/Qualification.jsx +12 -12
- package/react/Viewer/Panel/QualificationListItemContact.jsx +10 -9
- package/react/Viewer/Panel/QualificationListItemOther.jsx +18 -20
- package/react/Viewer/Panel/styles.styl +13 -0
- package/react/Viewer/Readme.md +9 -4
- package/react/Viewer/ViewerContainer.jsx +30 -20
- package/react/Viewer/helpers.js +27 -1
- package/react/Viewer/helpers.spec.js +42 -4
- package/react/Viewer/locales/en.json +3 -2
- package/react/Viewer/locales/fr.json +3 -2
- package/react/__snapshots__/examples.spec.jsx.snap +320 -304
- package/transpiled/react/DropdownButton/index.js +79 -22
- package/transpiled/react/DropdownText/index.js +24 -19
- package/transpiled/react/Viewer/Panel/ActionMenuDesktop.js +67 -0
- package/transpiled/react/Viewer/Panel/ActionMenuMobile.js +71 -0
- package/transpiled/react/Viewer/Panel/ActionMenuProvider.js +34 -0
- package/transpiled/react/Viewer/Panel/ActionMenuWrapper.js +58 -32
- package/transpiled/react/Viewer/Panel/Qualification.js +13 -13
- package/transpiled/react/Viewer/Panel/QualificationListItemContact.js +11 -10
- package/transpiled/react/Viewer/Panel/QualificationListItemOther.js +4 -4
- package/transpiled/react/Viewer/ViewerContainer.js +7 -3
- package/transpiled/react/Viewer/helpers.js +22 -1
- package/transpiled/react/Viewer/withViewerLocales.js +6 -4
- package/transpiled/react/stylesheet.css +1 -1
- package/react/DropdownButton/styles.styl +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
# [75.0.0](https://github.com/cozy/cozy-ui/compare/v74.7.0...v75.0.0) (2022-09-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **DropdownText:** Icon and text was misaligned for `body1` variant ([53cd532](https://github.com/cozy/cozy-ui/commit/53cd532))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **DropdownButton:** Add ripple effect and some props ([cecf1f0](https://github.com/cozy/cozy-ui/commit/cecf1f0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* **DropdownButton:** Horizontal alignment could be different. You have to use `className="u-mh-half"` if you want the old behavior.
|
|
17
|
+
|
|
18
|
+
# [74.7.0](https://github.com/cozy/cozy-ui/compare/v74.6.1...v74.7.0) (2022-09-16)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **Viewer:** Add "edit" option ([f40c926](https://github.com/cozy/cozy-ui/commit/f40c926))
|
|
24
|
+
* **Viewer:** Add ActionMenuDesktop component ([e5db778](https://github.com/cozy/cozy-ui/commit/e5db778))
|
|
25
|
+
* **Viewer:** Add ActionMenuMobile component ([87dac4d](https://github.com/cozy/cozy-ui/commit/87dac4d))
|
|
26
|
+
* **Viewer:** Add ActionMenuProvider component ([7938117](https://github.com/cozy/cozy-ui/commit/7938117))
|
|
27
|
+
* **Viewer:** Add buildEditAttributePath helper ([677bff7](https://github.com/cozy/cozy-ui/commit/677bff7))
|
|
28
|
+
* **Viewer:** Add editPathByModelProps prop to ViewerContainer ([c615600](https://github.com/cozy/cozy-ui/commit/c615600))
|
|
29
|
+
* **Viewer:** Add name & fileId props to ActionMenuWrapper ([fbcf1bc](https://github.com/cozy/cozy-ui/commit/fbcf1bc))
|
|
30
|
+
* **Viewer:** Add optionFile & file props to ActionMenuWrapper ([a5f0b2d](https://github.com/cozy/cozy-ui/commit/a5f0b2d))
|
|
31
|
+
* **Viewer:** Remove filename attribute in Viewer information ([8f76f46](https://github.com/cozy/cozy-ui/commit/8f76f46))
|
|
32
|
+
* **Viewer:** Use actionMenuContext in ActionMenuWrapper ([89518aa](https://github.com/cozy/cozy-ui/commit/89518aa))
|
|
33
|
+
|
|
1
34
|
## [74.6.1](https://github.com/cozy/cozy-ui/compare/v74.6.0...v74.6.1) (2022-09-15)
|
|
2
35
|
|
|
3
36
|
|
package/package.json
CHANGED
|
@@ -1,29 +1,77 @@
|
|
|
1
|
-
This component can be used as a trigger to open menus, for example an ActionMenu component.
|
|
1
|
+
This component can be used as a trigger to open menus, for example an ActionMenu component. It uses `DropdownText` so you can use all its props.
|
|
2
2
|
|
|
3
3
|
```jsx
|
|
4
|
-
import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton'
|
|
5
|
-
import Typography from
|
|
4
|
+
import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton'
|
|
5
|
+
import Typography from 'cozy-ui/transpiled/react/Typography'
|
|
6
|
+
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const variants = [
|
|
9
|
+
'h1',
|
|
10
|
+
'h2',
|
|
11
|
+
'h3',
|
|
12
|
+
'h4',
|
|
13
|
+
'h5',
|
|
14
|
+
'subtitle1',
|
|
15
|
+
'subtitle2',
|
|
16
|
+
'body1',
|
|
17
|
+
'body2',
|
|
18
|
+
'caption'
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
;
|
|
22
|
+
|
|
23
|
+
<>
|
|
24
|
+
<Grid container>
|
|
25
|
+
<Grid item xs={6}>
|
|
26
|
+
Default
|
|
27
|
+
{variants.map((variant, index) => (
|
|
28
|
+
<div key={index} className='u-mb-1'>
|
|
29
|
+
<DropdownButton textVariant={variant}>
|
|
30
|
+
{variant}
|
|
31
|
+
</DropdownButton>
|
|
32
|
+
</div>
|
|
33
|
+
))}
|
|
34
|
+
</Grid>
|
|
35
|
+
<Grid item xs={6}>
|
|
36
|
+
Disabled
|
|
37
|
+
{variants.map((variant, index) => (
|
|
38
|
+
<div key={index} className='u-mb-1'>
|
|
39
|
+
<DropdownButton textVariant={variant} disabled>
|
|
40
|
+
{variant}
|
|
41
|
+
</DropdownButton>
|
|
42
|
+
</div>
|
|
43
|
+
))}
|
|
44
|
+
</Grid>
|
|
45
|
+
</Grid>
|
|
46
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', marginBottom: '1rem' }}>
|
|
9
47
|
<DropdownButton>
|
|
10
|
-
|
|
48
|
+
This is a long text without ellipsis without restrictive container
|
|
11
49
|
</DropdownButton>
|
|
12
50
|
</div>
|
|
13
|
-
<div>
|
|
51
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
|
|
14
52
|
<DropdownButton>
|
|
15
|
-
|
|
53
|
+
This is a long text without ellipsis inside a restrictive container
|
|
16
54
|
</DropdownButton>
|
|
17
55
|
</div>
|
|
18
|
-
<div>
|
|
19
|
-
<DropdownButton>
|
|
20
|
-
|
|
56
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
|
|
57
|
+
<DropdownButton noWrap>
|
|
58
|
+
This is a long text with ellipsis inside a container
|
|
21
59
|
</DropdownButton>
|
|
22
60
|
</div>
|
|
23
|
-
<div>
|
|
61
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
|
|
24
62
|
<DropdownButton>
|
|
25
|
-
<
|
|
63
|
+
Text with<br />breaking spaces<br />inside content
|
|
64
|
+
</DropdownButton>
|
|
65
|
+
</div>
|
|
66
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
|
|
67
|
+
<DropdownButton fullWidth spaceBetween>
|
|
68
|
+
Space between text and icon (fullWidth needed)
|
|
69
|
+
</DropdownButton>
|
|
70
|
+
</div>
|
|
71
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '100%' }}>
|
|
72
|
+
<DropdownButton fullWidth>
|
|
73
|
+
Full width but no space between text and icon
|
|
26
74
|
</DropdownButton>
|
|
27
75
|
</div>
|
|
28
|
-
|
|
76
|
+
</>
|
|
29
77
|
```
|
|
@@ -1,26 +1,85 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import Icon from '../Icon'
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import Button from '@material-ui/core/Button'
|
|
5
4
|
|
|
6
|
-
import
|
|
5
|
+
import { makeStyles } from '../styles'
|
|
6
|
+
import DropdownText from '../DropdownText'
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
const useStyles = makeStyles({
|
|
9
|
+
root: {
|
|
10
|
+
height: 'auto',
|
|
11
|
+
width: ({ fullWidth, noWrap }) =>
|
|
12
|
+
fullWidth || noWrap ? `calc(100% + 16px)` : 'auto',
|
|
13
|
+
margin: '-8px',
|
|
14
|
+
padding: '8px'
|
|
15
|
+
},
|
|
16
|
+
text: {
|
|
17
|
+
textTransform: 'none',
|
|
18
|
+
textAlign: 'left'
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const DropdownButton = forwardRef(
|
|
23
|
+
(
|
|
24
|
+
{
|
|
25
|
+
spaceBetween,
|
|
26
|
+
textVariant,
|
|
27
|
+
disabled,
|
|
28
|
+
fullWidth,
|
|
29
|
+
noWrap,
|
|
30
|
+
children,
|
|
31
|
+
className,
|
|
32
|
+
dropdownTextProps,
|
|
33
|
+
...props
|
|
34
|
+
},
|
|
35
|
+
ref
|
|
36
|
+
) => {
|
|
37
|
+
const { root, text } = useStyles({ fullWidth, noWrap })
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Button
|
|
41
|
+
ref={ref}
|
|
42
|
+
classes={{ root, text }}
|
|
43
|
+
disabled={disabled}
|
|
44
|
+
className={className}
|
|
45
|
+
{...props}
|
|
46
|
+
>
|
|
47
|
+
<DropdownText
|
|
48
|
+
variant={textVariant}
|
|
49
|
+
spaceBetween={spaceBetween}
|
|
50
|
+
disabled={disabled}
|
|
51
|
+
noWrap={noWrap}
|
|
52
|
+
{...dropdownTextProps}
|
|
53
|
+
>
|
|
54
|
+
{children}
|
|
55
|
+
</DropdownText>
|
|
56
|
+
</Button>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
24
59
|
)
|
|
25
60
|
|
|
61
|
+
DropdownButton.defaultProps = {
|
|
62
|
+
spaceBetween: false,
|
|
63
|
+
textVariant: 'body1',
|
|
64
|
+
disabled: false,
|
|
65
|
+
fullWidth: false,
|
|
66
|
+
noWrap: false
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
DropdownButton.propTypes = {
|
|
70
|
+
/** Weither there is a space between the label and the icon */
|
|
71
|
+
spaceBetween: PropTypes.bool,
|
|
72
|
+
/** Like variant from Typography component */
|
|
73
|
+
textVariant: PropTypes.string,
|
|
74
|
+
/** Whether the component is disabled */
|
|
75
|
+
disabled: PropTypes.bool,
|
|
76
|
+
fullWidth: PropTypes.bool,
|
|
77
|
+
/** Whether using ellipsis on text */
|
|
78
|
+
noWrap: PropTypes.bool,
|
|
79
|
+
/** Props assigned to the DropdownText inner component */
|
|
80
|
+
dropdownTextProps: PropTypes.object,
|
|
81
|
+
className: PropTypes.string,
|
|
82
|
+
children: PropTypes.node
|
|
83
|
+
}
|
|
84
|
+
|
|
26
85
|
export default DropdownButton
|
|
@@ -43,17 +43,30 @@ const variants = [
|
|
|
43
43
|
))}
|
|
44
44
|
</Grid>
|
|
45
45
|
</Grid>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', marginBottom: '1rem' }}>
|
|
47
|
+
<DropdownText>
|
|
48
|
+
This is a long text without ellipsis without restrictive container
|
|
49
|
+
</DropdownText>
|
|
50
|
+
</div>
|
|
51
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
|
|
52
|
+
<DropdownText>
|
|
53
|
+
This is a long text without ellipsis inside a restrictive container
|
|
54
|
+
</DropdownText>
|
|
55
|
+
</div>
|
|
56
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
|
|
57
|
+
<DropdownText noWrap>
|
|
58
|
+
This is a long text with ellipsis inside a container
|
|
59
|
+
</DropdownText>
|
|
60
|
+
</div>
|
|
61
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
|
|
62
|
+
<DropdownText>
|
|
63
|
+
Text with<br />breaking spaces<br />inside content
|
|
64
|
+
</DropdownText>
|
|
65
|
+
</div>
|
|
66
|
+
<div style={{ border: '1px dashed var(--borderMainColor)', width: '100%' }}>
|
|
67
|
+
<DropdownText spaceBetween>
|
|
68
|
+
Space between text and icon
|
|
69
|
+
</DropdownText>
|
|
70
|
+
</div>
|
|
58
71
|
</>
|
|
59
72
|
```
|
|
@@ -21,6 +21,7 @@ const useStyles = makeStyles(theme => ({
|
|
|
21
21
|
endIcon: {
|
|
22
22
|
display: 'flex',
|
|
23
23
|
marginLeft: '5px',
|
|
24
|
+
marginTop: ({ variant }) => (variant === 'body1' ? '3px' : undefined),
|
|
24
25
|
color: ({ disabled }) =>
|
|
25
26
|
theme.palette.text[disabled ? 'disabled' : 'primary']
|
|
26
27
|
}
|
|
@@ -56,7 +57,7 @@ const DropdownText = forwardRef(
|
|
|
56
57
|
},
|
|
57
58
|
ref
|
|
58
59
|
) => {
|
|
59
|
-
const styles = useStyles({ spaceBetween, disabled, color })
|
|
60
|
+
const styles = useStyles({ spaceBetween, disabled, color, variant })
|
|
60
61
|
|
|
61
62
|
return (
|
|
62
63
|
<div ref={ref} className={styles.container} {...props}>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import styles from './styles.styl'
|
|
4
|
+
|
|
5
|
+
import Icon from '../../Icon'
|
|
6
|
+
import Copy from '../../Icons/Copy'
|
|
7
|
+
import Edit from '../../Icons/Rename'
|
|
8
|
+
import ActionMenu, { ActionMenuItem } from '../../ActionMenu'
|
|
9
|
+
import Typography from '../../Typography'
|
|
10
|
+
import { useI18n } from '../../I18n'
|
|
11
|
+
import AppLinker from '../../AppLinker'
|
|
12
|
+
|
|
13
|
+
const ActionMenuDesktop = forwardRef(
|
|
14
|
+
({ onClose, isEditable, actions, appLink, appSlug }, ref) => {
|
|
15
|
+
const { handleCopy, handleEdit } = actions
|
|
16
|
+
const { t } = useI18n()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ActionMenu
|
|
20
|
+
className={styles['ActionMenuDesktop-ActionMenu']}
|
|
21
|
+
onClose={onClose}
|
|
22
|
+
anchorElRef={ref}
|
|
23
|
+
>
|
|
24
|
+
{isEditable && (
|
|
25
|
+
<AppLinker app={{ slug: appSlug }} href={appLink}>
|
|
26
|
+
{({ onClick, href }) => {
|
|
27
|
+
return (
|
|
28
|
+
<a
|
|
29
|
+
href={href}
|
|
30
|
+
className={
|
|
31
|
+
!appLink &&
|
|
32
|
+
styles['ActionMenuDesktop-ActionMenu-link-disabled']
|
|
33
|
+
}
|
|
34
|
+
onClick={() => handleEdit(onClick)}
|
|
35
|
+
>
|
|
36
|
+
<ActionMenuItem left={<Icon icon={Edit} />}>
|
|
37
|
+
<Typography>
|
|
38
|
+
{t(`Viewer.panel.qualification.actions.edit`)}
|
|
39
|
+
</Typography>
|
|
40
|
+
</ActionMenuItem>
|
|
41
|
+
</a>
|
|
42
|
+
)
|
|
43
|
+
}}
|
|
44
|
+
</AppLinker>
|
|
45
|
+
)}
|
|
46
|
+
<ActionMenuItem onClick={handleCopy} left={<Icon icon={Copy} />}>
|
|
47
|
+
<Typography>
|
|
48
|
+
{t(`Viewer.panel.qualification.actions.copy`)}
|
|
49
|
+
</Typography>
|
|
50
|
+
</ActionMenuItem>
|
|
51
|
+
</ActionMenu>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
ActionMenuDesktop.displayName = 'ActionMenuDesktop'
|
|
56
|
+
|
|
57
|
+
ActionMenuDesktop.propTypes = {
|
|
58
|
+
onClose: PropTypes.func,
|
|
59
|
+
isEditable: PropTypes.bool,
|
|
60
|
+
actions: PropTypes.shape({
|
|
61
|
+
handleCopy: PropTypes.func,
|
|
62
|
+
handleEdit: PropTypes.func
|
|
63
|
+
}),
|
|
64
|
+
appLink: PropTypes.string,
|
|
65
|
+
appSlug: PropTypes.string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default ActionMenuDesktop
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import List from '../../MuiCozyTheme/List'
|
|
5
|
+
import ListItem from '../../MuiCozyTheme/ListItem'
|
|
6
|
+
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
7
|
+
import ListItemText from '../../ListItemText'
|
|
8
|
+
import Icon from '../../Icon'
|
|
9
|
+
import Copy from '../../Icons/Copy'
|
|
10
|
+
import Edit from '../../Icons/Rename'
|
|
11
|
+
import BottomSheet, { BottomSheetItem } from '../../BottomSheet'
|
|
12
|
+
import { useI18n } from '../../I18n'
|
|
13
|
+
import AppLinker from '../../AppLinker'
|
|
14
|
+
|
|
15
|
+
const ActionMenuMobile = ({
|
|
16
|
+
onClose,
|
|
17
|
+
isEditable,
|
|
18
|
+
actions,
|
|
19
|
+
appLink,
|
|
20
|
+
appSlug
|
|
21
|
+
}) => {
|
|
22
|
+
const { t } = useI18n()
|
|
23
|
+
const { handleCopy, handleEdit } = actions
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<BottomSheet backdrop onClose={onClose}>
|
|
27
|
+
<BottomSheetItem disableGutters>
|
|
28
|
+
<List>
|
|
29
|
+
{isEditable && (
|
|
30
|
+
<AppLinker app={{ slug: appSlug }} href={appLink}>
|
|
31
|
+
{({ onClick, href }) => {
|
|
32
|
+
return (
|
|
33
|
+
<ListItem
|
|
34
|
+
button
|
|
35
|
+
component="a"
|
|
36
|
+
href={href}
|
|
37
|
+
onClick={() => handleEdit(onClick)}
|
|
38
|
+
disabled={!appLink}
|
|
39
|
+
>
|
|
40
|
+
<ListItemIcon>
|
|
41
|
+
<Icon icon={Edit} />
|
|
42
|
+
</ListItemIcon>
|
|
43
|
+
<ListItemText
|
|
44
|
+
primary={t(`Viewer.panel.qualification.actions.edit`)}
|
|
45
|
+
/>
|
|
46
|
+
</ListItem>
|
|
47
|
+
)
|
|
48
|
+
}}
|
|
49
|
+
</AppLinker>
|
|
50
|
+
)}
|
|
51
|
+
<ListItem button onClick={handleCopy}>
|
|
52
|
+
<ListItemIcon>
|
|
53
|
+
<Icon icon={Copy} />
|
|
54
|
+
</ListItemIcon>
|
|
55
|
+
<ListItemText
|
|
56
|
+
primary={t(`Viewer.panel.qualification.actions.copyClipboard`)}
|
|
57
|
+
/>
|
|
58
|
+
</ListItem>
|
|
59
|
+
</List>
|
|
60
|
+
</BottomSheetItem>
|
|
61
|
+
</BottomSheet>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
ActionMenuMobile.propTypes = {
|
|
66
|
+
onClose: PropTypes.func,
|
|
67
|
+
isEditable: PropTypes.bool,
|
|
68
|
+
actions: PropTypes.shape({
|
|
69
|
+
handleCopy: PropTypes.func,
|
|
70
|
+
handleEdit: PropTypes.func
|
|
71
|
+
}),
|
|
72
|
+
appLink: PropTypes.string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default ActionMenuMobile
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {object} useActionMenuContextReturn
|
|
5
|
+
* @property {string} information
|
|
6
|
+
* @property {string} page
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const ActionMenuContext = createContext()
|
|
10
|
+
|
|
11
|
+
const ActionMenuProvider = ({ children, editPathByModelProps = {} }) => {
|
|
12
|
+
return (
|
|
13
|
+
<ActionMenuContext.Provider value={editPathByModelProps}>
|
|
14
|
+
{children}
|
|
15
|
+
</ActionMenuContext.Provider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @returns {useActionMenuContextReturn}
|
|
21
|
+
*/
|
|
22
|
+
const useActionMenuContext = () => {
|
|
23
|
+
const actionMenuContext = useContext(ActionMenuContext)
|
|
24
|
+
if (!actionMenuContext) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
'ActionMenuContext must be used within a ActionMenuProvider'
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return actionMenuContext
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default useActionMenuContext
|
|
34
|
+
|
|
35
|
+
export { ActionMenuProvider }
|
|
@@ -1,23 +1,45 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
7
|
-
import ListItemText from '../../ListItemText'
|
|
8
|
-
import Icon from '../../Icon'
|
|
9
|
-
import Copy from '../../Icons/Copy'
|
|
10
|
-
import BottomSheet, { BottomSheetItem } from '../../BottomSheet'
|
|
11
|
-
import ActionMenu, { ActionMenuItem } from '../../ActionMenu'
|
|
12
|
-
import Typography from '../../Typography'
|
|
4
|
+
import { useAppLinkWithStoreFallback, useClient } from 'cozy-client'
|
|
5
|
+
|
|
13
6
|
import useBreakpoints from '../../hooks/useBreakpoints'
|
|
14
7
|
import { useI18n } from '../../I18n'
|
|
15
8
|
import useViewerSnackbar from '../snackbar/ViewerSnackbarProvider'
|
|
9
|
+
import { buildEditAttributePath, getCurrentModel } from '../helpers'
|
|
10
|
+
import useActionMenuContext from './ActionMenuProvider'
|
|
11
|
+
import ActionMenuMobile from './ActionMenuMobile'
|
|
12
|
+
import ActionMenuDesktop from './ActionMenuDesktop'
|
|
13
|
+
|
|
14
|
+
const mespapiersAppSlug = 'mespapiers'
|
|
15
|
+
|
|
16
|
+
const checkEditableAttribute = name => {
|
|
17
|
+
const isNotEditableAttributes = ['datetime', 'qualification', 'contact']
|
|
18
|
+
return !isNotEditableAttributes.includes(name)
|
|
19
|
+
}
|
|
16
20
|
|
|
17
|
-
const ActionMenuWrapper = forwardRef(({ onClose,
|
|
21
|
+
const ActionMenuWrapper = forwardRef(({ onClose, optionFile }, ref) => {
|
|
22
|
+
const { name, value } = optionFile
|
|
23
|
+
const editPathByModelProps = useActionMenuContext()
|
|
18
24
|
const { isMobile } = useBreakpoints()
|
|
19
25
|
const { t } = useI18n()
|
|
20
26
|
const { showViewerSnackbar } = useViewerSnackbar()
|
|
27
|
+
const client = useClient()
|
|
28
|
+
|
|
29
|
+
const isEditableAttribute = checkEditableAttribute(name)
|
|
30
|
+
const currentModel = getCurrentModel(name)
|
|
31
|
+
const editPath = buildEditAttributePath(
|
|
32
|
+
editPathByModelProps,
|
|
33
|
+
currentModel,
|
|
34
|
+
optionFile.name
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
const { fetchStatus, url } = useAppLinkWithStoreFallback(
|
|
38
|
+
mespapiersAppSlug,
|
|
39
|
+
client,
|
|
40
|
+
editPath
|
|
41
|
+
)
|
|
42
|
+
const isAppLinkLoaded = fetchStatus === 'loaded'
|
|
21
43
|
|
|
22
44
|
const handleCopy = () => {
|
|
23
45
|
if (navigator?.clipboard) {
|
|
@@ -32,38 +54,44 @@ const ActionMenuWrapper = forwardRef(({ onClose, value }, ref) => {
|
|
|
32
54
|
onClose()
|
|
33
55
|
}
|
|
34
56
|
|
|
57
|
+
const handleEdit = cb => {
|
|
58
|
+
if (isAppLinkLoaded) {
|
|
59
|
+
onClose()
|
|
60
|
+
cb && cb()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
35
64
|
if (isMobile) {
|
|
36
65
|
return (
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<ListItemText
|
|
45
|
-
primary={t(`Viewer.panel.qualification.actions.copyClipboard`)}
|
|
46
|
-
/>
|
|
47
|
-
</ListItem>
|
|
48
|
-
</List>
|
|
49
|
-
</BottomSheetItem>
|
|
50
|
-
</BottomSheet>
|
|
66
|
+
<ActionMenuMobile
|
|
67
|
+
onClose={onClose}
|
|
68
|
+
isEditable={editPath && isEditableAttribute}
|
|
69
|
+
actions={{ handleCopy, handleEdit }}
|
|
70
|
+
appLink={url}
|
|
71
|
+
appSlug={mespapiersAppSlug}
|
|
72
|
+
/>
|
|
51
73
|
)
|
|
52
74
|
}
|
|
53
75
|
|
|
54
76
|
return (
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
<ActionMenuDesktop
|
|
78
|
+
ref={ref}
|
|
79
|
+
onClose={onClose}
|
|
80
|
+
isEditable={editPath && isEditableAttribute}
|
|
81
|
+
actions={{ handleCopy, handleEdit }}
|
|
82
|
+
appLink={url}
|
|
83
|
+
appSlug={mespapiersAppSlug}
|
|
84
|
+
/>
|
|
60
85
|
)
|
|
61
86
|
})
|
|
62
87
|
ActionMenuWrapper.displayName = 'ActionMenuWrapper'
|
|
63
88
|
|
|
64
89
|
ActionMenuWrapper.propTypes = {
|
|
65
90
|
onClose: PropTypes.func,
|
|
66
|
-
|
|
91
|
+
optionFile: PropTypes.shape({
|
|
92
|
+
name: PropTypes.string,
|
|
93
|
+
value: PropTypes.string
|
|
94
|
+
})
|
|
67
95
|
}
|
|
68
96
|
|
|
69
97
|
export default ActionMenuWrapper
|
|
@@ -19,19 +19,19 @@ const Qualification = ({ file = {} }) => {
|
|
|
19
19
|
const { metadata = {} } = file
|
|
20
20
|
const actionBtnRef = useRef([])
|
|
21
21
|
const [optionFile, setOptionFile] = useState({
|
|
22
|
-
isOpen: false,
|
|
23
22
|
id: '',
|
|
23
|
+
name: '',
|
|
24
24
|
value: ''
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
const hideActionsMenu = () => {
|
|
28
|
-
setOptionFile({
|
|
28
|
+
setOptionFile({ id: '', name: '', value: '' })
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const toggleActionsMenu = (id, value) => {
|
|
31
|
+
const toggleActionsMenu = (id, name, value) => {
|
|
32
32
|
setOptionFile(prev => {
|
|
33
|
-
if (prev.
|
|
34
|
-
return {
|
|
33
|
+
if (prev.value) return { id: '', name: '', value: '' }
|
|
34
|
+
return { id, name, value }
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -56,7 +56,7 @@ const Qualification = ({ file = {} }) => {
|
|
|
56
56
|
key={idx}
|
|
57
57
|
ref={actionBtnRef.current[idx]}
|
|
58
58
|
metadataComputed={meta}
|
|
59
|
-
toggleActionsMenu={val => toggleActionsMenu(idx, val)}
|
|
59
|
+
toggleActionsMenu={val => toggleActionsMenu(idx, name, val)}
|
|
60
60
|
/>
|
|
61
61
|
)
|
|
62
62
|
}
|
|
@@ -67,13 +67,13 @@ const Qualification = ({ file = {} }) => {
|
|
|
67
67
|
key={idx}
|
|
68
68
|
ref={actionBtnRef.current[idx]}
|
|
69
69
|
metadataComputed={meta}
|
|
70
|
-
toggleActionsMenu={val => toggleActionsMenu(idx, val)}
|
|
70
|
+
toggleActionsMenu={val => toggleActionsMenu(idx, name, val)}
|
|
71
71
|
/>
|
|
72
72
|
)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
if (knowOtherMetadataNames.includes(name)) {
|
|
76
|
-
if (name === '
|
|
76
|
+
if (name === 'contact') {
|
|
77
77
|
return <QualificationListItemContact key={idx} file={file} />
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -81,18 +81,18 @@ const Qualification = ({ file = {} }) => {
|
|
|
81
81
|
<QualificationListItemOther
|
|
82
82
|
key={idx}
|
|
83
83
|
ref={actionBtnRef.current[idx]}
|
|
84
|
-
filename={file.name}
|
|
85
84
|
metadataComputed={meta}
|
|
86
|
-
toggleActionsMenu={val => toggleActionsMenu(idx, val)}
|
|
85
|
+
toggleActionsMenu={val => toggleActionsMenu(idx, name, val)}
|
|
87
86
|
/>
|
|
88
87
|
)
|
|
89
88
|
}
|
|
90
89
|
})}
|
|
91
90
|
|
|
92
|
-
{optionFile.
|
|
91
|
+
{optionFile.value && (
|
|
93
92
|
<ActionMenuWrapper
|
|
94
93
|
onClose={hideActionsMenu}
|
|
95
|
-
|
|
94
|
+
file={file}
|
|
95
|
+
optionFile={optionFile}
|
|
96
96
|
ref={actionBtnRef.current[optionFile.id]}
|
|
97
97
|
/>
|
|
98
98
|
)}
|