cozy-harvest-lib 8.0.0 → 8.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/components/AccountModal.js +5 -4
  3. package/dist/components/AccountModal.spec.js +4 -1
  4. package/dist/components/AccountsListModal.js +3 -2
  5. package/dist/components/EditAccountModal.js +3 -3
  6. package/dist/components/HarvestModalRoot.js +3 -3
  7. package/dist/components/KonnectorConfiguration/ConfigurationTab/index.js +2 -2
  8. package/dist/components/MountPointContext.js +24 -10
  9. package/dist/components/MountPointContext.spec.js +17 -17
  10. package/dist/components/NewAccountModal.js +3 -3
  11. package/dist/components/NewAccountModal.spec.js +6 -6
  12. package/dist/components/RedirectToAccountFormButton.js +3 -3
  13. package/dist/components/RedirectToAccountFormButton.spec.js +4 -4
  14. package/dist/components/cards/AppLinkCard.js +2 -1
  15. package/dist/models/ConnectionFlow.js +63 -40
  16. package/dist/models/ConnectionFlow.spec.js +43 -4
  17. package/dist/models/konnector/KonnectorJobWatcher.js +6 -0
  18. package/package.json +2 -2
  19. package/src/components/AccountModal.jsx +5 -4
  20. package/src/components/AccountModal.spec.jsx +7 -2
  21. package/src/components/AccountsListModal.jsx +2 -2
  22. package/src/components/EditAccountModal.jsx +3 -3
  23. package/src/components/HarvestModalRoot.jsx +3 -3
  24. package/src/components/KonnectorConfiguration/ConfigurationTab/index.jsx +2 -2
  25. package/src/components/MountPointContext.jsx +29 -12
  26. package/src/components/MountPointContext.spec.jsx +17 -17
  27. package/src/components/NewAccountModal.jsx +3 -3
  28. package/src/components/NewAccountModal.spec.jsx +6 -6
  29. package/src/components/RedirectToAccountFormButton.jsx +3 -3
  30. package/src/components/RedirectToAccountFormButton.spec.jsx +4 -4
  31. package/src/components/cards/AppLinkCard.jsx +2 -1
  32. package/src/models/ConnectionFlow.js +23 -5
  33. package/src/models/ConnectionFlow.spec.js +30 -5
  34. package/src/models/konnector/KonnectorJobWatcher.js +5 -0
  35. package/test/fixtures.js +17 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,46 @@
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.2.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.1.1...cozy-harvest-lib@8.2.0) (2022-04-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * Fix back navigation ([89283ab](https://github.com/cozy/cozy-libs/commit/89283ab1beb06fa15625a7f108abbddf37216397))
12
+
13
+
14
+
15
+
16
+
17
+ ## [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)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **cozy-harvest-lib:** Correctly handle onClick on AppLinkCard ([c9068c5](https://github.com/cozy/cozy-libs/commit/c9068c53a1ec2e1f6b9b7636f6b25aadec69900f))
23
+ * **cozy-harvest-lib:** Disable AppLink button until fallback is resolved ([bedc90d](https://github.com/cozy/cozy-libs/commit/bedc90d80c899bb93a2be70d6963d62742fb600b))
24
+
25
+
26
+
27
+
28
+
29
+ # [8.1.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.0.0...cozy-harvest-lib@8.1.0) (2022-04-08)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * Remove unused restoreAllMocks ([6dd376a](https://github.com/cozy/cozy-libs/commit/6dd376a2a7f4393a9446375383d6b77510f87d95))
35
+
36
+
37
+ ### Features
38
+
39
+ * Do not mark a job as succeeded on login success ([39e6d01](https://github.com/cozy/cozy-libs/commit/39e6d0161839a6d00ef0dcf24eb6aa0ddeff5f78))
40
+ * Watch job changes when the trigger is already running ([ca01663](https://github.com/cozy/cozy-libs/commit/ca01663eb41bbbcfed5d1f146c9cd68956faa9df))
41
+
42
+
43
+
44
+
45
+
6
46
  # [8.0.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@7.3.7...cozy-harvest-lib@8.0.0) (2022-04-04)
7
47
 
8
48
 
@@ -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 { withMountPointPushHistory } from './MountPointContext';
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 pushHistory('/new');
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
- pushHistory: PropTypes.func.isRequired,
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, withMountPointPushHistory, withBreakpoints())(AccountModal);
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 pushHistory("/accounts/".concat(option.account._id));
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 { withMountPointPushHistory } from './MountPointContext';
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.pushHistory("/accounts/".concat(account._id));
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, withMountPointPushHistory, withTracker)(EditAccountModal);
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
- pushHistory = _useContext.pushHistory;
11
+ replaceHistory = _useContext.replaceHistory;
12
12
 
13
13
  if (accounts.length === 0) {
14
- pushHistory('/new');
14
+ replaceHistory('/new');
15
15
  return null;
16
16
  } else if (accounts.length === 1) {
17
- pushHistory("/accounts/".concat(accounts[0].account._id));
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
- pushHistory = _useContext.pushHistory;
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 pushHistory("/accounts/".concat(account._id, "/edit"));
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: "pushHistory",
38
- value: function pushHistory(route) {
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.push("/".concat(segments.join('/')));
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 withMountPointPushHistory = function withMountPointPushHistory(BaseComponent) {
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 = "withMountPointPushHistory(".concat(BaseComponent.displayName || BaseComponent.name, ")");
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, withMountPointPushHistory };
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
- push: jest.fn()
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().pushHistory('/one');
17
- expect(historyMock.push).toHaveBeenCalledWith('/root/one');
18
- component.instance().pushHistory('/one/two');
19
- expect(historyMock.push).toHaveBeenCalledWith('/root/one/two');
20
- component.instance().pushHistory('no/slash');
21
- expect(historyMock.push).toHaveBeenCalledWith('/root/no/slash');
22
- component.instance().pushHistory('too/many///slashes');
23
- expect(historyMock.push).toHaveBeenCalledWith('/root/too/many/slashes');
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().pushHistory('/one');
31
- expect(historyMock.push).toHaveBeenCalledWith('/root/one');
32
- component.instance().pushHistory('no/slash');
33
- expect(historyMock.push).toHaveBeenCalledWith('/root/no/slash');
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().pushHistory('/one');
41
- expect(historyMock.push).toHaveBeenCalledWith('/base/route/one');
42
- component.instance().pushHistory('/one/two');
43
- expect(historyMock.push).toHaveBeenCalledWith('/base/route/one/two');
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
- pushHistory = _useContext.pushHistory;
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
- pushHistory(path);
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
- pushHistory(path);
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 pushHistory = jest.fn();
30
+ var replaceHistory = jest.fn();
31
31
  var mountPointContextValue = {
32
- pushHistory: pushHistory
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(pushHistory).toHaveBeenCalledWith('/accounts/accountNumber/success');
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(pushHistory).toHaveBeenCalledWith('/accounts/accountNumberClient');
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(pushHistory).toHaveBeenCalledWith('/accounts/accountNumber/success');
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(pushHistory).toHaveBeenCalledWith('/accounts/accountNumberClient');
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
- pushHistory = _useContext.pushHistory;
16
+ replaceHistory = _useContext.replaceHistory;
17
17
 
18
18
  var handleClick = useCallback(function () {
19
- pushHistory("/accounts/".concat(accountId, "/edit?reconnect"));
20
- }, [accountId, pushHistory]);
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 pushHistory to navigate', function () {
8
- var pushHistory = jest.fn();
7
+ it('should use replaceHistory to navigate', function () {
8
+ var replaceHistory = jest.fn();
9
9
  var mountPointContextValue = {
10
- pushHistory: pushHistory
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(pushHistory).toHaveBeenCalledWith('/accounts/account-id-1337/edit?reconnect');
23
+ expect(replaceHistory).toHaveBeenCalledWith('/accounts/account-id-1337/edit?reconnect');
24
24
  });
25
25
  });
@@ -41,7 +41,8 @@ export var AppLinkButton = function AppLinkButton(_ref) {
41
41
  var onClick = _ref2.onClick,
42
42
  href = _ref2.href;
43
43
  return /*#__PURE__*/React.createElement(ButtonLink, {
44
- onClick: fetchStatus !== 'loaded' ? onClick : null,
44
+ disabled: fetchStatus !== 'loaded',
45
+ onClick: fetchStatus === 'loaded' ? onClick : null,
45
46
  href: href,
46
47
  icon: isInstalled ? /*#__PURE__*/React.createElement(AppIcon, {
47
48
  app: slug,
@@ -184,6 +184,7 @@ export var ConnectionFlow = /*#__PURE__*/function () {
184
184
  this.realtime = new Realtime({
185
185
  client: client
186
186
  });
187
+ this.watchCurrentJobIfTriggerIsAlreadyRunning();
187
188
  }
188
189
 
189
190
  _createClass(ConnectionFlow, [{
@@ -500,7 +501,8 @@ export var ConnectionFlow = /*#__PURE__*/function () {
500
501
  }, {
501
502
  key: "handleLoginSuccess",
502
503
  value: function handleLoginSuccess() {
503
- this.jobWatcher.handleSuccess();
504
+ this.jobWatcher.handleLoginSuccess();
505
+ this.triggerEvent(LOGIN_SUCCESS_EVENT);
504
506
  }
505
507
  }, {
506
508
  key: "handleLoginSuccessHandled",
@@ -848,16 +850,11 @@ export var ConnectionFlow = /*#__PURE__*/function () {
848
850
  key: "launch",
849
851
  value: function () {
850
852
  var _launch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
851
- var _this2 = this;
852
-
853
853
  var _ref5,
854
854
  _ref5$autoSuccessTime,
855
855
  autoSuccessTimer,
856
856
  computedAutoSuccessTimer,
857
857
  launcher,
858
- _iterator2,
859
- _step2,
860
- _loop,
861
858
  _args11 = arguments;
862
859
 
863
860
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
@@ -908,42 +905,11 @@ export var ConnectionFlow = /*#__PURE__*/function () {
908
905
  }
909
906
  }
910
907
 
911
- this.realtime.subscribe('updated', JOBS_DOCTYPE, this.job._id, this.handleJobUpdated.bind(this));
912
- this.jobWatcher = watchKonnectorJob(this.client, this.job, {
908
+ this.watchJob({
913
909
  autoSuccessTimer: computedAutoSuccessTimer
914
910
  });
915
- logger.info("ConnectionFlow: Subscribed to ".concat(JOBS_DOCTYPE, ":").concat(this.job._id));
916
- _iterator2 = _createForOfIteratorHelper(JOB_EVENTS);
917
-
918
- try {
919
- _loop = function _loop() {
920
- var ev = _step2.value;
921
-
922
- _this2.jobWatcher.on(ev, function () {
923
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
924
- args[_key2] = arguments[_key2];
925
- }
926
-
927
- return _this2.triggerEvent.apply(_this2, [ev].concat(args));
928
- });
929
- };
930
-
931
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
932
- _loop();
933
- }
934
- } catch (err) {
935
- _iterator2.e(err);
936
- } finally {
937
- _iterator2.f();
938
- }
939
-
940
- this.unsubscribeAllRealtime = function () {
941
- _this2.jobWatcher.unsubscribeAll();
942
-
943
- _this2.realtime.unsubscribeAll();
944
- };
945
911
 
946
- case 19:
912
+ case 14:
947
913
  case "end":
948
914
  return _context11.stop();
949
915
  }
@@ -957,6 +923,63 @@ export var ConnectionFlow = /*#__PURE__*/function () {
957
923
 
958
924
  return launch;
959
925
  }()
926
+ /**
927
+ * If the trigger we display is already running, subscribe to the associated job
928
+ */
929
+
930
+ }, {
931
+ key: "watchCurrentJobIfTriggerIsAlreadyRunning",
932
+ value: function watchCurrentJobIfTriggerIsAlreadyRunning() {
933
+ if (get(this, 'trigger.current_state.status') === 'running') {
934
+ this.job = {
935
+ _id: get(this, 'trigger.current_state.last_executed_job_id')
936
+ };
937
+ this.watchJob();
938
+ }
939
+ }
940
+ }, {
941
+ key: "watchJob",
942
+ value: function watchJob() {
943
+ var _this2 = this;
944
+
945
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
946
+ autoSuccessTimer: false
947
+ };
948
+ this.realtime.subscribe('updated', JOBS_DOCTYPE, this.job._id, this.handleJobUpdated.bind(this));
949
+ this.jobWatcher = watchKonnectorJob(this.client, this.job, options);
950
+ logger.info("ConnectionFlow: Subscribed to ".concat(JOBS_DOCTYPE, ":").concat(this.job._id));
951
+
952
+ var _iterator2 = _createForOfIteratorHelper(JOB_EVENTS),
953
+ _step2;
954
+
955
+ try {
956
+ var _loop = function _loop() {
957
+ var ev = _step2.value;
958
+
959
+ _this2.jobWatcher.on(ev, function () {
960
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
961
+ args[_key2] = arguments[_key2];
962
+ }
963
+
964
+ return _this2.triggerEvent.apply(_this2, [ev].concat(args));
965
+ });
966
+ };
967
+
968
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
969
+ _loop();
970
+ }
971
+ } catch (err) {
972
+ _iterator2.e(err);
973
+ } finally {
974
+ _iterator2.f();
975
+ }
976
+
977
+ this.unsubscribeAllRealtime = function () {
978
+ _this2.jobWatcher.unsubscribeAll();
979
+
980
+ _this2.realtime.unsubscribeAll();
981
+ };
982
+ }
960
983
  }, {
961
984
  key: "unwatch",
962
985
  value: function unwatch() {
@@ -985,7 +1008,7 @@ export var ConnectionFlow = /*#__PURE__*/function () {
985
1008
  accountError = _this$state.accountError;
986
1009
  var triggerError = triggersModel.getKonnectorJobError(trigger);
987
1010
  return {
988
- running: ![ERRORED, IDLE, SUCCESS].includes(status),
1011
+ running: get(trigger, 'current_state.status') === 'running' || ![ERRORED, IDLE, SUCCESS].includes(status),
989
1012
  twoFARunning: status === RUNNING_TWOFA,
990
1013
  twoFARetry: status == TWO_FA_MISMATCH,
991
1014
  triggerError: triggerError,