redux-paginator-immutable 17.0.16 → 17.0.21
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/lib/Info.d.ts +9 -0
- package/lib/Info.js +19 -41
- package/lib/Info.js.map +1 -0
- package/lib/LoadDataItem.d.ts +23 -0
- package/lib/LoadDataItem.js +59 -110
- package/lib/LoadDataItem.js.map +1 -0
- package/lib/LoadPaginator.d.ts +41 -0
- package/lib/LoadPaginator.js +109 -216
- package/lib/LoadPaginator.js.map +1 -0
- package/lib/LoadingButton.d.ts +11 -0
- package/lib/LoadingButton.js +22 -75
- package/lib/LoadingButton.js.map +1 -0
- package/lib/actionTypes.d.ts +9 -0
- package/lib/actionTypes.js +13 -16
- package/lib/actionTypes.js.map +1 -0
- package/lib/actions.d.ts +42 -0
- package/lib/actions.js +82 -136
- package/lib/actions.js.map +1 -0
- package/lib/agent.d.ts +8 -0
- package/lib/agent.js +37 -86
- package/lib/agent.js.map +1 -0
- package/lib/createDataReducer.d.ts +14 -0
- package/lib/createDataReducer.js +60 -79
- package/lib/createDataReducer.js.map +1 -0
- package/lib/createItemReducer.d.ts +9 -0
- package/lib/createItemReducer.js +14 -32
- package/lib/createItemReducer.js.map +1 -0
- package/lib/createPaginator.d.ts +14 -0
- package/lib/createPaginator.js +83 -140
- package/lib/createPaginator.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +30 -58
- package/lib/index.js.map +1 -0
- package/lib/paginatorMiddleware.d.ts +5 -0
- package/lib/paginatorMiddleware.js +68 -102
- package/lib/paginatorMiddleware.js.map +1 -0
- package/lib/reducerItemData.d.ts +18 -0
- package/lib/reducerItemData.js +56 -63
- package/lib/reducerItemData.js.map +1 -0
- package/lib/reducerOperations.d.ts +3 -0
- package/lib/reducerOperations.js +69 -114
- package/lib/reducerOperations.js.map +1 -0
- package/lib/reducers.d.ts +4 -0
- package/lib/reducers.js +75 -87
- package/lib/reducers.js.map +1 -0
- package/lib/selectors.d.ts +58 -0
- package/lib/selectors.js +79 -129
- package/lib/selectors.js.map +1 -0
- package/lib/types/actions.d.ts +85 -0
- package/lib/types/actions.js +3 -1
- package/lib/types/actions.js.map +1 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/index.js +16 -29
- package/lib/types/index.js.map +1 -0
- package/lib/types/state.d.ts +6 -0
- package/lib/types/state.js +3 -1
- package/lib/types/state.js.map +1 -0
- package/lib/util.d.ts +9 -0
- package/lib/util.js +49 -73
- package/lib/util.js.map +1 -0
- package/lib/words.d.ts +9 -0
- package/lib/words.js +12 -15
- package/lib/words.js.map +1 -0
- package/package.json +35 -21
- package/src/Info.tsx +29 -0
- package/src/LoadDataItem.tsx +84 -0
- package/src/{LoadPaginator.jsx → LoadPaginator.tsx} +77 -94
- package/src/LoadingButton.tsx +40 -0
- package/src/__tests__/createPaginator.spec.js +6 -6
- package/src/__tests__/reducers.spec.js +28 -28
- package/src/__tests__/selectors.spec.js +80 -81
- package/src/{actionTypes.js → actionTypes.ts} +0 -4
- package/src/actions.ts +157 -0
- package/src/agent.ts +62 -0
- package/src/createDataReducer.ts +91 -0
- package/src/{createItemReducer.js → createItemReducer.ts} +7 -13
- package/src/createPaginator.ts +107 -0
- package/src/{index.js → index.ts} +0 -13
- package/src/paginatorMiddleware.ts +93 -0
- package/src/reducerItemData.ts +74 -0
- package/src/reducerOperations.ts +101 -0
- package/src/{reducers.js → reducers.ts} +9 -18
- package/src/selectors.ts +113 -0
- package/src/types/{actions.js → actions.ts} +27 -39
- package/src/types/{index.js → index.ts} +6 -13
- package/src/types/{state.js → state.ts} +3 -6
- package/src/util.ts +51 -0
- package/src/{words.js → words.ts} +0 -2
- package/lib/__tests__/actions.spec.js +0 -117
- package/lib/__tests__/agent.spec.js +0 -32
- package/lib/__tests__/createPaginator.spec.js +0 -39
- package/lib/__tests__/reducers.spec.js +0 -126
- package/lib/__tests__/selectors.spec.js +0 -162
- package/lib/__tests__/setup.js +0 -3
- package/src/Info.jsx +0 -34
- package/src/LoadDataItem.jsx +0 -116
- package/src/LoadingButton.jsx +0 -55
- package/src/actions.js +0 -153
- package/src/agent.js +0 -55
- package/src/createDataReducer.js +0 -94
- package/src/createPaginator.js +0 -131
- package/src/paginatorMiddleware.js +0 -94
- package/src/reducerItemData.jsx +0 -64
- package/src/reducerOperations.jsx +0 -112
- package/src/selectors.js +0 -143
- package/src/util.js +0 -71
package/lib/util.js
CHANGED
|
@@ -1,73 +1,49 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (typeof old === "undefined") {
|
|
51
|
-
return Immutable.Map({
|
|
52
|
-
Data: normalizrEntity(item)
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return old;
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
manipulateDataItems = function manipulateDataItems() {
|
|
60
|
-
var sortKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "ID";
|
|
61
|
-
return (0, _reselect.createSelector)(function (data) {
|
|
62
|
-
return data;
|
|
63
|
-
}, function (data) {
|
|
64
|
-
return data.sortBy(function (current) {
|
|
65
|
-
return -current.getIn(["Data", sortKey]);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
exports.manageDataEntity = manageDataEntity;
|
|
71
|
-
exports.manipulateDataItems = manipulateDataItems;
|
|
72
|
-
exports.manipulateItems = manipulateItems;
|
|
73
|
-
exports.manageEntity = manageEntity;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.manageEntity = exports.manipulateItems = exports.manipulateDataItems = exports.manageDataEntity = void 0;
|
|
23
|
+
const Immutable = __importStar(require("immutable"));
|
|
24
|
+
const reselect_1 = require("reselect");
|
|
25
|
+
// simple item
|
|
26
|
+
const manageEntity = (normalizrEntity) => ((item, state, keyID) => {
|
|
27
|
+
// prevent rewrite
|
|
28
|
+
const old = state.get(String(item[keyID]));
|
|
29
|
+
if (typeof old === "undefined") {
|
|
30
|
+
return Immutable.Map(normalizrEntity(item));
|
|
31
|
+
}
|
|
32
|
+
return old;
|
|
33
|
+
}), manipulateItems = (sortKey = "ID") => (0, reselect_1.createSelector)((data) => data, (data) => data.sortBy((current) => -current.get(sortKey))),
|
|
34
|
+
// data item
|
|
35
|
+
manageDataEntity = (normalizrEntity) => ((item, state, keyID) => {
|
|
36
|
+
// prevent rewrite
|
|
37
|
+
const old = state.get(String(item[keyID]));
|
|
38
|
+
if (typeof old === "undefined") {
|
|
39
|
+
return Immutable.Map({
|
|
40
|
+
Data: normalizrEntity(item),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return old;
|
|
44
|
+
}), manipulateDataItems = (sortKey = "ID") => ((0, reselect_1.createSelector)((data) => data, (data) => data.sortBy((current) => -current.getIn(["Data", sortKey]))));
|
|
45
|
+
exports.manageEntity = manageEntity;
|
|
46
|
+
exports.manipulateItems = manipulateItems;
|
|
47
|
+
exports.manageDataEntity = manageDataEntity;
|
|
48
|
+
exports.manipulateDataItems = manipulateDataItems;
|
|
49
|
+
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIA,qDAAuC;AACvC,uCAA0C;AAI1C,cAAc;AACd,MACE,YAAY,GAAG,CAAC,eAAgC,EAAE,EAAE,CAAC,CACnD,CAAC,IAAS,EAAE,KAAU,EAAE,KAAa,EAAoB,EAAE;IACzD,kBAAkB;IAClB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE3C,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;QAC9B,OAAO,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;KAC7C;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CACF,EACD,eAAe,GAAG,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE,CAAC,IAAA,yBAAc,EAClD,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,EACpB,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAa,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CACtE;AAED,YAAY;AACZ,gBAAgB,GAAG,CAAC,eAAgC,EAAE,EAAE,CAAC,CACvD,CAAC,IAAS,EAAE,KAAU,EAAE,KAAa,EAAoB,EAAE;IACzD,kBAAkB;IAClB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE3C,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;QAC9B,OAAO,SAAS,CAAC,GAAG,CAAC;YACnB,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC;SAC5B,CAAC,CAAC;KACJ;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CACF,EACD,mBAAmB,GAAG,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE,CAAC,CACxC,IAAA,yBAAc,EACZ,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,EACpB,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAa,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAClF,CACF,CAAC;AAE6D,oCAAY;AAA7B,0CAAe;AAAtD,4CAAgB;AAAE,kDAAmB"}
|
package/lib/words.d.ts
ADDED
package/lib/words.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.default = words;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const words = {
|
|
4
|
+
ThereWasAProblem: "There was a problem. Try again",
|
|
5
|
+
Showing: "Showing",
|
|
6
|
+
All: "all",
|
|
7
|
+
Of: "of",
|
|
8
|
+
LoadingData: "Loading data...",
|
|
9
|
+
LoadMore: "Load more",
|
|
10
|
+
};
|
|
11
|
+
exports.default = words;
|
|
12
|
+
//# sourceMappingURL=words.js.map
|
package/lib/words.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"words.js","sourceRoot":"","sources":["../src/words.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAG;IACZ,gBAAgB,EAAG,gCAAgC;IACnD,OAAO,EAAY,SAAS;IAC5B,GAAG,EAAgB,KAAK;IACxB,EAAE,EAAiB,IAAI;IACvB,WAAW,EAAQ,iBAAiB;IACpC,QAAQ,EAAW,WAAW;CAC/B,CAAC;AAEF,kBAAe,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redux-paginator-immutable",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.21",
|
|
4
|
+
"types": "./lib/index.d.ts",
|
|
4
5
|
"description": "redux-paginator-immutable helps you deal with paginated API by composing your existing reducers",
|
|
5
6
|
"main": "./lib/index.js",
|
|
6
7
|
"babel": {
|
|
8
|
+
"ignore": [
|
|
9
|
+
"**/__tests__",
|
|
10
|
+
"**/types"
|
|
11
|
+
],
|
|
7
12
|
"presets": [
|
|
8
|
-
"env",
|
|
9
|
-
"
|
|
10
|
-
"react"
|
|
13
|
+
"@babel/env",
|
|
14
|
+
"@babel/preset-typescript",
|
|
15
|
+
"@babel/preset-react"
|
|
11
16
|
],
|
|
12
17
|
"env": {
|
|
13
18
|
"production": {
|
|
14
19
|
"plugins": [
|
|
15
20
|
"@babel/plugin-syntax-dynamic-import",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"transform-
|
|
19
|
-
"transform-react-constant-elements",
|
|
20
|
-
"transform-react-inline-elements",
|
|
21
|
-
"transform-
|
|
22
|
-
"transform-
|
|
21
|
+
"@babel/plugin-proposal-class-properties",
|
|
22
|
+
"@babel/plugin-proposal-export-default-from",
|
|
23
|
+
"@babel/plugin-transform-modules-commonjs",
|
|
24
|
+
"@babel/plugin-transform-react-constant-elements",
|
|
25
|
+
"@babel/plugin-transform-react-inline-elements",
|
|
26
|
+
"@babel/plugin-transform-typescript",
|
|
27
|
+
"transform-react-remove-prop-types"
|
|
23
28
|
]
|
|
24
29
|
},
|
|
25
30
|
"developmentTime": {
|
|
@@ -31,18 +36,19 @@
|
|
|
31
36
|
}
|
|
32
37
|
},
|
|
33
38
|
"scripts": {
|
|
34
|
-
"build:lib": "babel src --out-dir lib",
|
|
39
|
+
"build:lib": "@babel src --extensions .ts,.tsx --out-dir lib",
|
|
35
40
|
"build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/redux-paginator-immutable.js",
|
|
36
41
|
"build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/redux-paginator-immutable.min.js",
|
|
37
42
|
"build": "npm run build:lib",
|
|
38
43
|
"clean": "rimraf dist lib",
|
|
39
44
|
"check": "npm-check -u -i babel-jest -i jest --specials=bin,eslint,babel,webpack",
|
|
40
|
-
"eslint": "eslint --ext .jsx,.js src --fix",
|
|
41
|
-
"load": "npm run test && npm run
|
|
42
|
-
"test": "mocha
|
|
45
|
+
"eslint": "eslint --ext .jsx,.js,.ts,.tsx src --fix",
|
|
46
|
+
"load": "npm run test && npm run clean && npm run eslint && npm run ts && npm publish",
|
|
47
|
+
"test": "ts-mocha src/__tests__/*.spec.js",
|
|
43
48
|
"test:watch": "npm test -- --watch",
|
|
44
49
|
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive \"src/**/__tests__/*\" --require src/__tests__/setup.js",
|
|
45
|
-
"test:codecov": "cat ./coverage/coverage.json | ./node_modules/.bin/codecov"
|
|
50
|
+
"test:codecov": "cat ./coverage/coverage.json | ./node_modules/.bin/codecov",
|
|
51
|
+
"ts": "tsc --declaration"
|
|
46
52
|
},
|
|
47
53
|
"repository": {
|
|
48
54
|
"type": "git",
|
|
@@ -70,7 +76,12 @@
|
|
|
70
76
|
},
|
|
71
77
|
"homepage": "https://github.com/cristian-sima/redux-paginator-immutable#readme",
|
|
72
78
|
"devDependencies": {
|
|
73
|
-
"babel
|
|
79
|
+
"@babel/cli": "^7.17.0",
|
|
80
|
+
"@babel/preset-env": "^7.16.11",
|
|
81
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
82
|
+
"@types/superagent": "^4.1.15",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
84
|
+
"@typescript-eslint/parser": "^5.10.2",
|
|
74
85
|
"babel-eslint": "^10.1.0",
|
|
75
86
|
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
|
76
87
|
"babel-plugin-transform-flow-strip-types": "^6.22.0",
|
|
@@ -83,19 +94,22 @@
|
|
|
83
94
|
"codecov": "^3.8.1",
|
|
84
95
|
"cross-env": "^6.0.3",
|
|
85
96
|
"es3ify": "^0.2.2",
|
|
86
|
-
"eslint": "^
|
|
97
|
+
"eslint": "^8.8.0",
|
|
98
|
+
"eslint-plugin-import": "^2.25.4",
|
|
87
99
|
"eslint-plugin-react": "^7.23.1",
|
|
88
100
|
"expect": "^24.9.0",
|
|
89
|
-
"flow-bin": "^0.148.0",
|
|
90
101
|
"flux-standard-action": "^2.1.1",
|
|
91
102
|
"glob": "^7.1.6",
|
|
92
103
|
"isparta": "^4.1.1",
|
|
93
104
|
"mocha": "^6.2.2",
|
|
94
105
|
"npm-check": "^5.9.2",
|
|
95
106
|
"rimraf": "^3.0.2",
|
|
96
|
-
"
|
|
107
|
+
"ts-mocha": "^9.0.2",
|
|
108
|
+
"typescript": "^4.5.5",
|
|
109
|
+
"webpack": "^5.68.0"
|
|
97
110
|
},
|
|
98
111
|
"dependencies": {
|
|
112
|
+
"create-subscription": "^17.0.0",
|
|
99
113
|
"depcheck": "^1.4.3",
|
|
100
114
|
"immutable": "*",
|
|
101
115
|
"query-string": "^7.1.0",
|
|
@@ -103,6 +117,6 @@
|
|
|
103
117
|
"redux": "^4.1.2",
|
|
104
118
|
"reselect": "^4.1.5",
|
|
105
119
|
"superagent": "^7.1.1",
|
|
106
|
-
"x25": "^17.0.
|
|
120
|
+
"x25": "^17.0.17"
|
|
107
121
|
}
|
|
108
122
|
}
|
package/src/Info.tsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type InfoPropTypes = {
|
|
2
|
+
shown: number;
|
|
3
|
+
total: number;
|
|
4
|
+
one: string;
|
|
5
|
+
all: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { words as x25Words } from "x25/utility";
|
|
10
|
+
import words from "./words";
|
|
11
|
+
|
|
12
|
+
const
|
|
13
|
+
getNumberForm = (value: number, one: string, all: string): string => {
|
|
14
|
+
if (value === 1) {
|
|
15
|
+
return `1 ${one}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return `${x25Words.getNumberTense(value)} ${all}`;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
Info = ({ shown, total, one, all }: InfoPropTypes) => (
|
|
22
|
+
<div className="text-muted">
|
|
23
|
+
{`${words.Showing} `}
|
|
24
|
+
{shown === total ? `${words.All} - ` : `${shown} ${words.Of}`}
|
|
25
|
+
{` ${getNumberForm(total, one, all)}`}
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export default Info;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
type LoadDataItemPropTypes = {
|
|
4
|
+
isFetching: boolean;
|
|
5
|
+
fetched: boolean;
|
|
6
|
+
id: string;
|
|
7
|
+
hasError: boolean;
|
|
8
|
+
data: any;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
shouldFetch: any;
|
|
11
|
+
fetchItem: () => void;
|
|
12
|
+
};
|
|
13
|
+
type OwnProps = {
|
|
14
|
+
id: string;
|
|
15
|
+
settings: {
|
|
16
|
+
selectors: any;
|
|
17
|
+
dataItemURL: string;
|
|
18
|
+
endpoint: string;
|
|
19
|
+
manageEntity: any;
|
|
20
|
+
normalizeDataItem: any;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
import { connect } from "react-redux";
|
|
24
|
+
import { LargeErrorMessage, LoadingMessage } from "x25/Messages";
|
|
25
|
+
import { fetchItem as fetchItemAction } from "./actions";
|
|
26
|
+
import words from "./words";
|
|
27
|
+
|
|
28
|
+
const
|
|
29
|
+
mapStateToProps = (state: any, {
|
|
30
|
+
settings: {
|
|
31
|
+
selectors,
|
|
32
|
+
},
|
|
33
|
+
id,
|
|
34
|
+
}: OwnProps) => ({
|
|
35
|
+
data : selectors.getItem(state, id),
|
|
36
|
+
hasError : selectors.getItemHasError(state, id),
|
|
37
|
+
fetched : selectors.getItemIsFetched(state, id),
|
|
38
|
+
isFetching : selectors.getIsFetchingItemInfo(state, id),
|
|
39
|
+
shouldFetch : selectors.getShouldFetchItemInfo(state, id),
|
|
40
|
+
}),
|
|
41
|
+
mapDispatchToProps = (dispatch: any, {
|
|
42
|
+
id,
|
|
43
|
+
settings,
|
|
44
|
+
}: OwnProps) => ({
|
|
45
|
+
fetchItem () {
|
|
46
|
+
dispatch(fetchItemAction({
|
|
47
|
+
...settings,
|
|
48
|
+
id,
|
|
49
|
+
}));
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
|
|
53
|
+
LoadDataItem = (props: LoadDataItemPropTypes) : any => {
|
|
54
|
+
const {
|
|
55
|
+
children,
|
|
56
|
+
data,
|
|
57
|
+
isFetching,
|
|
58
|
+
shouldFetch,
|
|
59
|
+
hasError,
|
|
60
|
+
fetchItem,
|
|
61
|
+
} = props;
|
|
62
|
+
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
if (shouldFetch) {
|
|
65
|
+
fetchItem();
|
|
66
|
+
}
|
|
67
|
+
}, [shouldFetch, isFetching, hasError]);
|
|
68
|
+
|
|
69
|
+
if (isFetching) {
|
|
70
|
+
return <LoadingMessage message={words.LoadingData} />;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (hasError) {
|
|
74
|
+
return <LargeErrorMessage message={words.ThereWasAProblem} onRetry={fetchItem} />;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (data.size === 0) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return children;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default connect(mapStateToProps, mapDispatchToProps)(LoadDataItem);
|
|
@@ -1,72 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
import React, { Component } from "react";
|
|
3
|
+
import * as Immutable from "immutable";
|
|
4
|
+
import { connect } from "react-redux";
|
|
5
|
+
import { bindActionCreators } from "redux";
|
|
6
|
+
import { LargeErrorMessage, LoadingMessage } from "x25/Messages";
|
|
7
|
+
import selectors from "./selectors";
|
|
8
|
+
import LoadingButton from "./LoadingButton";
|
|
9
|
+
import words from "./words";
|
|
3
10
|
|
|
4
11
|
type Settings = {
|
|
5
12
|
key: string;
|
|
6
13
|
rowsPerLoad: number;
|
|
7
14
|
manipulateItems: (items: any) => void;
|
|
8
|
-
resetView: (data
|
|
15
|
+
resetView: (data: any) => void;
|
|
9
16
|
changeView: (data: any) => void;
|
|
10
|
-
requestPage: (page: string, token
|
|
11
|
-
}
|
|
12
|
-
|
|
17
|
+
requestPage: (page: string, token: string) => any;
|
|
18
|
+
};
|
|
13
19
|
type OwnProps = {
|
|
14
20
|
token: string;
|
|
15
21
|
settings: Settings;
|
|
16
22
|
};
|
|
17
|
-
|
|
18
23
|
type LoadPaginatorPropTypes = {
|
|
19
24
|
token: string;
|
|
20
25
|
children: any;
|
|
21
26
|
settings: Settings;
|
|
22
27
|
paginator: any;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
resetView: (token : string) => void;
|
|
35
|
-
|
|
36
|
-
loadData: (page : number) => void;
|
|
37
|
-
changeFilter: (filter : string) => (event : { target : { value : string } }) => void;
|
|
28
|
+
changeView: (info: {
|
|
29
|
+
token: string;
|
|
30
|
+
view: number;
|
|
31
|
+
}) => void;
|
|
32
|
+
resetView: (token: string) => void;
|
|
33
|
+
loadData: (page: number) => void;
|
|
34
|
+
changeFilter: (filter: string) => (event: {
|
|
35
|
+
target: {
|
|
36
|
+
value: string;
|
|
37
|
+
};
|
|
38
|
+
}) => void;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import { connect } from "react-redux";
|
|
43
|
-
import { bindActionCreators } from "redux";
|
|
44
|
-
|
|
45
|
-
import selectors from "./selectors";
|
|
46
|
-
|
|
47
|
-
import LoadingButton from "./LoadingButton";
|
|
48
|
-
|
|
49
|
-
import { LargeErrorMessage, LoadingMessage } from "x25/Messages";
|
|
50
|
-
import words from "./words";
|
|
51
|
-
|
|
52
|
-
const mapStateToProps = (state, { token, settings } : OwnProps) => {
|
|
53
|
-
|
|
54
|
-
const { list, entities } = selectors.getPaginators(state, settings.key);
|
|
55
|
-
|
|
41
|
+
const
|
|
42
|
+
mapStateToProps = (state : any, { token, settings }: OwnProps) => {
|
|
56
43
|
const
|
|
44
|
+
{ list, entities } = selectors.getPaginators(state, settings.key),
|
|
57
45
|
currentPage = selectors.getCurrentView(list, token),
|
|
58
46
|
isFetching = selectors.isPageFetching(list, token, currentPage),
|
|
59
47
|
isFetched = selectors.isPageFetched(list, token, currentPage),
|
|
60
48
|
isNextFetching = selectors.isPageFetching(list, token, currentPage + 1),
|
|
61
49
|
isNextFetched = selectors.isPageFetched(list, token, currentPage + 1),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
),
|
|
50
|
+
// eslint-disable-next-line max-len
|
|
51
|
+
resultsUpTo = selectors.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad),
|
|
65
52
|
items = settings.manipulateItems(resultsUpTo),
|
|
66
53
|
total = selectors.getCurrentTotalResultsCount(list, token),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
// currentPage was previously given to the following function
|
|
55
|
+
hasProblems = selectors.hasPageProblems(list, token),
|
|
56
|
+
shouldLoadNext = !isNextFetched && !isNextFetching;
|
|
70
57
|
|
|
71
58
|
return {
|
|
72
59
|
paginator: Immutable.Map({
|
|
@@ -80,27 +67,59 @@ const mapStateToProps = (state, { token, settings } : OwnProps) => {
|
|
|
80
67
|
}),
|
|
81
68
|
};
|
|
82
69
|
},
|
|
83
|
-
mapDispatchToProps = (dispatch
|
|
70
|
+
mapDispatchToProps = (dispatch : any, {
|
|
71
|
+
token,
|
|
72
|
+
settings,
|
|
73
|
+
}: OwnProps) => ({
|
|
84
74
|
...bindActionCreators({
|
|
85
75
|
resetView : settings.resetView,
|
|
86
76
|
changeView : settings.changeView,
|
|
87
77
|
}, dispatch),
|
|
88
|
-
loadData (page) {
|
|
78
|
+
loadData (page : any) {
|
|
89
79
|
dispatch(settings.requestPage(page, token));
|
|
90
80
|
},
|
|
91
81
|
});
|
|
92
82
|
|
|
83
|
+
|
|
84
|
+
// new
|
|
85
|
+
|
|
86
|
+
/* eslint-disable */
|
|
93
87
|
class LoadPaginator extends Component<LoadPaginatorPropTypes> {
|
|
94
88
|
|
|
95
|
-
handleLoadMoreClick: () =>
|
|
89
|
+
handleLoadMoreClick: () => any;
|
|
90
|
+
|
|
91
|
+
componentDidMount () {
|
|
92
|
+
const
|
|
93
|
+
{ paginator, loadData } = this.props,
|
|
94
|
+
isFetched = paginator.get("isFetched"),
|
|
95
|
+
isFetching = paginator.get("isFetching"),
|
|
96
|
+
currentPage = paginator.get("currentPage"),
|
|
97
|
+
shouldFetch = !isFetched && !isFetching;
|
|
98
|
+
|
|
99
|
+
if (shouldFetch) {
|
|
100
|
+
loadData(currentPage);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
UNSAFE_componentWillReceiveProps (nextProps : LoadPaginatorPropTypes) {
|
|
105
|
+
const
|
|
106
|
+
{ loadData, paginator } = nextProps,
|
|
107
|
+
isFetched = paginator.get("isFetched"),
|
|
108
|
+
isFetching = paginator.get("isFetching"),
|
|
109
|
+
currentPage = paginator.get("currentPage"),
|
|
110
|
+
shouldFetch = !isFetched && !isFetching;
|
|
96
111
|
|
|
97
|
-
|
|
112
|
+
if (shouldFetch) {
|
|
113
|
+
loadData(currentPage);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
constructor (props: LoadPaginatorPropTypes) {
|
|
98
118
|
super(props);
|
|
99
119
|
|
|
100
120
|
this.handleLoadMoreClick = () => {
|
|
101
|
-
const { paginator, token, changeView, loadData } = this.props;
|
|
102
|
-
|
|
103
121
|
const
|
|
122
|
+
{ paginator, token, changeView, loadData } = this.props,
|
|
104
123
|
currentPage = paginator.get("currentPage"),
|
|
105
124
|
hasProblems = paginator.get("hasProblems"),
|
|
106
125
|
shouldLoadNext = paginator.get("shouldLoadNext");
|
|
@@ -120,40 +139,8 @@ class LoadPaginator extends Component<LoadPaginatorPropTypes> {
|
|
|
120
139
|
};
|
|
121
140
|
}
|
|
122
141
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
isFetched = paginator.get("isFetched"),
|
|
128
|
-
isFetching = paginator.get("isFetching"),
|
|
129
|
-
currentPage = paginator.get("currentPage");
|
|
130
|
-
|
|
131
|
-
const shouldFetch = !isFetched && !isFetching;
|
|
132
|
-
|
|
133
|
-
if (shouldFetch) {
|
|
134
|
-
loadData(currentPage);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
UNSAFE_componentWillReceiveProps (nextProps) {
|
|
139
|
-
const { loadData, paginator } = nextProps;
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
isFetched = paginator.get("isFetched"),
|
|
143
|
-
isFetching = paginator.get("isFetching"),
|
|
144
|
-
currentPage = paginator.get("currentPage");
|
|
145
|
-
|
|
146
|
-
const shouldFetch = !isFetched && !isFetching;
|
|
147
|
-
|
|
148
|
-
if (shouldFetch) {
|
|
149
|
-
loadData(currentPage);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
shouldComponentUpdate (nextProps : LoadPaginatorPropTypes) {
|
|
154
|
-
return (
|
|
155
|
-
this.props.paginator !== nextProps.paginator
|
|
156
|
-
);
|
|
142
|
+
shouldComponentUpdate (nextProps: LoadPaginatorPropTypes) {
|
|
143
|
+
return this.props.paginator !== nextProps.paginator;
|
|
157
144
|
}
|
|
158
145
|
|
|
159
146
|
componentWillUnmount () {
|
|
@@ -161,23 +148,18 @@ class LoadPaginator extends Component<LoadPaginatorPropTypes> {
|
|
|
161
148
|
}
|
|
162
149
|
|
|
163
150
|
render () {
|
|
164
|
-
const { paginator } = this.props;
|
|
165
|
-
|
|
166
151
|
const
|
|
152
|
+
{ paginator } = this.props,
|
|
167
153
|
items = paginator.get("items"),
|
|
168
154
|
hasProblems = paginator.get("hasProblems"),
|
|
169
155
|
currentPage = paginator.get("currentPage"),
|
|
170
156
|
isFetching = paginator.get("isFetching"),
|
|
171
|
-
total = paginator.get("total")
|
|
172
|
-
|
|
173
|
-
const
|
|
157
|
+
total = paginator.get("total"),
|
|
174
158
|
isEmpty = items.size === 0,
|
|
175
159
|
showLoading = total !== items.size;
|
|
176
160
|
|
|
177
161
|
if (isEmpty && isFetching) {
|
|
178
|
-
return
|
|
179
|
-
<LoadingMessage message={words.LoadingData} />
|
|
180
|
-
);
|
|
162
|
+
return <LoadingMessage message={words.LoadingData} />;
|
|
181
163
|
}
|
|
182
164
|
|
|
183
165
|
if (hasProblems && currentPage === 1) {
|
|
@@ -190,7 +172,7 @@ class LoadPaginator extends Component<LoadPaginatorPropTypes> {
|
|
|
190
172
|
}
|
|
191
173
|
|
|
192
174
|
return (
|
|
193
|
-
|
|
175
|
+
<>
|
|
194
176
|
{React.cloneElement(this.props.children, this.props)}
|
|
195
177
|
{
|
|
196
178
|
showLoading ? (
|
|
@@ -201,9 +183,10 @@ class LoadPaginator extends Component<LoadPaginatorPropTypes> {
|
|
|
201
183
|
/>
|
|
202
184
|
) : null
|
|
203
185
|
}
|
|
204
|
-
|
|
186
|
+
</>
|
|
205
187
|
);
|
|
206
188
|
}
|
|
189
|
+
|
|
207
190
|
}
|
|
208
191
|
|
|
209
192
|
export default connect(mapStateToProps, mapDispatchToProps)(LoadPaginator);
|