cozy-harvest-lib 20.1.6 → 20.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 +12 -0
- package/dist/components/AccountModalWithoutTabs/TriggerError.js +1 -3
- package/dist/components/KonnectorConfiguration/DataTab/index.js +1 -1
- package/dist/components/KonnectorConfiguration/KonnectorAccountTabs.js +1 -1
- package/dist/components/NewAccountModal.js +1 -4
- package/dist/components/NewAccountModal.spec.js +11 -0
- package/dist/components/cards/LaunchTriggerAlert.js +1 -3
- package/dist/components/cards/LaunchTriggerAlert.spec.js +11 -0
- package/dist/components/cards/LaunchTriggerAlertMenu.js +1 -3
- package/dist/components/hooks/useMaintenanceStatus.js +28 -93
- package/dist/components/hooks/useMaintenanceStatus.spec.js +118 -0
- package/dist/helpers/queries.js +10 -0
- package/package.json +3 -3
- package/src/components/AccountModalWithoutTabs/TriggerError.jsx +1 -4
- package/src/components/KonnectorConfiguration/DataTab/index.jsx +1 -1
- package/src/components/KonnectorConfiguration/KonnectorAccountTabs.jsx +1 -1
- package/src/components/NewAccountModal.jsx +1 -3
- package/src/components/NewAccountModal.spec.jsx +4 -0
- package/src/components/cards/LaunchTriggerAlert.jsx +1 -3
- package/src/components/cards/LaunchTriggerAlert.spec.jsx +5 -0
- package/src/components/cards/LaunchTriggerAlertMenu.jsx +1 -3
- package/src/components/hooks/useMaintenanceStatus.jsx +28 -50
- package/src/components/hooks/useMaintenanceStatus.spec.jsx +82 -0
- package/src/helpers/queries.js +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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
|
+
# [20.2.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@20.1.6...cozy-harvest-lib@20.2.0) (2023-11-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Allow to skip maintenance for konnector with a flag ([64da8a7](https://github.com/cozy/cozy-libs/commit/64da8a73ef5abca82e2a7089cbcdccb6695a58ff))
|
|
12
|
+
* Update cozy-client from 41.9.0 to 43.1.0 ([66eeae0](https://github.com/cozy/cozy-libs/commit/66eeae0199fe48bd625be818edf18b993a6b32f6))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
## [20.1.6](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@20.1.5...cozy-harvest-lib@20.1.6) (2023-11-07)
|
|
7
19
|
|
|
8
20
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { useClient } from 'cozy-client';
|
|
4
3
|
import TriggerErrorAction from './TriggerErrorAction';
|
|
5
4
|
import { intentsApiProptype } from '../../helpers/proptypes';
|
|
6
5
|
import useMaintenanceStatus from '../hooks/useMaintenanceStatus';
|
|
@@ -12,11 +11,10 @@ var TriggerError = function TriggerError(_ref) {
|
|
|
12
11
|
account = _ref.account,
|
|
13
12
|
trigger = _ref.trigger,
|
|
14
13
|
intentsApi = _ref.intentsApi;
|
|
15
|
-
var client = useClient();
|
|
16
14
|
var flowState = flow.getState();
|
|
17
15
|
var error = flowState.error;
|
|
18
16
|
|
|
19
|
-
var _useMaintenanceStatus = useMaintenanceStatus(
|
|
17
|
+
var _useMaintenanceStatus = useMaintenanceStatus(konnector.slug),
|
|
20
18
|
isInMaintenance = _useMaintenanceStatus.data.isInMaintenance;
|
|
21
19
|
|
|
22
20
|
if (!error || isInMaintenance) return null;
|
|
@@ -53,7 +53,7 @@ export var DataTab = function DataTab(_ref) {
|
|
|
53
53
|
return client.appMetadata.slug !== app.slug;
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
var _useMaintenanceStatus = useMaintenanceStatus(
|
|
56
|
+
var _useMaintenanceStatus = useMaintenanceStatus(konnector.slug),
|
|
57
57
|
_useMaintenanceStatus2 = _useMaintenanceStatus.data,
|
|
58
58
|
isInMaintenance = _useMaintenanceStatus2.isInMaintenance,
|
|
59
59
|
maintenanceMessages = _useMaintenanceStatus2.messages;
|
|
@@ -85,7 +85,7 @@ var KonnectorAccountTabs = function KonnectorAccountTabs(props) {
|
|
|
85
85
|
tab = _useState2[0],
|
|
86
86
|
setTab = _useState2[1];
|
|
87
87
|
|
|
88
|
-
var _useMaintenanceStatus = useMaintenanceStatus(
|
|
88
|
+
var _useMaintenanceStatus = useMaintenanceStatus(konnector.slug),
|
|
89
89
|
isInMaintenance = _useMaintenanceStatus.data.isInMaintenance;
|
|
90
90
|
|
|
91
91
|
var webviewIntent = useWebviewIntent();
|
|
@@ -2,7 +2,6 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React, { useContext } from 'react';
|
|
5
|
-
import { useClient } from 'cozy-client';
|
|
6
5
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
|
|
7
6
|
import flag from 'cozy-flags';
|
|
8
7
|
import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog';
|
|
@@ -33,12 +32,10 @@ var NewAccountModal = function NewAccountModal(_ref) {
|
|
|
33
32
|
var _useI18n = useI18n(),
|
|
34
33
|
t = _useI18n.t;
|
|
35
34
|
|
|
36
|
-
var client = useClient();
|
|
37
|
-
|
|
38
35
|
var _useContext = useContext(MountPointContext),
|
|
39
36
|
replaceHistory = _useContext.replaceHistory;
|
|
40
37
|
|
|
41
|
-
var _useMaintenanceStatus = useMaintenanceStatus(
|
|
38
|
+
var _useMaintenanceStatus = useMaintenanceStatus(konnector.slug),
|
|
42
39
|
fetchStatus = _useMaintenanceStatus.fetchStatus,
|
|
43
40
|
_useMaintenanceStatus2 = _useMaintenanceStatus.data,
|
|
44
41
|
isInMaintenance = _useMaintenanceStatus2.isInMaintenance,
|
|
@@ -15,6 +15,17 @@ jest.mock('./TriggerManager', function () {
|
|
|
15
15
|
return null;
|
|
16
16
|
};
|
|
17
17
|
});
|
|
18
|
+
jest.mock('./hooks/useMaintenanceStatus', function () {
|
|
19
|
+
return function () {
|
|
20
|
+
return {
|
|
21
|
+
fetchStatus: 'loaded',
|
|
22
|
+
data: {
|
|
23
|
+
isInMaintenance: false,
|
|
24
|
+
messages: {}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
});
|
|
18
29
|
describe('NewAccountModal', function () {
|
|
19
30
|
var replaceHistory = jest.fn();
|
|
20
31
|
var mountPointContextValue = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import React, { useState, useEffect } from 'react';
|
|
4
|
-
import { useClient } from 'cozy-client';
|
|
5
4
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
|
|
6
5
|
import Alert from 'cozy-ui/transpiled/react/Alert';
|
|
7
6
|
import Button from 'cozy-ui/transpiled/react/Buttons';
|
|
@@ -53,7 +52,6 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
53
52
|
intentsApi = _ref2.intentsApi,
|
|
54
53
|
account = _ref2.account,
|
|
55
54
|
withMaintenanceDescription = _ref2.withMaintenanceDescription;
|
|
56
|
-
var client = useClient();
|
|
57
55
|
|
|
58
56
|
var _useState = useState(false),
|
|
59
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -70,7 +68,7 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
70
68
|
var launch = flow.launch,
|
|
71
69
|
konnector = flow.konnector;
|
|
72
70
|
|
|
73
|
-
var _useMaintenanceStatus = useMaintenanceStatus(
|
|
71
|
+
var _useMaintenanceStatus = useMaintenanceStatus(konnector.slug),
|
|
74
72
|
_useMaintenanceStatus2 = _useMaintenanceStatus.data,
|
|
75
73
|
isInMaintenance = _useMaintenanceStatus2.isInMaintenance,
|
|
76
74
|
maintenanceMessages = _useMaintenanceStatus2.messages;
|
|
@@ -23,6 +23,17 @@ jest.mock('../../models/ConnectionFlow', function () {
|
|
|
23
23
|
return mockConnectionFlow;
|
|
24
24
|
});
|
|
25
25
|
jest.mock('cozy-flags');
|
|
26
|
+
jest.mock('../hooks/useMaintenanceStatus', function () {
|
|
27
|
+
return function () {
|
|
28
|
+
return {
|
|
29
|
+
fetchStatus: 'loaded',
|
|
30
|
+
data: {
|
|
31
|
+
isInMaintenance: false,
|
|
32
|
+
messages: {}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
});
|
|
26
37
|
var triggerFixture = {
|
|
27
38
|
_id: 'd861818b62204988bf0bb78c182a9149',
|
|
28
39
|
arguments: '0 0 0 * * 0'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import React, { useRef, useState } from 'react';
|
|
4
|
-
import { useClient } from 'cozy-client';
|
|
5
4
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
|
|
6
5
|
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
7
6
|
import IconButton from 'cozy-ui/transpiled/react/IconButton';
|
|
@@ -24,7 +23,6 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
|
|
|
24
23
|
historyAction = _ref.historyAction,
|
|
25
24
|
account = _ref.account,
|
|
26
25
|
intentsApi = _ref.intentsApi;
|
|
27
|
-
var client = useClient();
|
|
28
26
|
|
|
29
27
|
var _useFlowState = useFlowState(flow),
|
|
30
28
|
running = _useFlowState.running,
|
|
@@ -34,7 +32,7 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
|
|
|
34
32
|
var launch = flow.launch,
|
|
35
33
|
konnector = flow.konnector;
|
|
36
34
|
|
|
37
|
-
var _useMaintenanceStatus = useMaintenanceStatus(
|
|
35
|
+
var _useMaintenanceStatus = useMaintenanceStatus(konnector.slug),
|
|
38
36
|
isInMaintenance = _useMaintenanceStatus.data.isInMaintenance;
|
|
39
37
|
|
|
40
38
|
var isKonnectorDisconnected = isDisconnected(konnector, trigger);
|
|
@@ -1,106 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
import get from 'lodash/get';
|
|
5
|
-
import memoize from 'lodash/memoize';
|
|
6
|
-
import { useState, useEffect } from 'react';
|
|
7
|
-
import { Registry } from 'cozy-client';
|
|
8
|
-
var memoizedFetchApp = memoize(function (registry, slug) {
|
|
9
|
-
return registry.fetchApp(slug);
|
|
10
|
-
}, function (registry, slug) {
|
|
11
|
-
return slug;
|
|
12
|
-
});
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
13
2
|
|
|
14
|
-
var
|
|
15
|
-
var slug = konnector.slug,
|
|
16
|
-
source = konnector.source;
|
|
3
|
+
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; }
|
|
17
4
|
|
|
18
|
-
|
|
19
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
-
isInMaintenance = _useState2[0],
|
|
21
|
-
setIsInMaintenance = _useState2[1];
|
|
5
|
+
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; }
|
|
22
6
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
setMessages = _useState4[1];
|
|
7
|
+
import { useQuery } from 'cozy-client';
|
|
8
|
+
import flag from 'cozy-flags';
|
|
9
|
+
import { buildAppsRegistryBySlug } from '../../helpers/queries';
|
|
27
10
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
fetchStatus = _useState6[0],
|
|
31
|
-
setFetchStatus = _useState6[1];
|
|
11
|
+
var useMaintenanceStatus = function useMaintenanceStatus(slug) {
|
|
12
|
+
var _flag, _registryResult$data$, _registryResult$data, _registryResult$data$2, _registryResult$data2, _registryResult$data3;
|
|
32
13
|
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
var skipMaintenanceList = (_flag = flag('harvest.skip-maintenance-for.list')) !== null && _flag !== void 0 ? _flag : [];
|
|
15
|
+
var skipMaintenance = skipMaintenanceList.includes(slug);
|
|
16
|
+
var registryQuery = buildAppsRegistryBySlug(slug);
|
|
17
|
+
var registryResult = useQuery(registryQuery.definition, _objectSpread(_objectSpread({}, registryQuery.options), {}, {
|
|
18
|
+
enabled: !skipMaintenance
|
|
19
|
+
}));
|
|
37
20
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
if (skipMaintenance) {
|
|
22
|
+
return {
|
|
23
|
+
data: {
|
|
24
|
+
isInMaintenance: false,
|
|
25
|
+
messages: {}
|
|
26
|
+
},
|
|
27
|
+
fetchStatus: 'loaded',
|
|
28
|
+
lastError: null
|
|
29
|
+
};
|
|
30
|
+
}
|
|
42
31
|
|
|
43
|
-
var fetchData = /*#__PURE__*/function () {
|
|
44
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
45
|
-
var appStatus, _isInMaintenance, _messages;
|
|
46
|
-
|
|
47
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
48
|
-
while (1) {
|
|
49
|
-
switch (_context.prev = _context.next) {
|
|
50
|
-
case 0:
|
|
51
|
-
if (!(/^registry:\/\//i.test(source) === false)) {
|
|
52
|
-
_context.next = 3;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Only konnectors from the registry have a maintenance status, manually installed once are always considered OK
|
|
57
|
-
setFetchStatus('loaded');
|
|
58
|
-
return _context.abrupt("return");
|
|
59
|
-
|
|
60
|
-
case 3:
|
|
61
|
-
_context.prev = 3;
|
|
62
|
-
setFetchStatus('loading');
|
|
63
|
-
_context.next = 7;
|
|
64
|
-
return memoizedFetchApp(registry, slug);
|
|
65
|
-
|
|
66
|
-
case 7:
|
|
67
|
-
appStatus = _context.sent;
|
|
68
|
-
_isInMaintenance = get(appStatus, 'maintenance_activated', false);
|
|
69
|
-
_messages = get(appStatus, 'maintenance_options.messages', {});
|
|
70
|
-
setFetchStatus('loaded');
|
|
71
|
-
setIsInMaintenance(_isInMaintenance);
|
|
72
|
-
setMessages(_messages);
|
|
73
|
-
_context.next = 19;
|
|
74
|
-
break;
|
|
75
|
-
|
|
76
|
-
case 15:
|
|
77
|
-
_context.prev = 15;
|
|
78
|
-
_context.t0 = _context["catch"](3);
|
|
79
|
-
setFetchStatus('failed');
|
|
80
|
-
setLastError(_context.t0);
|
|
81
|
-
|
|
82
|
-
case 19:
|
|
83
|
-
case "end":
|
|
84
|
-
return _context.stop();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}, _callee, null, [[3, 15]]);
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
return function fetchData() {
|
|
91
|
-
return _ref.apply(this, arguments);
|
|
92
|
-
};
|
|
93
|
-
}();
|
|
94
|
-
|
|
95
|
-
fetchData();
|
|
96
|
-
}, [client, slug, source]);
|
|
97
32
|
return {
|
|
98
33
|
data: {
|
|
99
|
-
isInMaintenance:
|
|
100
|
-
messages: messages
|
|
34
|
+
isInMaintenance: (_registryResult$data$ = (_registryResult$data = registryResult.data) === null || _registryResult$data === void 0 ? void 0 : _registryResult$data.maintenance_activated) !== null && _registryResult$data$ !== void 0 ? _registryResult$data$ : false,
|
|
35
|
+
messages: (_registryResult$data$2 = (_registryResult$data2 = registryResult.data) === null || _registryResult$data2 === void 0 ? void 0 : (_registryResult$data3 = _registryResult$data2.maintenance_options) === null || _registryResult$data3 === void 0 ? void 0 : _registryResult$data3.messages) !== null && _registryResult$data$2 !== void 0 ? _registryResult$data$2 : {}
|
|
101
36
|
},
|
|
102
|
-
fetchStatus: fetchStatus,
|
|
103
|
-
lastError: lastError
|
|
37
|
+
fetchStatus: registryResult.fetchStatus,
|
|
38
|
+
lastError: registryResult.lastError
|
|
104
39
|
};
|
|
105
40
|
};
|
|
106
41
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { CozyProvider, createMockClient } from 'cozy-client';
|
|
6
|
+
import flag from 'cozy-flags';
|
|
7
|
+
import useMaintenanceStatus from './useMaintenanceStatus';
|
|
8
|
+
jest.mock('cozy-flags');
|
|
9
|
+
describe('useMaintenanceStatus', function () {
|
|
10
|
+
var setup = function setup() {
|
|
11
|
+
var slug = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test';
|
|
12
|
+
var mockClient = createMockClient({
|
|
13
|
+
queries: {
|
|
14
|
+
'io.cozy.apps_registry/test': {
|
|
15
|
+
doctype: 'io.cozy.apps_registry',
|
|
16
|
+
definition: {
|
|
17
|
+
doctype: 'io.cozy.apps_registry',
|
|
18
|
+
id: 'io.cozy.apps_registry/test'
|
|
19
|
+
},
|
|
20
|
+
data: [{
|
|
21
|
+
id: 'test',
|
|
22
|
+
slug: 'test',
|
|
23
|
+
maintenance_activated: true,
|
|
24
|
+
maintenance_options: {
|
|
25
|
+
messages: {
|
|
26
|
+
en: 'Maintenance in progress'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}]
|
|
30
|
+
},
|
|
31
|
+
'io.cozy.apps_registry/not-found': {
|
|
32
|
+
doctype: 'io.cozy.apps_registry',
|
|
33
|
+
queryError: new Error('Failed to found konnector')
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
var wrapper = function wrapper(_ref) {
|
|
39
|
+
var children = _ref.children;
|
|
40
|
+
return /*#__PURE__*/React.createElement(CozyProvider, {
|
|
41
|
+
client: mockClient
|
|
42
|
+
}, children);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return renderHook(function () {
|
|
46
|
+
return useMaintenanceStatus(slug);
|
|
47
|
+
}, {
|
|
48
|
+
wrapper: wrapper
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
beforeEach(function () {
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
});
|
|
55
|
+
it('should return maintenance status of registry konnector', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
56
|
+
var _setup, result;
|
|
57
|
+
|
|
58
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
59
|
+
while (1) {
|
|
60
|
+
switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
_setup = setup(), result = _setup.result;
|
|
63
|
+
expect(result.current.fetchStatus).toBe('loaded');
|
|
64
|
+
expect(result.current.data.isInMaintenance).toBe(true);
|
|
65
|
+
expect(result.current.data.messages).toEqual({
|
|
66
|
+
en: 'Maintenance in progress'
|
|
67
|
+
});
|
|
68
|
+
expect(result.current.lastError).toBe(null);
|
|
69
|
+
|
|
70
|
+
case 5:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context.stop();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, _callee);
|
|
76
|
+
})));
|
|
77
|
+
it('should not be consider under maintenance if the slug is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
78
|
+
var _setup2, result;
|
|
79
|
+
|
|
80
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
81
|
+
while (1) {
|
|
82
|
+
switch (_context2.prev = _context2.next) {
|
|
83
|
+
case 0:
|
|
84
|
+
_setup2 = setup('not-found'), result = _setup2.result;
|
|
85
|
+
expect(result.current.fetchStatus).toBe('failed');
|
|
86
|
+
expect(result.current.data.isInMaintenance).toBe(false);
|
|
87
|
+
expect(result.current.data.messages).toEqual({});
|
|
88
|
+
expect(result.current.lastError).toEqual(new Error('Failed to found konnector'));
|
|
89
|
+
|
|
90
|
+
case 5:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context2.stop();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, _callee2);
|
|
96
|
+
})));
|
|
97
|
+
it('should not be consider under maintenance if the slug is declared in the skip flag', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
98
|
+
var _setup3, result;
|
|
99
|
+
|
|
100
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
101
|
+
while (1) {
|
|
102
|
+
switch (_context3.prev = _context3.next) {
|
|
103
|
+
case 0:
|
|
104
|
+
flag.mockReturnValue(['test']);
|
|
105
|
+
_setup3 = setup(), result = _setup3.result;
|
|
106
|
+
expect(result.current.fetchStatus).toBe('loaded');
|
|
107
|
+
expect(result.current.data.isInMaintenance).toBe(false);
|
|
108
|
+
expect(result.current.data.messages).toEqual({});
|
|
109
|
+
expect(result.current.lastError).toBe(null);
|
|
110
|
+
|
|
111
|
+
case 6:
|
|
112
|
+
case "end":
|
|
113
|
+
return _context3.stop();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, _callee3);
|
|
117
|
+
})));
|
|
118
|
+
});
|
package/dist/helpers/queries.js
CHANGED
|
@@ -104,4 +104,14 @@ export var buildAppsRegistryMaintenance = function buildAppsRegistryMaintenance(
|
|
|
104
104
|
fetchPolicy: defaultFetchPolicy
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
+
};
|
|
108
|
+
export var buildAppsRegistryBySlug = function buildAppsRegistryBySlug(slug) {
|
|
109
|
+
return {
|
|
110
|
+
definition: Q('io.cozy.apps_registry').getById(slug),
|
|
111
|
+
options: {
|
|
112
|
+
as: "io.cozy.apps_registry/".concat(slug),
|
|
113
|
+
fetchPolicy: defaultFetchPolicy,
|
|
114
|
+
singleDocData: true
|
|
115
|
+
}
|
|
116
|
+
};
|
|
107
117
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-harvest-lib",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.2.0",
|
|
4
4
|
"description": "Provides logic, modules and components for Cozy's harvest applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"babel-jest": "26.6.3",
|
|
73
73
|
"babel-plugin-inline-react-svg": "1.1.2",
|
|
74
74
|
"babel-preset-cozy-app": "^2.1.0",
|
|
75
|
-
"cozy-client": "^
|
|
75
|
+
"cozy-client": "^43.1.0",
|
|
76
76
|
"cozy-device-helper": "^3.0.0",
|
|
77
77
|
"cozy-flags": "^3.1.0",
|
|
78
78
|
"cozy-intent": "^2.18.0",
|
|
@@ -112,5 +112,5 @@
|
|
|
112
112
|
"react-router-dom": ">=4.3.1"
|
|
113
113
|
},
|
|
114
114
|
"sideEffects": false,
|
|
115
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "ee73cd53aef763628c7aedb4c43c36157333bde7"
|
|
116
116
|
}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import PropTypes from 'prop-types'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
|
-
import { useClient } from 'cozy-client'
|
|
5
|
-
|
|
6
4
|
import TriggerErrorAction from './TriggerErrorAction'
|
|
7
5
|
import { intentsApiProptype } from '../../helpers/proptypes'
|
|
8
6
|
import useMaintenanceStatus from '../hooks/useMaintenanceStatus'
|
|
9
7
|
import TriggerErrorInfo from '../infos/TriggerErrorInfo'
|
|
10
8
|
|
|
11
9
|
const TriggerError = ({ flow, konnector, account, trigger, intentsApi }) => {
|
|
12
|
-
const client = useClient()
|
|
13
10
|
const flowState = flow.getState()
|
|
14
11
|
const { error } = flowState
|
|
15
12
|
|
|
16
13
|
const {
|
|
17
14
|
data: { isInMaintenance }
|
|
18
|
-
} = useMaintenanceStatus(
|
|
15
|
+
} = useMaintenanceStatus(konnector.slug)
|
|
19
16
|
|
|
20
17
|
if (!error || isInMaintenance) return null
|
|
21
18
|
|
|
@@ -2,7 +2,6 @@ import cx from 'classnames'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import React, { useContext } from 'react'
|
|
4
4
|
|
|
5
|
-
import { useClient } from 'cozy-client'
|
|
6
5
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
|
|
7
6
|
import flag from 'cozy-flags'
|
|
8
7
|
import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog'
|
|
@@ -28,12 +27,11 @@ import useMaintenanceStatus from './hooks/useMaintenanceStatus'
|
|
|
28
27
|
*/
|
|
29
28
|
const NewAccountModal = ({ konnector, onSuccess, onDismiss }) => {
|
|
30
29
|
const { t } = useI18n()
|
|
31
|
-
const client = useClient()
|
|
32
30
|
const { replaceHistory } = useContext(MountPointContext)
|
|
33
31
|
const {
|
|
34
32
|
fetchStatus,
|
|
35
33
|
data: { isInMaintenance, messages: maintenanceMessages }
|
|
36
|
-
} = useMaintenanceStatus(
|
|
34
|
+
} = useMaintenanceStatus(konnector.slug)
|
|
37
35
|
const isMaintenanceLoaded =
|
|
38
36
|
fetchStatus === 'loaded' || fetchStatus === 'failed'
|
|
39
37
|
const serverSideKonnector = !(konnector.oauth || konnector.clientSide)
|
|
@@ -13,6 +13,10 @@ jest.mock('./TriggerManager', () => ({ onLoginSuccess, onSuccess }) => {
|
|
|
13
13
|
onSuccessFn = onSuccess
|
|
14
14
|
return null
|
|
15
15
|
})
|
|
16
|
+
jest.mock('./hooks/useMaintenanceStatus', () => () => ({
|
|
17
|
+
fetchStatus: 'loaded',
|
|
18
|
+
data: { isInMaintenance: false, messages: {} }
|
|
19
|
+
}))
|
|
16
20
|
|
|
17
21
|
describe('NewAccountModal', () => {
|
|
18
22
|
const replaceHistory = jest.fn()
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import PropTypes from 'prop-types'
|
|
2
2
|
import React, { useState, useEffect } from 'react'
|
|
3
3
|
|
|
4
|
-
import { useClient } from 'cozy-client'
|
|
5
4
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
|
|
6
5
|
import Alert from 'cozy-ui/transpiled/react/Alert'
|
|
7
6
|
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
@@ -54,14 +53,13 @@ export const LaunchTriggerAlert = ({
|
|
|
54
53
|
account,
|
|
55
54
|
withMaintenanceDescription
|
|
56
55
|
}) => {
|
|
57
|
-
const client = useClient()
|
|
58
56
|
const [showSuccessSnackbar, setShowSuccessSnackbar] = useState(false)
|
|
59
57
|
const { error, trigger, running, expectingTriggerLaunch, status } =
|
|
60
58
|
useFlowState(flow)
|
|
61
59
|
const { launch, konnector } = flow
|
|
62
60
|
const {
|
|
63
61
|
data: { isInMaintenance, messages: maintenanceMessages }
|
|
64
|
-
} = useMaintenanceStatus(
|
|
62
|
+
} = useMaintenanceStatus(konnector.slug)
|
|
65
63
|
|
|
66
64
|
const isInError = !!error
|
|
67
65
|
const block = isInError || (!!withMaintenanceDescription && isInMaintenance)
|
|
@@ -21,6 +21,11 @@ jest.mock('../../models/ConnectionFlow', () => {
|
|
|
21
21
|
|
|
22
22
|
jest.mock('cozy-flags')
|
|
23
23
|
|
|
24
|
+
jest.mock('../hooks/useMaintenanceStatus', () => () => ({
|
|
25
|
+
fetchStatus: 'loaded',
|
|
26
|
+
data: { isInMaintenance: false, messages: {} }
|
|
27
|
+
}))
|
|
28
|
+
|
|
24
29
|
const triggerFixture = {
|
|
25
30
|
_id: 'd861818b62204988bf0bb78c182a9149',
|
|
26
31
|
arguments: '0 0 0 * * 0'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import PropTypes from 'prop-types'
|
|
2
2
|
import React, { useRef, useState } from 'react'
|
|
3
3
|
|
|
4
|
-
import { useClient } from 'cozy-client'
|
|
5
4
|
import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
|
|
6
5
|
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
7
6
|
import IconButton from 'cozy-ui/transpiled/react/IconButton'
|
|
@@ -28,12 +27,11 @@ const LaunchTriggerAlertMenu = ({
|
|
|
28
27
|
account,
|
|
29
28
|
intentsApi
|
|
30
29
|
}) => {
|
|
31
|
-
const client = useClient()
|
|
32
30
|
const { running, trigger, error } = useFlowState(flow)
|
|
33
31
|
const { launch, konnector } = flow
|
|
34
32
|
const {
|
|
35
33
|
data: { isInMaintenance }
|
|
36
|
-
} = useMaintenanceStatus(
|
|
34
|
+
} = useMaintenanceStatus(konnector.slug)
|
|
37
35
|
const isKonnectorDisconnected = isDisconnected(konnector, trigger)
|
|
38
36
|
const konnectorPolicy = findKonnectorPolicy(konnector)
|
|
39
37
|
const isKonnectorRunnable = konnectorPolicy.isRunnable()
|
|
@@ -1,58 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
client
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const fetchData = async () => {
|
|
28
|
-
if (/^registry:\/\//i.test(source) === false) {
|
|
29
|
-
// Only konnectors from the registry have a maintenance status, manually installed once are always considered OK
|
|
30
|
-
setFetchStatus('loaded')
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
setFetchStatus('loading')
|
|
35
|
-
const appStatus = await memoizedFetchApp(registry, slug)
|
|
36
|
-
const isInMaintenance = get(appStatus, 'maintenance_activated', false)
|
|
37
|
-
const messages = get(appStatus, 'maintenance_options.messages', {})
|
|
38
|
-
setFetchStatus('loaded')
|
|
39
|
-
setIsInMaintenance(isInMaintenance)
|
|
40
|
-
setMessages(messages)
|
|
41
|
-
} catch (error) {
|
|
42
|
-
setFetchStatus('failed')
|
|
43
|
-
setLastError(error)
|
|
44
|
-
}
|
|
1
|
+
import { useQuery } from 'cozy-client'
|
|
2
|
+
import flag from 'cozy-flags'
|
|
3
|
+
|
|
4
|
+
import { buildAppsRegistryBySlug } from '../../helpers/queries'
|
|
5
|
+
|
|
6
|
+
const useMaintenanceStatus = slug => {
|
|
7
|
+
const skipMaintenanceList = flag('harvest.skip-maintenance-for.list') ?? []
|
|
8
|
+
const skipMaintenance = skipMaintenanceList.includes(slug)
|
|
9
|
+
|
|
10
|
+
const registryQuery = buildAppsRegistryBySlug(slug)
|
|
11
|
+
const registryResult = useQuery(registryQuery.definition, {
|
|
12
|
+
...registryQuery.options,
|
|
13
|
+
enabled: !skipMaintenance
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
if (skipMaintenance) {
|
|
17
|
+
return {
|
|
18
|
+
data: {
|
|
19
|
+
isInMaintenance: false,
|
|
20
|
+
messages: {}
|
|
21
|
+
},
|
|
22
|
+
fetchStatus: 'loaded',
|
|
23
|
+
lastError: null
|
|
45
24
|
}
|
|
46
|
-
|
|
47
|
-
}, [client, slug, source])
|
|
25
|
+
}
|
|
48
26
|
|
|
49
27
|
return {
|
|
50
28
|
data: {
|
|
51
|
-
isInMaintenance,
|
|
52
|
-
messages
|
|
29
|
+
isInMaintenance: registryResult.data?.maintenance_activated ?? false,
|
|
30
|
+
messages: registryResult.data?.maintenance_options?.messages ?? {}
|
|
53
31
|
},
|
|
54
|
-
fetchStatus,
|
|
55
|
-
lastError
|
|
32
|
+
fetchStatus: registryResult.fetchStatus,
|
|
33
|
+
lastError: registryResult.lastError
|
|
56
34
|
}
|
|
57
35
|
}
|
|
58
36
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { CozyProvider, createMockClient } from 'cozy-client'
|
|
5
|
+
import flag from 'cozy-flags'
|
|
6
|
+
|
|
7
|
+
import useMaintenanceStatus from './useMaintenanceStatus'
|
|
8
|
+
|
|
9
|
+
jest.mock('cozy-flags')
|
|
10
|
+
|
|
11
|
+
describe('useMaintenanceStatus', () => {
|
|
12
|
+
const setup = (slug = 'test') => {
|
|
13
|
+
const mockClient = createMockClient({
|
|
14
|
+
queries: {
|
|
15
|
+
'io.cozy.apps_registry/test': {
|
|
16
|
+
doctype: 'io.cozy.apps_registry',
|
|
17
|
+
definition: {
|
|
18
|
+
doctype: 'io.cozy.apps_registry',
|
|
19
|
+
id: 'io.cozy.apps_registry/test'
|
|
20
|
+
},
|
|
21
|
+
data: [
|
|
22
|
+
{
|
|
23
|
+
id: 'test',
|
|
24
|
+
slug: 'test',
|
|
25
|
+
maintenance_activated: true,
|
|
26
|
+
maintenance_options: {
|
|
27
|
+
messages: {
|
|
28
|
+
en: 'Maintenance in progress'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
'io.cozy.apps_registry/not-found': {
|
|
35
|
+
doctype: 'io.cozy.apps_registry',
|
|
36
|
+
queryError: new Error('Failed to found konnector')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
const wrapper = ({ children }) => (
|
|
41
|
+
<CozyProvider client={mockClient}>{children}</CozyProvider>
|
|
42
|
+
)
|
|
43
|
+
return renderHook(() => useMaintenanceStatus(slug), { wrapper })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
jest.clearAllMocks()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('should return maintenance status of registry konnector', async () => {
|
|
51
|
+
const { result } = setup()
|
|
52
|
+
|
|
53
|
+
expect(result.current.fetchStatus).toBe('loaded')
|
|
54
|
+
expect(result.current.data.isInMaintenance).toBe(true)
|
|
55
|
+
expect(result.current.data.messages).toEqual({
|
|
56
|
+
en: 'Maintenance in progress'
|
|
57
|
+
})
|
|
58
|
+
expect(result.current.lastError).toBe(null)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should not be consider under maintenance if the slug is not found', async () => {
|
|
62
|
+
const { result } = setup('not-found')
|
|
63
|
+
|
|
64
|
+
expect(result.current.fetchStatus).toBe('failed')
|
|
65
|
+
expect(result.current.data.isInMaintenance).toBe(false)
|
|
66
|
+
expect(result.current.data.messages).toEqual({})
|
|
67
|
+
expect(result.current.lastError).toEqual(
|
|
68
|
+
new Error('Failed to found konnector')
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should not be consider under maintenance if the slug is declared in the skip flag', async () => {
|
|
73
|
+
flag.mockReturnValue(['test'])
|
|
74
|
+
|
|
75
|
+
const { result } = setup()
|
|
76
|
+
|
|
77
|
+
expect(result.current.fetchStatus).toBe('loaded')
|
|
78
|
+
expect(result.current.data.isInMaintenance).toBe(false)
|
|
79
|
+
expect(result.current.data.messages).toEqual({})
|
|
80
|
+
expect(result.current.lastError).toBe(null)
|
|
81
|
+
})
|
|
82
|
+
})
|
package/src/helpers/queries.js
CHANGED
|
@@ -92,3 +92,12 @@ export const buildAppsRegistryMaintenance = () => ({
|
|
|
92
92
|
fetchPolicy: defaultFetchPolicy
|
|
93
93
|
}
|
|
94
94
|
})
|
|
95
|
+
|
|
96
|
+
export const buildAppsRegistryBySlug = slug => ({
|
|
97
|
+
definition: Q('io.cozy.apps_registry').getById(slug),
|
|
98
|
+
options: {
|
|
99
|
+
as: `io.cozy.apps_registry/${slug}`,
|
|
100
|
+
fetchPolicy: defaultFetchPolicy,
|
|
101
|
+
singleDocData: true
|
|
102
|
+
}
|
|
103
|
+
})
|