cozy-viewer 13.2.1 → 13.2.3

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
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [13.2.3](https://github.com/cozy/cozy-libs/compare/cozy-viewer@13.2.2...cozy-viewer@13.2.3) (2025-01-20)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **Viewer:** Now use the folder as a reference when sharing ([21f4d9a](https://github.com/cozy/cozy-libs/commit/21f4d9af0c926a780789483be800a7ed3f2882ae))
12
+
13
+
14
+
15
+
16
+
17
+ ## [13.2.2](https://github.com/cozy/cozy-libs/compare/cozy-viewer@13.2.1...cozy-viewer@13.2.2) (2025-01-16)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **Viewer:** Editing a contact use now the correct intent path ([44881c3](https://github.com/cozy/cozy-libs/commit/44881c3cefcc2bae3d331e789424cecf8a3ee126))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [13.2.1](https://github.com/cozy/cozy-libs/compare/cozy-viewer@13.2.0...cozy-viewer@13.2.1) (2025-01-16)
7
29
 
8
30
  **Note:** Version bump only for package cozy-viewer
@@ -49,7 +49,7 @@ var ActionMenuWrapper = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
49
49
  showAlert = _useAlert.showAlert;
50
50
 
51
51
  var isEditable = (0, _helpers.isEditableAttribute)(name, file) && !isReadOnly;
52
- var editPath = "".concat(file.metadata.qualification.label, "/").concat(file._id, "/edit/information?metadata=").concat(optionFile.name);
52
+ var editPath = name === 'contact' ? "".concat(file.metadata.qualification.label, "/").concat(file._id, "/edit/contact") : "".concat(file.metadata.qualification.label, "/").concat(file._id, "/edit/information?metadata=").concat(optionFile.name);
53
53
 
54
54
  var handleCopy = /*#__PURE__*/function () {
55
55
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
@@ -151,11 +151,11 @@ var Qualification = function Qualification(_ref) {
151
151
  variant: "inset"
152
152
  }));
153
153
  }), optionFile.name && /*#__PURE__*/_react.default.createElement(_ActionMenuWrapper.default, {
154
- onClose: hideActionsMenu,
154
+ ref: actionBtnRef.current[optionFile.id],
155
155
  file: file,
156
156
  optionFile: optionFile,
157
- ref: actionBtnRef.current[optionFile.id],
158
- isReadOnly: isPublic ? true : isReadOnly
157
+ isReadOnly: isPublic ? true : isReadOnly,
158
+ onClose: hideActionsMenu
159
159
  })));
160
160
  };
161
161
 
@@ -1,12 +1,3 @@
1
1
  export default QualificationListItemContact;
2
- declare function QualificationListItemContact({ file, isReadOnly }: {
3
- file: any;
4
- isReadOnly: any;
5
- }): JSX.Element | null;
6
- declare namespace QualificationListItemContact {
7
- namespace propTypes {
8
- const file: PropTypes.Validator<object>;
9
- const isReadOnly: PropTypes.Requireable<boolean>;
10
- }
11
- }
12
- import PropTypes from "prop-types";
2
+ declare const QualificationListItemContact: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
+ import React from "react";
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
-
12
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
11
 
14
12
  var _react = _interopRequireWildcard(require("react"));
