cozy-harvest-lib 8.1.1 → 8.3.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 +33 -0
- package/dist/components/AccountModal.js +5 -4
- package/dist/components/AccountModal.spec.js +4 -1
- package/dist/components/AccountsListModal.js +3 -2
- package/dist/components/EditAccountModal.js +3 -3
- package/dist/components/HarvestModalRoot.js +3 -3
- package/dist/components/KonnectorConfiguration/ConfigurationTab/index.js +2 -2
- package/dist/components/MountPointContext.js +24 -10
- package/dist/components/MountPointContext.spec.js +17 -17
- package/dist/components/NewAccountModal.js +3 -3
- package/dist/components/NewAccountModal.spec.js +6 -6
- package/dist/components/RedirectToAccountFormButton.js +3 -3
- package/dist/components/RedirectToAccountFormButton.spec.js +4 -4
- package/dist/components/Routes.js +8 -1
- package/dist/datacards/FileDataCard.js +25 -90
- package/dist/datacards/ViewerModal.js +40 -0
- package/dist/datacards/useDataCardFiles.js +63 -0
- package/dist/datacards/useDataCardFiles.spec.js +242 -0
- package/package.json +3 -3
- package/src/components/AccountModal.jsx +5 -4
- package/src/components/AccountModal.spec.jsx +7 -2
- package/src/components/AccountsListModal.jsx +2 -2
- package/src/components/EditAccountModal.jsx +3 -3
- package/src/components/HarvestModalRoot.jsx +3 -3
- package/src/components/KonnectorConfiguration/ConfigurationTab/index.jsx +2 -2
- package/src/components/MountPointContext.jsx +29 -12
- package/src/components/MountPointContext.spec.jsx +17 -17
- package/src/components/NewAccountModal.jsx +3 -3
- package/src/components/NewAccountModal.spec.jsx +6 -6
- package/src/components/RedirectToAccountFormButton.jsx +3 -3
- package/src/components/RedirectToAccountFormButton.spec.jsx +4 -4
- package/src/components/Routes.jsx +14 -5
- package/src/datacards/FileDataCard.jsx +24 -90
- package/src/datacards/ViewerModal.jsx +43 -0
- package/src/datacards/useDataCardFiles.js +84 -0
- package/src/datacards/useDataCardFiles.spec.js +135 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
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
|
+
# [8.3.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.2.1...cozy-harvest-lib@8.3.0) (2022-04-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Implement ViewerModal as Route ([bdb6e88](https://github.com/cozy/cozy-libs/commit/bdb6e88e4c70217654f3b72828dee964aa2a4d1b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [8.2.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.2.0...cozy-harvest-lib@8.2.1) (2022-04-13)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* Get correct bi mapping for bnp_es and cic_es ([f304f89](https://github.com/cozy/cozy-libs/commit/f304f8978f1857f3f1d1e74c0c19385ab96dde24))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [8.2.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.1.1...cozy-harvest-lib@8.2.0) (2022-04-13)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* Fix back navigation ([89283ab](https://github.com/cozy/cozy-libs/commit/89283ab1beb06fa15625a7f108abbddf37216397))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
6
39
|
## [8.1.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.1.0...cozy-harvest-lib@8.1.1) (2022-04-11)
|
|
7
40
|
|
|
8
41
|
|
|
@@ -26,7 +26,7 @@ import * as triggersModel from '../helpers/triggers';
|
|
|
26
26
|
import KonnectorAccountTabs from './KonnectorConfiguration/KonnectorAccountTabs';
|
|
27
27
|
import AccountSelectBox from './AccountSelectBox/AccountSelectBox';
|
|
28
28
|
import KonnectorModalHeader from './KonnectorModalHeader';
|
|
29
|
-
import {
|
|
29
|
+
import { withMountPointHistory } from './MountPointContext';
|
|
30
30
|
import withLocales from './hoc/withLocales';
|
|
31
31
|
import DialogContent from '@material-ui/core/DialogContent';
|
|
32
32
|
/**
|
|
@@ -247,6 +247,7 @@ export var AccountModal = /*#__PURE__*/function (_Component) {
|
|
|
247
247
|
accountsAndTriggers = _this$props2.accountsAndTriggers,
|
|
248
248
|
t = _this$props2.t,
|
|
249
249
|
pushHistory = _this$props2.pushHistory,
|
|
250
|
+
replaceHistory = _this$props2.replaceHistory,
|
|
250
251
|
initialActiveTab = _this$props2.initialActiveTab,
|
|
251
252
|
isMobile = _this$props2.breakpoints.isMobile,
|
|
252
253
|
showAccountSelection = _this$props2.showAccountSelection,
|
|
@@ -293,7 +294,7 @@ export var AccountModal = /*#__PURE__*/function (_Component) {
|
|
|
293
294
|
account: account,
|
|
294
295
|
onAccountDeleted: onDismiss,
|
|
295
296
|
addAccount: function addAccount() {
|
|
296
|
-
return
|
|
297
|
+
return replaceHistory('/new');
|
|
297
298
|
},
|
|
298
299
|
showNewAccountButton: showNewAccountButton
|
|
299
300
|
})));
|
|
@@ -324,7 +325,7 @@ AccountModal.propTypes = {
|
|
|
324
325
|
trigger: PropTypes.object.isRequired
|
|
325
326
|
})).isRequired,
|
|
326
327
|
t: PropTypes.func.isRequired,
|
|
327
|
-
|
|
328
|
+
replaceHistory: PropTypes.func.isRequired,
|
|
328
329
|
accountId: PropTypes.string.isRequired,
|
|
329
330
|
|
|
330
331
|
/** @type {string} Can be set to force the initial active tab */
|
|
@@ -336,4 +337,4 @@ AccountModal.propTypes = {
|
|
|
336
337
|
/** @type {Boolean} Whether to show the button to add a new account */
|
|
337
338
|
showNewAccountButton: PropTypes.bool
|
|
338
339
|
};
|
|
339
|
-
export default flow(withClient, withLocales,
|
|
340
|
+
export default flow(withClient, withLocales, withMountPointHistory, withBreakpoints())(AccountModal);
|
|
@@ -38,6 +38,7 @@ var accountIdMock = '123';
|
|
|
38
38
|
describe('AccountModal', function () {
|
|
39
39
|
var setup = function setup() {
|
|
40
40
|
var mockHistoryPush = jest.fn();
|
|
41
|
+
var mockHistoryReplace = jest.fn();
|
|
41
42
|
var component = shallow( /*#__PURE__*/React.createElement(AccountModal, {
|
|
42
43
|
konnector: {},
|
|
43
44
|
t: function t(x) {
|
|
@@ -46,6 +47,7 @@ describe('AccountModal', function () {
|
|
|
46
47
|
accountId: accountIdMock,
|
|
47
48
|
accountsAndTriggers: accountsAndTriggersMock,
|
|
48
49
|
pushHistory: mockHistoryPush,
|
|
50
|
+
replaceHistory: mockHistoryReplace,
|
|
49
51
|
breakpoints: {
|
|
50
52
|
isMobile: true
|
|
51
53
|
},
|
|
@@ -53,7 +55,8 @@ describe('AccountModal', function () {
|
|
|
53
55
|
}));
|
|
54
56
|
return {
|
|
55
57
|
component: component,
|
|
56
|
-
mockHistoryPush: mockHistoryPush
|
|
58
|
+
mockHistoryPush: mockHistoryPush,
|
|
59
|
+
mockHistoryReplace: mockHistoryReplace
|
|
57
60
|
};
|
|
58
61
|
};
|
|
59
62
|
|
|
@@ -13,7 +13,8 @@ var AccountsListModal = function AccountsListModal(_ref) {
|
|
|
13
13
|
t = _ref.t;
|
|
14
14
|
|
|
15
15
|
var _useContext = useContext(MountPointContext),
|
|
16
|
-
pushHistory = _useContext.pushHistory
|
|
16
|
+
pushHistory = _useContext.pushHistory,
|
|
17
|
+
replaceHistory = _useContext.replaceHistory;
|
|
17
18
|
|
|
18
19
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DialogContent, null, /*#__PURE__*/React.createElement(Stack, {
|
|
19
20
|
className: "u-mb-3"
|
|
@@ -29,7 +30,7 @@ var AccountsListModal = function AccountsListModal(_ref) {
|
|
|
29
30
|
accounts: accounts,
|
|
30
31
|
konnector: konnector,
|
|
31
32
|
onPick: function onPick(option) {
|
|
32
|
-
return
|
|
33
|
+
return replaceHistory("/accounts/".concat(option.account._id));
|
|
33
34
|
},
|
|
34
35
|
addAccount: function addAccount() {
|
|
35
36
|
return pushHistory('/new');
|
|
@@ -27,7 +27,7 @@ import { DialogCloseButton, useCozyDialog } from 'cozy-ui/transpiled/react/CozyD
|
|
|
27
27
|
import { fetchAccount as _fetchAccount } from '../connections/accounts';
|
|
28
28
|
import * as triggersModel from '../helpers/triggers';
|
|
29
29
|
import TriggerManager from './TriggerManager';
|
|
30
|
-
import {
|
|
30
|
+
import { withMountPointHistory } from './MountPointContext';
|
|
31
31
|
import logger from '../logger';
|
|
32
32
|
import { withTracker } from './hoc/tracking';
|
|
33
33
|
import useTimeout from './hooks/useTimeout';
|
|
@@ -213,7 +213,7 @@ export var EditAccountModal = /*#__PURE__*/function (_Component) {
|
|
|
213
213
|
var account = this.state.account;
|
|
214
214
|
|
|
215
215
|
if (account) {
|
|
216
|
-
this.props.
|
|
216
|
+
this.props.replaceHistory("/accounts/".concat(account._id));
|
|
217
217
|
} else {
|
|
218
218
|
this.props.pushHistory("/accounts");
|
|
219
219
|
}
|
|
@@ -255,4 +255,4 @@ EditAccountModal.propTypes = {
|
|
|
255
255
|
accounts: PropTypes.array.isRequired,
|
|
256
256
|
reconnect: PropTypes.bool
|
|
257
257
|
};
|
|
258
|
-
export default flow(withClient,
|
|
258
|
+
export default flow(withClient, withMountPointHistory, withTracker)(EditAccountModal);
|
|
@@ -8,13 +8,13 @@ var HarvestModalRoot = function HarvestModalRoot(_ref) {
|
|
|
8
8
|
konnector = _ref.konnector;
|
|
9
9
|
|
|
10
10
|
var _useContext = useContext(MountPointContext),
|
|
11
|
-
|
|
11
|
+
replaceHistory = _useContext.replaceHistory;
|
|
12
12
|
|
|
13
13
|
if (accounts.length === 0) {
|
|
14
|
-
|
|
14
|
+
replaceHistory('/new');
|
|
15
15
|
return null;
|
|
16
16
|
} else if (accounts.length === 1) {
|
|
17
|
-
|
|
17
|
+
replaceHistory("/accounts/".concat(accounts[0].account._id));
|
|
18
18
|
return null;
|
|
19
19
|
} else {
|
|
20
20
|
return /*#__PURE__*/React.createElement(AccountsListModal, {
|
|
@@ -76,7 +76,7 @@ var ConfigurationTab = function ConfigurationTab(_ref2) {
|
|
|
76
76
|
isMobile = _useBreakpoints.isMobile;
|
|
77
77
|
|
|
78
78
|
var _useContext = useContext(MountPointContext),
|
|
79
|
-
|
|
79
|
+
replaceHistory = _useContext.replaceHistory;
|
|
80
80
|
|
|
81
81
|
var client = useClient();
|
|
82
82
|
var vaultClient = useVaultClient();
|
|
@@ -238,7 +238,7 @@ var ConfigurationTab = function ConfigurationTab(_ref2) {
|
|
|
238
238
|
button: true,
|
|
239
239
|
divider: true,
|
|
240
240
|
onClick: function onClick() {
|
|
241
|
-
return
|
|
241
|
+
return replaceHistory("/accounts/".concat(account._id, "/edit"));
|
|
242
242
|
}
|
|
243
243
|
}, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
244
244
|
icon: KeyIcon,
|
|
@@ -26,20 +26,32 @@ export var RawMountPointProvider = /*#__PURE__*/function (_React$Component) {
|
|
|
26
26
|
|
|
27
27
|
_this = _super.call(this, props);
|
|
28
28
|
_this.pushHistory = _this.pushHistory.bind(_assertThisInitialized(_this));
|
|
29
|
+
_this.replaceHistory = _this.replaceHistory.bind(_assertThisInitialized(_this));
|
|
29
30
|
_this.state = {
|
|
30
31
|
baseRoute: props.baseRoute || '/',
|
|
31
|
-
pushHistory: _this.pushHistory
|
|
32
|
+
pushHistory: _this.pushHistory,
|
|
33
|
+
replaceHistory: _this.replaceHistory
|
|
32
34
|
};
|
|
33
35
|
return _this;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
_createClass(RawMountPointProvider, [{
|
|
37
|
-
key: "
|
|
38
|
-
value: function
|
|
39
|
+
key: "historyAction",
|
|
40
|
+
value: function historyAction(route, method) {
|
|
39
41
|
var history = this.props.history;
|
|
40
42
|
var baseRoute = this.state.baseRoute;
|
|
41
|
-
var segments = baseRoute.split('/').concat(route.split('/')).filter(Boolean);
|
|
42
|
-
history
|
|
43
|
+
var segments = '/'.concat(baseRoute.split('/').concat(route.split('/')).filter(Boolean).join('/'));
|
|
44
|
+
history[method](segments);
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "pushHistory",
|
|
48
|
+
value: function pushHistory(route) {
|
|
49
|
+
this.historyAction(route, 'push');
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "replaceHistory",
|
|
53
|
+
value: function replaceHistory(route) {
|
|
54
|
+
this.historyAction(route, 'replace');
|
|
43
55
|
}
|
|
44
56
|
}, {
|
|
45
57
|
key: "render",
|
|
@@ -57,19 +69,21 @@ RawMountPointProvider.propTypes = {
|
|
|
57
69
|
history: PropTypes.object
|
|
58
70
|
};
|
|
59
71
|
|
|
60
|
-
var
|
|
72
|
+
var withMountPointHistory = function withMountPointHistory(BaseComponent) {
|
|
61
73
|
var Component = function Component(props) {
|
|
62
74
|
var _useContext = useContext(MountPointContext),
|
|
63
|
-
pushHistory = _useContext.pushHistory
|
|
75
|
+
pushHistory = _useContext.pushHistory,
|
|
76
|
+
replaceHistory = _useContext.replaceHistory;
|
|
64
77
|
|
|
65
78
|
return /*#__PURE__*/React.createElement(BaseComponent, _extends({
|
|
66
|
-
pushHistory: pushHistory
|
|
79
|
+
pushHistory: pushHistory,
|
|
80
|
+
replaceHistory: replaceHistory
|
|
67
81
|
}, props));
|
|
68
82
|
};
|
|
69
83
|
|
|
70
|
-
Component.displayName = "
|
|
84
|
+
Component.displayName = "withMountPointHistory(".concat(BaseComponent.displayName || BaseComponent.name, ")");
|
|
71
85
|
return Component;
|
|
72
86
|
};
|
|
73
87
|
|
|
74
88
|
var MountPointProvider = withRouter(RawMountPointProvider);
|
|
75
|
-
export { MountPointContext, MountPointProvider,
|
|
89
|
+
export { MountPointContext, MountPointProvider, withMountPointHistory };
|
|
@@ -3,7 +3,7 @@ import { shallow } from 'enzyme';
|
|
|
3
3
|
import { RawMountPointProvider } from 'components/MountPointContext';
|
|
4
4
|
describe('MountPointProvider', function () {
|
|
5
5
|
var historyMock = {
|
|
6
|
-
|
|
6
|
+
replace: jest.fn()
|
|
7
7
|
};
|
|
8
8
|
beforeEach(function () {
|
|
9
9
|
jest.resetAllMocks();
|
|
@@ -13,33 +13,33 @@ describe('MountPointProvider', function () {
|
|
|
13
13
|
baseRoute: "/root",
|
|
14
14
|
history: historyMock
|
|
15
15
|
}));
|
|
16
|
-
component.instance().
|
|
17
|
-
expect(historyMock.
|
|
18
|
-
component.instance().
|
|
19
|
-
expect(historyMock.
|
|
20
|
-
component.instance().
|
|
21
|
-
expect(historyMock.
|
|
22
|
-
component.instance().
|
|
23
|
-
expect(historyMock.
|
|
16
|
+
component.instance().replaceHistory('/one');
|
|
17
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/root/one');
|
|
18
|
+
component.instance().replaceHistory('/one/two');
|
|
19
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/root/one/two');
|
|
20
|
+
component.instance().replaceHistory('no/slash');
|
|
21
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/root/no/slash');
|
|
22
|
+
component.instance().replaceHistory('too/many///slashes');
|
|
23
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/root/too/many/slashes');
|
|
24
24
|
});
|
|
25
25
|
it('should handle a trailing slash in the base route', function () {
|
|
26
26
|
var component = shallow( /*#__PURE__*/React.createElement(RawMountPointProvider, {
|
|
27
27
|
baseRoute: "/root/",
|
|
28
28
|
history: historyMock
|
|
29
29
|
}));
|
|
30
|
-
component.instance().
|
|
31
|
-
expect(historyMock.
|
|
32
|
-
component.instance().
|
|
33
|
-
expect(historyMock.
|
|
30
|
+
component.instance().replaceHistory('/one');
|
|
31
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/root/one');
|
|
32
|
+
component.instance().replaceHistory('no/slash');
|
|
33
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/root/no/slash');
|
|
34
34
|
});
|
|
35
35
|
it('should handle a base route with multiple segments', function () {
|
|
36
36
|
var component = shallow( /*#__PURE__*/React.createElement(RawMountPointProvider, {
|
|
37
37
|
baseRoute: "/base/route/",
|
|
38
38
|
history: historyMock
|
|
39
39
|
}));
|
|
40
|
-
component.instance().
|
|
41
|
-
expect(historyMock.
|
|
42
|
-
component.instance().
|
|
43
|
-
expect(historyMock.
|
|
40
|
+
component.instance().replaceHistory('/one');
|
|
41
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/base/route/one');
|
|
42
|
+
component.instance().replaceHistory('/one/two');
|
|
43
|
+
expect(historyMock.replace).toHaveBeenCalledWith('/base/route/one/two');
|
|
44
44
|
});
|
|
45
45
|
});
|
|
@@ -32,7 +32,7 @@ var NewAccountModal = function NewAccountModal(_ref) {
|
|
|
32
32
|
var client = useClient();
|
|
33
33
|
|
|
34
34
|
var _useContext = useContext(MountPointContext),
|
|
35
|
-
|
|
35
|
+
replaceHistory = _useContext.replaceHistory;
|
|
36
36
|
|
|
37
37
|
var _useMaintenanceStatus = useMaintenanceStatus(client, konnector),
|
|
38
38
|
fetchStatus = _useMaintenanceStatus.fetchStatus,
|
|
@@ -78,7 +78,7 @@ var NewAccountModal = function NewAccountModal(_ref) {
|
|
|
78
78
|
path += '/success';
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
replaceHistory(path);
|
|
82
82
|
},
|
|
83
83
|
onSuccess: function onSuccess(trigger) {
|
|
84
84
|
var accountId = triggersModel.getAccountId(trigger);
|
|
@@ -88,7 +88,7 @@ var NewAccountModal = function NewAccountModal(_ref) {
|
|
|
88
88
|
path += '/success';
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
replaceHistory(path);
|
|
92
92
|
},
|
|
93
93
|
onVaultDismiss: onDismiss,
|
|
94
94
|
fieldOptions: fieldOptions
|
|
@@ -27,9 +27,9 @@ jest.mock('./DialogContext', function () {
|
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
29
|
describe('NewAccountModal', function () {
|
|
30
|
-
var
|
|
30
|
+
var replaceHistory = jest.fn();
|
|
31
31
|
var mountPointContextValue = {
|
|
32
|
-
|
|
32
|
+
replaceHistory: replaceHistory
|
|
33
33
|
};
|
|
34
34
|
var konnectorTrigger = {
|
|
35
35
|
worker: 'konnector',
|
|
@@ -58,7 +58,7 @@ describe('NewAccountModal', function () {
|
|
|
58
58
|
}
|
|
59
59
|
}))));
|
|
60
60
|
onLoginSuccessFn(konnectorTrigger);
|
|
61
|
-
expect(
|
|
61
|
+
expect(replaceHistory).toHaveBeenCalledWith('/accounts/accountNumber/success');
|
|
62
62
|
});
|
|
63
63
|
it('should redirect to route without success on login success for client triggers', function () {
|
|
64
64
|
render( /*#__PURE__*/React.createElement(AppLike, {
|
|
@@ -72,7 +72,7 @@ describe('NewAccountModal', function () {
|
|
|
72
72
|
}
|
|
73
73
|
}))));
|
|
74
74
|
onLoginSuccessFn(clientTrigger);
|
|
75
|
-
expect(
|
|
75
|
+
expect(replaceHistory).toHaveBeenCalledWith('/accounts/accountNumberClient');
|
|
76
76
|
});
|
|
77
77
|
it('should redirect to success route on success for non client triggers', function () {
|
|
78
78
|
render( /*#__PURE__*/React.createElement(AppLike, {
|
|
@@ -86,7 +86,7 @@ describe('NewAccountModal', function () {
|
|
|
86
86
|
}
|
|
87
87
|
}))));
|
|
88
88
|
onSuccessFn(konnectorTrigger);
|
|
89
|
-
expect(
|
|
89
|
+
expect(replaceHistory).toHaveBeenCalledWith('/accounts/accountNumber/success');
|
|
90
90
|
});
|
|
91
91
|
it('should redirect to route without success on success for client triggers', function () {
|
|
92
92
|
render( /*#__PURE__*/React.createElement(AppLike, {
|
|
@@ -100,6 +100,6 @@ describe('NewAccountModal', function () {
|
|
|
100
100
|
}
|
|
101
101
|
}))));
|
|
102
102
|
onSuccessFn(clientTrigger);
|
|
103
|
-
expect(
|
|
103
|
+
expect(replaceHistory).toHaveBeenCalledWith('/accounts/accountNumberClient');
|
|
104
104
|
});
|
|
105
105
|
});
|
|
@@ -13,11 +13,11 @@ var RedirectToAccountFormButton = function RedirectToAccountFormButton(_ref) {
|
|
|
13
13
|
var accountId = getAccountId(trigger);
|
|
14
14
|
|
|
15
15
|
var _useContext = useContext(MountPointContext),
|
|
16
|
-
|
|
16
|
+
replaceHistory = _useContext.replaceHistory;
|
|
17
17
|
|
|
18
18
|
var handleClick = useCallback(function () {
|
|
19
|
-
|
|
20
|
-
}, [accountId,
|
|
19
|
+
replaceHistory("/accounts/".concat(accountId, "/edit?reconnect"));
|
|
20
|
+
}, [accountId, replaceHistory]);
|
|
21
21
|
return /*#__PURE__*/React.createElement(Button, {
|
|
22
22
|
className: "u-ml-0",
|
|
23
23
|
theme: "secondary",
|
|
@@ -4,10 +4,10 @@ import { MountPointContext } from './MountPointContext';
|
|
|
4
4
|
import RedirectToAccountFormButton from './RedirectToAccountFormButton';
|
|
5
5
|
import AppLike from '../../test/AppLike';
|
|
6
6
|
describe('redirect to account form button', function () {
|
|
7
|
-
it('should use
|
|
8
|
-
var
|
|
7
|
+
it('should use replaceHistory to navigate', function () {
|
|
8
|
+
var replaceHistory = jest.fn();
|
|
9
9
|
var mountPointContextValue = {
|
|
10
|
-
|
|
10
|
+
replaceHistory: replaceHistory
|
|
11
11
|
};
|
|
12
12
|
var trigger = {
|
|
13
13
|
message: {
|
|
@@ -20,6 +20,6 @@ describe('redirect to account form button', function () {
|
|
|
20
20
|
trigger: trigger
|
|
21
21
|
}))));
|
|
22
22
|
fireEvent.click(root.getByText('Reconnect'));
|
|
23
|
-
expect(
|
|
23
|
+
expect(replaceHistory).toHaveBeenCalledWith('/accounts/account-id-1337/edit?reconnect');
|
|
24
24
|
});
|
|
25
25
|
});
|
|
@@ -4,6 +4,7 @@ import { Switch, Route, Redirect } from 'react-router';
|
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
5
|
import Dialog from 'cozy-ui/transpiled/react/Dialog';
|
|
6
6
|
import { DialogCloseButton, useCozyDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
|
|
7
|
+
import { useVaultUnlockContext, VaultUnlockProvider, VaultUnlockPlaceholder } from 'cozy-keys-lib';
|
|
7
8
|
import KonnectorAccounts from './KonnectorAccounts';
|
|
8
9
|
import AccountModal from './AccountModal';
|
|
9
10
|
import NewAccountModal from './NewAccountModal';
|
|
@@ -14,7 +15,7 @@ import HarvestVaultProvider from './HarvestVaultProvider';
|
|
|
14
15
|
import { MountPointProvider } from './MountPointContext';
|
|
15
16
|
import DialogContext from './DialogContext';
|
|
16
17
|
import { DatacardOptions } from './Datacards/DatacardOptionsContext';
|
|
17
|
-
import {
|
|
18
|
+
import { ViewerModal } from '../datacards/ViewerModal';
|
|
18
19
|
/**
|
|
19
20
|
* Dialog will not be centered vertically since we need the modal to "stay in place"
|
|
20
21
|
* when changing tabs. Since tabs content's height is not the same between the data
|
|
@@ -98,6 +99,12 @@ var Routes = function Routes(_ref) {
|
|
|
98
99
|
accounts: accountsAndTriggers
|
|
99
100
|
});
|
|
100
101
|
}
|
|
102
|
+
}), /*#__PURE__*/React.createElement(Route, {
|
|
103
|
+
path: "".concat(konnectorRoot, "/viewer/:accountId/:folderToSaveId/:fileIndex"),
|
|
104
|
+
exact: true,
|
|
105
|
+
render: function render(routeComponentProps) {
|
|
106
|
+
return /*#__PURE__*/React.createElement(ViewerModal, routeComponentProps);
|
|
107
|
+
}
|
|
101
108
|
}), /*#__PURE__*/React.createElement(Route, {
|
|
102
109
|
path: "".concat(konnectorRoot, "/new"),
|
|
103
110
|
exact: true,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import React, {
|
|
2
|
+
import React, { useContext, useState } from 'react';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import get from 'lodash/get';
|
|
6
|
-
import sortBy from 'lodash/sortBy';
|
|
7
|
-
import uniq from 'lodash/uniq';
|
|
8
5
|
import keyBy from 'lodash/keyBy';
|
|
9
6
|
import 'leaflet/dist/leaflet.css';
|
|
10
7
|
import Skeleton from '@material-ui/lab/Skeleton';
|
|
@@ -12,13 +9,11 @@ import List from '@material-ui/core/List';
|
|
|
12
9
|
import ListItem from '@material-ui/core/ListItem';
|
|
13
10
|
import ListItemIcon from '@material-ui/core/ListItemIcon';
|
|
14
11
|
import Slide from '@material-ui/core/Slide';
|
|
15
|
-
import Modal from '@material-ui/core/Modal';
|
|
16
12
|
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
13
|
+
import { RealTimeQueries } from 'cozy-client';
|
|
17
14
|
import palette from 'cozy-ui/transpiled/react/palette';
|
|
18
15
|
import { Media, Bd, Img } from 'cozy-ui/transpiled/react/Media';
|
|
19
16
|
import Circle from 'cozy-ui/transpiled/react/Circle';
|
|
20
|
-
import Portal from 'cozy-ui/transpiled/react/Portal';
|
|
21
|
-
import Viewer from 'cozy-ui/transpiled/react/Viewer';
|
|
22
17
|
import Card from 'cozy-ui/transpiled/react/Card';
|
|
23
18
|
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
24
19
|
import FileIcon from 'cozy-ui/transpiled/react/Icons/File';
|
|
@@ -26,8 +21,9 @@ import Typography from 'cozy-ui/transpiled/react/Typography';
|
|
|
26
21
|
import { useI18n } from 'cozy-ui/transpiled/react/I18n';
|
|
27
22
|
import AppLinkCard, { AppLinkButton } from '../components/cards/AppLinkCard';
|
|
28
23
|
import appLinksProps from '../components/KonnectorConfiguration/DataTab/appLinksProps';
|
|
29
|
-
import
|
|
24
|
+
import { MountPointContext } from '../components/MountPointContext';
|
|
30
25
|
import { getFileIcon } from './mime-utils';
|
|
26
|
+
import { useDataCardFiles } from './useDataCardFiles';
|
|
31
27
|
|
|
32
28
|
var LoadingFileListItem = function LoadingFileListItem(_ref) {
|
|
33
29
|
var divider = _ref.divider;
|
|
@@ -85,10 +81,14 @@ var FileCard = function FileCard(_ref4) {
|
|
|
85
81
|
var files = _ref4.files,
|
|
86
82
|
loading = _ref4.loading,
|
|
87
83
|
konnector = _ref4.konnector,
|
|
88
|
-
trigger = _ref4.trigger
|
|
84
|
+
trigger = _ref4.trigger,
|
|
85
|
+
accountId = _ref4.accountId;
|
|
89
86
|
|
|
90
87
|
var _useI18n2 = useI18n(),
|
|
91
|
-
t = _useI18n2.t;
|
|
88
|
+
t = _useI18n2.t;
|
|
89
|
+
|
|
90
|
+
var _useContext = useContext(MountPointContext),
|
|
91
|
+
pushHistory = _useContext.pushHistory; // Remember files that were there initially so that we do not
|
|
92
92
|
// animate their ListItem.
|
|
93
93
|
// Only files coming from realtime and that are added to files
|
|
94
94
|
// while the component is mounted will be animated.
|
|
@@ -102,19 +102,6 @@ var FileCard = function FileCard(_ref4) {
|
|
|
102
102
|
_useState2 = _slicedToArray(_useState, 1),
|
|
103
103
|
initialFilesById = _useState2[0];
|
|
104
104
|
|
|
105
|
-
var _useState3 = useState(null),
|
|
106
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
107
|
-
viewerIndex = _useState4[0],
|
|
108
|
-
setViewerIndex = _useState4[1];
|
|
109
|
-
|
|
110
|
-
var handleCloseViewer = function handleCloseViewer() {
|
|
111
|
-
return setViewerIndex(null);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
var handleFileChange = function handleFileChange(file, newIndex) {
|
|
115
|
-
return setViewerIndex(newIndex);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
105
|
return /*#__PURE__*/React.createElement(Card, {
|
|
119
106
|
className: "u-ph-0 u-pb-0 u-ov-hidden"
|
|
120
107
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -149,21 +136,12 @@ var FileCard = function FileCard(_ref4) {
|
|
|
149
136
|
key: file._id
|
|
150
137
|
}, /*#__PURE__*/React.createElement(FileListItem, {
|
|
151
138
|
onClick: function onClick() {
|
|
152
|
-
|
|
139
|
+
pushHistory("/viewer/".concat(accountId, "/").concat(get(trigger, 'message.folder_to_save'), "/").concat(i));
|
|
153
140
|
},
|
|
154
141
|
file: file,
|
|
155
142
|
divider: i !== files.length - 1
|
|
156
143
|
}));
|
|
157
|
-
})),
|
|
158
|
-
into: "body"
|
|
159
|
-
}, /*#__PURE__*/React.createElement(Modal, {
|
|
160
|
-
open: true
|
|
161
|
-
}, /*#__PURE__*/React.createElement(Viewer, {
|
|
162
|
-
files: files,
|
|
163
|
-
currentIndex: viewerIndex,
|
|
164
|
-
onCloseRequest: handleCloseViewer,
|
|
165
|
-
onChangeRequest: handleFileChange
|
|
166
|
-
}))), /*#__PURE__*/React.createElement("div", {
|
|
144
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
167
145
|
className: "u-ta-right u-mv-half u-mh-1"
|
|
168
146
|
}, /*#__PURE__*/React.createElement(AppLinkButton, {
|
|
169
147
|
slug: "drive",
|
|
@@ -171,63 +149,27 @@ var FileCard = function FileCard(_ref4) {
|
|
|
171
149
|
})));
|
|
172
150
|
};
|
|
173
151
|
|
|
174
|
-
var
|
|
175
|
-
var
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
dir_id: trigger.message.folder_to_save,
|
|
179
|
-
trashed: false
|
|
180
|
-
}).indexFields(['dir_id', 'cozyMetadata.createdAt']).sortBy([{
|
|
181
|
-
dir_id: 'desc'
|
|
182
|
-
}, {
|
|
183
|
-
'cozyMetadata.createdAt': 'desc'
|
|
184
|
-
}]).limitBy(5),
|
|
185
|
-
as: "fileDataCard_io.cozy.files/".concat(trigger.message.folder_to_save, "/io.cozy.files"),
|
|
186
|
-
fetchPolicy: CozyClient.fetchPolicies.olderThan(30 * 1000)
|
|
187
|
-
};
|
|
188
|
-
};
|
|
152
|
+
var FileDataCard = function FileDataCard(_ref5) {
|
|
153
|
+
var accountId = _ref5.accountId,
|
|
154
|
+
konnector = _ref5.konnector,
|
|
155
|
+
trigger = _ref5.trigger;
|
|
189
156
|
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
query: Q('io.cozy.files').where({
|
|
194
|
-
'cozyMetadata.sourceAccount': accountId,
|
|
195
|
-
trashed: false
|
|
196
|
-
}).indexFields(['cozyMetadata.sourceAccount', 'cozyMetadata.createdAt']).sortBy([{
|
|
197
|
-
'cozyMetadata.sourceAccount': 'desc'
|
|
198
|
-
}, {
|
|
199
|
-
'cozyMetadata.createdAt': 'desc'
|
|
200
|
-
}]).limitBy(5),
|
|
201
|
-
as: "fileDataCard_io.cozy.accounts/".concat(accountId, "/io.cozy.files"),
|
|
202
|
-
fetchPolicy: CozyClient.fetchPolicies.olderThan(30 * 1000)
|
|
203
|
-
};
|
|
204
|
-
};
|
|
157
|
+
var _useDataCardFiles = useDataCardFiles(accountId, trigger.message.folder_to_save),
|
|
158
|
+
data = _useDataCardFiles.data,
|
|
159
|
+
fetchStatus = _useDataCardFiles.fetchStatus;
|
|
205
160
|
|
|
206
|
-
var
|
|
207
|
-
var
|
|
208
|
-
sourceAccountFiles = _ref7.sourceAccountFiles,
|
|
209
|
-
konnector = _ref7.konnector,
|
|
210
|
-
trigger = _ref7.trigger;
|
|
211
|
-
var files1 = folderToSaveFiles.data;
|
|
212
|
-
var files2 = sourceAccountFiles.data;
|
|
213
|
-
var noFiles = hasQueryBeenLoaded(folderToSaveFiles) && files1.length === 0 && hasQueryBeenLoaded(sourceAccountFiles) && files2.length === 0;
|
|
214
|
-
var isLoading = isQueryLoading(folderToSaveFiles) || isQueryLoading(sourceAccountFiles);
|
|
215
|
-
var files = useMemo(function () {
|
|
216
|
-
return sortBy(uniq([].concat(_toConsumableArray(files1), _toConsumableArray(files2)), function (x) {
|
|
217
|
-
return x._id;
|
|
218
|
-
}), function (x) {
|
|
219
|
-
return get(x, 'cozyMetadata.createdAt');
|
|
220
|
-
}).reverse().slice(0, 5);
|
|
221
|
-
}, [files1, files2]);
|
|
161
|
+
var isLoading = fetchStatus === 'loading';
|
|
162
|
+
var noFiles = fetchStatus === 'empty' || fetchStatus === 'failed';
|
|
222
163
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RealTimeQueries, {
|
|
223
164
|
doctype: "io.cozy.files"
|
|
224
165
|
}), noFiles ? /*#__PURE__*/React.createElement(AppLinkCard, appLinksProps.drive({
|
|
225
166
|
trigger: trigger
|
|
226
167
|
})) : /*#__PURE__*/React.createElement(FileCard, {
|
|
227
|
-
files:
|
|
168
|
+
files: data,
|
|
228
169
|
loading: isLoading,
|
|
229
170
|
konnector: konnector,
|
|
230
|
-
trigger: trigger
|
|
171
|
+
trigger: trigger,
|
|
172
|
+
accountId: accountId
|
|
231
173
|
}));
|
|
232
174
|
};
|
|
233
175
|
|
|
@@ -236,11 +178,4 @@ FileDataCard.propTypes = {
|
|
|
236
178
|
accountId: PropTypes.string.isRequired,
|
|
237
179
|
trigger: PropTypes.object.isRequired
|
|
238
180
|
};
|
|
239
|
-
export default
|
|
240
|
-
folderToSaveFiles: function folderToSaveFiles(props) {
|
|
241
|
-
return makeFolderToSaveQueryFromProps(props);
|
|
242
|
-
},
|
|
243
|
-
sourceAccountFiles: function sourceAccountFiles(props) {
|
|
244
|
-
return makeSourceAccountQueryFromProps(props);
|
|
245
|
-
}
|
|
246
|
-
})(FileDataCard);
|
|
181
|
+
export default FileDataCard;
|