cozy-harvest-lib 21.0.4 → 22.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/.storybook/StoryContainer.tsx +3 -0
- package/CHANGELOG.md +26 -0
- package/dist/components/AccountForm/ConnectionBackdrop.js +1 -2
- package/dist/components/AccountForm/ConnectionBackdrop.stories.js +11 -0
- package/dist/components/HarvestWrapper.js +14 -3
- package/dist/components/Providers/IntentProvider.js +30 -0
- package/dist/components/Routes.js +13 -3
- package/dist/components/cards/AppLinkCard.js +11 -3
- package/package.json +4 -2
- package/src/components/AccountForm/ConnectionBackdrop.jsx +1 -1
- package/src/components/AccountForm/ConnectionBackdrop.stories.jsx +14 -0
- package/src/components/HarvestWrapper.jsx +20 -8
- package/src/components/Providers/IntentProvider.jsx +29 -0
- package/src/components/Routes.jsx +10 -2
- package/src/components/cards/AppLinkCard.jsx +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
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
|
+
# [22.0.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@21.0.5...cozy-harvest-lib@22.0.0) (2024-01-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add context to store Intent data ([1efe0c4](https://github.com/cozy/cozy-libs/commit/1efe0c437342c92c0e779ae13043b33b232236f1))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* If you import Harvest's component without using the
|
|
17
|
+
HarvestWrapper or the Route Component, you have to wrap manually the
|
|
18
|
+
component in the IntentProvider.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [21.0.5](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@21.0.4...cozy-harvest-lib@21.0.5) (2024-01-02)
|
|
25
|
+
|
|
26
|
+
**Note:** Version bump only for package cozy-harvest-lib
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
6
32
|
## [21.0.4](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@21.0.3...cozy-harvest-lib@21.0.4) (2023-12-29)
|
|
7
33
|
|
|
8
34
|
|
|
@@ -3,9 +3,17 @@ import React from 'react';
|
|
|
3
3
|
import HarvestVaultProvider from './HarvestVaultProvider';
|
|
4
4
|
import { MountPointProvider } from './MountPointContext';
|
|
5
5
|
import ComponentsPropsProvider from './Providers/ComponentsPropsProvider';
|
|
6
|
+
import { IntentProvider } from './Providers/IntentProvider';
|
|
6
7
|
import VaultUnlockProvider from './VaultUnlockProvider';
|
|
7
8
|
/**
|
|
8
|
-
* @param {{
|
|
9
|
+
* @param {{
|
|
10
|
+
* mountPointProviderProps?: { baseRoute: string; };
|
|
11
|
+
* componentsPropsProviderProps?: {
|
|
12
|
+
* ComponentsProps: import("./Providers/ComponentsPropsProvider").ComponentsProps;
|
|
13
|
+
* };
|
|
14
|
+
* intentData?: object;
|
|
15
|
+
* intentId?: string;
|
|
16
|
+
* children: JSX.Element; }} props
|
|
9
17
|
*/
|
|
10
18
|
|
|
11
19
|
export default function HarvestWrapper(props) {
|
|
@@ -13,7 +21,10 @@ export default function HarvestWrapper(props) {
|
|
|
13
21
|
|
|
14
22
|
return /*#__PURE__*/React.createElement(MountPointProvider, {
|
|
15
23
|
baseRoute: props === null || props === void 0 ? void 0 : (_props$mountPointProv = props.mountPointProviderProps) === null || _props$mountPointProv === void 0 ? void 0 : _props$mountPointProv.baseRoute
|
|
16
|
-
}, /*#__PURE__*/React.createElement(HarvestVaultProvider, null, /*#__PURE__*/React.createElement(VaultUnlockProvider, null, /*#__PURE__*/React.createElement(
|
|
24
|
+
}, /*#__PURE__*/React.createElement(HarvestVaultProvider, null, /*#__PURE__*/React.createElement(VaultUnlockProvider, null, /*#__PURE__*/React.createElement(IntentProvider, {
|
|
25
|
+
intentData: props.intentData,
|
|
26
|
+
intentId: props.intentId
|
|
27
|
+
}, /*#__PURE__*/React.createElement(ComponentsPropsProvider, {
|
|
17
28
|
ComponentsProps: props === null || props === void 0 ? void 0 : (_props$componentsProp = props.componentsPropsProviderProps) === null || _props$componentsProp === void 0 ? void 0 : _props$componentsProp.ComponentsProps
|
|
18
|
-
}, props.children))));
|
|
29
|
+
}, props.children)))));
|
|
19
30
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
|
+
var IntentProviderContext = /*#__PURE__*/createContext();
|
|
3
|
+
/**
|
|
4
|
+
* @param {object} param
|
|
5
|
+
* @param {JSX.Element} param.children
|
|
6
|
+
* @param {object=} param.intentData
|
|
7
|
+
* @param {string=} param.intentId
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export var IntentProvider = function IntentProvider(_ref) {
|
|
12
|
+
var children = _ref.children,
|
|
13
|
+
intentData = _ref.intentData,
|
|
14
|
+
intentId = _ref.intentId;
|
|
15
|
+
return /*#__PURE__*/React.createElement(IntentProviderContext.Provider, {
|
|
16
|
+
value: {
|
|
17
|
+
intentData: intentData,
|
|
18
|
+
intentId: intentId
|
|
19
|
+
}
|
|
20
|
+
}, children);
|
|
21
|
+
};
|
|
22
|
+
export var useIntentProviderData = function useIntentProviderData() {
|
|
23
|
+
var intentProviderData = React.useContext(IntentProviderContext);
|
|
24
|
+
|
|
25
|
+
if (!intentProviderData) {
|
|
26
|
+
throw new Error('useIntentProviderData must be used within a IntentProvider');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return intentProviderData;
|
|
30
|
+
};
|
|
@@ -70,7 +70,9 @@ var Routes = function Routes(_ref) {
|
|
|
70
70
|
onDismiss = _ref.onDismiss,
|
|
71
71
|
datacardOptions = _ref.datacardOptions,
|
|
72
72
|
ComponentsProps = _ref.ComponentsProps,
|
|
73
|
-
closable = _ref.closable
|
|
73
|
+
closable = _ref.closable,
|
|
74
|
+
intentData = _ref.intentData,
|
|
75
|
+
intentId = _ref.intentId;
|
|
74
76
|
var RoutesV4orV6 = isRouterV6 ? RoutesV6 : RoutesV4;
|
|
75
77
|
|
|
76
78
|
var _useI18n = useI18n(),
|
|
@@ -102,7 +104,9 @@ var Routes = function Routes(_ref) {
|
|
|
102
104
|
},
|
|
103
105
|
componentsPropsProviderProps: {
|
|
104
106
|
ComponentsProps: ComponentsProps
|
|
105
|
-
}
|
|
107
|
+
},
|
|
108
|
+
intentData: intentData,
|
|
109
|
+
intentId: intentId
|
|
106
110
|
}, /*#__PURE__*/React.createElement(DialogContext.Provider, {
|
|
107
111
|
value: dialogContext
|
|
108
112
|
}, /*#__PURE__*/React.createElement(HarvestDialog, _extends({}, dialogContext.dialogProps, {
|
|
@@ -146,6 +150,12 @@ Routes.propTypes = {
|
|
|
146
150
|
ComponentsProps: PropTypes.object,
|
|
147
151
|
|
|
148
152
|
/** Whether the dialog is closable or not */
|
|
149
|
-
closable: PropTypes.bool
|
|
153
|
+
closable: PropTypes.bool,
|
|
154
|
+
|
|
155
|
+
/** Data received from the Intent if called from an intent */
|
|
156
|
+
intentData: PropTypes.object,
|
|
157
|
+
|
|
158
|
+
/** Id of the intent if called from an intent */
|
|
159
|
+
intentId: PropTypes.string
|
|
150
160
|
};
|
|
151
161
|
export default Routes;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
import PropTypes from 'prop-types';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { useClient } from 'cozy-client';
|
|
@@ -12,6 +13,7 @@ import { ButtonLink } from 'cozy-ui/transpiled/react/deprecated/Button';
|
|
|
12
13
|
import palette from 'cozy-ui/transpiled/react/palette';
|
|
13
14
|
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints';
|
|
14
15
|
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
16
|
+
import { useIntentProviderData } from '../Providers/IntentProvider';
|
|
15
17
|
import useAppLinkWithStoreFallback from '../hooks/useAppLinkWithStoreFallback';
|
|
16
18
|
export var AppLinkButton = function AppLinkButton(_ref) {
|
|
17
19
|
var slug = _ref.slug,
|
|
@@ -31,6 +33,9 @@ export var AppLinkButton = function AppLinkButton(_ref) {
|
|
|
31
33
|
url = _useAppLinkWithStoreF.url,
|
|
32
34
|
isInstalled = _useAppLinkWithStoreF.isInstalled;
|
|
33
35
|
|
|
36
|
+
var _useIntentProviderDat = useIntentProviderData(),
|
|
37
|
+
intentId = _useIntentProviderDat.intentId;
|
|
38
|
+
|
|
34
39
|
return /*#__PURE__*/React.createElement(AppLinker, {
|
|
35
40
|
app: {
|
|
36
41
|
slug: slug
|
|
@@ -40,10 +45,13 @@ export var AppLinkButton = function AppLinkButton(_ref) {
|
|
|
40
45
|
}, function (_ref2) {
|
|
41
46
|
var onClick = _ref2.onClick,
|
|
42
47
|
href = _ref2.href;
|
|
43
|
-
return /*#__PURE__*/React.createElement(ButtonLink, {
|
|
48
|
+
return /*#__PURE__*/React.createElement(ButtonLink, _extends({
|
|
44
49
|
disabled: fetchStatus !== 'loaded',
|
|
45
50
|
onClick: fetchStatus === 'loaded' ? onClick : null,
|
|
46
|
-
href: href
|
|
51
|
+
href: href
|
|
52
|
+
}, intentId ? {
|
|
53
|
+
target: '_blank'
|
|
54
|
+
} : {}, {
|
|
47
55
|
icon: isInstalled ? /*#__PURE__*/React.createElement(AppIcon, {
|
|
48
56
|
app: slug,
|
|
49
57
|
domain: cozyURL.host,
|
|
@@ -53,7 +61,7 @@ export var AppLinkButton = function AppLinkButton(_ref) {
|
|
|
53
61
|
theme: "secondary",
|
|
54
62
|
label: t("card.appLink.".concat(slug, ".").concat(isInstalled ? 'button' : 'install')),
|
|
55
63
|
className: isMobile ? 'u-w-100' : null
|
|
56
|
-
});
|
|
64
|
+
}));
|
|
57
65
|
});
|
|
58
66
|
};
|
|
59
67
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-harvest-lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "Provides logic, modules and components for Cozy's harvest applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"cozy-device-helper": "^3.0.0",
|
|
69
69
|
"cozy-flags": "^3.2.0",
|
|
70
70
|
"cozy-intent": "^2.18.1",
|
|
71
|
+
"cozy-interapp": ">=0.8.1",
|
|
71
72
|
"cozy-keys-lib": "^6.0.0",
|
|
72
73
|
"cozy-realtime": "^5.0.0",
|
|
73
74
|
"cozy-tsconfig": "^1.0.0",
|
|
@@ -96,6 +97,7 @@
|
|
|
96
97
|
"cozy-device-helper": ">=2.6.0",
|
|
97
98
|
"cozy-flags": ">=2.3.5",
|
|
98
99
|
"cozy-intent": ">=1.14.1",
|
|
100
|
+
"cozy-interapp": ">=0.8.1",
|
|
99
101
|
"cozy-keys-lib": ">=6.0.0",
|
|
100
102
|
"cozy-realtime": ">=4.2.8",
|
|
101
103
|
"cozy-ui": ">=95.9.0",
|
|
@@ -104,5 +106,5 @@
|
|
|
104
106
|
"react-router-dom": ">=4.3.1"
|
|
105
107
|
},
|
|
106
108
|
"sideEffects": false,
|
|
107
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "0fcee5c88aa15edf44ff2e558053c2d53b4c060f"
|
|
108
110
|
}
|
|
@@ -4,23 +4,35 @@ import React from 'react'
|
|
|
4
4
|
import HarvestVaultProvider from './HarvestVaultProvider'
|
|
5
5
|
import { MountPointProvider } from './MountPointContext'
|
|
6
6
|
import ComponentsPropsProvider from './Providers/ComponentsPropsProvider'
|
|
7
|
+
import { IntentProvider } from './Providers/IntentProvider'
|
|
7
8
|
import VaultUnlockProvider from './VaultUnlockProvider'
|
|
8
|
-
|
|
9
9
|
/**
|
|
10
|
-
* @param {{
|
|
10
|
+
* @param {{
|
|
11
|
+
* mountPointProviderProps?: { baseRoute: string; };
|
|
12
|
+
* componentsPropsProviderProps?: {
|
|
13
|
+
* ComponentsProps: import("./Providers/ComponentsPropsProvider").ComponentsProps;
|
|
14
|
+
* };
|
|
15
|
+
* intentData?: object;
|
|
16
|
+
* intentId?: string;
|
|
17
|
+
* children: JSX.Element; }} props
|
|
11
18
|
*/
|
|
12
19
|
export default function HarvestWrapper(props) {
|
|
13
20
|
return (
|
|
14
21
|
<MountPointProvider baseRoute={props?.mountPointProviderProps?.baseRoute}>
|
|
15
22
|
<HarvestVaultProvider>
|
|
16
23
|
<VaultUnlockProvider>
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
24
|
+
<IntentProvider
|
|
25
|
+
intentData={props.intentData}
|
|
26
|
+
intentId={props.intentId}
|
|
21
27
|
>
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
<ComponentsPropsProvider
|
|
29
|
+
ComponentsProps={
|
|
30
|
+
props?.componentsPropsProviderProps?.ComponentsProps
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
{props.children}
|
|
34
|
+
</ComponentsPropsProvider>
|
|
35
|
+
</IntentProvider>
|
|
24
36
|
</VaultUnlockProvider>
|
|
25
37
|
</HarvestVaultProvider>
|
|
26
38
|
</MountPointProvider>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { createContext } from 'react'
|
|
2
|
+
|
|
3
|
+
const IntentProviderContext = createContext()
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {object} param
|
|
7
|
+
* @param {JSX.Element} param.children
|
|
8
|
+
* @param {object=} param.intentData
|
|
9
|
+
* @param {string=} param.intentId
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export const IntentProvider = ({ children, intentData, intentId }) => {
|
|
13
|
+
return (
|
|
14
|
+
<IntentProviderContext.Provider value={{ intentData, intentId }}>
|
|
15
|
+
{children}
|
|
16
|
+
</IntentProviderContext.Provider>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const useIntentProviderData = () => {
|
|
21
|
+
const intentProviderData = React.useContext(IntentProviderContext)
|
|
22
|
+
if (!intentProviderData) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'useIntentProviderData must be used within a IntentProvider'
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return intentProviderData
|
|
29
|
+
}
|
|
@@ -67,7 +67,9 @@ const Routes = ({
|
|
|
67
67
|
onDismiss,
|
|
68
68
|
datacardOptions,
|
|
69
69
|
ComponentsProps,
|
|
70
|
-
closable
|
|
70
|
+
closable,
|
|
71
|
+
intentData,
|
|
72
|
+
intentId
|
|
71
73
|
}) => {
|
|
72
74
|
const RoutesV4orV6 = isRouterV6 ? RoutesV6 : RoutesV4
|
|
73
75
|
|
|
@@ -94,6 +96,8 @@ const Routes = ({
|
|
|
94
96
|
<HarvestWrapper
|
|
95
97
|
mountPointProviderProps={{ baseRoute: konnectorRoot }}
|
|
96
98
|
componentsPropsProviderProps={{ ComponentsProps: ComponentsProps }}
|
|
99
|
+
intentData={intentData}
|
|
100
|
+
intentId={intentId}
|
|
97
101
|
>
|
|
98
102
|
<DialogContext.Provider value={dialogContext}>
|
|
99
103
|
<HarvestDialog
|
|
@@ -142,7 +146,11 @@ Routes.propTypes = {
|
|
|
142
146
|
/** The props for the components */
|
|
143
147
|
ComponentsProps: PropTypes.object,
|
|
144
148
|
/** Whether the dialog is closable or not */
|
|
145
|
-
closable: PropTypes.bool
|
|
149
|
+
closable: PropTypes.bool,
|
|
150
|
+
/** Data received from the Intent if called from an intent */
|
|
151
|
+
intentData: PropTypes.object,
|
|
152
|
+
/** Id of the intent if called from an intent */
|
|
153
|
+
intentId: PropTypes.string
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
export default Routes
|
|
@@ -14,6 +14,7 @@ import palette from 'cozy-ui/transpiled/react/palette'
|
|
|
14
14
|
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
|
|
15
15
|
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
16
16
|
|
|
17
|
+
import { useIntentProviderData } from '../Providers/IntentProvider'
|
|
17
18
|
import useAppLinkWithStoreFallback from '../hooks/useAppLinkWithStoreFallback'
|
|
18
19
|
|
|
19
20
|
export const AppLinkButton = ({ slug, path }) => {
|
|
@@ -26,6 +27,8 @@ export const AppLinkButton = ({ slug, path }) => {
|
|
|
26
27
|
client,
|
|
27
28
|
path
|
|
28
29
|
)
|
|
30
|
+
|
|
31
|
+
const { intentId } = useIntentProviderData()
|
|
29
32
|
return (
|
|
30
33
|
<AppLinker app={{ slug }} nativePath={path} href={url || '#'}>
|
|
31
34
|
{({ onClick, href }) => (
|
|
@@ -33,6 +36,7 @@ export const AppLinkButton = ({ slug, path }) => {
|
|
|
33
36
|
disabled={fetchStatus !== 'loaded'}
|
|
34
37
|
onClick={fetchStatus === 'loaded' ? onClick : null}
|
|
35
38
|
href={href}
|
|
39
|
+
{...(intentId ? { target: '_blank' } : {})}
|
|
36
40
|
icon={
|
|
37
41
|
isInstalled ? (
|
|
38
42
|
<AppIcon
|