orc-shared 1.7.0-dev.6 → 1.7.0-dev.7

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.setRoutingPerformed = exports.setNewScopeAndModuleName = exports.setModulesStructure = exports.setModuleAsVisible = exports.initializeFirstModuleScope = exports.SET_ROUTING_PERFORMED = exports.SET_NEW_SCOPE_AND_MODULE_NAME = exports.SET_MODULE_AS_VISIBLE = exports.SET_MODULES_STRUCTURE = exports.INITIALIZE_FIRST_MODULE_SCOPE = void 0;
4
+ exports.setRoutingPerformed = exports.setModulesStructure = exports.setModuleAsVisible = exports.initializeFirstModuleScope = exports.SET_ROUTING_PERFORMED = exports.SET_MODULE_AS_VISIBLE = exports.SET_MODULES_STRUCTURE = exports.INITIALIZE_FIRST_MODULE_SCOPE = void 0;
5
5
  (function () {
6
6
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
7
7
  enterModule && enterModule(module);
@@ -37,16 +37,6 @@ var initializeFirstModuleScope = exports.initializeFirstModuleScope = function i
37
37
  payload: scope
38
38
  };
39
39
  };
40
- var SET_NEW_SCOPE_AND_MODULE_NAME = exports.SET_NEW_SCOPE_AND_MODULE_NAME = "SET_NEW_SCOPE_AND_MODULE_NAME";
41
- var setNewScopeAndModuleName = exports.setNewScopeAndModuleName = function setNewScopeAndModuleName(scope, moduleName) {
42
- return {
43
- type: SET_NEW_SCOPE_AND_MODULE_NAME,
44
- payload: {
45
- scope: scope,
46
- moduleName: moduleName
47
- }
48
- };
49
- };
50
40
  var SET_ROUTING_PERFORMED = exports.SET_ROUTING_PERFORMED = "SET_ROUTING_PERFORMED";
51
41
  var setRoutingPerformed = exports.setRoutingPerformed = function setRoutingPerformed() {
52
42
  return {
@@ -65,8 +55,6 @@ var setRoutingPerformed = exports.setRoutingPerformed = function setRoutingPerfo
65
55
  reactHotLoader.register(setModuleAsVisible, "setModuleAsVisible", "/home/vsts/work/1/s/src/actions/modules.js");
66
56
  reactHotLoader.register(INITIALIZE_FIRST_MODULE_SCOPE, "INITIALIZE_FIRST_MODULE_SCOPE", "/home/vsts/work/1/s/src/actions/modules.js");
67
57
  reactHotLoader.register(initializeFirstModuleScope, "initializeFirstModuleScope", "/home/vsts/work/1/s/src/actions/modules.js");
68
- reactHotLoader.register(SET_NEW_SCOPE_AND_MODULE_NAME, "SET_NEW_SCOPE_AND_MODULE_NAME", "/home/vsts/work/1/s/src/actions/modules.js");
69
- reactHotLoader.register(setNewScopeAndModuleName, "setNewScopeAndModuleName", "/home/vsts/work/1/s/src/actions/modules.js");
70
58
  reactHotLoader.register(SET_ROUTING_PERFORMED, "SET_ROUTING_PERFORMED", "/home/vsts/work/1/s/src/actions/modules.js");
71
59
  reactHotLoader.register(setRoutingPerformed, "setRoutingPerformed", "/home/vsts/work/1/s/src/actions/modules.js");
72
60
  })();
@@ -87,8 +75,6 @@ var setRoutingPerformed = exports.setRoutingPerformed = function setRoutingPerfo
87
75
  reactHotLoader.register(setModuleAsVisible, "setModuleAsVisible", "/home/vsts/work/1/s/src/actions/modules.js");
88
76
  reactHotLoader.register(INITIALIZE_FIRST_MODULE_SCOPE, "INITIALIZE_FIRST_MODULE_SCOPE", "/home/vsts/work/1/s/src/actions/modules.js");
89
77
  reactHotLoader.register(initializeFirstModuleScope, "initializeFirstModuleScope", "/home/vsts/work/1/s/src/actions/modules.js");
90
- reactHotLoader.register(SET_NEW_SCOPE_AND_MODULE_NAME, "SET_NEW_SCOPE_AND_MODULE_NAME", "/home/vsts/work/1/s/src/actions/modules.js");
91
- reactHotLoader.register(setNewScopeAndModuleName, "setNewScopeAndModuleName", "/home/vsts/work/1/s/src/actions/modules.js");
92
78
  reactHotLoader.register(SET_ROUTING_PERFORMED, "SET_ROUTING_PERFORMED", "/home/vsts/work/1/s/src/actions/modules.js");
93
79
  reactHotLoader.register(setRoutingPerformed, "setRoutingPerformed", "/home/vsts/work/1/s/src/actions/modules.js");
94
80
  })();
@@ -68,12 +68,13 @@ var getDefaultScope = exports.getDefaultScope = function getDefaultScope(module)
68
68
  });
69
69
  };
70
70
  var APPLICATION_SCOPE_HAS_CHANGED = exports.APPLICATION_SCOPE_HAS_CHANGED = "APPLICATION_SCOPE_HAS_CHANGED";
