cozy-sharing 39.0.3 → 40.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/ShareButton.js +3 -15
- package/dist/hoc/withLocales.js +9 -2
- package/dist/hoc/withLocales.spec.js +31 -0
- package/package.json +4 -4
- package/src/ShareButton.jsx +3 -7
- package/src/hoc/withLocales.jsx +2 -2
- package/src/hoc/withLocales.spec.jsx +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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
|
+
# [40.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@39.0.4...cozy-sharing@40.0.0) (2026-10-19)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **cozy-sharing:** Stop passing translate props to wrapped components ([fe0a85a](https://github.com/cozy/cozy-libs/commit/fe0a85aa9bc830bfc26aa338edae5df0eddb4882))
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
- **cozy-sharing:** components wrapped with the exported withLocales HOC
|
|
15
|
+
no longer receive the t, f and lang props. Read them with useI18n()
|
|
16
|
+
from twake-i18n instead.
|
|
17
|
+
|
|
18
|
+
## [39.0.4](https://github.com/cozy/cozy-libs/compare/cozy-sharing@39.0.3...cozy-sharing@39.0.4) (2026-10-12)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package cozy-sharing
|
|
21
|
+
|
|
6
22
|
## [39.0.3](https://github.com/cozy/cozy-libs/compare/cozy-sharing@39.0.2...cozy-sharing@39.0.3) (2026-10-08)
|
|
7
23
|
|
|
8
24
|
### Bug Fixes
|
package/dist/ShareButton.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
3
|
var _excluded = ["docId", "useShortLabel"];
|
|
5
|
-
|
|
6
|
-
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; }
|
|
7
|
-
|
|
8
|
-
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; }
|
|
9
|
-
|
|
10
4
|
import React from 'react';
|
|
11
5
|
import { useI18n } from 'twake-i18n';
|
|
12
6
|
import { default as DumbShareButton, SharedByMeButton, SharedWithMeButton } from './components/ShareButton';
|
|
@@ -20,22 +14,16 @@ export var ShareButton = withLocales(function (_ref) {
|
|
|
20
14
|
var _useI18n = useI18n(),
|
|
21
15
|
t = _useI18n.t;
|
|
22
16
|
|
|
23
|
-
var restProps = _objectSpread(_objectSpread({}, rest), {}, {
|
|
24
|
-
t: null,
|
|
25
|
-
f: null,
|
|
26
|
-
lang: null
|
|
27
|
-
});
|
|
28
|
-
|
|
29
17
|
return /*#__PURE__*/React.createElement(SharingContext.Consumer, null, function (_ref2) {
|
|
30
18
|
var byDocId = _ref2.byDocId,
|
|
31
19
|
documentType = _ref2.documentType,
|
|
32
20
|
isOwner = _ref2.isOwner;
|
|
33
21
|
return !byDocId[docId] ? /*#__PURE__*/React.createElement(DumbShareButton, _extends({
|
|
34
22
|
label: t("".concat(documentType, ".share.cta"))
|
|
35
|
-
},
|
|
23
|
+
}, rest)) : isOwner(docId) ? /*#__PURE__*/React.createElement(SharedByMeButton, _extends({
|
|
36
24
|
label: useShortLabel ? t("".concat(documentType, ".share.shared")) : t("".concat(documentType, ".share.sharedByMe"))
|
|
37
|
-
},
|
|
25
|
+
}, rest)) : /*#__PURE__*/React.createElement(SharedWithMeButton, _extends({
|
|
38
26
|
label: useShortLabel ? t("".concat(documentType, ".share.shared")) : t("".concat(documentType, ".share.sharedWithMe"))
|
|
39
|
-
},
|
|
27
|
+
}, rest));
|
|
40
28
|
});
|
|
41
29
|
});
|
package/dist/hoc/withLocales.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
var _excluded = ["t", "f", "lang"];
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import { I18n, translate } from 'twake-i18n';
|
|
3
5
|
import { getI18n } from 'twake-i18n';
|
|
@@ -22,12 +24,17 @@ export var getActionsI18n = function getActionsI18n() {
|
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
var withLocales = function withLocales(Component) {
|
|
25
|
-
return translate()(function (
|
|
27
|
+
return translate()(function (_ref) {
|
|
28
|
+
var t = _ref.t,
|
|
29
|
+
f = _ref.f,
|
|
30
|
+
lang = _ref.lang,
|
|
31
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
32
|
+
|
|
26
33
|
return /*#__PURE__*/React.createElement(I18n, {
|
|
27
34
|
dictRequire: function dictRequire(localeCode) {
|
|
28
35
|
return locales[localeCode];
|
|
29
36
|
},
|
|
30
|
-
lang:
|
|
37
|
+
lang: lang
|
|
31
38
|
}, /*#__PURE__*/React.createElement(Component, props));
|
|
32
39
|
});
|
|
33
40
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { I18n, useI18n } from 'twake-i18n';
|
|
4
|
+
import withLocales from './withLocales';
|
|
5
|
+
describe('withLocales', function () {
|
|
6
|
+
it('should provide the sharing translations without leaking translate props', function () {
|
|
7
|
+
var receivedProps = jest.fn();
|
|
8
|
+
var Wrapped = withLocales(function (props) {
|
|
9
|
+
var _useI18n = useI18n(),
|
|
10
|
+
t = _useI18n.t;
|
|
11
|
+
|
|
12
|
+
receivedProps(props);
|
|
13
|
+
return /*#__PURE__*/React.createElement("span", null, t('Share.recipients.you'));
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var _render = render( /*#__PURE__*/React.createElement(I18n, {
|
|
17
|
+
lang: "en",
|
|
18
|
+
dictRequire: function dictRequire() {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
}, /*#__PURE__*/React.createElement(Wrapped, {
|
|
22
|
+
docId: "123"
|
|
23
|
+
}))),
|
|
24
|
+
queryByText = _render.queryByText;
|
|
25
|
+
|
|
26
|
+
expect(receivedProps).toHaveBeenCalledWith({
|
|
27
|
+
docId: '123'
|
|
28
|
+
});
|
|
29
|
+
expect(queryByText('You')).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "40.0.0",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"cozy-intent": "^2.31.1",
|
|
59
59
|
"cozy-minilog": "^3.10.1",
|
|
60
60
|
"cozy-ui": "^140.5.0",
|
|
61
|
-
"cozy-ui-plus": "^14.0.
|
|
61
|
+
"cozy-ui-plus": "^14.0.4",
|
|
62
62
|
"jest": "30.3.0",
|
|
63
63
|
"jest-environment-jsdom": "30.3.0",
|
|
64
64
|
"react": "16.12.0",
|
|
65
65
|
"react-dom": "16.13.0",
|
|
66
66
|
"react-router": "^5.0.1",
|
|
67
67
|
"storybook": "7.6.0",
|
|
68
|
-
"twake-i18n": "^0.7.
|
|
68
|
+
"twake-i18n": "^0.7.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@linagora/twake-icons": ">=2.9.0",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sideEffects": [
|
|
85
85
|
"*.css"
|
|
86
86
|
],
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "16f6ad8265fe6d1265dc944ca73c9274cf26f7ea"
|
|
88
88
|
}
|
package/src/ShareButton.jsx
CHANGED
|
@@ -12,15 +12,11 @@ import withLocales from './hoc/withLocales'
|
|
|
12
12
|
|
|
13
13
|
export const ShareButton = withLocales(({ docId, useShortLabel, ...rest }) => {
|
|
14
14
|
const { t } = useI18n()
|
|
15
|
-
const restProps = { ...rest, t: null, f: null, lang: null }
|
|
16
15
|
return (
|
|
17
16
|
<SharingContext.Consumer>
|
|
18
17
|
{({ byDocId, documentType, isOwner }) => {
|
|
19
18
|
return !byDocId[docId] ? (
|
|
20
|
-
<DumbShareButton
|
|
21
|
-
label={t(`${documentType}.share.cta`)}
|
|
22
|
-
{...restProps}
|
|
23
|
-
/>
|
|
19
|
+
<DumbShareButton label={t(`${documentType}.share.cta`)} {...rest} />
|
|
24
20
|
) : isOwner(docId) ? (
|
|
25
21
|
<SharedByMeButton
|
|
26
22
|
label={
|
|
@@ -28,7 +24,7 @@ export const ShareButton = withLocales(({ docId, useShortLabel, ...rest }) => {
|
|
|
28
24
|
? t(`${documentType}.share.shared`)
|
|
29
25
|
: t(`${documentType}.share.sharedByMe`)
|
|
30
26
|
}
|
|
31
|
-
{...
|
|
27
|
+
{...rest}
|
|
32
28
|
/>
|
|
33
29
|
) : (
|
|
34
30
|
<SharedWithMeButton
|
|
@@ -37,7 +33,7 @@ export const ShareButton = withLocales(({ docId, useShortLabel, ...rest }) => {
|
|
|
37
33
|
? t(`${documentType}.share.shared`)
|
|
38
34
|
: t(`${documentType}.share.sharedWithMe`)
|
|
39
35
|
}
|
|
40
|
-
{...
|
|
36
|
+
{...rest}
|
|
41
37
|
/>
|
|
42
38
|
)
|
|
43
39
|
}}
|
package/src/hoc/withLocales.jsx
CHANGED
|
@@ -21,9 +21,9 @@ export const getActionsI18n = () => getI18n(undefined, lang => locales[lang])
|
|
|
21
21
|
* @param {Function} Component - React component
|
|
22
22
|
*/
|
|
23
23
|
const withLocales = Component =>
|
|
24
|
-
translate()(props => {
|
|
24
|
+
translate()(({ t, f, lang, ...props }) => {
|
|
25
25
|
return (
|
|
26
|
-
<I18n dictRequire={localeCode => locales[localeCode]} lang={
|
|
26
|
+
<I18n dictRequire={localeCode => locales[localeCode]} lang={lang}>
|
|
27
27
|
<Component {...props} />
|
|
28
28
|
</I18n>
|
|
29
29
|
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { I18n, useI18n } from 'twake-i18n'
|
|
5
|
+
|
|
6
|
+
import withLocales from './withLocales'
|
|
7
|
+
|
|
8
|
+
describe('withLocales', () => {
|
|
9
|
+
it('should provide the sharing translations without leaking translate props', () => {
|
|
10
|
+
const receivedProps = jest.fn()
|
|
11
|
+
const Wrapped = withLocales(props => {
|
|
12
|
+
const { t } = useI18n()
|
|
13
|
+
receivedProps(props)
|
|
14
|
+
return <span>{t('Share.recipients.you')}</span>
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const { queryByText } = render(
|
|
18
|
+
<I18n lang="en" dictRequire={() => ({})}>
|
|
19
|
+
<Wrapped docId="123" />
|
|
20
|
+
</I18n>
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
expect(receivedProps).toHaveBeenCalledWith({ docId: '123' })
|
|
24
|
+
expect(queryByText('You')).toBeTruthy()
|
|
25
|
+
})
|
|
26
|
+
})
|