cozy-viewer 1.1.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.
Files changed (250) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +21 -0
  3. package/Readme.md +44 -0
  4. package/babel.config.js +23 -0
  5. package/dist/Footer/BottomSheetContent.d.ts +12 -0
  6. package/dist/Footer/BottomSheetContent.js +45 -0
  7. package/dist/Footer/DownloadButton.d.ts +16 -0
  8. package/dist/Footer/DownloadButton.js +113 -0
  9. package/dist/Footer/FooterActionButtons.d.ts +13 -0
  10. package/dist/Footer/FooterActionButtons.js +33 -0
  11. package/dist/Footer/FooterActionButtons.spec.d.ts +1 -0
  12. package/dist/Footer/FooterContent.d.ts +16 -0
  13. package/dist/Footer/FooterContent.js +120 -0
  14. package/dist/Footer/ForwardButton.d.ts +20 -0
  15. package/dist/Footer/ForwardButton.js +177 -0
  16. package/dist/Footer/ForwardButton.spec.d.ts +1 -0
  17. package/dist/Footer/ForwardOrDownloadButton.d.ts +11 -0
  18. package/dist/Footer/ForwardOrDownloadButton.js +42 -0
  19. package/dist/Footer/Sharing.d.ts +16 -0
  20. package/dist/Footer/Sharing.js +79 -0
  21. package/dist/Footer/helpers.d.ts +8 -0
  22. package/dist/Footer/helpers.js +179 -0
  23. package/dist/Footer/helpers.spec.d.ts +1 -0
  24. package/dist/NoViewer/DownloadButton.d.ts +2 -0
  25. package/dist/NoViewer/DownloadButton.js +52 -0
  26. package/dist/NoViewer/FileIcon.d.ts +4 -0
  27. package/dist/NoViewer/FileIcon.js +76 -0
  28. package/dist/NoViewer/NoViewer.d.ts +18 -0
  29. package/dist/NoViewer/NoViewer.js +64 -0
  30. package/dist/NoViewer/NoViewer.spec.d.ts +1 -0
  31. package/dist/NoViewer/index.d.ts +1 -0
  32. package/dist/NoViewer/index.js +15 -0
  33. package/dist/Panel/ActionMenuDesktop.d.ts +3 -0
  34. package/dist/Panel/ActionMenuDesktop.js +91 -0
  35. package/dist/Panel/ActionMenuMobile.d.ts +20 -0
  36. package/dist/Panel/ActionMenuMobile.js +95 -0
  37. package/dist/Panel/ActionMenuWrapper.d.ts +3 -0
  38. package/dist/Panel/ActionMenuWrapper.js +155 -0
  39. package/dist/Panel/Certifications.d.ts +2 -0
  40. package/dist/Panel/Certifications.js +80 -0
  41. package/dist/Panel/PanelContent.d.ts +2 -0
  42. package/dist/Panel/PanelContent.js +71 -0
  43. package/dist/Panel/Qualification.d.ts +2 -0
  44. package/dist/Panel/Qualification.js +148 -0
  45. package/dist/Panel/QualificationListItemContact.d.ts +10 -0
  46. package/dist/Panel/QualificationListItemContact.js +123 -0
  47. package/dist/Panel/QualificationListItemDate.d.ts +3 -0
  48. package/dist/Panel/QualificationListItemDate.js +90 -0
  49. package/dist/Panel/QualificationListItemInformation.d.ts +3 -0
  50. package/dist/Panel/QualificationListItemInformation.js +84 -0
  51. package/dist/Panel/QualificationListItemInformation.spec.d.ts +1 -0
  52. package/dist/Panel/QualificationListItemOther.d.ts +3 -0
  53. package/dist/Panel/QualificationListItemOther.js +78 -0
  54. package/dist/Panel/QualificationListItemText.d.ts +13 -0
  55. package/dist/Panel/QualificationListItemText.js +42 -0
  56. package/dist/Panel/getPanelBlocks.d.ts +26 -0
  57. package/dist/Panel/getPanelBlocks.js +79 -0
  58. package/dist/Panel/getPanelBlocks.spec.d.ts +1 -0
  59. package/dist/Viewer.d.ts +39 -0
  60. package/dist/Viewer.js +191 -0
  61. package/dist/ViewerContainer.d.ts +22 -0
  62. package/dist/ViewerContainer.js +221 -0
  63. package/dist/ViewerExposer.d.ts +2 -0
  64. package/dist/ViewerExposer.js +13 -0
  65. package/dist/ViewerInformationsWrapper.d.ts +20 -0
  66. package/dist/ViewerInformationsWrapper.js +68 -0
  67. package/dist/ViewerInformationsWrapper.spec.d.ts +1 -0
  68. package/dist/ViewerWithCustomPanelAndFooter.d.ts +2 -0
  69. package/dist/ViewerWithCustomPanelAndFooter.js +78 -0
  70. package/dist/ViewersByFile/AudioViewer.d.ts +74 -0
  71. package/dist/ViewersByFile/AudioViewer.js +57 -0
  72. package/dist/ViewersByFile/AudioViewer.spec.d.ts +1 -0
  73. package/dist/ViewersByFile/BlankPaperViewer.d.ts +2 -0
  74. package/dist/ViewersByFile/BlankPaperViewer.js +97 -0
  75. package/dist/ViewersByFile/ImageViewer.d.ts +31 -0
  76. package/dist/ViewersByFile/ImageViewer.js +385 -0
  77. package/dist/ViewersByFile/ImageViewer.spec.d.ts +1 -0
  78. package/dist/ViewersByFile/NoNetworkViewer.d.ts +2 -0
  79. package/dist/ViewersByFile/NoNetworkViewer.js +54 -0
  80. package/dist/ViewersByFile/OnlyOfficeViewer.d.ts +2 -0
  81. package/dist/ViewersByFile/OnlyOfficeViewer.js +46 -0
  82. package/dist/ViewersByFile/PdfJsViewer.d.ts +31 -0
  83. package/dist/ViewersByFile/PdfJsViewer.js +283 -0
  84. package/dist/ViewersByFile/PdfJsViewer.spec.d.ts +1 -0
  85. package/dist/ViewersByFile/PdfMobileViewer.d.ts +4 -0
  86. package/dist/ViewersByFile/PdfMobileViewer.js +185 -0
  87. package/dist/ViewersByFile/PdfMobileViewer.spec.d.ts +1 -0
  88. package/dist/ViewersByFile/ShortcutViewer.d.ts +2 -0
  89. package/dist/ViewersByFile/ShortcutViewer.js +61 -0
  90. package/dist/ViewersByFile/ShortcutViewer.spec.d.ts +4 -0
  91. package/dist/ViewersByFile/TextViewer.d.ts +90 -0
  92. package/dist/ViewersByFile/TextViewer.js +250 -0
  93. package/dist/ViewersByFile/TextViewer.spec.d.ts +1 -0
  94. package/dist/ViewersByFile/VideoViewer.d.ts +74 -0
  95. package/dist/ViewersByFile/VideoViewer.js +46 -0
  96. package/dist/ViewersByFile/VideoViewer.spec.d.ts +1 -0
  97. package/dist/assets/IlluGenericNewPage.svg +10 -0
  98. package/dist/components/ExpirationAlert.d.ts +2 -0
  99. package/dist/components/ExpirationAlert.js +129 -0
  100. package/dist/components/ExpirationAnnotation.d.ts +10 -0
  101. package/dist/components/ExpirationAnnotation.js +56 -0
  102. package/dist/components/Footer.d.ts +4 -0
  103. package/dist/components/Footer.js +41 -0
  104. package/dist/components/InformationPanel.d.ts +12 -0
  105. package/dist/components/InformationPanel.js +36 -0
  106. package/dist/components/Navigation.d.ts +18 -0
  107. package/dist/components/Navigation.js +63 -0
  108. package/dist/components/PdfToolbarButton.d.ts +16 -0
  109. package/dist/components/PdfToolbarButton.js +40 -0
  110. package/dist/components/PrintButton.d.ts +16 -0
  111. package/dist/components/PrintButton.js +163 -0
  112. package/dist/components/Toolbar.d.ts +2 -0
  113. package/dist/components/Toolbar.js +146 -0
  114. package/dist/components/ToolbarButtons.d.ts +5 -0
  115. package/dist/components/ToolbarButtons.js +20 -0
  116. package/dist/components/ToolbarFilePath.d.ts +3 -0
  117. package/dist/components/ToolbarFilePath.js +92 -0
  118. package/dist/components/ViewerByFile.d.ts +7 -0
  119. package/dist/components/ViewerByFile.js +137 -0
  120. package/dist/components/ViewerByFile.spec.d.ts +1 -0
  121. package/dist/components/ViewerControls.d.ts +9 -0
  122. package/dist/components/ViewerControls.js +251 -0
  123. package/dist/components/ViewerControls.spec.d.ts +1 -0
  124. package/dist/components/ViewerSpinner.d.ts +2 -0
  125. package/dist/components/ViewerSpinner.js +31 -0
  126. package/dist/docs/DemoProvider.d.ts +6 -0
  127. package/dist/docs/DemoProvider.js +159 -0
  128. package/dist/helpers.d.ts +37 -0
  129. package/dist/helpers.js +190 -0
  130. package/dist/helpers.spec.d.ts +1 -0
  131. package/dist/hoc/withFileUrl.d.ts +75 -0
  132. package/dist/hoc/withFileUrl.js +231 -0
  133. package/dist/hoc/withViewerLocales.d.ts +1 -0
  134. package/dist/hoc/withViewerLocales.js +15 -0
  135. package/dist/hooks/useReferencedContactName.d.ts +5 -0
  136. package/dist/hooks/useReferencedContactName.js +45 -0
  137. package/dist/index.d.ts +10 -0
  138. package/dist/index.js +75 -0
  139. package/dist/locales/index.d.ts +6 -0
  140. package/dist/locales/index.js +18 -0
  141. package/dist/proptypes.d.ts +7 -0
  142. package/dist/proptypes.js +25 -0
  143. package/dist/providers/ActionMenuProvider.d.ts +13 -0
  144. package/dist/providers/ActionMenuProvider.js +47 -0
  145. package/dist/providers/EncryptedProvider.d.ts +8 -0
  146. package/dist/providers/EncryptedProvider.js +43 -0
  147. package/dist/queries.d.ts +15 -0
  148. package/dist/queries.js +40 -0
  149. package/dist/stylesheet.css +218 -0
  150. package/jest.config.js +23 -0
  151. package/package.json +62 -0
  152. package/preprocess.js +16 -0
  153. package/src/Footer/BottomSheetContent.jsx +30 -0
  154. package/src/Footer/DownloadButton.jsx +66 -0
  155. package/src/Footer/FooterActionButtons.jsx +22 -0
  156. package/src/Footer/FooterActionButtons.spec.jsx +30 -0
  157. package/src/Footer/FooterContent.jsx +102 -0
  158. package/src/Footer/ForwardButton.jsx +95 -0
  159. package/src/Footer/ForwardButton.spec.jsx +87 -0
  160. package/src/Footer/ForwardOrDownloadButton.jsx +24 -0
  161. package/src/Footer/Sharing.jsx +59 -0
  162. package/src/Footer/helpers.js +106 -0
  163. package/src/Footer/helpers.spec.js +77 -0
  164. package/src/NoViewer/DownloadButton.jsx +28 -0
  165. package/src/NoViewer/FileIcon.jsx +46 -0
  166. package/src/NoViewer/NoViewer.jsx +30 -0
  167. package/src/NoViewer/NoViewer.spec.jsx +44 -0
  168. package/src/NoViewer/__snapshots__/NoViewer.spec.jsx.snap +82 -0
  169. package/src/NoViewer/index.jsx +1 -0
  170. package/src/Panel/ActionMenuDesktop.jsx +69 -0
  171. package/src/Panel/ActionMenuMobile.jsx +76 -0
  172. package/src/Panel/ActionMenuWrapper.jsx +104 -0
  173. package/src/Panel/Certifications.jsx +63 -0
  174. package/src/Panel/PanelContent.jsx +50 -0
  175. package/src/Panel/Qualification.jsx +114 -0
  176. package/src/Panel/QualificationListItemContact.jsx +85 -0
  177. package/src/Panel/QualificationListItemDate.jsx +78 -0
  178. package/src/Panel/QualificationListItemInformation.jsx +68 -0
  179. package/src/Panel/QualificationListItemInformation.spec.jsx +73 -0
  180. package/src/Panel/QualificationListItemOther.jsx +61 -0
  181. package/src/Panel/QualificationListItemText.jsx +30 -0
  182. package/src/Panel/getPanelBlocks.jsx +56 -0
  183. package/src/Panel/getPanelBlocks.spec.jsx +79 -0
  184. package/src/Panel/styles.styl +13 -0
  185. package/src/Readme.md +352 -0
  186. package/src/Viewer.jsx +135 -0
  187. package/src/ViewerContainer.jsx +170 -0
  188. package/src/ViewerExposer.js +3 -0
  189. package/src/ViewerInformationsWrapper.jsx +70 -0
  190. package/src/ViewerInformationsWrapper.spec.jsx +63 -0
  191. package/src/ViewerWithCustomPanelAndFooter.jsx +57 -0
  192. package/src/ViewersByFile/AudioViewer.jsx +22 -0
  193. package/src/ViewersByFile/AudioViewer.spec.jsx +40 -0
  194. package/src/ViewersByFile/BlankPaperViewer.jsx +47 -0
  195. package/src/ViewersByFile/ImageViewer.jsx +331 -0
  196. package/src/ViewersByFile/ImageViewer.spec.jsx +73 -0
  197. package/src/ViewersByFile/NoNetworkViewer.jsx +18 -0
  198. package/src/ViewersByFile/OnlyOfficeViewer.jsx +29 -0
  199. package/src/ViewersByFile/PdfJsViewer.jsx +210 -0
  200. package/src/ViewersByFile/PdfJsViewer.spec.jsx +161 -0
  201. package/src/ViewersByFile/PdfMobileViewer.jsx +106 -0
  202. package/src/ViewersByFile/PdfMobileViewer.spec.jsx +76 -0
  203. package/src/ViewersByFile/ShortcutViewer.jsx +38 -0
  204. package/src/ViewersByFile/ShortcutViewer.spec.jsx +32 -0
  205. package/src/ViewersByFile/TextViewer.jsx +126 -0
  206. package/src/ViewersByFile/TextViewer.spec.jsx +118 -0
  207. package/src/ViewersByFile/VideoViewer.jsx +13 -0
  208. package/src/ViewersByFile/VideoViewer.spec.jsx +40 -0
  209. package/src/ViewersByFile/__snapshots__/AudioViewer.spec.jsx.snap +43 -0
  210. package/src/ViewersByFile/__snapshots__/ShortcutViewer.spec.jsx.snap +57 -0
  211. package/src/ViewersByFile/__snapshots__/TextViewer.spec.jsx.snap +100 -0
  212. package/src/ViewersByFile/__snapshots__/VideoViewer.spec.jsx.snap +19 -0
  213. package/src/ViewersByFile/styles.styl +87 -0
  214. package/src/assets/IlluGenericNewPage.svg +10 -0
  215. package/src/components/ExpirationAlert.jsx +86 -0
  216. package/src/components/ExpirationAnnotation.jsx +39 -0
  217. package/src/components/Footer.jsx +14 -0
  218. package/src/components/InformationPanel.jsx +26 -0
  219. package/src/components/Navigation.jsx +40 -0
  220. package/src/components/PdfToolbarButton.jsx +26 -0
  221. package/src/components/PrintButton.jsx +89 -0
  222. package/src/components/Toolbar.jsx +111 -0
  223. package/src/components/ToolbarButtons.jsx +11 -0
  224. package/src/components/ToolbarFilePath.jsx +61 -0
  225. package/src/components/ViewerByFile.jsx +112 -0
  226. package/src/components/ViewerByFile.spec.jsx +100 -0
  227. package/src/components/ViewerControls.jsx +191 -0
  228. package/src/components/ViewerControls.spec.jsx +54 -0
  229. package/src/components/ViewerSpinner.jsx +17 -0
  230. package/src/components/styles.styl +93 -0
  231. package/src/docs/DemoProvider.jsx +90 -0
  232. package/src/helpers.js +131 -0
  233. package/src/helpers.spec.js +136 -0
  234. package/src/hoc/withFileUrl.jsx +93 -0
  235. package/src/hoc/withViewerLocales.jsx +5 -0
  236. package/src/hooks/useReferencedContactName.jsx +26 -0
  237. package/src/index.jsx +12 -0
  238. package/src/locales/en.json +66 -0
  239. package/src/locales/fr.json +66 -0
  240. package/src/locales/index.js +4 -0
  241. package/src/proptypes.js +12 -0
  242. package/src/providers/ActionMenuProvider.jsx +35 -0
  243. package/src/providers/EncryptedProvider.jsx +25 -0
  244. package/src/queries.js +20 -0
  245. package/src/styles.styl +22 -0
  246. package/src/vars.styl +6 -0
  247. package/test/__mocks__/fileMock.js +3 -0
  248. package/test/jestLib/setup.js +5 -0
  249. package/tsconfig-build.json +13 -0
  250. package/tsconfig.json +34 -0