71
- var applicationScopeHasChanged = exports.applicationScopeHasChanged = function applicationScopeHasChanged(previousScope, newScope) {
71
+ var applicationScopeHasChanged = exports.applicationScopeHasChanged = function applicationScopeHasChanged(previousScope, newScope, moduleName) {
72
72
  return {
73
73
  type: APPLICATION_SCOPE_HAS_CHANGED,
74
74
  payload: {
75
75
  previousScope: previousScope,
76
- newScope: newScope
76
+ newScope: newScope,
77
+ moduleName: moduleName
77
78
  }
78
79
  };
79
80
  };
@@ -26,6 +26,7 @@ var _metadata = _interopRequireDefault(require("./reducers/metadata"));
26
26
  var _requestStates = _interopRequireDefault(require("./reducers/requestStates"));
27
27
  var _tasks = _interopRequireDefault(require("./reducers/tasks"));
28
28
  var _globalErrorMessages = _interopRequireDefault(require("./reducers/globalErrorMessages"));
29
+ var _scopeRouteState = _interopRequireDefault(require("./reducers/scopeRouteState"));
29
30
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
30
31
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
31
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -90,7 +91,8 @@ var buildStore = function buildStore(reducers, devOptions) {
90
91
  metadata: _metadata.default,
91
92
  requestStates: _requestStates.default,
92
93
  tasks: _tasks.default,
93
- globalErrorMessages: _globalErrorMessages.default
94
+ globalErrorMessages: _globalErrorMessages.default,
95
+ scopeRouteState: _scopeRouteState.default
94
96
  }));
95
97
  };
96
98
  var rootReducer = buildReducer(reducers);
@@ -10,7 +10,6 @@ var _scopes = require("../../actions/scopes");
10
10
  var _useScopeData3 = _interopRequireDefault(require("./useScopeData"));
11
11
  var _view = require("../../selectors/view");
12
12
  var _constants = require("../../constants");
13
- var _modules = require("../../actions/modules");
14
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
16
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -77,8 +76,7 @@ var useApplicationScopeChanger = function useApplicationScopeChanger(closingTabH
77
76
  var moduleName = (0, _useSelectorAndUnwrap.default)(_navigation.selectCurrentModuleName);
78
77
  return function (previousScope, newScope) {
79
78
  ExecuteClosingTabHandlerActions(closingTabHandlerActions).then(function () {
80
- dispatch((0, _modules.setNewScopeAndModuleName)(newScope, moduleName));
81
- dispatch((0, _scopes.applicationScopeHasChanged)(previousScope, newScope));
79
+ dispatch((0, _scopes.applicationScopeHasChanged)(previousScope, newScope, moduleName));
82
80
  });
83
81
  };
84
82
  };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _reactRedux = require("react-redux");
6
+ var _scopeRouteState = require("../selectors/scopeRouteState");
7
+ var _useLoader = _interopRequireDefault(require("./useLoader"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ (function () {
10
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
11
+ enterModule && enterModule(module);
12
+ })();
13
+ (function () {
14
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
15
+ enterModule && enterModule(module);
16
+ })();
17
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
18
+ return a;
19
+ };
20
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
21
+ return a;
22
+ };
23
+ // look at scopeRouteState.js for documentation
24
+
25
+ var useScopeGuardLoader = function useScopeGuardLoader(actions, cutoutSelector) {
26
+ var changeInProgress = (0, _reactRedux.useSelector)(_scopeRouteState.getScopeChangeInProgress);
27
+ var cutoutSelectorGuard = function cutoutSelectorGuard() {
28
+ if (changeInProgress) {
29
+ return true;
30
+ }
31
+ if (cutoutSelector) {
32
+ for (var _len = arguments.length, selArgs = new Array(_len), _key = 0; _key < _len; _key++) {
33
+ selArgs[_key] = arguments[_key];
34
+ }
35
+ return cutoutSelector.apply(null, selArgs);
36
+ }
37
+ return true;
38
+ };
39
+ (0, _useLoader.default)(actions, cutoutSelectorGuard);
40
+ };
41
+ __signature__(useScopeGuardLoader, "useSelector{changeInProgress}\nuseLoader{}", function () {
42
+ return [_reactRedux.useSelector, _useLoader.default];
43
+ });
44
+ __signature__(useScopeGuardLoader, "useSelector{changeInProgress}\nuseLoader{}", function () {
45
+ return [_reactRedux.useSelector, _useLoader.default];
46
+ });
47
+ var _default = useScopeGuardLoader;
48
+ var _default2 = _default;
49
+ var _default3 = exports.default = _default2;
50
+ ;
51
+ (function () {
52
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
53
+ if (!reactHotLoader) {
54
+ return;
55
+ }
56
+ reactHotLoader.register(useScopeGuardLoader, "useScopeGuardLoader", "/home/vsts/work/1/s/src/hooks/useScopeGuardLoader.js");
57
+ reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/hooks/useScopeGuardLoader.js");
58
+ })();
59
+ ;
60
+ (function () {
61
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
62
+ leaveModule && leaveModule(module);
63
+ })();
64
+ ;
65
+ (function () {
66
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
67
+ if (!reactHotLoader) {
68
+ return;
69
+ }
70
+ reactHotLoader.register(useScopeGuardLoader, "useScopeGuardLoader", "/home/vsts/work/1/s/src/hooks/useScopeGuardLoader.js");
71
+ reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/hooks/useScopeGuardLoader.js");
72
+ })();
73
+ ;
74
+ (function () {
75
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
76
+ leaveModule && leaveModule(module);
77
+ })();
@@ -5,6 +5,7 @@ exports.default = void 0;
5
5
  var _immutable = _interopRequireDefault(require("immutable"));