@@ -33,8 +31,6 @@ var _Spinner = _interopRequireDefault(require("cozy-ui/transpiled/react/Spinner"
33
31
 
34
32
  var _I18n = require("cozy-ui/transpiled/react/providers/I18n");
35
33
 
36
- var _ActionMenuWrapper = _interopRequireDefault(require("./ActionMenuWrapper"));
37
-
38
34
  var _QualificationListItemText = _interopRequireDefault(require("./QualificationListItemText"));
39
35
 
40
36
  var _IntentOpener = _interopRequireDefault(require("../components/IntentOpener"));
@@ -45,23 +41,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
45
41
 
46
42
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
47
43
 
48
- var QualificationListItemContact = function QualificationListItemContact(_ref) {
44
+ var QualificationListItemContact = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
49
45
  var file = _ref.file,
50
- isReadOnly = _ref.isReadOnly;
46
+ isReadOnly = _ref.isReadOnly,
47
+ toggleActionsMenu = _ref.toggleActionsMenu;
51
48
 
52
49
  var _useI18n = (0, _I18n.useI18n)(),
53
50
  lang = _useI18n.lang;
54
51
 
55
- var actionBtnRef = (0, _react.useRef)();
56
-
57
- var _useState = (0, _react.useState)({
58
- name: '',
59
- value: ''
60
- }),
61
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
62
- optionFile = _useState2[0],
63
- setOptionFile = _useState2[1];
64
-
65
52
  var _useReferencedContact = (0, _useReferencedContactName.default)(file),
66
53
  contacts = _useReferencedContact.contacts,
67
54
  isLoadingContacts = _useReferencedContact.isLoadingContacts;
@@ -82,27 +69,6 @@ var QualificationListItemContact = function QualificationListItemContact(_ref) {
82
69
  lang: lang
83
70
  });
84
71
  var qualificationLabel = file.metadata.qualification.label;
85
-
86
- var hideActionsMenu = function hideActionsMenu() {
87
- return setOptionFile({
88
- name: '',
89
- value: ''
90
- });
91
- };
92
-
93
- var toggleActionsMenu = function toggleActionsMenu(name, value) {
94
- return setOptionFile(function (prev) {
95
- if (prev.value) return {
96
- name: '',
97
- value: ''
98
- };
99
- return {
100
- name: name,
101
- value: value
102
- };
103
- });
104
- };
105
-
106
72
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_IntentOpener.default, {
107
73
  action: "OPEN",
108
74
  doctype: "io.cozy.files.paper",
@@ -118,21 +84,15 @@ var QualificationListItemContact = function QualificationListItemContact(_ref) {
118
84
  primary: formattedTitle,
119
85
  secondary: formattedValue
120
86
  }), /*#__PURE__*/_react.default.createElement(_ListItemSecondaryAction.default, null, /*#__PURE__*/_react.default.createElement(_IconButton.default, {
121
- ref: actionBtnRef,
87
+ ref: ref,
122
88
  onClick: function onClick() {
123
89
  return toggleActionsMenu('contact', formattedValue);
124
90
  }
125
91
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
126
92
  icon: _Dots.default
127
- }))))), optionFile.value && /*#__PURE__*/_react.default.createElement(_ActionMenuWrapper.default, {
128
- onClose: hideActionsMenu,
129
- file: file,
130
- optionFile: optionFile,
131
- ref: actionBtnRef,
132
- isReadOnly: isReadOnly
133
- }));
134
- };
135
-
93
+ }))))));
94
+ });
95
+ QualificationListItemContact.displayName = 'QualificationListItemContact';
136
96
  QualificationListItemContact.propTypes = {
137
97
  file: _propTypes.default.object.isRequired,
138
98
  isReadOnly: _propTypes.default.bool
@@ -51,11 +51,16 @@ var Sharing = function Sharing(_ref) {
51
51
  getDocumentPermissions = _useSharingContext.getDocumentPermissions,
52
52
  getSharingLink = _useSharingContext.getSharingLink,
53
53
  allLoaded = _useSharingContext.allLoaded,
54
+ hasSharedParent = _useSharingContext.hasSharedParent,
54
55
  getRecipients = _useSharingContext.getRecipients;
55
56
 
56
- var recipients = getRecipients(file._id);
57
- var permissions = getDocumentPermissions(file._id);
58
- var link = getSharingLink(file._id);
57
+ var shareFileRefId = hasSharedParent(file.path) ? file.dir_id : file._id;
58
+ var recipients = getRecipients(shareFileRefId);
59
+ var permissions = getDocumentPermissions(shareFileRefId);
60
+ var link = getSharingLink(shareFileRefId);
61
+
62
+ var _isOwner = isOwner(shareFileRefId);
63
+
59
64
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ListItem.default, {
60
65
  size: "large",
61
66
  divider: true,
@@ -81,7 +86,7 @@ var Sharing = function Sharing(_ref) {
81
86
  return /*#__PURE__*/_react.default.createElement(_cozySharing.MemberRecipientLite, {
82
87
  key: recipient.index,
83
88
  recipient: recipient,
84
- isOwner: isOwner(file._id)
89
+ isOwner: _isOwner
85
90
  });
86
91
  }) : /*#__PURE__*/_react.default.createElement(_cozySharing.OwnerRecipientDefaultLite, null)), showModal && /*#__PURE__*/_react.default.createElement(_cozySharing.ShareModal, {
87
92
  document: file,
@@ -94,7 +94,8 @@ var ViewerContainer = function ViewerContainer(props) {
94
94
  (0, _I18n.useExtendI18n)(_locales.locales);
95
95
 
96
96
  var _useSharingContext = (0, _cozySharing.useSharingContext)(),
97
- hasWriteAccess = _useSharingContext.hasWriteAccess;
97
+ hasWriteAccess = _useSharingContext.hasWriteAccess,
98
+ hasSharedParent = _useSharingContext.hasSharedParent;
98
99
 
99
100
  var currentFile = files[currentIndex];
100
101
  var fileCount = files.length;
@@ -133,7 +134,7 @@ var ViewerContainer = function ViewerContainer(props) {
133
134
  break;
134
135
 
135
136
  case 6:
136
- _context.t0 = !hasWriteAccess(currentFile._id);
137
+ _context.t0 = !hasWriteAccess(hasSharedParent(currentFile.path) ? currentFile.dir_id : currentFile._id);
137
138
 
138
139
  case 7:
139
140
  res = _context.t0;
@@ -152,7 +153,7 @@ var ViewerContainer = function ViewerContainer(props) {
152
153
  }();
153
154
 
154
155
  getIsReadOnly();
155
- }, [client, currentFile, hasWriteAccess, isPublic]);
156
+ }, [client, currentFile, hasWriteAccess, hasSharedParent, isPublic]);
156
157
  return /*#__PURE__*/_react.default.createElement(_Alert.default, null, /*#__PURE__*/_react.default.createElement("div", {
157
158
  id: "viewer-wrapper",
158
159
  className: (0, _classnames.default)(styles['viewer-wrapper'], className)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-viewer",
3
- "version": "13.2.1",
3
+ "version": "13.2.3",
4
4
  "description": "Cozy-Viewer provides a component to show files in a viewer.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "babel-preset-cozy-app": "^2.8.1",
28
28
  "cozy-client": "^52.1.0",
29
29
  "cozy-device-helper": "2.0.0",
30
- "cozy-harvest-lib": "^32.2.11",
30
+ "cozy-harvest-lib": "^32.2.13",
31
31
  "cozy-intent": "^2.29.1",
32
32
  "cozy-logger": "^1.16.1",
33
33
  "cozy-sharing": "^19.0.0",
@@ -59,5 +59,5 @@
59
59
  "react": ">=16.12.0",
60
60
  "react-dom": ">=16.12.0"
61
61
  },
62
- "gitHead": "92e93154d3679fb181f185c9963297efd0c69c2f"
62
+ "gitHead": "2f6508f4594f8bbed84b81fb99f76365d9ccabb9"
63
63
  }
@@ -17,7 +17,10 @@ const ActionMenuWrapper = forwardRef(
17
17
  const { showAlert } = useAlert()
18
18
 
19
19
  const isEditable = isEditableAttribute(name, file) && !isReadOnly
20
- const editPath = `${file.metadata.qualification.label}/${file._id}/edit/information?metadata=${optionFile.name}`
20
+ const editPath =
21
+ name === 'contact'
22
+ ? `${file.metadata.qualification.label}/${file._id}/edit/contact`
23
+ : `${file.metadata.qualification.label}/${file._id}/edit/information?metadata=${optionFile.name}`
21
24
 
22
25
  const handleCopy = async () => {
23
26
  try {
@@ -120,11 +120,11 @@ const Qualification = ({ file, isPublic, isReadOnly }) => {
120
120
  })}
121
121
  {optionFile.name && (
122
122
  <ActionMenuWrapper
123
- onClose={hideActionsMenu}
123
+ ref={actionBtnRef.current[optionFile.id]}
124
124
  file={file}
125
125
  optionFile={optionFile}
126
- ref={actionBtnRef.current[optionFile.id]}
127
126
  isReadOnly={isPublic ? true : isReadOnly}
127
+ onClose={hideActionsMenu}
128
128
  />
129
129
  )}
130
130
  </List>
@@ -1,5 +1,5 @@
1
1
  import PropTypes from 'prop-types'
2
- import React, { useRef, useState } from 'react'
2
+ import React, { forwardRef } from 'react'
3
3
 
4
4
  import {
5
5
  getTranslatedNameForContact,
@@ -15,85 +15,66 @@ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryA
15
15
  import Spinner from 'cozy-ui/transpiled/react/Spinner'
16
16
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
17
17
 
18
- import ActionMenuWrapper from './ActionMenuWrapper'
19
18
  import QualificationListItemText from './QualificationListItemText'
20
19
  import IntentOpener from '../components/IntentOpener'
21
20
  import useReferencedContactName from '../hooks/useReferencedContactName'
22
21
 
23
- const QualificationListItemContact = ({ file, isReadOnly }) => {
24
- const { lang } = useI18n()
25
- const actionBtnRef = useRef()
26
- const [optionFile, setOptionFile] = useState({
27
- name: '',
28
- value: ''
29
- })
30
- const { contacts, isLoadingContacts } = useReferencedContactName(file)
22
+ const QualificationListItemContact = forwardRef(
23
+ ({ file, isReadOnly, toggleActionsMenu }, ref) => {
24
+ const { lang } = useI18n()
25
+ const { contacts, isLoadingContacts } = useReferencedContactName(file)
31
26
 
32
- if (isLoadingContacts) {
33
- return (
34
- <ListItem>
35
- <Spinner color="var(--secondaryTextColor)" />
36
- </ListItem>
37
- )
38
- }
39
-
40
- const formattedValue = formatContactValue(contacts)
27
+ if (isLoadingContacts) {
28
+ return (
29
+ <ListItem>
30
+ <Spinner color="var(--secondaryTextColor)" />
31
+ </ListItem>
32
+ )
33
+ }
41
34
 
42
- if (!formattedValue) {
43
- return null
44
- }
35
+ const formattedValue = formatContactValue(contacts)
45
36
 
46
- const formattedTitle = getTranslatedNameForContact({ lang })
47
- const qualificationLabel = file.metadata.qualification.label
37
+ if (!formattedValue) {
38
+ return null
39
+ }
48
40
 
49
- const hideActionsMenu = () => setOptionFile({ name: '', value: '' })
50
- const toggleActionsMenu = (name, value) =>
51
- setOptionFile(prev => {
52
- if (prev.value) return { name: '', value: '' }
53
- return { name, value }
54
- })
41
+ const formattedTitle = getTranslatedNameForContact({ lang })
42
+ const qualificationLabel = file.metadata.qualification.label
55
43
 
56
- return (
57
- <>
58
- <IntentOpener
59
- action="OPEN"
60
- doctype="io.cozy.files.paper"
61
- options={{
62
- path: `${qualificationLabel}/${file._id}/edit/contact`
63
- }}
64
- disabled={!!formattedValue || isReadOnly}
65
- >
66
- <ListItem button={!formattedValue && !isReadOnly}>
67
- <ListItemIcon>
68
- <Icon icon={PeopleIcon} />
69
- </ListItemIcon>
70
- <QualificationListItemText
71
- primary={formattedTitle}
72
- secondary={formattedValue}
73
- />
74
- <ListItemSecondaryAction>
75
- <IconButton
76
- ref={actionBtnRef}
77
- onClick={() => toggleActionsMenu('contact', formattedValue)}
78
- >
79
- <Icon icon={Dots} />
80
- </IconButton>
81
- </ListItemSecondaryAction>
82
- </ListItem>
83
- </IntentOpener>
44
+ return (
45
+ <>
46
+ <IntentOpener
47
+ action="OPEN"
48
+ doctype="io.cozy.files.paper"
49
+ options={{
50
+ path: `${qualificationLabel}/${file._id}/edit/contact`
51
+ }}
52
+ disabled={!!formattedValue || isReadOnly}
53
+ >
54
+ <ListItem button={!formattedValue && !isReadOnly}>
55
+ <ListItemIcon>
56
+ <Icon icon={PeopleIcon} />
57
+ </ListItemIcon>
58
+ <QualificationListItemText
59
+ primary={formattedTitle}
60
+ secondary={formattedValue}
61
+ />
62
+ <ListItemSecondaryAction>
63
+ <IconButton
64
+ ref={ref}
65
+ onClick={() => toggleActionsMenu('contact', formattedValue)}
66
+ >
67
+ <Icon icon={Dots} />
68
+ </IconButton>
69
+ </ListItemSecondaryAction>
70
+ </ListItem>
71
+ </IntentOpener>
72
+ </>
73
+ )
74
+ }
75
+ )
84
76
 
85
- {optionFile.value && (
86
- <ActionMenuWrapper
87
- onClose={hideActionsMenu}
88
- file={file}
89
- optionFile={optionFile}
90
- ref={actionBtnRef}
91
- isReadOnly={isReadOnly}
92
- />
93
- )}
94
- </>
95
- )
96
- }
77
+ QualificationListItemContact.displayName = 'QualificationListItemContact'
97
78
 
98
79
  QualificationListItemContact.propTypes = {
99
80
  file: PropTypes.object.isRequired,
@@ -26,12 +26,15 @@ const Sharing = ({ file, t }) => {
26
26
  getDocumentPermissions,
27
27
  getSharingLink,
28
28
  allLoaded,
29
+ hasSharedParent,
29
30
  getRecipients
30
31
  } = useSharingContext()
31
32
 
32
- const recipients = getRecipients(file._id)
33
- const permissions = getDocumentPermissions(file._id)
34
- const link = getSharingLink(file._id)
33
+ const shareFileRefId = hasSharedParent(file.path) ? file.dir_id : file._id
34
+ const recipients = getRecipients(shareFileRefId)
35
+ const permissions = getDocumentPermissions(shareFileRefId)
36
+ const link = getSharingLink(shareFileRefId)
37
+ const _isOwner = isOwner(shareFileRefId)
35
38
 
36
39
  return (
37
40
  <>
@@ -56,7 +59,7 @@ const Sharing = ({ file, t }) => {
56
59
  <MemberRecipientLite
57
60
  key={recipient.index}
58
61
  recipient={recipient}
59
- isOwner={isOwner(file._id)}
62
+ isOwner={_isOwner}
60
63
  />
61
64
  ))
62
65
  ) : (
@@ -35,7 +35,7 @@ const ViewerContainer = props => {
35
35
  const [isReadOnly, setIsReadOnly] = useState(true)
36
36
  const client = useClient()
37
37
  useExtendI18n(locales)
38
- const { hasWriteAccess } = useSharingContext()
38
+ const { hasWriteAccess, hasSharedParent } = useSharingContext()
39
39
 
40
40
  const currentFile = files[currentIndex]
41
41
  const fileCount = files.length
@@ -59,13 +59,17 @@ const ViewerContainer = props => {
59
59
  document: currentFile,
60
60
  client
61
61
  })
62
- : !hasWriteAccess(currentFile._id)
62
+ : !hasWriteAccess(
63
+ hasSharedParent(currentFile.path)
64
+ ? currentFile.dir_id
65
+ : currentFile._id
66
+ )
63
67
 
64
68
  setIsReadOnly(res)
65
69
  }
66
70
 
67
71
  getIsReadOnly()
68
- }, [client, currentFile, hasWriteAccess, isPublic])
72
+ }, [client, currentFile, hasWriteAccess, hasSharedParent, isPublic])
69
73
 
70
74
  return (
71
75
  <AlertProvider>