cozy-sharing 16.11.0 → 16.12.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 +13 -0
- package/dist/OpenSharingLinkButton.js +52 -0
- package/dist/OpenSharingLinkFabButton.js +80 -0
- package/dist/actions/openSharingLink.js +45 -0
- package/dist/helpers/sharings.js +45 -0
- package/dist/index.js +4 -1
- package/package.json +9 -6
- package/src/OpenSharingLinkButton.jsx +49 -0
- package/src/OpenSharingLinkFabButton.jsx +63 -0
- package/src/actions/openSharingLink.js +42 -0
- package/src/helpers/sharings.js +31 -0
- package/src/index.jsx +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
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
|
+
# [16.12.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.11.0...cozy-sharing@16.12.0) (2024-12-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add openSharingLink action ([de97967](https://github.com/cozy/cozy-libs/commit/de979676b43ab73e412683895437f108740ab5e2))
|
|
12
|
+
* Add OpenSharingLinkButton & OpenSharingLinkFabButton components ([ffc603c](https://github.com/cozy/cozy-libs/commit/ffc603c798954b5ebffb4a860c82f231765bda8d))
|
|
13
|
+
* Upgrade cozy-ui to 113.5.0 ([9bbd797](https://github.com/cozy/cozy-libs/commit/9bbd797056e085f00d1d867641abb12695fbf52b))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
# [16.11.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.10.0...cozy-sharing@16.11.0) (2024-12-05)
|
|
7
20
|
|
|
8
21
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["link", "isSharingShortcutCreated"];
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import Button from 'cozy-ui/transpiled/react/Buttons';
|
|
7
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
8
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
9
|
+
import { getIconWithlabel, openExternalLink } from './helpers/sharings';
|
|
10
|
+
/**
|
|
11
|
+
* OpenSharingLinkButton component renders a Button
|
|
12
|
+
* that opens an link for Add/Synchronize/Create Cozy when clicked.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} props - The props for the component.
|
|
15
|
+
* @param {string} props.link - The URL to be opened when the button is clicked.
|
|
16
|
+
* @param {boolean} [props.isSharingShortcutCreated=false] - Indicates if a sharing shortcut has been created. (default false)
|
|
17
|
+
* @param {Object} [props] - Additional props to be passed to the Button component.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export var OpenSharingLinkButton = function OpenSharingLinkButton(_ref) {
|
|
21
|
+
var link = _ref.link,
|
|
22
|
+
_ref$isSharingShortcu = _ref.isSharingShortcutCreated,
|
|
23
|
+
isSharingShortcutCreated = _ref$isSharingShortcu === void 0 ? false : _ref$isSharingShortcu,
|
|
24
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
|
|
26
|
+
var _useI18n = useI18n(),
|
|
27
|
+
t = _useI18n.t;
|
|
28
|
+
|
|
29
|
+
var handleClick = function handleClick() {
|
|
30
|
+
openExternalLink(link);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var _getIconWithlabel = getIconWithlabel({
|
|
34
|
+
link: link,
|
|
35
|
+
isSharingShortcutCreated: isSharingShortcutCreated,
|
|
36
|
+
t: t
|
|
37
|
+
}),
|
|
38
|
+
icon = _getIconWithlabel.icon,
|
|
39
|
+
label = _getIconWithlabel.label;
|
|
40
|
+
|
|
41
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
42
|
+
onClick: handleClick,
|
|
43
|
+
startIcon: /*#__PURE__*/React.createElement(Icon, {
|
|
44
|
+
icon: icon
|
|
45
|
+
}),
|
|
46
|
+
label: label
|
|
47
|
+
}, props));
|
|
48
|
+
};
|
|
49
|
+
OpenSharingLinkButton.propTypes = {
|
|
50
|
+
link: PropTypes.string,
|
|
51
|
+
isSharingShortcutCreated: PropTypes.bool
|
|
52
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["position", "right", "bottom"],
|
|
5
|
+
_excluded2 = ["link", "isSharingShortcutCreated"],
|
|
6
|
+
_excluded3 = ["style"];
|
|
7
|
+
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { ExtendableFab } from 'cozy-ui/transpiled/react/Fab';
|
|
15
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
16
|
+
import { getIconWithlabel, openExternalLink } from './helpers/sharings';
|
|
17
|
+
|
|
18
|
+
var makeStyles = function makeStyles(customStyle) {
|
|
19
|
+
var position = customStyle.position,
|
|
20
|
+
right = customStyle.right,
|
|
21
|
+
bottom = customStyle.bottom,
|
|
22
|
+
rest = _objectWithoutProperties(customStyle, _excluded);
|
|
23
|
+
|
|
24
|
+
return _objectSpread({
|
|
25
|
+
position: position !== null && position !== void 0 ? position : 'fixed',
|
|
26
|
+
right: right !== null && right !== void 0 ? right : '1rem',
|
|
27
|
+
bottom: bottom !== null && bottom !== void 0 ? bottom : '1rem'
|
|
28
|
+
}, rest);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* OpenSharingLinkFabButton component renders a ExtendableFab button
|
|
32
|
+
* that opens an link for Add/Synchronize/Create Cozy when clicked.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} props - The props for the component.
|
|
35
|
+
* @param {string} props.link - The URL to be opened when the button is clicked.
|
|
36
|
+
* @param {boolean} [props.isSharingShortcutCreated=false] - Indicates if a sharing shortcut has been created. (default false)
|
|
37
|
+
* @param {Object} [props] - Additional props to be passed to the ExtendableFab component.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export var OpenSharingLinkFabButton = function OpenSharingLinkFabButton(_ref) {
|
|
42
|
+
var link = _ref.link,
|
|
43
|
+
_ref$isSharingShortcu = _ref.isSharingShortcutCreated,
|
|
44
|
+
isSharingShortcutCreated = _ref$isSharingShortcu === void 0 ? false : _ref$isSharingShortcu,
|
|
45
|
+
props = _objectWithoutProperties(_ref, _excluded2);
|
|
46
|
+
|
|
47
|
+
var _props$style = props.style,
|
|
48
|
+
style = _props$style === void 0 ? {} : _props$style,
|
|
49
|
+
rest = _objectWithoutProperties(props, _excluded3);
|
|
50
|
+
|
|
51
|
+
var _useI18n = useI18n(),
|
|
52
|
+
t = _useI18n.t;
|
|
53
|
+
|
|
54
|
+
var fabStyles = makeStyles(style);
|
|
55
|
+
|
|
56
|
+
var handleClick = function handleClick() {
|
|
57
|
+
openExternalLink(link);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var _getIconWithlabel = getIconWithlabel({
|
|
61
|
+
link: link,
|
|
62
|
+
isSharingShortcutCreated: isSharingShortcutCreated,
|
|
63
|
+
t: t
|
|
64
|
+
}),
|
|
65
|
+
icon = _getIconWithlabel.icon,
|
|
66
|
+
label = _getIconWithlabel.label;
|
|
67
|
+
|
|
68
|
+
return /*#__PURE__*/React.createElement(ExtendableFab, _extends({
|
|
69
|
+
color: "primary",
|
|
70
|
+
label: label,
|
|
71
|
+
style: fabStyles,
|
|
72
|
+
icon: icon,
|
|
73
|
+
follow: window,
|
|
74
|
+
onClick: handleClick
|
|
75
|
+
}, rest));
|
|
76
|
+
};
|
|
77
|
+
OpenSharingLinkFabButton.propTypes = {
|
|
78
|
+
link: PropTypes.string.isRequired,
|
|
79
|
+
isSharingShortcutCreated: PropTypes.bool
|
|
80
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
5
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
6
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
7
|
+
import { getIconWithlabel, openExternalLink } from '../helpers/sharings';
|
|
8
|
+
|
|
9
|
+
var makeComponent = function makeComponent(label, icon) {
|
|
10
|
+
var Component = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
11
|
+
return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
|
|
12
|
+
ref: ref
|
|
13
|
+
}), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
14
|
+
icon: icon
|
|
15
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
16
|
+
primary: label
|
|
17
|
+
}));
|
|
18
|
+
});
|
|
19
|
+
Component.displayName = 'OpenSharingLink';
|
|
20
|
+
return Component;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export var openSharingLink = function openSharingLink(_ref) {
|
|
24
|
+
var t = _ref.t,
|
|
25
|
+
isSharingShortcutCreated = _ref.isSharingShortcutCreated,
|
|
26
|
+
link = _ref.link;
|
|
27
|
+
|
|
28
|
+
var _getIconWithlabel = getIconWithlabel({
|
|
29
|
+
link: link,
|
|
30
|
+
isSharingShortcutCreated: isSharingShortcutCreated,
|
|
31
|
+
t: t
|
|
32
|
+
}),
|
|
33
|
+
icon = _getIconWithlabel.icon,
|
|
34
|
+
label = _getIconWithlabel.label;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
name: 'openSharingLink',
|
|
38
|
+
label: label,
|
|
39
|
+
icon: icon,
|
|
40
|
+
action: function action() {
|
|
41
|
+
openExternalLink(link);
|
|
42
|
+
},
|
|
43
|
+
Component: makeComponent(label, icon)
|
|
44
|
+
};
|
|
45
|
+
};
|
package/dist/helpers/sharings.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { Q } from 'cozy-client';
|
|
4
|
+
import CloudPlusOutlinedIcon from 'cozy-ui/transpiled/react/Icons/CloudPlusOutlined';
|
|
5
|
+
import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync';
|
|
6
|
+
import ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud';
|
|
4
7
|
import { fetchFilesPaths } from './files';
|
|
5
8
|
import { updateInternalObjectFromRealtime, normalizeDocFromRealtime } from './realtime';
|
|
6
9
|
import logger from '../logger';
|
|
7
10
|
import { addSharing, updateSharing } from '../state';
|
|
11
|
+
var CREATE_COZY_HREF = 'https://manager.cozycloud.cc/cozy/create';
|
|
8
12
|
export var getSharingObject = function getSharingObject(internalSharing, sharing) {
|
|
9
13
|
if (internalSharing) {
|
|
10
14
|
return updateInternalObjectFromRealtime(internalSharing, sharing);
|
|
@@ -105,4 +109,45 @@ export var createSharingInStore = /*#__PURE__*/function () {
|
|
|
105
109
|
}();
|
|
106
110
|
export var updateSharingInStore = function updateSharingInStore(dispatch, sharing) {
|
|
107
111
|
dispatch(updateSharing(sharing));
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Open the link in a new tab
|
|
115
|
+
* @param {string} url
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
export var openExternalLink = function openExternalLink(url) {
|
|
119
|
+
window.open(url, '_blank');
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Get the icon and label to display in the button
|
|
123
|
+
* @param {object} params
|
|
124
|
+
* @param {string} params.link
|
|
125
|
+
* @param {boolean} params.isSharingShortcutCreated
|
|
126
|
+
* @param {object} params.t
|
|
127
|
+
* @returns {{ icon: React.Component, label: string }}
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
export var getIconWithlabel = function getIconWithlabel(_ref4) {
|
|
131
|
+
var link = _ref4.link,
|
|
132
|
+
isSharingShortcutCreated = _ref4.isSharingShortcutCreated,
|
|
133
|
+
t = _ref4.t;
|
|
134
|
+
|
|
135
|
+
if (link === CREATE_COZY_HREF) {
|
|
136
|
+
return {
|
|
137
|
+
icon: ToTheCloudIcon,
|
|
138
|
+
label: t('Share.create-cozy')
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!isSharingShortcutCreated) {
|
|
143
|
+
return {
|
|
144
|
+
icon: CloudPlusOutlinedIcon,
|
|
145
|
+
label: t('toolbar.add_to_mine')
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
icon: SyncIcon,
|
|
151
|
+
label: t('toolbar.menu_sync_cozy')
|
|
152
|
+
};
|
|
108
153
|
};
|
package/dist/index.js
CHANGED
|
@@ -22,4 +22,7 @@ export { SharingBannerPlugin } from './components/SharingBanner';
|
|
|
22
22
|
export { useSharingInfos } from './components/SharingBanner/hooks/useSharingInfos';
|
|
23
23
|
export { ConfirmTrustedRecipientsDialog } from './ConfirmTrustedRecipientsDialog';
|
|
24
24
|
export { ShareButtonWithRecipients } from './ShareButtonWithRecipients';
|
|
25
|
-
export { DOCUMENT_TYPE } from './helpers/documentType';
|
|
25
|
+
export { DOCUMENT_TYPE } from './helpers/documentType';
|
|
26
|
+
export { OpenSharingLinkButton } from './OpenSharingLinkButton';
|
|
27
|
+
export { OpenSharingLinkFabButton } from './OpenSharingLinkFabButton';
|
|
28
|
+
export { openSharingLink } from './actions/openSharingLink';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.12.0",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -46,11 +46,14 @@
|
|
|
46
46
|
"@storybook/react": "7.6.0",
|
|
47
47
|
"@storybook/react-webpack5": "7.6.0",
|
|
48
48
|
"@storybook/testing-library": "0.2.2",
|
|
49
|
+
"@testing-library/jest-dom": "5.16.4",
|
|
50
|
+
"@testing-library/react": "10.4.9",
|
|
51
|
+
"@testing-library/react-hooks": "8.0.1",
|
|
49
52
|
"babel-jest": "26.6.3",
|
|
50
53
|
"babel-plugin-css-modules-transform": "1.6.2",
|
|
51
54
|
"babel-plugin-inline-react-svg": "1.1.2",
|
|
52
|
-
"cozy-client": "^
|
|
53
|
-
"cozy-ui": "
|
|
55
|
+
"cozy-client": "^51.4.0",
|
|
56
|
+
"cozy-ui": "113.5.0",
|
|
54
57
|
"enzyme": "3.11.0",
|
|
55
58
|
"enzyme-adapter-react-16": "1.15.6",
|
|
56
59
|
"enzyme-to-json": "3.6.2",
|
|
@@ -61,9 +64,9 @@
|
|
|
61
64
|
"storybook": "7.6.0"
|
|
62
65
|
},
|
|
63
66
|
"peerDependencies": {
|
|
64
|
-
"cozy-client": ">=
|
|
67
|
+
"cozy-client": ">=51.4.0",
|
|
65
68
|
"cozy-realtime": "^3.11.0",
|
|
66
|
-
"cozy-ui": ">=
|
|
69
|
+
"cozy-ui": ">=113.5.0",
|
|
67
70
|
"prop-types": "^15.7.2",
|
|
68
71
|
"react": "^16.12.0",
|
|
69
72
|
"react-router": "^5.0.1"
|
|
@@ -71,5 +74,5 @@
|
|
|
71
74
|
"sideEffects": [
|
|
72
75
|
"*.css"
|
|
73
76
|
],
|
|
74
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "2f410e1905e3b74d32346b2be30377e31516f195"
|
|
75
78
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
5
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
6
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
7
|
+
|
|
8
|
+
import { getIconWithlabel, openExternalLink } from './helpers/sharings'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* OpenSharingLinkButton component renders a Button
|
|
12
|
+
* that opens an link for Add/Synchronize/Create Cozy when clicked.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} props - The props for the component.
|
|
15
|
+
* @param {string} props.link - The URL to be opened when the button is clicked.
|
|
16
|
+
* @param {boolean} [props.isSharingShortcutCreated=false] - Indicates if a sharing shortcut has been created. (default false)
|
|
17
|
+
* @param {Object} [props] - Additional props to be passed to the Button component.
|
|
18
|
+
*/
|
|
19
|
+
export const OpenSharingLinkButton = ({
|
|
20
|
+
link,
|
|
21
|
+
isSharingShortcutCreated = false,
|
|
22
|
+
...props
|
|
23
|
+
}) => {
|
|
24
|
+
const { t } = useI18n()
|
|
25
|
+
|
|
26
|
+
const handleClick = () => {
|
|
27
|
+
openExternalLink(link)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { icon, label } = getIconWithlabel({
|
|
31
|
+
link,
|
|
32
|
+
isSharingShortcutCreated,
|
|
33
|
+
t
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Button
|
|
38
|
+
onClick={handleClick}
|
|
39
|
+
startIcon={<Icon icon={icon} />}
|
|
40
|
+
label={label}
|
|
41
|
+
{...props}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
OpenSharingLinkButton.propTypes = {
|
|
47
|
+
link: PropTypes.string,
|
|
48
|
+
isSharingShortcutCreated: PropTypes.bool
|
|
49
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { ExtendableFab } from 'cozy-ui/transpiled/react/Fab'
|
|
5
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
6
|
+
|
|
7
|
+
import { getIconWithlabel, openExternalLink } from './helpers/sharings'
|
|
8
|
+
|
|
9
|
+
const makeStyles = customStyle => {
|
|
10
|
+
const { position, right, bottom, ...rest } = customStyle
|
|
11
|
+
return {
|
|
12
|
+
position: position ?? 'fixed',
|
|
13
|
+
right: right ?? '1rem',
|
|
14
|
+
bottom: bottom ?? '1rem',
|
|
15
|
+
...rest
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* OpenSharingLinkFabButton component renders a ExtendableFab button
|
|
21
|
+
* that opens an link for Add/Synchronize/Create Cozy when clicked.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} props - The props for the component.
|
|
24
|
+
* @param {string} props.link - The URL to be opened when the button is clicked.
|
|
25
|
+
* @param {boolean} [props.isSharingShortcutCreated=false] - Indicates if a sharing shortcut has been created. (default false)
|
|
26
|
+
* @param {Object} [props] - Additional props to be passed to the ExtendableFab component.
|
|
27
|
+
*/
|
|
28
|
+
export const OpenSharingLinkFabButton = ({
|
|
29
|
+
link,
|
|
30
|
+
isSharingShortcutCreated = false,
|
|
31
|
+
...props
|
|
32
|
+
}) => {
|
|
33
|
+
const { style = {}, ...rest } = props
|
|
34
|
+
const { t } = useI18n()
|
|
35
|
+
const fabStyles = makeStyles(style)
|
|
36
|
+
|
|
37
|
+
const handleClick = () => {
|
|
38
|
+
openExternalLink(link)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { icon, label } = getIconWithlabel({
|
|
42
|
+
link,
|
|
43
|
+
isSharingShortcutCreated,
|
|
44
|
+
t
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ExtendableFab
|
|
49
|
+
color="primary"
|
|
50
|
+
label={label}
|
|
51
|
+
style={fabStyles}
|
|
52
|
+
icon={icon}
|
|
53
|
+
follow={window}
|
|
54
|
+
onClick={handleClick}
|
|
55
|
+
{...rest}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
OpenSharingLinkFabButton.propTypes = {
|
|
61
|
+
link: PropTypes.string.isRequired,
|
|
62
|
+
isSharingShortcutCreated: PropTypes.bool
|
|
63
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
5
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
|
|
6
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
|
|
7
|
+
|
|
8
|
+
import { getIconWithlabel, openExternalLink } from '../helpers/sharings'
|
|
9
|
+
|
|
10
|
+
const makeComponent = (label, icon) => {
|
|
11
|
+
const Component = forwardRef((props, ref) => {
|
|
12
|
+
return (
|
|
13
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
14
|
+
<ListItemIcon>
|
|
15
|
+
<Icon icon={icon} />
|
|
16
|
+
</ListItemIcon>
|
|
17
|
+
<ListItemText primary={label} />
|
|
18
|
+
</ActionsMenuItem>
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
Component.displayName = 'OpenSharingLink'
|
|
22
|
+
|
|
23
|
+
return Component
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const openSharingLink = ({ t, isSharingShortcutCreated, link }) => {
|
|
27
|
+
const { icon, label } = getIconWithlabel({
|
|
28
|
+
link,
|
|
29
|
+
isSharingShortcutCreated,
|
|
30
|
+
t
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: 'openSharingLink',
|
|
35
|
+
label,
|
|
36
|
+
icon,
|
|
37
|
+
action: () => {
|
|
38
|
+
openExternalLink(link)
|
|
39
|
+
},
|
|
40
|
+
Component: makeComponent(label, icon)
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/helpers/sharings.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Q } from 'cozy-client'
|
|
2
|
+
import CloudPlusOutlinedIcon from 'cozy-ui/transpiled/react/Icons/CloudPlusOutlined'
|
|
3
|
+
import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync'
|
|
4
|
+
import ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud'
|
|
2
5
|
|
|
3
6
|
import { fetchFilesPaths } from './files'
|
|
4
7
|
import {
|
|
@@ -8,6 +11,8 @@ import {
|
|
|
8
11
|
import logger from '../logger'
|
|
9
12
|
import { addSharing, updateSharing } from '../state'
|
|
10
13
|
|
|
14
|
+
const CREATE_COZY_HREF = 'https://manager.cozycloud.cc/cozy/create'
|
|
15
|
+
|
|
11
16
|
export const getSharingObject = (internalSharing, sharing) => {
|
|
12
17
|
if (internalSharing) {
|
|
13
18
|
return updateInternalObjectFromRealtime(internalSharing, sharing)
|
|
@@ -48,3 +53,29 @@ export const createSharingInStore = async ({
|
|
|
48
53
|
export const updateSharingInStore = (dispatch, sharing) => {
|
|
49
54
|
dispatch(updateSharing(sharing))
|
|
50
55
|
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Open the link in a new tab
|
|
59
|
+
* @param {string} url
|
|
60
|
+
*/
|
|
61
|
+
export const openExternalLink = url => {
|
|
62
|
+
window.open(url, '_blank')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get the icon and label to display in the button
|
|
67
|
+
* @param {object} params
|
|
68
|
+
* @param {string} params.link
|
|
69
|
+
* @param {boolean} params.isSharingShortcutCreated
|
|
70
|
+
* @param {object} params.t
|
|
71
|
+
* @returns {{ icon: React.Component, label: string }}
|
|
72
|
+
*/
|
|
73
|
+
export const getIconWithlabel = ({ link, isSharingShortcutCreated, t }) => {
|
|
74
|
+
if (link === CREATE_COZY_HREF) {
|
|
75
|
+
return { icon: ToTheCloudIcon, label: t('Share.create-cozy') }
|
|
76
|
+
}
|
|
77
|
+
if (!isSharingShortcutCreated) {
|
|
78
|
+
return { icon: CloudPlusOutlinedIcon, label: t('toolbar.add_to_mine') }
|
|
79
|
+
}
|
|
80
|
+
return { icon: SyncIcon, label: t('toolbar.menu_sync_cozy') }
|
|
81
|
+
}
|
package/src/index.jsx
CHANGED
|
@@ -27,3 +27,6 @@ export { useSharingInfos } from './components/SharingBanner/hooks/useSharingInfo
|
|
|
27
27
|
export { ConfirmTrustedRecipientsDialog } from './ConfirmTrustedRecipientsDialog'
|
|
28
28
|
export { ShareButtonWithRecipients } from './ShareButtonWithRecipients'
|
|
29
29
|
export { DOCUMENT_TYPE } from './helpers/documentType'
|
|
30
|
+
export { OpenSharingLinkButton } from './OpenSharingLinkButton'
|
|
31
|
+
export { OpenSharingLinkFabButton } from './OpenSharingLinkFabButton'
|
|
32
|
+
export { openSharingLink } from './actions/openSharingLink'
|