6
6
  var _modules = require("../actions/modules");
7
7
  var _constants = require("./../constants");
8
+ var _scopes = require("../actions/scopes");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  (function () {
10
11
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
@@ -73,15 +74,15 @@ var viewStateReducer = function viewStateReducer(state, action) {
73
74
  visibleModules.push(action.payload);
74
75
  return state.set("visibleModules", _immutable.default.fromJS(visibleModules));
75
76
  }
76
- case _modules.SET_NEW_SCOPE_AND_MODULE_NAME:
77
+ case _scopes.APPLICATION_SCOPE_HAS_CHANGED:
77
78
  {
78
79
  var lastScopeAndModuleSelection = state.get("lastScopeAndModuleSelection").toJS();
79
- if (action.payload.scope !== lastScopeAndModuleSelection.scope) {
80
+ if (action.payload.newScope !== lastScopeAndModuleSelection.scope) {
80
81
  state = state.set("visibleModules", _immutable.default.fromJS([]));
81
82
  }
82
83
  return state.set("lastScopeAndModuleSelection", _immutable.default.fromJS({
83
84
  moduleName: action.payload.moduleName,
84
- scope: action.payload.scope,
85
+ scope: action.payload.newScope,
85
86
  routingPerformed: false
86
87
  }));
87
88
  }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _immutable = _interopRequireDefault(require("immutable"));
6
+ var _navigation = require("../actions/navigation");
7
+ var _scopes = require("../actions/scopes");
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ (function () {
10
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
11
+ enterModule && enterModule(module);
12
+ })();
13
+ (function () {
14
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
15
+ enterModule && enterModule(module);
16
+ })();
17
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
18
+ return a;
19
+ };
20
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
21
+ return a;
22
+ };
23
+ var initialState = _immutable.default.fromJS({
24
+ scopeChangeInProgress: false
25
+ });
26
+
27
+ /*
28
+ This reducer and its associated hook is used to prevent a request from being sent out while the application's scope is changing.
29
+ Basically the reducer responds to an action, set a flag to true and then set it to false once another action is triggered (route change).
30
+
31
+ This is a pretty hackish way to ensure that the correct requests are being executed (references #74924, #74764) however we know of no other way to achieve the desired result.
32
+ * */
33
+
34
+ var viewStateReducer = function viewStateReducer(state, action) {
35
+ if (state === void 0) {
36
+ state = initialState;
37
+ }
38
+ switch (action.type) {
39
+ case _scopes.APPLICATION_SCOPE_HAS_CHANGED:
40
+ {
41
+ return state.set("scopeChangeInProgress", action.payload.newScope !== action.payload.previousScope);
42
+ }
43
+ case _navigation.SET_ROUTE:
44
+ {
45
+ return state.set("scopeChangeInProgress", false);
46
+ }
47
+ default:
48
+ return state;
49
+ }
50
+ };
51
+ var _default = viewStateReducer;
52
+ var _default2 = _default;
53
+ var _default3 = exports.default = _default2;
54
+ ;
55
+ (function () {
56
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
57
+ if (!reactHotLoader) {
58
+ return;
59
+ }
60
+ reactHotLoader.register(initialState, "initialState", "/home/vsts/work/1/s/src/reducers/scopeRouteState.js");
61
+ reactHotLoader.register(viewStateReducer, "viewStateReducer", "/home/vsts/work/1/s/src/reducers/scopeRouteState.js");
62
+ reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/reducers/scopeRouteState.js");
63
+ })();
64
+ ;
65
+ (function () {
66
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
67
+ leaveModule && leaveModule(module);
68
+ })();
69
+ ;
70
+ (function () {
71
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
72
+ if (!reactHotLoader) {
73
+ return;
74
+ }
75
+ reactHotLoader.register(initialState, "initialState", "/home/vsts/work/1/s/src/reducers/scopeRouteState.js");
76
+ reactHotLoader.register(viewStateReducer, "viewStateReducer", "/home/vsts/work/1/s/src/reducers/scopeRouteState.js");
77
+ reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/reducers/scopeRouteState.js");
78
+ })();
79
+ ;
80
+ (function () {
81
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
82
+ leaveModule && leaveModule(module);
83
+ })();
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getScopeChangeInProgress = void 0;
5
+ var _reselect = require("reselect");
6
+ (function () {
7
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
8
+ enterModule && enterModule(module);
9
+ })();
10
+ (function () {
11
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
12
+ enterModule && enterModule(module);
13
+ })();
14
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
15
+ return a;
16
+ };
17
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
18
+ return a;
19
+ };
20
+ var scopeRouteStateData = function scopeRouteStateData(state) {
21
+ return state.get("scopeRouteState");
22
+ };
23
+ var getScopeChangeInProgress = exports.getScopeChangeInProgress = (0, _reselect.createSelector)(scopeRouteStateData, function (data) {
24
+ return data.get("scopeChangeInProgress");
25
+ });
26
+ ;
27
+ (function () {
28
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
29
+ if (!reactHotLoader) {
30
+ return;
31
+ }
32
+ reactHotLoader.register(scopeRouteStateData, "scopeRouteStateData", "/home/vsts/work/1/s/src/selectors/scopeRouteState.js");
33
+ reactHotLoader.register(getScopeChangeInProgress, "getScopeChangeInProgress", "/home/vsts/work/1/s/src/selectors/scopeRouteState.js");
34
+ })();
35
+ ;
36
+ (function () {
37
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
38
+ leaveModule && leaveModule(module);
39
+ })();
40
+ ;
41
+ (function () {
42
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
43
+ if (!reactHotLoader) {
44
+ return;
45
+ }
46
+ reactHotLoader.register(scopeRouteStateData, "scopeRouteStateData", "/home/vsts/work/1/s/src/selectors/scopeRouteState.js");
47
+ reactHotLoader.register(getScopeChangeInProgress, "getScopeChangeInProgress", "/home/vsts/work/1/s/src/selectors/scopeRouteState.js");
48
+ })();
49
+ ;
50
+ (function () {
51
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
52
+ leaveModule && leaveModule(module);
53
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.7.0-dev.6",
3
+ "version": "1.7.0-dev.7",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -19,16 +19,6 @@ export const initializeFirstModuleScope = scope => ({
19
19
  payload: scope,
20
20
  });
21
21
 
22
- export const SET_NEW_SCOPE_AND_MODULE_NAME = "SET_NEW_SCOPE_AND_MODULE_NAME";
23
-
24
- export const setNewScopeAndModuleName = (scope, moduleName) => ({
25
- type: SET_NEW_SCOPE_AND_MODULE_NAME,
26
- payload: {
27
- scope,
28
- moduleName,
29
- },
30
- });
31
-
32
22
  export const SET_ROUTING_PERFORMED = "SET_ROUTING_PERFORMED";
33
23
 
34
24
  export const setRoutingPerformed = () => ({
@@ -3,11 +3,9 @@ import {
3
3
  initializeFirstModuleScope,
4
4
  SET_MODULE_AS_VISIBLE,
5
5
  SET_MODULES_STRUCTURE,
6
- SET_NEW_SCOPE_AND_MODULE_NAME,
7
6
  SET_ROUTING_PERFORMED,
8
7
  setModuleAsVisible,
9
8
  setModulesStructure,
10
- setNewScopeAndModuleName,
11
9
  setRoutingPerformed,
12
10
  } from "./modules";
13
11
 
@@ -38,18 +36,6 @@ describe("setModuleAsVisible", () => {
38
36
  });
39
37
  });
40
38
 
41
- describe("setNewScopeAndModuleName", () => {
42
- it("creates an action object", () => {
43
- expect(setNewScopeAndModuleName, "when called with", ["matrixScope", "moduleNeo"], "to equal", {
44
- type: SET_NEW_SCOPE_AND_MODULE_NAME,
45
- payload: {
46
- scope: "matrixScope",
47
- moduleName: "moduleNeo",
48
- },
49
- });
50
- });
51
- });
52
-
53
39
  describe("setRoutingPerformed", () => {
54
40
  it("creates an action object", () => {
55
41
  expect(setRoutingPerformed, "when called", "to equal", {
@@ -50,12 +50,13 @@ export const getDefaultScope = module =>
50
50
 
51
51
  export const APPLICATION_SCOPE_HAS_CHANGED = "APPLICATION_SCOPE_HAS_CHANGED";
52
52
 
53
- export const applicationScopeHasChanged = (previousScope, newScope) => {
53
+ export const applicationScopeHasChanged = (previousScope, newScope, moduleName) => {
54
54
  return {
55
55
  type: APPLICATION_SCOPE_HAS_CHANGED,
56
56
  payload: {
57
57
  previousScope,
58
58
  newScope,
59
+ moduleName,
59
60
  },
60
61
  };
61
62
  };
@@ -140,11 +140,12 @@ describe("getScopes", () => {
140
140
 
141
141
  describe("applicationScopeHasChanged", () => {
142
142
  it("creates an action object", () => {
143
- expect(applicationScopeHasChanged, "when called with", ["oldScope", "newScope"], "to equal", {
143
+ expect(applicationScopeHasChanged, "when called with", ["oldScope", "newScope", "module"], "to equal", {
144
144
  type: APPLICATION_SCOPE_HAS_CHANGED,
145
145
  payload: {
146
146
  previousScope: "oldScope",
147
147
  newScope: "newScope",
148
+ moduleName: "module",
148
149
  },
149
150
  });
150
151
  });
package/src/buildStore.js CHANGED
@@ -22,6 +22,7 @@ import metadataReducer from "./reducers/metadata";
22
22
  import requestStatesReducer from "./reducers/requestStates";
23
23
  import tasksReducer from "./reducers/tasks";
24
24
  import globalErrorMessagesReducer from "./reducers/globalErrorMessages";
25
+ import scopeRouteStateReducer from "./reducers/scopeRouteState";
25
26
 
26
27
  window.BUILD_ID = BUILD_ID;
27
28
  window.BUILD_NUMBER = BUILD_NUMBER;
@@ -69,6 +70,7 @@ const buildStore = (reducers, devOptions = {}) => {
69
70
  requestStates: requestStatesReducer,
70
71
  tasks: tasksReducer,
71
72
  globalErrorMessages: globalErrorMessagesReducer,
73
+ scopeRouteState: scopeRouteStateReducer,
72
74
  });
73
75
  const rootReducer = buildReducer(reducers);
74
76
 
@@ -6,7 +6,6 @@ import { applicationScopeHasChanged } from "../../actions/scopes";
6
6
  import useScopeData from "./useScopeData";
7
7
  import { hasUnsavedDataSelector } from "../../selectors/view";
8
8
  import { scopeConfirmationDialogTypes } from "../../constants";
9
- import { setNewScopeAndModuleName } from "../../actions/modules";
10
9
 
11
10
  const ExecuteClosingTabHandlerActions = async closingTabHandlerActions => {
12
11
  if (closingTabHandlerActions.length <= 0) return Promise.resolve();
@@ -22,8 +21,7 @@ const useApplicationScopeChanger = closingTabHandlerActions => {
22
21
 
23
22
  return (previousScope, newScope) => {
24
23
  ExecuteClosingTabHandlerActions(closingTabHandlerActions).then(() => {
25
- dispatch(setNewScopeAndModuleName(newScope, moduleName));
26
- dispatch(applicationScopeHasChanged(previousScope, newScope));
24
+ dispatch(applicationScopeHasChanged(previousScope, newScope, moduleName));
27
25
  });
28
26
  };
29
27
  };
@@ -5,7 +5,6 @@ import { TestWrapper } from "../../utils/testUtils";
5
5
  import useScopeConfirmationModalState from "./useScopeConfirmationModalState";
6
6
  import { mount } from "enzyme";
7
7
  import { APPLICATION_SCOPE_HAS_CHANGED } from "../../actions/scopes";
8
- import { SET_NEW_SCOPE_AND_MODULE_NAME } from "../../actions/modules";
9
8
 
10
9
  jest.mock("../../utils/buildUrl", () => {
11
10
  const modExport = {};
@@ -180,17 +179,6 @@ describe("useScopeConfirmationModalState", () => {
180
179
  await new Promise(resolve => setTimeout(resolve, 10));
181
180
 
182
181
  expect(store.dispatch, "to have calls satisfying", [
183
- {
184
- args: [
185
- {
186
- type: SET_NEW_SCOPE_AND_MODULE_NAME,
187
- payload: {
188
- scope: "newScope",
189
- moduleName: "TheModuleName",
190
- },
191
- },
192
- ],
193
- },
194
182
  {
195
183
  args: [
196
184
  {
@@ -198,6 +186,7 @@ describe("useScopeConfirmationModalState", () => {
198
186
  payload: {
199
187
  previousScope: "TheOldScope",
200
188
  newScope: "newScope",
189
+ moduleName: "TheModuleName",
201
190
  },
202
191
  },
203
192
  ],
@@ -255,17 +244,6 @@ describe("useScopeConfirmationModalState", () => {
255
244
  expect(isModalOpened, "to equal", "false");
256
245
 
257
246
  expect(store.dispatch, "to have calls satisfying", [
258
- {
259
- args: [
260
- {
261
- type: SET_NEW_SCOPE_AND_MODULE_NAME,
262
- payload: {
263
- scope: "newScope",
264
- moduleName: "TheModuleName",
265
- },
266
- },
267
- ],
268
- },
269
247
  {
270
248
  args: [
271
249
  {
@@ -273,6 +251,7 @@ describe("useScopeConfirmationModalState", () => {
273
251
  payload: {
274
252
  previousScope: "TheOldScope",
275
253
  newScope: "newScope",
254
+ moduleName: "TheModuleName",
276
255
  },
277
256
  },
278
257
  ],
@@ -325,19 +304,8 @@ describe("useScopeConfirmationModalState", () => {
325
304
  { args: [null, true] },
326
305
  ]);
327
306
 
328
- expect(store.dispatch.callCount, "to be", 2);
307
+ expect(store.dispatch.callCount, "to be", 1);
329
308
  expect(store.dispatch, "to have calls satisfying", [
330
- {
331
- args: [
332
- {
333
- type: SET_NEW_SCOPE_AND_MODULE_NAME,
334
- payload: {
335
- scope: "newScope",
336
- moduleName: "TheModuleName",
337
- },
338
- },
339
- ],
340
- },
341
309
  {
342
310
  args: [
343
311
  {
@@ -345,6 +313,7 @@ describe("useScopeConfirmationModalState", () => {
345
313
  payload: {
346
314
  previousScope: "TheOldScope",
347
315
  newScope: "newScope",
316
+ moduleName: "TheModuleName",
348
317
  },
349
318
  },
350
319
  ],
@@ -0,0 +1,25 @@
1
+ import { useSelector } from "react-redux";
2
+ import { getScopeChangeInProgress } from "../selectors/scopeRouteState";
3
+ import useLoader from "./useLoader";
4
+
5
+ // look at scopeRouteState.js for documentation
6
+
7
+ const useScopeGuardLoader = (actions, cutoutSelector) => {
8
+ const changeInProgress = useSelector(getScopeChangeInProgress);
9
+
10
+ const cutoutSelectorGuard = (...selArgs) => {
11
+ if (changeInProgress) {
12
+ return true;
13
+ }
14
+
15
+ if (cutoutSelector) {
16
+ return cutoutSelector.apply(null, selArgs);
17
+ }
18
+
19
+ return true;
20
+ };
21
+
22
+ useLoader(actions, cutoutSelectorGuard);
23
+ };
24
+
25
+ export default useScopeGuardLoader;
@@ -0,0 +1,187 @@
1
+ import React, { useState } from "react";
2
+ import { mount, act } from "unexpected-reaction";
3
+ import { Provider, useSelector } from "react-redux";
4
+ import Immutable from "immutable";
5
+ import sinon from "sinon";
6
+ import { spyOnConsole } from "../utils/testUtils";
7
+ import useScopeGuardLoader from "./useScopeGuardLoader";
8
+
9
+ const TestComp = ({ loader, cutout }) => {
10
+ useScopeGuardLoader(loader, cutout);
11
+ const [tick, setTick] = useState(0);
12
+ const live = useSelector(state => state.get("live"));
13
+ return (
14
+ <div id="test" onClick={() => setTick(tick + 1)} data-live={live}>
15
+ {tick}
16
+ </div>
17
+ );
18
+ };
19
+
20
+ describe("useScopeGuardLoader", () => {
21
+ spyOnConsole(["warn"]);
22
+
23
+ let loader, state, store, appNode;
24
+ beforeEach(() => {
25
+ state = Immutable.fromJS({
26
+ cutout: "yes",
27
+ live: 0,
28
+ requests: {
29
+ logout: false,
30
+ },
31
+ scopeRouteState: {
32
+ scopeChangeInProgress: false,
33
+ },
34
+ });
35
+ const subs = [];
36
+ store = {
37
+ updateState: () => {
38
+ subs.forEach((sub, i) => {
39
+ sub();
40
+ });
41
+ },
42
+ subscribe: sub => {
43
+ subs.push(sub);
44
+ return () => {};
45
+ },
46
+ getState: () => state,
47
+ dispatch: sinon.spy().named("dispatch"),
48
+ };
49
+ loader = { type: "TEST_ACTION" };
50
+ appNode = document.createElement("div");
51
+ document.body.appendChild(appNode);
52
+ });
53
+ afterEach(() => {
54
+ document.body.removeChild(appNode);
55
+ });
56
+
57
+ it("dispatches the loader action on mount if cutout returns falsy", () =>
58
+ expect(
59
+ <Provider store={store}>
60
+ <TestComp loader={loader} cutout={state => state.get("live")} />
61
+ </Provider>,
62
+ "when mounted",
63
+ "to satisfy",
64
+ <div>0</div>,
65
+ ).then(() => expect(store.dispatch, "to have calls satisfying", [{ args: [loader] }])));
66
+
67
+ it("does not dispatch the loader action on mount because scope change is in progress", () => {
68
+ state = state.setIn(["scopeRouteState", "scopeChangeInProgress"], true);
69
+
70
+ return expect(
71
+ <Provider store={store}>
72
+ <TestComp loader={loader} cutout={state => state.get("live")} />
73
+ </Provider>,
74
+ "when mounted",
75
+ "to satisfy",
76
+ <div>0</div>,
77
+ ).then(() => expect(store.dispatch, "not to have calls satisfying", [{ args: [loader] }]));
78
+ });
79
+
80
+ it("does not dispatch loader if cutout returns truthy", () =>
81
+ expect(
82
+ <Provider store={store}>
83
+ <TestComp loader={loader} cutout={state => state.get("cutout")} />
84
+ </Provider>,
85
+ "when mounted",
86
+ "to satisfy",
87
+ <div>0</div>,
88
+ ).then(() => expect(store.dispatch, "was not called")));
89
+
90
+ it("does not dispatch loader if logged out", () => {
91
+ state = state.setIn(["requests", "logout"], true);
92
+
93
+ expect(
94
+ <Provider store={store}>
95
+ <TestComp loader={loader} cutout={state => state.get("cutout")} />
96
+ </Provider>,
97
+ "when mounted",
98
+ "to satisfy",
99
+ <div>0</div>,
100
+ ).then(() => expect(store.dispatch, "was not called"));
101
+ });
102
+
103
+ it("does not dispatch loader if no cutout selector given, warns", () =>
104
+ expect(
105
+ <Provider store={store}>
106
+ <TestComp loader={loader} />
107
+ </Provider>,
108
+ "when mounted",
109
+ "to satisfy",
110
+ <div>0</div>,
111
+ )
112
+ .then(() => expect(store.dispatch, "was not called"))
113
+ .then(() =>
114
+ expect(console.warn, "not to have calls satisfying", [
115
+ {
116
+ args: ["useLoader hook called without cutout selector, loader will never be dispatched."],
117
+ },
118
+ ]),
119
+ ));
120
+
121
+ it("dispatches multiple loader actions", () => {
122
+ const loaderSeries = [{ type: "TEST_ACTION1" }, { type: "TEST_ACTION2" }, { type: "TEST_ACTION3" }];
123
+ return expect(
124
+ <Provider store={store}>
125
+ <TestComp loader={loaderSeries} cutout={state => state.get("live")} />
126
+ </Provider>,
127
+ "when mounted",
128
+ "to satisfy",
129
+ <div>0</div>,
130
+ ).then(() =>
131
+ expect(store.dispatch, "to have calls satisfying", [
132
+ { args: [loaderSeries[0]] },
133
+ { args: [loaderSeries[1]] },
134
+ { args: [loaderSeries[2]] },
135
+ ]),
136
+ );
137
+ });
138
+
139
+ it("only dispatches once if cutout does not change", () =>
140
+ expect(
141
+ <Provider store={store}>
142
+ <TestComp loader={loader} cutout={state => state.get("live")} />
143
+ </Provider>,
144
+ "when mounted",
145
+ "with event",
146
+ "click",
147
+ "with event",
148
+ "click",
149
+ "with event",
150
+ "click",
151
+ "with event",
152
+ "click",
153
+ "to satisfy",
154
+ <div>4</div>,
155
+ ).then(() => expect(store.dispatch, "to have calls satisfying", [{ args: [loader] }])));
156
+
157
+ it("fires loader if cutout is falsy, but not again if it becomes truthy", () => {
158
+ const selector = state => state.get("live");
159
+ mount(
160
+ <Provider store={store}>
161
+ <TestComp loader={loader} cutout={selector} />
162
+ </Provider>,
163
+ );
164
+ expect(store.dispatch, "to have calls satisfying", [{}]);
165
+ act(() => {
166
+ state = state.set("live", 1);
167
+ store.updateState();
168
+ });
169
+ expect(store.dispatch, "was called once");
170
+ });
171
+
172
+ it("fires loader if cutout was truthy, becomes falsy", () => {
173
+ const selector = state => state.get("live");
174
+ state = state.set("live", 1);
175
+ mount(
176
+ <Provider store={store}>
177
+ <TestComp loader={loader} cutout={selector} />
178
+ </Provider>,
179
+ );
180
+ expect(store.dispatch, "was not called");
181
+ act(() => {
182
+ state = state.set("live", 0);
183
+ store.updateState();
184
+ });
185
+ expect(store.dispatch, "was called");
186
+ });
187
+ });
@@ -3,10 +3,10 @@ import {
3
3
  INITIALIZE_FIRST_MODULE_SCOPE,
4
4
  SET_MODULE_AS_VISIBLE,
5
5
  SET_MODULES_STRUCTURE,
6
- SET_NEW_SCOPE_AND_MODULE_NAME,
7
6
  SET_ROUTING_PERFORMED,
8
7
  } from "../actions/modules";
9
8
  import { infoBar } from "./../constants";
9
+ import { APPLICATION_SCOPE_HAS_CHANGED } from "../actions/scopes";
10
10
 
11
11
  const initialState = Immutable.fromJS({
12
12
  tree: {},
@@ -58,10 +58,10 @@ const viewStateReducer = (state = initialState, action) => {
58
58
  return state.set("visibleModules", Immutable.fromJS(visibleModules));
59
59
  }
60
60
 
61
- case SET_NEW_SCOPE_AND_MODULE_NAME: {
61
+ case APPLICATION_SCOPE_HAS_CHANGED: {
62
62
  const lastScopeAndModuleSelection = state.get("lastScopeAndModuleSelection").toJS();
63
63
 
64
- if (action.payload.scope !== lastScopeAndModuleSelection.scope) {
64
+ if (action.payload.newScope !== lastScopeAndModuleSelection.scope) {
65
65
  state = state.set("visibleModules", Immutable.fromJS([]));
66
66
  }
67
67
 
@@ -69,7 +69,7 @@ const viewStateReducer = (state = initialState, action) => {
69
69
  "lastScopeAndModuleSelection",
70
70
  Immutable.fromJS({
71
71
  moduleName: action.payload.moduleName,
72
- scope: action.payload.scope,
72
+ scope: action.payload.newScope,
73
73
  routingPerformed: false,
74
74
  }),
75
75
  );
@@ -3,10 +3,10 @@ import {
3
3
  initializeFirstModuleScope,
4
4
  setModuleAsVisible,
5
5
  setModulesStructure,
6
- setNewScopeAndModuleName,
7
6
  setRoutingPerformed,
8
7
  } from "../actions/modules";
9
8
  import modulesReducer from "./modules";
9
+ import { applicationScopeHasChanged } from "../actions/scopes";
10
10
 
11
11
  describe("View state reducer", () => {
12
12
  const initialState = {
@@ -145,7 +145,7 @@ describe("View state reducer", () => {
145
145
  const oldState = Immutable.fromJS({
146
146
  ...initialState,
147
147
  lastScopeAndModuleSelection: {
148
- scope: "aScope",
148
+ scope: "newScope",
149
149
  moduleName: null,
150
150
  routingPerformed: true,
151
151
  },
@@ -154,13 +154,13 @@ describe("View state reducer", () => {
154
154
  const expected = {
155
155
  ...initialState,
156
156
  lastScopeAndModuleSelection: {
157
- scope: "aScope",
157
+ scope: "newScope",
158
158
  moduleName: "moduleMatrix",
159
159
  routingPerformed: false,
160
160
  },
161
161
  };
162
162
 
163
- const action = setNewScopeAndModuleName("aScope", "moduleMatrix");
163
+ const action = applicationScopeHasChanged("prevScope", "newScope", "moduleMatrix");
164
164
  const newState = modulesReducer(oldState, action);
165
165
  return expect(newState, "not to be", oldState).and("to equal", Immutable.fromJS(expected));
166
166
  });
@@ -180,7 +180,7 @@ describe("View state reducer", () => {
180
180
  },
181
181
  };
182
182
 
183
- const action = setNewScopeAndModuleName("newScope", "moduleMatrix");
183
+ const action = applicationScopeHasChanged("prevScope", "newScope", "moduleMatrix");
184
184
  const newState = modulesReducer(oldState, action);
185
185
  return expect(newState, "not to be", oldState).and("to equal", Immutable.fromJS(expected));
186
186
  });
@@ -0,0 +1,29 @@
1
+ import Immutable from "immutable";
2
+ import { SET_ROUTE } from "../actions/navigation";
3
+ import { APPLICATION_SCOPE_HAS_CHANGED } from "../actions/scopes";
4
+
5
+ const initialState = Immutable.fromJS({
6
+ scopeChangeInProgress: false,
7
+ });
8
+
9
+ /*
10
+ This reducer and its associated hook is used to prevent a request from being sent out while the application's scope is changing.
11
+ Basically the reducer responds to an action, set a flag to true and then set it to false once another action is triggered (route change).
12
+
13
+ This is a pretty hackish way to ensure that the correct requests are being executed (references #74924, #74764) however we know of no other way to achieve the desired result.
14
+ * */
15
+
16
+ const viewStateReducer = (state = initialState, action) => {
17
+ switch (action.type) {
18
+ case APPLICATION_SCOPE_HAS_CHANGED: {
19
+ return state.set("scopeChangeInProgress", action.payload.newScope !== action.payload.previousScope);
20
+ }
21
+ case SET_ROUTE: {
22
+ return state.set("scopeChangeInProgress", false);
23
+ }
24
+ default:
25
+ return state;
26
+ }
27
+ };
28
+
29
+ export default viewStateReducer;
@@ -0,0 +1,49 @@
1
+ import Immutable from "immutable";
2
+ import { applicationScopeHasChanged } from "../actions/scopes";
3
+ import reducer from "./scopeRouteState";
4
+ import { setRoute } from "../actions/navigation";
5
+
6
+ describe("scopeRouteState", () => {
7
+ it("behaves as a reducer should", () =>
8
+ expect(reducer, "to be a reducer with initial state", { scopeChangeInProgress: false }));
9
+
10
+ it("set scopeChangeInProgress to true if scope is different", () => {
11
+ const oldState = Immutable.Map({
12
+ scopeChangeInProgress: false,
13
+ });
14
+ const action = applicationScopeHasChanged("prevScope", "newScope", "module");
15
+
16
+ const newState = reducer(oldState, action);
17
+ return expect(newState, "not to be", oldState).and(
18
+ "to satisfy",
19
+ Immutable.fromJS({
20
+ scopeChangeInProgress: true,
21
+ }),
22
+ );
23
+ });
24
+
25
+ it("scopeChangeInProgress stays false if prev and new scope are identical", () => {
26
+ const oldState = Immutable.Map({
27
+ scopeChangeInProgress: false,
28
+ });
29
+ const action = applicationScopeHasChanged("sameScope", "sameScope", "module");
30
+
31
+ const newState = reducer(oldState, action);
32
+ return expect(newState, "to be", oldState);
33
+ });
34
+
35
+ it("set scopeChangeInProgress to false when route changes", () => {
36
+ const oldState = Immutable.Map({
37
+ scopeChangeInProgress: true,
38
+ });
39
+ const action = setRoute("loc", {});
40
+
41
+ const newState = reducer(oldState, action);
42
+ return expect(newState, "not to be", oldState).and(
43
+ "to satisfy",
44
+ Immutable.fromJS({
45
+ scopeChangeInProgress: false,
46
+ }),
47
+ );
48
+ });
49
+ });
@@ -0,0 +1,5 @@
1
+ import { createSelector } from "reselect";
2
+
3
+ const scopeRouteStateData = state => state.get("scopeRouteState");
4
+
5
+ export const getScopeChangeInProgress = createSelector(scopeRouteStateData, data => data.get("scopeChangeInProgress"));
@@ -0,0 +1,13 @@
1
+ import Immutable from "immutable";
2
+ import { getScopeChangeInProgress } from "./scopeRouteState";
3
+
4
+ describe("getScopeChangeInProgress", () => {
5
+ it("return the value from the store", () => {
6
+ const state = Immutable.fromJS({
7
+ scopeRouteState: {
8
+ scopeChangeInProgress: true,
9
+ },
10
+ });
11
+ return expect(getScopeChangeInProgress, "called with", [state], "to equal", true);
12
+ });
13
+ });