cozy-ui 58.3.0 → 58.4.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 CHANGED
@@ -1,3 +1,11 @@
1
+ # [58.4.0](https://github.com/cozy/cozy-ui/compare/v58.3.0...v58.4.0) (2021-12-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * Added Qualification panel block ([9fbaaa6](https://github.com/cozy/cozy-ui/commit/9fbaaa6))
7
+ * Upgrade cozy-client ([8820f81](https://github.com/cozy/cozy-ui/commit/8820f81))
8
+
1
9
  # [58.3.0](https://github.com/cozy/cozy-ui/compare/v58.2.0...v58.3.0) (2021-12-13)
2
10
 
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "58.3.0",
3
+ "version": "58.4.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -87,7 +87,7 @@
87
87
  "commitlint": "7.6.1",
88
88
  "commitlint-config-cozy": "0.6.0",
89
89
  "copyfiles": "2.1.1",
90
- "cozy-client": "^18.1.2",
90
+ "cozy-client": "^27.5.1",
91
91
  "cozy-device-helper": "1.12.0",
92
92
  "cozy-doctypes": "^1.69.0",
93
93
  "cozy-harvest-lib": "^6.7.3",
@@ -164,7 +164,7 @@
164
164
  },
165
165
  "peerDependencies": {
166
166
  "@material-ui/core": "4",
167
- "cozy-client": ">=18.1.2",
167
+ "cozy-client": ">=27.5.1",
168
168
  "cozy-device-helper": "^1.10.0",
169
169
  "cozy-doctypes": "^1.69.0",
170
170
  "cozy-harvest-lib": "^6.7.3",
@@ -40,7 +40,7 @@ const BottomSheetContent = forwardRef(({ file, disableSharing }, ref) => {
40
40
  elevation={index === panelBlocks.length - 1 ? 0 : 2}
41
41
  square
42
42
  >
43
- <Typography variant="h4">
43
+ <Typography variant="h4" className={'u-pv-1 u-ph-1'}>
44
44
  <PanelBlock file={file} />
45
45
  </Typography>
46
46
  </Paper>
@@ -36,7 +36,7 @@ const Certifications = ({ file, t }) => {
36
36
  const hasElectronicSafe = has(file, 'metadata.electronicSafe')
37
37
 
38
38
  return (
39
- <div className="u-pv-1-half u-ph-2">
39
+ <>
40
40
  {hasCarbonCopy && (
41
41
  <Certification
42
42
  icon={CarbonCopyIcon}
@@ -51,7 +51,7 @@ const Certifications = ({ file, t }) => {
51
51
  caption={t('Viewer.panel.certifications.electronicSafe.caption')}
52
52
  />
53
53
  )}
54
- </div>
54
+ </>
55
55
  )
56
56
  }
57
57
 
@@ -30,7 +30,7 @@ const PanelContent = ({ file, t }) => {
30
30
  elevation={2}
31
31
  square
32
32
  >
33
- <Typography variant="h4">
33
+ <Typography variant="h4" className={'u-pv-1 u-ph-2'}>
34
34
  <PanelBlock file={file} />
35
35
  </Typography>
36
36
  </Paper>
@@ -0,0 +1,95 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import { useQuery, models, getReferencedBy } from 'cozy-client'
5
+
6
+ import List from '../../MuiCozyTheme/List'
7
+ import ListItem from '../../MuiCozyTheme/ListItem'
8
+ import QualificationListItemText from './QualificationListItemText'
9
+ import { withViewerLocales } from '../withViewerLocales'
10
+ import { buildContactByIdsQuery } from '../queries'
11
+
12
+ const {
13
+ contact: { getDisplayName },
14
+ document: {
15
+ locales: { getBoundT }
16
+ }
17
+ } = models
18
+
19
+ const Qualification = ({ file = {}, t, f, lang }) => {
20
+ const scannerT = getBoundT(lang)
21
+
22
+ const { name: filename, metadata = {} } = file
23
+ const {
24
+ qualification = {},
25
+ page: pageLabel,
26
+ datetime,
27
+ datetimeLabel
28
+ } = metadata
29
+
30
+ const contactIds = getReferencedBy(file, 'io.cozy.contacts').map(
31
+ ref => ref.id
32
+ )
33
+
34
+ const contactByIdsQuery = buildContactByIdsQuery(contactIds)
35
+ const { data: contactList } = useQuery(
36
+ contactByIdsQuery.definition,
37
+ contactByIdsQuery.options
38
+ )
39
+
40
+ const contactsFullname = Array.isArray(contactList)
41
+ ? contactList.map(contact => `${getDisplayName(contact)}`).join(', ')
42
+ : ''
43
+
44
+ return (
45
+ <List>
46
+ {datetime && (
47
+ <ListItem className={'u-ph-0'}>
48
+ <QualificationListItemText
49
+ primary={t(
50
+ `Viewer.panel.qualification.date.title.${
51
+ datetimeLabel === 'datetime' || datetimeLabel === undefined
52
+ ? 'addedOn'
53
+ : datetimeLabel
54
+ }`
55
+ )}
56
+ secondary={f(datetime, 'DD/MM/YYYY')}
57
+ />
58
+ </ListItem>
59
+ )}
60
+ {contactsFullname && (
61
+ <ListItem className={'u-ph-0'}>
62
+ <QualificationListItemText
63
+ primary={t('Viewer.panel.qualification.identity')}
64
+ secondary={contactsFullname}
65
+ />
66
+ </ListItem>
67
+ )}
68
+ <ListItem className={'u-ph-0'}>
69
+ <QualificationListItemText
70
+ primary={t('Viewer.panel.qualification.label.title')}
71
+ secondary={
72
+ pageLabel
73
+ ? t(`Viewer.panel.qualification.label.${pageLabel}`)
74
+ : filename
75
+ }
76
+ />
77
+ </ListItem>
78
+ <ListItem className={'u-ph-0'}>
79
+ <QualificationListItemText
80
+ primary={t('Viewer.panel.qualification.qualification')}
81
+ secondary={scannerT(`Scan.items.${qualification.label}`)}
82
+ />
83
+ </ListItem>
84
+ </List>
85
+ )
86
+ }
87
+
88
+ Qualification.propTypes = {
89
+ file: PropTypes.object.isRequired,
90
+ t: PropTypes.func.isRequired,
91
+ f: PropTypes.func.isRequired,
92
+ lang: PropTypes.string.isRequired
93
+ }
94
+
95
+ export default withViewerLocales(Qualification)
@@ -0,0 +1,23 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import ListItemText from '../../ListItemText'
5
+ import Typography from '../../Typography'
6
+
7
+ const QualificationListItemText = ({ primary, secondary }) => {
8
+ return (
9
+ <ListItemText
10
+ className={'u-pv-0'}
11
+ disableTypography
12
+ primary={<Typography variant={'caption'}>{primary}</Typography>}
13
+ secondary={<Typography variant={'body1'}>{secondary}</Typography>}
14
+ />
15
+ )
16
+ }
17
+
18
+ QualificationListItemText.propTypes = {
19
+ primary: PropTypes.string.isRequired,
20
+ secondary: PropTypes.string.isRequired
21
+ }
22
+
23
+ export default QualificationListItemText
@@ -1,9 +1,18 @@
1
1
  import KonnectorBlock from 'cozy-harvest-lib/dist/components/KonnectorBlock'
2
2
 
3
- import { hasCertifications, isFromKonnector } from '../helpers'
3
+ import {
4
+ hasCertifications,
5
+ hasQualifications,
6
+ isFromKonnector
7
+ } from '../helpers'
4
8
  import Certifications from './Certifications'
9
+ import Qualification from './Qualification'
5
10
 
6
11
  export const panelBlocksSpecs = {
12
+ qualifications: {
13
+ condition: hasQualifications,
14
+ component: Qualification
15
+ },
7
16
  konnector: {
8
17
  condition: isFromKonnector,
9
18
  component: KonnectorBlock
@@ -18,7 +18,7 @@ import cx from 'classnames';
18
18
  import Variants from 'cozy-ui/docs/components/Variants';
19
19
  import Card from 'cozy-ui/transpiled/react/Card';
20
20
  import Checkbox from 'cozy-ui/transpiled/react/Checkbox';
21
- import { ViewerWithCustomPanelAndFooter as Viewer } from 'cozy-ui/transpiled/react/Viewer';
21
+ import Viewer from 'cozy-ui/transpiled/react/Viewer';
22
22
  import Stack from 'cozy-ui/transpiled/react/Stack';
23
23
  import Paper from 'cozy-ui/transpiled/react/Paper';
24
24
  import Typography from 'cozy-ui/transpiled/react/Typography';
@@ -54,19 +54,20 @@ const files = [
54
54
  class: 'pdf',
55
55
  name: 'Demo.pdf',
56
56
  mime: 'application/pdf',
57
- links: {
58
- preview: 'https://viewerdemo.cozycloud.cc/IMG_0062.PNG'
59
- },
60
57
  metadata: {
61
- carbonCopy: true
58
+ carbonCopy: true,
59
+ datetime: "2021-01-01T12:00:00.000Z",
60
+ datetimeLabel: "referencedDate",
61
+ referencedDate: "2021-01-01T12:00:00.000Z",
62
+ qualification: {
63
+ label: "isp_invoice",
64
+ purpose: "invoice",
65
+ sourceCategory: "telecom",
66
+ sourceSubCategory: "internet",
67
+ subjects: ["subscription"]
68
+ }
62
69
  }
63
70
  },
64
- {
65
- _id: 'pdf',
66
- class: 'pdf',
67
- name: 'Demo.pdf',
68
- mime: 'application/pdf'
69
- },
70
71
  {
71
72
  _id: 'text',
72
73
  class: 'text',
@@ -102,113 +103,6 @@ const toggleViewer = () => setState({ viewerOpened: !state.viewerOpened });
102
103
  const handleToggleToolbarClose = () => setState({ showToolbarCloseButton: !state.showToolbarCloseButton });
103
104
  const onFileChange = (file, nextIndex) => setState({ currentIndex: nextIndex });
104
105
 
105
- const PanelContent = ({ file }) => {
106
- return (
107
- <Stack
108
- spacing="s"
109
- className="u-flex u-flex-column u-h-100"
110
- >
111
- <Paper className={'u-ph-2 u-flex u-flex-items-center u-h-3'} elevation={2} square>
112
- <Typography variant="h4">Informations utiles</Typography>
113
- </Paper>
114
- <Paper className={'u-ph-2 u-pv-1-half'} elevation={2} square>
115
- <Typography variant="body1">Titre du fichier : {file.name}</Typography>
116
- </Paper>
117
- <Paper className={'u-ph-2 u-pv-1-half u-flex-grow-1'} elevation={2} square>
118
- <Typography variant="h4">
119
- <Media className="u-mb-half">
120
- <Img>
121
- <Icon icon={CarbonCopyIcon} className="u-mr-half" />
122
- </Img>
123
- <Bd>
124
- <Typography variant="body1">Copie conforme</Typography>
125
- </Bd>
126
- </Media>
127
- <Typography variant="caption">Ce document a été fourni par Grand Lyon. Il est défini “authentique et original” par Cozy Cloud, hébergeur de votre Cozy, car il peut affirmer qu'il provient directement du service du Grand Lyon, sans qu’il n’ait subit aucune modification.</Typography>
128
- </Typography>
129
- </Paper>
130
- </Stack>
131
- )
132
- };
133
-
134
- const useStyles = makeStyles({
135
- footer: {
136
- display: 'flex',
137
- alignItems: 'center',
138
- width: 'calc(100% - 2rem)',
139
- height: '100%',
140
- paddingLeft: '1rem',
141
- paddingRight: '1rem',
142
- borderTop: '1px solid var(--dividerColor)'
143
- }
144
- });
145
-
146
- const FooterContent = ({ file, toolbarRef }) => {
147
- const styles = useStyles()
148
- const actionButtonsRef = React.useRef()
149
- const panelBlocks = getPanelBlocks({ panelBlocksSpecs, file })
150
-
151
- if (isValidForPanel({ file })) {
152
- return (
153
- <BottomSheetWrapper
154
- file={file}
155
- actionButtonsRef={actionButtonsRef}
156
- toolbarRef={toolbarRef}
157
- >
158
- <Stack
159
- spacing="s"
160
- className={cx('u-flex u-flex-column u-ov-hidden', styles.stack)}
161
- >
162
- <Paper className={'u-flex u-ph-1 u-pb-1'} elevation={2} square ref={actionButtonsRef}>
163
- <Button
164
- className="u-mr-half"
165
- extension="full"
166
- theme="secondary"
167
- icon={ShareIcon}
168
- label="Share"
169
- />
170
- <Button
171
- extension="full"
172
- theme="secondary"
173
- icon={DownloadIcon}
174
- label="Download"
175
- />
176
- </Paper>
177
- {panelBlocks.map((PanelBlock, index) => (
178
- <Paper
179
- key={index}
180
- elevation={index === panelBlocks.length - 1 ? 0 : 2}
181
- square
182
- >
183
- <Typography variant="h4">
184
- <PanelBlock file={file} />
185
- </Typography>
186
- </Paper>
187
- ))}
188
- </Stack>
189
- </BottomSheetWrapper>
190
- )
191
- }
192
-
193
- return (
194
- <div className={styles.footer}>
195
- <Button
196
- className="u-mr-half"
197
- extension="full"
198
- theme="secondary"
199
- icon={ShareIcon}
200
- label="Share"
201
- />
202
- <Button
203
- extension="full"
204
- theme="secondary"
205
- icon={DownloadIcon}
206
- label="Download"
207
- />
208
- </div>
209
- )
210
- }
211
-
212
106
  <DemoProvider>
213
107
  <Variants initialVariants={initialVariants}>{
214
108
  variant => (
@@ -241,13 +135,6 @@ const FooterContent = ({ file, toolbarRef }) => {
241
135
  showToolbar: variant.toolbar,
242
136
  showClose: state.showToolbarCloseButton
243
137
  }}
244
- panelInfoProps={{
245
- showPanel: isValidForPanel,
246
- PanelContent
247
- }}
248
- footerProps={{
249
- FooterContent
250
- }}
251
138
  />
252
139
  </Overlay>
253
140
  )}
@@ -1,10 +1,20 @@
1
1
  import has from 'lodash/has'
2
2
 
3
+ /**
4
+ * @typedef {object} Reference
5
+ * @property {string} id - id of the document
6
+ * @property {string} type - doctype of the document
7
+ */
8
+
3
9
  // TODO : should be in file model of cozy-client
4
10
  export const isPlainText = (mimeType = '', fileName = '') => {
5
11
  return mimeType ? /^text\//.test(mimeType) : /\.(txt|md)$/.test(fileName)
6
12
  }
7
13
 
14
+ export const hasQualifications = ({ file }) => {
15
+ return has(file, 'metadata.qualification')
16
+ }
17
+
8
18
  export const hasCertifications = ({ file }) => {
9
19
  return (
10
20
  has(file, 'metadata.carbonCopy') || has(file, 'metadata.electronicSafe')
@@ -16,5 +26,9 @@ export const isFromKonnector = ({ file }) => {
16
26
  }
17
27
 
18
28
  export const isValidForPanel = ({ file }) => {
19
- return hasCertifications({ file }) || isFromKonnector({ file })
29
+ return (
30
+ hasCertifications({ file }) ||
31
+ hasQualifications({ file }) ||
32
+ isFromKonnector({ file })
33
+ )
20
34
  }
@@ -1,42 +1,48 @@
1
1
  import { isPlainText } from './helpers'
2
2
 
3
- describe('isPlainText', () => {
4
- describe('using mime types', () => {
5
- it('should match mime types starting with "text/"', () => {
6
- expect(isPlainText('text/plain')).toBe(true)
7
- expect(isPlainText('text/markdown')).toBe(true)
8
- expect(isPlainText('application/text')).toBe(false)
9
- expect(isPlainText('something/text/else')).toBe(false)
10
- expect(isPlainText('text/vnd.cozy.note+markdown')).toBe(true)
11
- })
3
+ describe('helpers', () => {
4
+ describe('isPlainText', () => {
5
+ describe('using mime types', () => {
6
+ it('should match mime types starting with "text/"', () => {
7
+ expect(isPlainText('text/plain')).toBe(true)
8
+ expect(isPlainText('text/markdown')).toBe(true)
9
+ expect(isPlainText('application/text')).toBe(false)
10
+ expect(isPlainText('something/text/else')).toBe(false)
11
+ expect(isPlainText('text/vnd.cozy.note+markdown')).toBe(true)
12
+ })
12
13
 
13
- it('should not match complex text formats', () => {
14
- expect(isPlainText('application/msword')).toBe(false)
15
- expect(isPlainText('application/vnd.oasis.opendocument.text')).toBe(false)
16
- expect(isPlainText('application/x-iwork-pages-sffpages')).toBe(false)
17
- })
14
+ it('should not match complex text formats', () => {
15
+ expect(isPlainText('application/msword')).toBe(false)
16
+ expect(isPlainText('application/vnd.oasis.opendocument.text')).toBe(
17
+ false
18
+ )
19
+ expect(isPlainText('application/x-iwork-pages-sffpages')).toBe(false)
20
+ })
18
21
 
19
- it('should not use the filename if a mime type is present', () => {
20
- expect(isPlainText('application/msword', 'iswearitstext.txt')).toBe(false)
22
+ it('should not use the filename if a mime type is present', () => {
23
+ expect(isPlainText('application/msword', 'iswearitstext.txt')).toBe(
24
+ false
25
+ )
26
+ })
21
27
  })
22
- })
23
28
 
24
- describe('using file names', () => {
25
- it('should match txt files', () => {
26
- expect(isPlainText(undefined, 'iswearitstext.txt')).toBe(true)
27
- })
29
+ describe('using file names', () => {
30
+ it('should match txt files', () => {
31
+ expect(isPlainText(undefined, 'iswearitstext.txt')).toBe(true)
32
+ })
28
33
 
29
- it('should match md files', () => {
30
- expect(isPlainText(undefined, 'markdown.md')).toBe(true)
31
- })
34
+ it('should match md files', () => {
35
+ expect(isPlainText(undefined, 'markdown.md')).toBe(true)
36
+ })
32
37
 
33
- it('should not match anything else', () => {
34
- expect(isPlainText(undefined, 'file.doc')).toBe(false)
35
- expect(isPlainText(undefined, 'file.docx')).toBe(false)
36
- expect(isPlainText(undefined, 'file.pages')).toBe(false)
37
- expect(isPlainText(undefined, 'file.odt')).toBe(false)
38
- expect(isPlainText(undefined, 'file.csv')).toBe(false)
39
- expect(isPlainText(undefined, 'file.vcf')).toBe(false)
38
+ it('should not match anything else', () => {
39
+ expect(isPlainText(undefined, 'file.doc')).toBe(false)
40
+ expect(isPlainText(undefined, 'file.docx')).toBe(false)
41
+ expect(isPlainText(undefined, 'file.pages')).toBe(false)
42
+ expect(isPlainText(undefined, 'file.odt')).toBe(false)
43
+ expect(isPlainText(undefined, 'file.csv')).toBe(false)
44
+ expect(isPlainText(undefined, 'file.vcf')).toBe(false)
45
+ })
40
46
  })
41
47
  })
42
48
  })
@@ -119,7 +119,7 @@ export const toolbarPropsPropType = {
119
119
 
120
120
  Viewer.propTypes = {
121
121
  /** One `io.cozy.files` to display */
122
- currentFile: PropTypes.shape(FileDoctype).isRequired,
122
+ currentFile: FileDoctype.isRequired,
123
123
  hasNext: PropTypes.bool,
124
124
  hasPrevious: PropTypes.bool,
125
125
  /** Called when the user wants to leave the Viewer */
@@ -170,7 +170,7 @@ const ViewerInformationsWrapper = ({
170
170
  }
171
171
 
172
172
  ViewerInformationsWrapper.propTypes = {
173
- currentFile: PropTypes.shape(FileDoctype).isRequired,
173
+ currentFile: FileDoctype.isRequired,
174
174
  disableFooter: PropTypes.bool,
175
175
  disableSharing: PropTypes.bool,
176
176
  validForPanel: PropTypes.bool,
@@ -34,6 +34,25 @@
34
34
  "caption": "Indicates whether the original document is secured by your personal digital safe with the certifications that give it probative value and a 50-year retention guarantee beyond its deposit."
35
35
  }
36
36
  },
37
+ "qualification": {
38
+ "date": {
39
+ "title": {
40
+ "addedOn": "Added on",
41
+ "obtentionDate": "Delivered on",
42
+ "issueDate": "Delivered on",
43
+ "expirationDate": "Expiration date",
44
+ "referencedDate": "Referenced date",
45
+ "shootingDate": "Shooting date"
46
+ }
47
+ },
48
+ "identity": "Identity",
49
+ "label": {
50
+ "title": "Label",
51
+ "front": "Front side",
52
+ "back": "Back side"
53
+ },
54
+ "qualification": "Qualification"
55
+ },
37
56
  "title": "Useful information"
38
57
  },
39
58
  "previous": "Previous",
@@ -34,6 +34,25 @@
34
34
  "caption": "Indique si le document original est sécurisé par votre coffre-fort numérique personnel avec les certifications qui lui confèrent une valeur probante et une garantie de conservation de 50 ans au-delà de son dépôt."
35
35
  }
36
36
  },
37
+ "qualification": {
38
+ "date": {
39
+ "title": {
40
+ "addedOn": "Ajouté le",
41
+ "obtentionDate": "Délivré le",
42
+ "issueDate": "Délivré le",
43
+ "expirationDate": "Expire le",
44
+ "referencedDate": "Date de référence",
45
+ "shootingDate": "Date de prise de vue"
46
+ }
47
+ },
48
+ "identity": "Identité",
49
+ "label": {
50
+ "title": "Label",
51
+ "front": "Face avant",
52
+ "back": "Face arrière"
53
+ },
54
+ "qualification": "Qualification"
55
+ },
37
56
  "title": "Informations utiles"
38
57
  },
39
58
  "previous": "Précédente",
@@ -0,0 +1,11 @@
1
+ import { Q, fetchPolicies } from 'cozy-client'
2
+
3
+ const defaultFetchPolicy = fetchPolicies.olderThan(30 * 1000)
4
+
5
+ export const buildContactByIdsQuery = (ids = []) => ({
6
+ definition: () => Q('io.cozy.contacts').getByIds(ids),
7
+ options: {
8
+ as: `io.cozy.contacts/${ids.join('')}`,
9
+ fetchPolicy: defaultFetchPolicy
10
+ }
11
+ })
@@ -44,7 +44,8 @@ var BottomSheetContent = forwardRef(function (_ref, ref) {
44
44
  elevation: index === panelBlocks.length - 1 ? 0 : 2,
45
45
  square: true
46
46
  }, React.createElement(Typography, {
47
- variant: "h4"
47
+ variant: "h4",
48
+ className: 'u-pv-1 u-ph-1'
48
49
  }, React.createElement(PanelBlock, {
49
50
  file: file
50
51
  })));
@@ -39,9 +39,7 @@ var Certifications = function Certifications(_ref2) {
39
39
  t = _ref2.t;
40
40
  var hasCarbonCopy = has(file, 'metadata.carbonCopy');
41
41
  var hasElectronicSafe = has(file, 'metadata.electronicSafe');
42
- return React.createElement("div", {
43
- className: "u-pv-1-half u-ph-2"
44
- }, hasCarbonCopy && React.createElement(Certification, {
42
+ return React.createElement(React.Fragment, null, hasCarbonCopy && React.createElement(Certification, {
45
43
  icon: CarbonCopyIcon,
46
44
  title: t('Viewer.panel.certifications.carbonCopy.title'),
47
45
  caption: t('Viewer.panel.certifications.carbonCopy.caption')
@@ -32,7 +32,8 @@ var PanelContent = function PanelContent(_ref) {
32
32
  elevation: 2,
33
33
  square: true
34
34
  }, React.createElement(Typography, {
35
- variant: "h4"
35
+ variant: "h4",
36
+ className: 'u-pv-1 u-ph-2'
36
37
  }, React.createElement(PanelBlock, {
37
38
  file: file
38
39
  })));
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useQuery, models, getReferencedBy } from 'cozy-client';
4
+ import List from "cozy-ui/transpiled/react/MuiCozyTheme/List";
5
+ import ListItem from "cozy-ui/transpiled/react/MuiCozyTheme/ListItem";
6
+ import QualificationListItemText from "cozy-ui/transpiled/react/Viewer/Panel/QualificationListItemText";
7
+ import { withViewerLocales } from "cozy-ui/transpiled/react/Viewer/withViewerLocales";
8
+ import { buildContactByIdsQuery } from "cozy-ui/transpiled/react/Viewer/queries";
9
+ var getDisplayName = models.contact.getDisplayName,
10
+ getBoundT = models.document.locales.getBoundT;
11
+
12
+ var Qualification = function Qualification(_ref) {
13
+ var _ref$file = _ref.file,
14
+ file = _ref$file === void 0 ? {} : _ref$file,
15
+ t = _ref.t,
16
+ f = _ref.f,
17
+ lang = _ref.lang;
18
+ var scannerT = getBoundT(lang);
19
+ var filename = file.name,
20
+ _file$metadata = file.metadata,
21
+ metadata = _file$metadata === void 0 ? {} : _file$metadata;
22
+ var _metadata$qualificati = metadata.qualification,
23
+ qualification = _metadata$qualificati === void 0 ? {} : _metadata$qualificati,
24
+ pageLabel = metadata.page,
25
+ datetime = metadata.datetime,
26
+ datetimeLabel = metadata.datetimeLabel;
27
+ var contactIds = getReferencedBy(file, 'io.cozy.contacts').map(function (ref) {
28
+ return ref.id;
29
+ });
30
+ var contactByIdsQuery = buildContactByIdsQuery(contactIds);
31
+
32
+ var _useQuery = useQuery(contactByIdsQuery.definition, contactByIdsQuery.options),
33
+ contactList = _useQuery.data;
34
+
35
+ var contactsFullname = Array.isArray(contactList) ? contactList.map(function (contact) {
36
+ return "".concat(getDisplayName(contact));
37
+ }).join(', ') : '';
38
+ return React.createElement(List, null, datetime && React.createElement(ListItem, {
39
+ className: 'u-ph-0'
40
+ }, React.createElement(QualificationListItemText, {
41
+ primary: t("Viewer.panel.qualification.date.title.".concat(datetimeLabel === 'datetime' || datetimeLabel === undefined ? 'addedOn' : datetimeLabel)),
42
+ secondary: f(datetime, 'DD/MM/YYYY')
43
+ })), contactsFullname && React.createElement(ListItem, {
44
+ className: 'u-ph-0'
45
+ }, React.createElement(QualificationListItemText, {
46
+ primary: t('Viewer.panel.qualification.identity'),
47
+ secondary: contactsFullname
48
+ })), React.createElement(ListItem, {
49
+ className: 'u-ph-0'
50
+ }, React.createElement(QualificationListItemText, {
51
+ primary: t('Viewer.panel.qualification.label.title'),
52
+ secondary: pageLabel ? t("Viewer.panel.qualification.label.".concat(pageLabel)) : filename
53
+ })), React.createElement(ListItem, {
54
+ className: 'u-ph-0'
55
+ }, React.createElement(QualificationListItemText, {
56
+ primary: t('Viewer.panel.qualification.qualification'),
57
+ secondary: scannerT("Scan.items.".concat(qualification.label))
58
+ })));
59
+ };
60
+
61
+ Qualification.propTypes = {
62
+ file: PropTypes.object.isRequired,
63
+ t: PropTypes.func.isRequired,
64
+ f: PropTypes.func.isRequired,
65
+ lang: PropTypes.string.isRequired
66
+ };
67
+ export default withViewerLocales(Qualification);
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ListItemText from "cozy-ui/transpiled/react/ListItemText";
4
+ import Typography from "cozy-ui/transpiled/react/Typography";
5
+
6
+ var QualificationListItemText = function QualificationListItemText(_ref) {
7
+ var primary = _ref.primary,
8
+ secondary = _ref.secondary;
9
+ return React.createElement(ListItemText, {
10
+ className: 'u-pv-0',
11
+ disableTypography: true,
12
+ primary: React.createElement(Typography, {
13
+ variant: 'caption'
14
+ }, primary),
15
+ secondary: React.createElement(Typography, {
16
+ variant: 'body1'
17
+ }, secondary)
18
+ });
19
+ };
20
+
21
+ QualificationListItemText.propTypes = {
22
+ primary: PropTypes.string.isRequired,
23
+ secondary: PropTypes.string.isRequired
24
+ };
25
+ export default QualificationListItemText;
@@ -1,7 +1,12 @@
1
1
  import KonnectorBlock from 'cozy-harvest-lib/dist/components/KonnectorBlock';
2
- import { hasCertifications, isFromKonnector } from "cozy-ui/transpiled/react/Viewer/helpers";
2
+ import { hasCertifications, hasQualifications, isFromKonnector } from "cozy-ui/transpiled/react/Viewer/helpers";
3
3
  import Certifications from "cozy-ui/transpiled/react/Viewer/Panel/Certifications";
4
+ import Qualification from "cozy-ui/transpiled/react/Viewer/Panel/Qualification";
4
5
  export var panelBlocksSpecs = {
6
+ qualifications: {
7
+ condition: hasQualifications,
8
+ component: Qualification
9
+ },
5
10
  konnector: {
6
11
  condition: isFromKonnector,
7
12
  component: KonnectorBlock
@@ -1,22 +1,34 @@
1
- import has from 'lodash/has'; // TODO : should be in file model of cozy-client
1
+ import has from 'lodash/has';
2
+ /**
3
+ * @typedef {object} Reference
4
+ * @property {string} id - id of the document
5
+ * @property {string} type - doctype of the document
6
+ */
7
+ // TODO : should be in file model of cozy-client
2
8
 
3
9
  export var isPlainText = function isPlainText() {
4
10
  var mimeType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
5
11
  var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
6
12
  return mimeType ? /^text\//.test(mimeType) : /\.(txt|md)$/.test(fileName);
7
13
  };
8
- export var hasCertifications = function hasCertifications(_ref) {
14
+ export var hasQualifications = function hasQualifications(_ref) {
9
15
  var file = _ref.file;
10
- return has(file, 'metadata.carbonCopy') || has(file, 'metadata.electronicSafe');
16
+ return has(file, 'metadata.qualification');
11
17
  };
12
- export var isFromKonnector = function isFromKonnector(_ref2) {
18
+ export var hasCertifications = function hasCertifications(_ref2) {
13
19
  var file = _ref2.file;
14
- return has(file, 'cozyMetadata.sourceAccount');
20
+ return has(file, 'metadata.carbonCopy') || has(file, 'metadata.electronicSafe');
15
21
  };
16
- export var isValidForPanel = function isValidForPanel(_ref3) {
22
+ export var isFromKonnector = function isFromKonnector(_ref3) {
17
23
  var file = _ref3.file;
24
+ return has(file, 'cozyMetadata.sourceAccount');
25
+ };
26
+ export var isValidForPanel = function isValidForPanel(_ref4) {
27
+ var file = _ref4.file;
18
28
  return hasCertifications({
19
29
  file: file
30
+ }) || hasQualifications({
31
+ file: file
20
32
  }) || isFromKonnector({
21
33
  file: file
22
34
  });
@@ -142,7 +142,7 @@ export var toolbarPropsPropType = {
142
142
  };
143
143
  Viewer.propTypes = {
144
144
  /** One `io.cozy.files` to display */
145
- currentFile: PropTypes.shape(FileDoctype).isRequired,
145
+ currentFile: FileDoctype.isRequired,
146
146
  hasNext: PropTypes.bool,
147
147
  hasPrevious: PropTypes.bool,
148
148
 
@@ -187,7 +187,7 @@ var ViewerInformationsWrapper = function ViewerInformationsWrapper(_ref) {
187
187
  };
188
188
 
189
189
  ViewerInformationsWrapper.propTypes = {
190
- currentFile: PropTypes.shape(FileDoctype).isRequired,
190
+ currentFile: FileDoctype.isRequired,
191
191
  disableFooter: PropTypes.bool,
192
192
  disableSharing: PropTypes.bool,
193
193
  validForPanel: PropTypes.bool,
@@ -0,0 +1,14 @@
1
+ import { Q, fetchPolicies } from 'cozy-client';
2
+ var defaultFetchPolicy = fetchPolicies.olderThan(30 * 1000);
3
+ export var buildContactByIdsQuery = function buildContactByIdsQuery() {
4
+ var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
5
+ return {
6
+ definition: function definition() {
7
+ return Q('io.cozy.contacts').getByIds(ids);
8
+ },
9
+ options: {
10
+ as: "io.cozy.contacts/".concat(ids.join('')),
11
+ fetchPolicy: defaultFetchPolicy
12
+ }
13
+ };
14
+ };
@@ -35,6 +35,25 @@ var en = {
35
35
  caption: "Indicates whether the original document is secured by your personal digital safe with the certifications that give it probative value and a 50-year retention guarantee beyond its deposit."
36
36
  }
37
37
  },
38
+ qualification: {
39
+ date: {
40
+ title: {
41
+ addedOn: "Added on",
42
+ obtentionDate: "Delivered on",
43
+ issueDate: "Delivered on",
44
+ expirationDate: "Expiration date",
45
+ referencedDate: "Referenced date",
46
+ shootingDate: "Shooting date"
47
+ }
48
+ },
49
+ identity: "Identity",
50
+ label: {
51
+ title: "Label",
52
+ front: "Front side",
53
+ back: "Back side"
54
+ },
55
+ qualification: "Qualification"
56
+ },
38
57
  title: "Useful information"
39
58
  },
40
59
  previous: "Previous",
@@ -82,6 +101,25 @@ var fr = {
82
101
  caption: "Indique si le document original est s\xE9curis\xE9 par votre coffre-fort num\xE9rique personnel avec les certifications qui lui conf\xE8rent une valeur probante et une garantie de conservation de 50 ans au-del\xE0 de son d\xE9p\xF4t."
83
102
  }
84
103
  },
104
+ qualification: {
105
+ date: {
106
+ title: {
107
+ addedOn: "Ajout\xE9 le",
108
+ obtentionDate: "D\xE9livr\xE9 le",
109
+ issueDate: "D\xE9livr\xE9 le",
110
+ expirationDate: "Expire le",
111
+ referencedDate: "Date de r\xE9f\xE9rence",
112
+ shootingDate: "Date de prise de vue"
113
+ }
114
+ },
115
+ identity: "Identit\xE9",
116
+ label: {
117
+ title: "Label",
118
+ front: "Face avant",
119
+ back: "Face arri\xE8re"
120
+ },
121
+ qualification: "Qualification"
122
+ },
85
123
  title: "Informations utiles"
86
124
  },
87
125
  previous: "Pr\xE9c\xE9dente",