@inseefr/lunatic 2.4.7-beta → 2.4.7-go-to-page
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.
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _actions = require("../actions");
|
|
8
|
+
var _pageTag = require("../commons/page-tag");
|
|
8
9
|
var _commons = require("./commons");
|
|
9
10
|
var _reduceGoNextPage = _interopRequireDefault(require("./reduce-go-next-page"));
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -15,14 +16,13 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
15
16
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
17
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
18
|
function validateChange(state) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return (0, _reduceGoNextPage["default"])(updatedState, {
|
|
19
|
+
if ((0, _commons.isOnEmptyPage)(state)) {
|
|
20
|
+
return (0, _reduceGoNextPage["default"])(state, {
|
|
21
21
|
type: _actions.ActionKind.GO_NEXT_PAGE,
|
|
22
22
|
payload: {}
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return state;
|
|
26
26
|
}
|
|
27
27
|
function resolveSubPage(state, action) {
|
|
28
28
|
var pager = state.pager,
|
|
@@ -54,26 +54,42 @@ function resolveSubPage(state, action) {
|
|
|
54
54
|
function reduceGoToPage(state, action) {
|
|
55
55
|
var isInLoop = state.isInLoop,
|
|
56
56
|
pager = state.pager;
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
|
|
57
|
+
var newState = _objectSpread({}, state);
|
|
58
|
+
|
|
59
|
+
// The page contains non digit, extract information from it
|
|
60
|
+
if (action.payload.page.match(/\D/)) {
|
|
61
|
+
var _pager = (0, _pageTag.getPagerFromPageTag)(action.payload.page);
|
|
62
|
+
if (_pager) {
|
|
63
|
+
action.payload.iteration = _pager.iteration;
|
|
64
|
+
action.payload.subPage = _pager.subPage;
|
|
65
|
+
action.payload.page = _pager.page;
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
|
|
69
|
+
// The page is still not a number, cancel the action
|
|
70
|
+
if (action.payload.page.match(/\D/)) {
|
|
71
|
+
console.error("Cannot reach page \"".concat(action.payload.page, "\", not a number"));
|
|
72
|
+
return state;
|
|
73
|
+
}
|
|
74
|
+
if (action.payload.iteration !== undefined) {
|
|
75
|
+
newState = resolveSubPage(state, action);
|
|
76
|
+
} else if (!isInLoop) {
|
|
77
|
+
newState = _objectSpread(_objectSpread({}, state), {}, {
|
|
78
|
+
pager: _objectSpread(_objectSpread({}, pager), {}, {
|
|
79
|
+
subPage: undefined,
|
|
80
|
+
nbSubPages: undefined,
|
|
81
|
+
iteration: undefined,
|
|
82
|
+
nbIterations: undefined,
|
|
83
|
+
page: action.payload.page
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
// TODO: fix when redirect to loop component
|
|
87
|
+
// How to calculate nbSubPages & nbIterations?
|
|
88
|
+
// How to calculate lazy variables we need?
|
|
89
|
+
// Handle setLoopBindings with the good iteration
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return validateChange(newState);
|
|
77
93
|
}
|
|
78
94
|
var _default = reduceGoToPage;
|
|
79
95
|
exports["default"] = _default;
|