cozy-ui-plus 13.1.0 → 13.2.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 +8 -0
- package/dist/Intent/IntentDialogOpener/index.js +6 -1
- package/dist/Intent/IntentIframe/index.js +19 -3
- package/dist/src/Intent/IntentDialogOpener/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/Intent/IntentDialogOpener/Readme.md +4 -0
- package/src/Intent/IntentDialogOpener/index.jsx +4 -0
- package/src/Intent/IntentDialogOpener/index.spec.jsx +23 -2
- package/src/Intent/IntentIframe/Readme.md +8 -0
- package/src/Intent/IntentIframe/index.jsx +19 -7
- package/src/Intent/IntentIframe/index.spec.jsx +40 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@13.1.0...cozy-ui-plus@13.2.0) (2026-10-06)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **cozy-ui-plus:** Give the results of an intent that stays open ([15d3786](https://github.com/cozy/cozy-libs/commit/15d37864880fefc03f39db1e94a3aea736e6eeb1))
|
|
11
|
+
- **cozy-ui-plus:** Require cozy-interapp 0.21.0 ([2ad529c](https://github.com/cozy/cozy-libs/commit/2ad529c641ca44f77f0d06f98b81d01f7050be32))
|
|
12
|
+
- **cozy-ui-plus:** Send new data to an open intent ([320438e](https://github.com/cozy/cozy-libs/commit/320438e6b30051c8002e6e8195363d804e1a774d))
|
|
13
|
+
|
|
6
14
|
# [13.1.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@13.0.17...cozy-ui-plus@13.1.0) (2026-10-06)
|
|
7
15
|
|
|
8
16
|
### Features
|
|
@@ -25,7 +25,7 @@ var _CozyTheme = _interopRequireDefault(require("../../providers/CozyTheme"));
|
|
|
25
25
|
|
|
26
26
|
var _IntentIframe = _interopRequireWildcard(require("../IntentIframe"));
|
|
27
27
|
|
|
28
|
-
var _excluded = ["options", "action", "doctype", "children", "closable", "showCloseButton", "create", "tag", "onComplete", "onDismiss", "onReadyToUse", "waitForReadyToUse", "iframeProps", "Component"];
|
|
28
|
+
var _excluded = ["options", "action", "doctype", "children", "closable", "showCloseButton", "create", "tag", "onComplete", "onDismiss", "onReadyToUse", "onResult", "waitForReadyToUse", "iframeProps", "Component"];
|
|
29
29
|
|
|
30
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
31
|
|
|
@@ -49,6 +49,7 @@ var IntentDialogOpener = function IntentDialogOpener(props) {
|
|
|
49
49
|
onComplete = props.onComplete,
|
|
50
50
|
onDismiss = props.onDismiss,
|
|
51
51
|
onReadyToUse = props.onReadyToUse,
|
|
52
|
+
onResult = props.onResult,
|
|
52
53
|
waitForReadyToUse = props.waitForReadyToUse,
|
|
53
54
|
iframeProps = props.iframeProps,
|
|
54
55
|
Component = props.Component,
|
|
@@ -105,6 +106,7 @@ var IntentDialogOpener = function IntentDialogOpener(props) {
|
|
|
105
106
|
onCancel: handleDismiss,
|
|
106
107
|
onTerminate: handleComplete,
|
|
107
108
|
onReadyToUse: onReadyToUse,
|
|
109
|
+
onResult: onResult,
|
|
108
110
|
waitForReadyToUse: waitForReadyToUse,
|
|
109
111
|
iframeProps: iframeProps
|
|
110
112
|
}))));
|
|
@@ -126,6 +128,9 @@ IntentDialogOpener.propTypes = {
|
|
|
126
128
|
/** Called when the intent service signals it is ready to use */
|
|
127
129
|
onReadyToUse: _propTypes.default.func,
|
|
128
130
|
|
|
131
|
+
/** Called with each result the intent service sends while it stays open */
|
|
132
|
+
onResult: _propTypes.default.func,
|
|
133
|
+
|
|
129
134
|
/** Keep the loading state until the intent service signals it is ready to use */
|
|
130
135
|
waitForReadyToUse: _propTypes.default.bool,
|
|
131
136
|
|
|
@@ -25,6 +25,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
25
25
|
|
|
26
26
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
27
27
|
|
|
28
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
29
|
+
|
|
28
30
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
29
31
|
|
|
30
32
|
var _react = _interopRequireDefault(require("react"));
|
|
@@ -133,12 +135,14 @@ var IntentIframe = /*#__PURE__*/function (_React$Component) {
|
|
|
133
135
|
create = intents.create;
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
create(action, type, _objectSpread(_objectSpread({}, DEFAULT_DATA), data)).start(this.intentViewer, {
|
|
138
|
+
this.intent = create(action, type, _objectSpread(_objectSpread({}, DEFAULT_DATA), data)).start(this.intentViewer, {
|
|
137
139
|
onReady: this.onFrameLoaded,
|
|
138
140
|
onHideCross: this.props.onHideCross,
|
|
139
141
|
onShowCross: this.props.onShowCross,
|
|
140
|
-
onReadyToUse: this.onReadyToUse
|
|
141
|
-
|
|
142
|
+
onReadyToUse: this.onReadyToUse,
|
|
143
|
+
onResult: this.props.onResult
|
|
144
|
+
});
|
|
145
|
+
this.intent.then(function (result) {
|
|
142
146
|
// eslint-disable-next-line promise/always-return
|
|
143
147
|
result ? onTerminate && onTerminate(result) : onCancel();
|
|
144
148
|
}).catch(function (error) {
|
|
@@ -151,6 +155,17 @@ var IntentIframe = /*#__PURE__*/function (_React$Component) {
|
|
|
151
155
|
_this2.setIsLoading(false);
|
|
152
156
|
});
|
|
153
157
|
}
|
|
158
|
+
}, {
|
|
159
|
+
key: "componentDidUpdate",
|
|
160
|
+
value: function componentDidUpdate(prevProps) {
|
|
161
|
+
// A service that stays open gets the new data, an older cozy-interapp
|
|
162
|
+
// cannot send them
|
|
163
|
+
if (!(0, _isEqual.default)(prevProps.data, this.props.data)) {
|
|
164
|
+
var _this$intent, _this$intent$sendData;
|
|
165
|
+
|
|
166
|
+
(_this$intent = this.intent) === null || _this$intent === void 0 ? void 0 : (_this$intent$sendData = _this$intent.sendData) === null || _this$intent$sendData === void 0 ? void 0 : _this$intent$sendData.call(_this$intent, _objectSpread(_objectSpread({}, DEFAULT_DATA), this.props.data));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
154
169
|
}, {
|
|
155
170
|
key: "render",
|
|
156
171
|
value: function render() {
|
|
@@ -211,6 +226,7 @@ IntentIframe.propTypes = {
|
|
|
211
226
|
onHideCross: _propTypes.default.func,
|
|
212
227
|
onShowCross: _propTypes.default.func,
|
|
213
228
|
onReadyToUse: _propTypes.default.func,
|
|
229
|
+
onResult: _propTypes.default.func,
|
|
214
230
|
waitForReadyToUse: _propTypes.default.bool
|
|
215
231
|
};
|
|
216
232
|
IntentIframe.defaultProps = {
|
|
@@ -10,6 +10,7 @@ declare namespace IntentDialogOpener {
|
|
|
10
10
|
export let onComplete: PropTypes.Requireable<(...args: any[]) => any>;
|
|
11
11
|
export let onDismiss: PropTypes.Requireable<(...args: any[]) => any>;
|
|
12
12
|
export let onReadyToUse: PropTypes.Requireable<(...args: any[]) => any>;
|
|
13
|
+
export let onResult: PropTypes.Requireable<(...args: any[]) => any>;
|
|
13
14
|
export let waitForReadyToUse: PropTypes.Requireable<boolean>;
|
|
14
15
|
export let action: PropTypes.Validator<string>;
|
|
15
16
|
export let options: PropTypes.Requireable<PropTypes.InferProps<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui-plus",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"description": "Cozy-ui-plus is an extension of cozy-ui and provides components based on cozy-client",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"cozy-intent": "^2.31.1",
|
|
39
39
|
"cozy-interapp": "^0.21.0",
|
|
40
40
|
"cozy-logger": "^1.18.1",
|
|
41
|
-
"cozy-sharing": "^38.2.
|
|
41
|
+
"cozy-sharing": "^38.2.1",
|
|
42
42
|
"cozy-stack-client": "^60.21.1",
|
|
43
43
|
"cozy-ui": "^138.1.0",
|
|
44
44
|
"jest": "30.3.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"cozy-client": ">=60.21.3",
|
|
71
71
|
"cozy-device-helper": ">=2.0.0",
|
|
72
72
|
"cozy-intent": ">=2.30.0",
|
|
73
|
-
"cozy-interapp": ">=0.
|
|
73
|
+
"cozy-interapp": ">=0.21.0",
|
|
74
74
|
"cozy-logger": ">=1.17.0",
|
|
75
75
|
"cozy-sharing": ">=36.4.0",
|
|
76
76
|
"cozy-ui": ">=138.1.0",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"react-dom": "^16 || ^17 || ^18",
|
|
79
79
|
"twake-i18n": ">=0.3.0"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "cda284e9a6b5c8f96847f0c962edee03de193c69"
|
|
82
82
|
}
|
|
@@ -30,6 +30,10 @@ Set `waitForReadyToUse` to keep the intent hidden behind the loading spinner
|
|
|
30
30
|
until its service sends the `readyToUse` signal. This option is disabled by
|
|
31
31
|
default because older intent services do not send this signal.
|
|
32
32
|
|
|
33
|
+
Set `onResult` to receive the results a service hands over while it stays
|
|
34
|
+
open. The dialog is not closed: `onComplete` is still called when the intent
|
|
35
|
+
ends.
|
|
36
|
+
|
|
33
37
|
Set `options.theme.type` to `light` or `dark` to force that theme on the
|
|
34
38
|
dialog, close button and loading surface as well as passing it to the intent
|
|
35
39
|
service. Any other value or no value keeps the caller's theme.
|
|
@@ -24,6 +24,7 @@ const IntentDialogOpener = props => {
|
|
|
24
24
|
onComplete,
|
|
25
25
|
onDismiss,
|
|
26
26
|
onReadyToUse,
|
|
27
|
+
onResult,
|
|
27
28
|
waitForReadyToUse,
|
|
28
29
|
iframeProps,
|
|
29
30
|
Component,
|
|
@@ -76,6 +77,7 @@ const IntentDialogOpener = props => {
|
|
|
76
77
|
onCancel={handleDismiss}
|
|
77
78
|
onTerminate={handleComplete}
|
|
78
79
|
onReadyToUse={onReadyToUse}
|
|
80
|
+
onResult={onResult}
|
|
79
81
|
waitForReadyToUse={waitForReadyToUse}
|
|
80
82
|
iframeProps={iframeProps}
|
|
81
83
|
/>
|
|
@@ -96,6 +98,8 @@ IntentDialogOpener.propTypes = {
|
|
|
96
98
|
onDismiss: PropTypes.func,
|
|
97
99
|
/** Called when the intent service signals it is ready to use */
|
|
98
100
|
onReadyToUse: PropTypes.func,
|
|
101
|
+
/** Called with each result the intent service sends while it stays open */
|
|
102
|
+
onResult: PropTypes.func,
|
|
99
103
|
/** Keep the loading state until the intent service signals it is ready to use */
|
|
100
104
|
waitForReadyToUse: PropTypes.bool,
|
|
101
105
|
/** Action you want to execute */
|
|
@@ -13,10 +13,12 @@ jest.mock('cozy-ui/transpiled/react/Dialog', () => ({ children }) => (
|
|
|
13
13
|
|
|
14
14
|
jest.mock('../IntentIframe', () => ({
|
|
15
15
|
__esModule: true,
|
|
16
|
-
default: ({ waitForReadyToUse }) => (
|
|
17
|
-
<
|
|
16
|
+
default: ({ waitForReadyToUse, onResult }) => (
|
|
17
|
+
<button
|
|
18
|
+
type="button"
|
|
18
19
|
data-testid="intent-iframe"
|
|
19
20
|
data-wait-for-ready-to-use={waitForReadyToUse}
|
|
21
|
+
onClick={() => onResult?.({ id: '1' })}
|
|
20
22
|
/>
|
|
21
23
|
),
|
|
22
24
|
iframeProps: require('prop-types').shape({})
|
|
@@ -41,4 +43,23 @@ describe('IntentDialogOpener', () => {
|
|
|
41
43
|
'true'
|
|
42
44
|
)
|
|
43
45
|
})
|
|
46
|
+
|
|
47
|
+
it('gives the results of the intent and stays open', () => {
|
|
48
|
+
const onResult = jest.fn()
|
|
49
|
+
const { getByRole, getByTestId, queryByTestId } = render(
|
|
50
|
+
<IntentDialogOpener
|
|
51
|
+
action="OPEN"
|
|
52
|
+
doctype="io.cozy.ai.chat.conversations"
|
|
53
|
+
onResult={onResult}
|
|
54
|
+
>
|
|
55
|
+
<button type="button">Open</button>
|
|
56
|
+
</IntentDialogOpener>
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
fireEvent.click(getByRole('button', { name: 'Open' }))
|
|
60
|
+
fireEvent.click(getByTestId('intent-iframe'))
|
|
61
|
+
|
|
62
|
+
expect(onResult).toHaveBeenCalledWith({ id: '1' })
|
|
63
|
+
expect(queryByTestId('intent-iframe')).toBeInTheDocument()
|
|
64
|
+
})
|
|
44
65
|
})
|
|
@@ -27,6 +27,14 @@ Set `waitForReadyToUse` to keep the intent hidden behind the loading spinner
|
|
|
27
27
|
until its service sends the `readyToUse` signal. This option is disabled by
|
|
28
28
|
default because older intent services do not send this signal.
|
|
29
29
|
|
|
30
|
+
Set `onResult` to receive the results a service hands over while it stays
|
|
31
|
+
open, with `service.sendResult(result)`. `onTerminate` still receives the one
|
|
32
|
+
that ends the intent.
|
|
33
|
+
|
|
34
|
+
When `data` changes while the intent is open, the new data are sent to its
|
|
35
|
+
service, which gets them with `service.onData()`: the intent is not started
|
|
36
|
+
again.
|
|
37
|
+
|
|
30
38
|
Set `data.theme.type` to `light` or `dark` to force that theme on the
|
|
31
39
|
loading surface and pass it to the intent service. Any other value or no value
|
|
32
40
|
keeps the caller's theme.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
3
|
import get from 'lodash/get'
|
|
4
|
+
import isEqual from 'lodash/isEqual'
|
|
4
5
|
import PropTypes from 'prop-types'
|
|
5
6
|
import React from 'react'
|
|
6
7
|
|
|
@@ -37,16 +38,18 @@ class IntentIframe extends React.Component {
|
|
|
37
38
|
create = intents.create
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
create(action, type, {
|
|
41
|
+
this.intent = create(action, type, {
|
|
41
42
|
...DEFAULT_DATA,
|
|
42
43
|
...data
|
|
44
|
+
}).start(this.intentViewer, {
|
|
45
|
+
onReady: this.onFrameLoaded,
|
|
46
|
+
onHideCross: this.props.onHideCross,
|
|
47
|
+
onShowCross: this.props.onShowCross,
|
|
48
|
+
onReadyToUse: this.onReadyToUse,
|
|
49
|
+
onResult: this.props.onResult
|
|
43
50
|
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
onHideCross: this.props.onHideCross,
|
|
47
|
-
onShowCross: this.props.onShowCross,
|
|
48
|
-
onReadyToUse: this.onReadyToUse
|
|
49
|
-
})
|
|
51
|
+
|
|
52
|
+
this.intent
|
|
50
53
|
.then(result => {
|
|
51
54
|
// eslint-disable-next-line promise/always-return
|
|
52
55
|
result ? onTerminate && onTerminate(result) : onCancel()
|
|
@@ -58,6 +61,14 @@ class IntentIframe extends React.Component {
|
|
|
58
61
|
})
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
componentDidUpdate(prevProps) {
|
|
65
|
+
// A service that stays open gets the new data, an older cozy-interapp
|
|
66
|
+
// cannot send them
|
|
67
|
+
if (!isEqual(prevProps.data, this.props.data)) {
|
|
68
|
+
this.intent?.sendData?.({ ...DEFAULT_DATA, ...this.props.data })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
61
72
|
onFrameLoaded = () => {
|
|
62
73
|
this.setState({ frameLoaded: true }, () => {
|
|
63
74
|
if (!this.props.waitForReadyToUse || this.state.readyToUse) {
|
|
@@ -136,6 +147,7 @@ IntentIframe.propTypes = {
|
|
|
136
147
|
onHideCross: PropTypes.func,
|
|
137
148
|
onShowCross: PropTypes.func,
|
|
138
149
|
onReadyToUse: PropTypes.func,
|
|
150
|
+
onResult: PropTypes.func,
|
|
139
151
|
waitForReadyToUse: PropTypes.bool
|
|
140
152
|
}
|
|
141
153
|
|
|
@@ -9,37 +9,49 @@ jest.mock('cozy-ui/transpiled/react/Spinner', () => () => (
|
|
|
9
9
|
|
|
10
10
|
function setup({ data, startError = null, waitForReadyToUse = false } = {}) {
|
|
11
11
|
let startOptions
|
|
12
|
+
const sendData = jest.fn()
|
|
12
13
|
const start = jest.fn((element, options) => {
|
|
13
14
|
startOptions = options
|
|
14
15
|
element.appendChild(document.createElement('iframe'))
|
|
15
|
-
|
|
16
|
+
const started = startError
|
|
17
|
+
? Promise.reject(startError)
|
|
18
|
+
: new Promise(() => {})
|
|
19
|
+
started.sendData = sendData
|
|
20
|
+
return started
|
|
16
21
|
})
|
|
17
22
|
const create = jest.fn(() => ({ start }))
|
|
18
23
|
const onError = jest.fn()
|
|
19
24
|
const onReadyToUse = jest.fn()
|
|
25
|
+
const onResult = jest.fn()
|
|
20
26
|
const setIsLoading = jest.fn()
|
|
21
27
|
|
|
22
|
-
const
|
|
28
|
+
const makeIframe = iframeData => (
|
|
23
29
|
<IntentIframe
|
|
24
30
|
action="PICK"
|
|
25
31
|
client={{}}
|
|
26
32
|
create={create}
|
|
27
|
-
data={
|
|
33
|
+
data={iframeData}
|
|
28
34
|
iframeProps={{ setIsLoading }}
|
|
29
35
|
onCancel={jest.fn()}
|
|
30
36
|
onError={onError}
|
|
31
37
|
onReadyToUse={onReadyToUse}
|
|
38
|
+
onResult={onResult}
|
|
32
39
|
onTerminate={jest.fn()}
|
|
33
40
|
type="io.cozy.files"
|
|
34
41
|
waitForReadyToUse={waitForReadyToUse}
|
|
35
42
|
/>
|
|
36
43
|
)
|
|
44
|
+
const result = render(makeIframe(data))
|
|
37
45
|
|
|
38
46
|
return {
|
|
39
47
|
...result,
|
|
48
|
+
rerenderWithData: newData => result.rerender(makeIframe(newData)),
|
|
49
|
+
create,
|
|
50
|
+
sendData,
|
|
40
51
|
getStartOptions: () => startOptions,
|
|
41
52
|
onError,
|
|
42
53
|
onReadyToUse,
|
|
54
|
+
onResult,
|
|
43
55
|
setIsLoading
|
|
44
56
|
}
|
|
45
57
|
}
|
|
@@ -53,6 +65,21 @@ describe('IntentIframe', () => {
|
|
|
53
65
|
jest.restoreAllMocks()
|
|
54
66
|
})
|
|
55
67
|
|
|
68
|
+
it('sends new data to the open intent, without starting it again', () => {
|
|
69
|
+
const { create, sendData, rerenderWithData } = setup({
|
|
70
|
+
data: { content: 'Bonjour' }
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
rerenderWithData({ content: 'Bonjour' })
|
|
74
|
+
expect(sendData).not.toHaveBeenCalled()
|
|
75
|
+
|
|
76
|
+
rerenderWithData({ content: 'Au revoir' })
|
|
77
|
+
expect(sendData).toHaveBeenCalledWith(
|
|
78
|
+
expect.objectContaining({ content: 'Au revoir' })
|
|
79
|
+
)
|
|
80
|
+
expect(create).toHaveBeenCalledTimes(1)
|
|
81
|
+
})
|
|
82
|
+
|
|
56
83
|
it('keeps the iframe rendered behind the spinner until it is ready to use', () => {
|
|
57
84
|
const {
|
|
58
85
|
container,
|
|
@@ -106,6 +133,16 @@ describe('IntentIframe', () => {
|
|
|
106
133
|
expect(setIsLoading).toHaveBeenCalledTimes(1)
|
|
107
134
|
})
|
|
108
135
|
|
|
136
|
+
it('gives the results the service sends while the intent goes on', () => {
|
|
137
|
+
const { container, getStartOptions, onResult } = setup()
|
|
138
|
+
|
|
139
|
+
act(() => getStartOptions().onReady())
|
|
140
|
+
act(() => getStartOptions().onResult({ id: '1' }))
|
|
141
|
+
|
|
142
|
+
expect(onResult).toHaveBeenCalledWith({ id: '1' })
|
|
143
|
+
expect(container.querySelector('iframe')).toBeInTheDocument()
|
|
144
|
+
})
|
|
145
|
+
|
|
109
146
|
it('shows intent errors instead of waiting for readyToUse', async () => {
|
|
110
147
|
const error = new Error('Intent failed')
|
|
111
148
|
const { container, onError, queryByTestId, setIsLoading } = setup({
|