@@ -0,0 +1,78 @@
1
+ import PropTypes from 'prop-types'
2
+ import React, { forwardRef } from 'react'
3
+
4
+ import {
5
+ isExpired,
6
+ isExpiringSoon,
7
+ getTranslatedNameForDateMetadata,
8
+ formatDateMetadataValue
9
+ } from 'cozy-client/dist/models/paper'
10
+ import Icon from 'cozy-ui/transpiled/react/Icon'
11
+ import IconButton from 'cozy-ui/transpiled/react/IconButton'
12
+ import Dots from 'cozy-ui/transpiled/react/Icons/Dots'
13
+ import ListItem from 'cozy-ui/transpiled/react/ListItem'
14
+ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction'
15
+ import Typography from 'cozy-ui/transpiled/react/Typography'
16
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
17
+
18
+ import QualificationListItemText from './QualificationListItemText'
19
+ import ExpirationAnnotation from '../components/ExpirationAnnotation'
20
+
21
+ const QualificationListItemDate = forwardRef(
22
+ ({ file, formattedMetadataQualification, toggleActionsMenu }, ref) => {
23
+ const { f, lang } = useI18n()
24
+ const { name, value } = formattedMetadataQualification
25
+ const formattedTitle = getTranslatedNameForDateMetadata(name, { lang })
26
+ const formattedDate = formatDateMetadataValue(value, {
27
+ f,
28
+ lang
29
+ })
30
+ const isExpirationDate = name === 'expirationDate'
31
+
32
+ return (
33
+ <ListItem className="u-pl-2 u-pr-3">
34
+ <QualificationListItemText
35
+ primary={formattedTitle}
36
+ secondary={
37
+ <>
38
+ <Typography component="span" variant="inherit">
39
+ {formattedDate}
40
+ </Typography>
41
+ {isExpirationDate &&
42
+ (isExpired(file) || isExpiringSoon(file)) && (
43
+ <>
44
+ <Typography component="span" variant="inherit">
45
+ {' · '}
46
+ </Typography>
47
+ <ExpirationAnnotation file={file} />
48
+ </>
49
+ )}
50
+ </>
51
+ }
52
+ disabled={!value}
53
+ />
54
+ <ListItemSecondaryAction>
55
+ <IconButton
56
+ ref={ref}
57
+ onClick={() => toggleActionsMenu(formattedDate)}
58
+ >
59
+ <Icon icon={Dots} />
60
+ </IconButton>
61
+ </ListItemSecondaryAction>
62
+ </ListItem>
63
+ )
64
+ }
65
+ )
66
+
67
+ QualificationListItemDate.displayName = 'QualificationListItemDate'
68
+
69
+ QualificationListItemDate.propTypes = {
70
+ file: PropTypes.object.isRequired,
71
+ formattedMetadataQualification: PropTypes.shape({
72
+ name: PropTypes.string,
73
+ value: PropTypes.string
74
+ }).isRequired,
75
+ toggleActionsMenu: PropTypes.func.isRequired
76
+ }
77
+
78
+ export default QualificationListItemDate
@@ -0,0 +1,68 @@
1
+ import PropTypes from 'prop-types'
2
+ import React, { forwardRef } from 'react'
3
+
4
+ import {
5
+ getTranslatedNameForInformationMetadata,
6
+ formatInformationMetadataValue
7
+ } from 'cozy-client/dist/models/paper'
8
+ import Icon from 'cozy-ui/transpiled/react/Icon'
9
+ import IconButton from 'cozy-ui/transpiled/react/IconButton'
10
+ import Dots from 'cozy-ui/transpiled/react/Icons/Dots'
11
+ import ListItem from 'cozy-ui/transpiled/react/ListItem'
12
+ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction'
13
+ import MidEllipsis from 'cozy-ui/transpiled/react/MidEllipsis'
14
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
15
+
16
+ import QualificationListItemText from './QualificationListItemText'
17
+
18
+ const QualificationListItemInformation = forwardRef(
19
+ ({ formattedMetadataQualification, file, toggleActionsMenu }, ref) => {
20
+ const { lang } = useI18n()
21
+ const { name, value } = formattedMetadataQualification
22
+ const qualificationLabel = file.metadata.qualification.label
23
+
24
+ const formattedTitle = getTranslatedNameForInformationMetadata(name, {
25
+ lang,
26
+ qualificationLabel
27
+ })
28
+ const formattedValue = formatInformationMetadataValue(value, {
29
+ lang,
30
+ name,
31
+ qualificationLabel
32
+ })
33
+
34
+ const titleComponent =
35
+ formattedTitle === name ? <MidEllipsis text={name} /> : formattedTitle
36
+
37
+ return (
38
+ <ListItem className="u-pl-2 u-pr-3">
39
+ <QualificationListItemText
40
+ primary={titleComponent}
41
+ secondary={formattedValue}
42
+ disabled={!value}
43
+ />
44
+ <ListItemSecondaryAction>
45
+ <IconButton
46
+ ref={ref}
47
+ onClick={() => toggleActionsMenu(value)}
48
+ data-testid="toggleActionsMenuBtn"
49
+ >
50
+ <Icon icon={Dots} />
51
+ </IconButton>
52
+ </ListItemSecondaryAction>
53
+ </ListItem>
54
+ )
55
+ }
56
+ )
57
+
58
+ QualificationListItemInformation.displayName = 'QualificationListItemNumber'
59
+
60
+ QualificationListItemInformation.propTypes = {
61
+ formattedMetadataQualification: PropTypes.shape({
62
+ name: PropTypes.string,
63
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
64
+ }).isRequired,
65
+ toggleActionsMenu: PropTypes.func.isRequired
66
+ }
67
+
68
+ export default QualificationListItemInformation
@@ -0,0 +1,73 @@
1
+ import { fireEvent, render } from '@testing-library/react'
2
+ import React from 'react'
3
+
4
+ import QualificationListItemInformation from './QualificationListItemInformation'
5
+
6
+ jest.mock('cozy-ui/transpiled/react/providers/I18n', () => ({
7
+ useI18n: jest.fn(() => ({ t: x => x }))
8
+ }))
9
+
10
+ const setup = ({
11
+ formattedMetadataQualification = {},
12
+ toggleActionsMenu = jest.fn()
13
+ } = {}) => {
14
+ return render(
15
+ <QualificationListItemInformation
16
+ formattedMetadataQualification={formattedMetadataQualification}
17
+ toggleActionsMenu={toggleActionsMenu}
18
+ file={{
19
+ metadata: { qualification: { label: 'label_of_qualification' } }
20
+ }}
21
+ />
22
+ )
23
+ }
24
+
25
+ describe('QualificationListItemInformation', () => {
26
+ describe('formattedMetadataQualification', () => {
27
+ it('should display default text if value is falsy', () => {
28
+ const formattedMetadataQualification = { name: 'country', value: '' }
29
+ const { getByText } = setup({ formattedMetadataQualification })
30
+
31
+ expect(getByText('No information'))
32
+ })
33
+ // eslint-disable-next-line jest/no-focused-tests
34
+ it.only('should display current value if it is truthy', () => {
35
+ const formattedMetadataQualification = {
36
+ name: 'country',
37
+ value: 'Italie'
38
+ }
39
+ const { queryByText } = setup({
40
+ formattedMetadataQualification
41
+ })
42
+
43
+ expect(queryByText('No information')).toBeNull()
44
+ expect(queryByText('Italie')).toBeInTheDocument()
45
+ })
46
+ it('should display current value if it number type', () => {
47
+ const formattedMetadataQualification = { name: 'country', value: 0 }
48
+ const { queryByText } = setup({
49
+ formattedMetadataQualification
50
+ })
51
+
52
+ expect(queryByText('No information')).toBeNull()
53
+ expect(queryByText('0')).toBeInTheDocument()
54
+ })
55
+ })
56
+ describe('toggleActionsMenu', () => {
57
+ it('should call toggleActionsMenu with current value on click it', () => {
58
+ const formattedMetadataQualification = {
59
+ name: 'country',
60
+ value: 'Italie'
61
+ }
62
+ const toggleActionsMenu = jest.fn()
63
+ const { getByTestId } = setup({
64
+ toggleActionsMenu,
65
+ formattedMetadataQualification
66
+ })
67
+ const toggleActionsMenuBtn = getByTestId('toggleActionsMenuBtn')
68
+ fireEvent.click(toggleActionsMenuBtn)
69
+
70
+ expect(toggleActionsMenu).toBeCalledWith('Italie')
71
+ })
72
+ })
73
+ })
@@ -0,0 +1,61 @@
1
+ import PropTypes from 'prop-types'
2
+ import React, { forwardRef } from 'react'
3
+
4
+ import {
5
+ getTranslatedNameForOtherMetadata,
6
+ formatOtherMetadataValue
7
+ } from 'cozy-client/dist/models/paper'
8
+ import Icon from 'cozy-ui/transpiled/react/Icon'
9
+ import IconButton from 'cozy-ui/transpiled/react/IconButton'
10
+ import Dots from 'cozy-ui/transpiled/react/Icons/Dots'
11
+ import ListItem from 'cozy-ui/transpiled/react/ListItem'
12
+ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction'
13
+ import MidEllipsis from 'cozy-ui/transpiled/react/MidEllipsis'
14
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
15
+
16
+ import QualificationListItemText from './QualificationListItemText'
17
+
18
+ const QualificationListItemOther = forwardRef(
19
+ ({ formattedMetadataQualification, toggleActionsMenu }, ref) => {
20
+ const { lang } = useI18n()
21
+ const { name, value } = formattedMetadataQualification
22
+
23
+ if (!value) return null
24
+
25
+ const formattedTitle = getTranslatedNameForOtherMetadata(name, {
26
+ lang
27
+ })
28
+ const formattedValue = formatOtherMetadataValue(value, {
29
+ lang,
30
+ name
31
+ })
32
+
33
+ return (
34
+ <ListItem className="u-pl-2 u-pr-3">
35
+ <QualificationListItemText
36
+ primary={formattedTitle}
37
+ secondary={<MidEllipsis text={formattedValue} />}
38
+ />
39
+ <ListItemSecondaryAction>
40
+ <IconButton
41
+ ref={ref}
42
+ onClick={() => toggleActionsMenu(formattedValue)}
43
+ >
44
+ <Icon icon={Dots} />
45
+ </IconButton>
46
+ </ListItemSecondaryAction>
47
+ </ListItem>
48
+ )
49
+ }
50
+ )
51
+ QualificationListItemOther.displayName = 'QualificationListItemOther'
52
+
53
+ QualificationListItemOther.propTypes = {
54
+ formattedMetadataQualification: PropTypes.shape({
55
+ name: PropTypes.string,
56
+ value: PropTypes.string
57
+ }).isRequired,
58
+ toggleActionsMenu: PropTypes.func.isRequired
59
+ }
60
+
61
+ export default QualificationListItemOther
@@ -0,0 +1,30 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+
4
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
5
+ import Typography from 'cozy-ui/transpiled/react/Typography'
6
+
7
+ const QualificationListItemText = ({ primary, secondary, disabled }) => {
8
+ return (
9
+ <ListItemText
10
+ disableTypography
11
+ primary={<Typography variant="caption">{primary}</Typography>}
12
+ secondary={
13
+ <Typography
14
+ component="div"
15
+ variant="body1"
16
+ style={disabled ? { color: 'var(--disabledTextColor)' } : undefined}
17
+ >
18
+ {secondary}
19
+ </Typography>
20
+ }
21
+ />
22
+ )
23
+ }
24
+
25
+ QualificationListItemText.propTypes = {
26
+ primary: PropTypes.string.isRequired,
27
+ secondary: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired
28
+ }
29
+
30
+ export default QualificationListItemText
@@ -0,0 +1,56 @@
1
+ import { models } from 'cozy-client'
2
+ import KonnectorBlock from 'cozy-harvest-lib/dist/components/KonnectorBlock'
3
+
4
+ import Certifications from './Certifications'
5
+ import Qualification from './Qualification'
6
+
7
+ const { isFromKonnector, hasQualifications, hasCertifications } = models.file
8
+
9
+ /**
10
+ * @typedef {Object} PanelBlockSpec
11
+ * @property {Function} condition - Function that returns true if the block should be displayed
12
+ * @property {React.Component} component - Component to display
13
+ */
14
+
15
+ /**
16
+ * @typedef {Object.<string, PanelBlockSpec>} PanelBlocksSpecs
17
+ */
18
+
19
+ /**
20
+ * Returns the specs of the blocks to display in the panel
21
+ * @param {boolean} isPublic - Whether the panel is displayed in public view
22
+ * @returns {PanelBlocksSpecs}
23
+ */
24
+ export const getPanelBlocksSpecs = (isPublic = false) => ({
25
+ qualifications: {
26
+ condition: hasQualifications,
27
+ component: Qualification
28
+ },
29
+ konnector: {
30
+ condition: file => isFromKonnector(file) && !isPublic,
31
+ component: KonnectorBlock
32
+ },
33
+ certifications: {
34
+ condition: hasCertifications,
35
+ component: Certifications
36
+ }
37
+ })
38
+
39
+ /**
40
+ * Returns the blocks to display in the panel
41
+ * @param {Object} options
42
+ * @param {PanelBlocksSpecs} options.panelBlocksSpecs - Specs of the blocks to display in the panel
43
+ * @param {import('cozy-client/types/types').FileDocument} options.file - File object
44
+ * @returns {Array.<React.Component>}
45
+ */
46
+ const getPanelBlocks = ({ panelBlocksSpecs, file }) => {
47
+ const panelBlocks = []
48
+
49
+ Object.values(panelBlocksSpecs).forEach(panelBlock => {
50
+ panelBlock.condition(file) && panelBlocks.push(panelBlock.component)
51
+ })
52
+
53
+ return panelBlocks
54
+ }
55
+
56
+ export default getPanelBlocks
@@ -0,0 +1,79 @@
1
+ import getPanelBlocks, { getPanelBlocksSpecs } from './getPanelBlocks'
2
+
3
+ jest.mock('cozy-harvest-lib/dist/components/KonnectorBlock', () => jest.fn())
4
+ const block1Component = jest.fn()
5
+ const block2Component = jest.fn()
6
+
7
+ describe('getPanelBlocks', () => {
8
+ it('should return only blocks with truthy condition', () => {
9
+ // with two truthy component
10
+ expect(
11
+ getPanelBlocks({
12
+ panelBlocksSpecs: {
13
+ block1: {
14
+ condition: () => true,
15
+ component: block1Component
16
+ },
17
+ block2: {
18
+ condition: () => true,
19
+ component: block2Component
20
+ }
21
+ }
22
+ })
23
+ ).toMatchObject([block1Component, block2Component])
24
+
25
+ // with one truthy component
26
+ expect(
27
+ getPanelBlocks({
28
+ panelBlocksSpecs: {
29
+ block1: {
30
+ condition: () => false,
31
+ component: block1Component
32
+ },
33
+ block2: {
34
+ condition: () => true,
35
+ component: block2Component
36
+ }
37
+ }
38
+ })
39
+ ).toMatchObject([block2Component])
40
+
41
+ // with no truthy component
42
+ expect(
43
+ getPanelBlocks({
44
+ panelBlocksSpecs: {
45
+ block1: {
46
+ condition: () => false,
47
+ component: block1Component
48
+ },
49
+ block2: {
50
+ condition: () => false,
51
+ component: block2Component
52
+ }
53
+ }
54
+ })
55
+ ).toMatchObject([])
56
+
57
+ // with no specs
58
+ expect(getPanelBlocks({ panelBlocksSpecs: {} })).toMatchObject([])
59
+ })
60
+ })
61
+
62
+ describe('getPanelBlocksSpecs', () => {
63
+ it('should return the specs of the blocks to display in the panel', () => {
64
+ expect(getPanelBlocksSpecs()).toEqual({
65
+ qualifications: {
66
+ condition: expect.any(Function),
67
+ component: expect.anything()
68
+ },
69
+ konnector: {
70
+ condition: expect.any(Function),
71
+ component: expect.anything()
72
+ },
73
+ certifications: {
74
+ condition: expect.any(Function),
75
+ component: expect.anything()
76
+ }
77
+ })
78
+ })
79
+ })
@@ -0,0 +1,13 @@
1
+ .ActionMenuDesktop-ActionMenu
2
+ a
3
+ padding 0 !important // Waiting for the migration of the ActionMenu on the Viewer
4
+ .ActionMenuDesktop-ActionMenu-link-disabled
5
+ > div
6
+ cursor default
7
+ &:hover
8
+ background-color initial
9
+ > div
10
+ svg
11
+ fill var(--disabledTextColor)
12
+ p
13
+ color var(--disabledTextColor)