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
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _chai = require("chai");
|
|
4
|
-
|
|
5
|
-
var _chai2 = _interopRequireDefault(_chai);
|
|
6
|
-
|
|
7
|
-
var _chaiImmutable = require("chai-immutable");
|
|
8
|
-
|
|
9
|
-
var _chaiImmutable2 = _interopRequireDefault(_chaiImmutable);
|
|
10
|
-
|
|
11
|
-
var _selectors = require("../selectors");
|
|
12
|
-
|
|
13
|
-
var _selectors2 = _interopRequireDefault(_selectors);
|
|
14
|
-
|
|
15
|
-
var _immutable = require("immutable");
|
|
16
|
-
|
|
17
|
-
var Immutable = _interopRequireWildcard(_immutable);
|
|
18
|
-
|
|
19
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
/* eslint-disable max-len, no-undefined, max-lines-per-function, no-magic-numbers */
|
|
24
|
-
|
|
25
|
-
_chai2.default.use(_chaiImmutable2.default);
|
|
26
|
-
|
|
27
|
-
var getCurrentTotalResultsCount = _selectors2.default.getCurrentTotalResultsCount,
|
|
28
|
-
getAllResults = _selectors2.default.getAllResults,
|
|
29
|
-
getResultsUpToPage = _selectors2.default.getResultsUpToPage,
|
|
30
|
-
isPageFetched = _selectors2.default.isPageFetched,
|
|
31
|
-
isPageFetching = _selectors2.default.isPageFetching,
|
|
32
|
-
getCurrentView = _selectors2.default.getCurrentView;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var paginator = Immutable.Map({
|
|
36
|
-
"foo=bar": Immutable.Map({
|
|
37
|
-
page: 3,
|
|
38
|
-
token: "foo=bar",
|
|
39
|
-
ids: Immutable.List([1, 2, 3, 7, 8, 9]),
|
|
40
|
-
total: 42,
|
|
41
|
-
view: 2,
|
|
42
|
-
fetching: false,
|
|
43
|
-
fetched: true
|
|
44
|
-
}),
|
|
45
|
-
"foo=baz": Immutable.Map({
|
|
46
|
-
page: 1,
|
|
47
|
-
token: "foo=baz",
|
|
48
|
-
ids: Immutable.List([1, 4, 6]),
|
|
49
|
-
fetching: false,
|
|
50
|
-
fetched: true,
|
|
51
|
-
total: 17,
|
|
52
|
-
view: 1
|
|
53
|
-
})
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
var items = Immutable.Map({
|
|
57
|
-
"1": Immutable.Map({
|
|
58
|
-
data: "foo1",
|
|
59
|
-
id: 1
|
|
60
|
-
}),
|
|
61
|
-
"2": Immutable.Map({
|
|
62
|
-
data: "foo2",
|
|
63
|
-
id: 2
|
|
64
|
-
}),
|
|
65
|
-
"3": Immutable.Map({
|
|
66
|
-
data: "foo3",
|
|
67
|
-
id: 3
|
|
68
|
-
}),
|
|
69
|
-
"4": Immutable.Map({
|
|
70
|
-
data: "foo4",
|
|
71
|
-
id: 4
|
|
72
|
-
}),
|
|
73
|
-
"5": Immutable.Map({
|
|
74
|
-
data: "foo5",
|
|
75
|
-
id: 5
|
|
76
|
-
}),
|
|
77
|
-
"6": Immutable.Map({
|
|
78
|
-
data: "foo6",
|
|
79
|
-
id: 6
|
|
80
|
-
}),
|
|
81
|
-
"7": Immutable.Map({
|
|
82
|
-
data: "foo7",
|
|
83
|
-
id: 7
|
|
84
|
-
}),
|
|
85
|
-
"8": Immutable.Map({
|
|
86
|
-
data: "foo8",
|
|
87
|
-
id: 8
|
|
88
|
-
}),
|
|
89
|
-
"9": Immutable.Map({
|
|
90
|
-
data: "foo9",
|
|
91
|
-
id: 9
|
|
92
|
-
})
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe("selectors", function () {
|
|
96
|
-
|
|
97
|
-
it("getAllResults shoud select all the items ids for pages with same params than the current page", function () {
|
|
98
|
-
(0, _chai.expect)(getAllResults(paginator, "foo=bar", items)).to.equal(Immutable.List([Immutable.Map({
|
|
99
|
-
data: "foo1",
|
|
100
|
-
id: 1
|
|
101
|
-
}), Immutable.Map({
|
|
102
|
-
data: "foo2",
|
|
103
|
-
id: 2
|
|
104
|
-
}), Immutable.Map({
|
|
105
|
-
data: "foo3",
|
|
106
|
-
id: 3
|
|
107
|
-
}), Immutable.Map({
|
|
108
|
-
data: "foo7",
|
|
109
|
-
id: 7
|
|
110
|
-
}), Immutable.Map({
|
|
111
|
-
data: "foo8",
|
|
112
|
-
id: 8
|
|
113
|
-
}), Immutable.Map({
|
|
114
|
-
data: "foo9",
|
|
115
|
-
id: 9
|
|
116
|
-
})]));
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("getResultsUpToPage shoud select all the items ids for pages with same params than the current page", function () {
|
|
120
|
-
(0, _chai.expect)(getResultsUpToPage(paginator, "foo=bar", items, 2, 2)).to.equal(Immutable.List([Immutable.Map({
|
|
121
|
-
data: "foo1",
|
|
122
|
-
id: 1
|
|
123
|
-
}), Immutable.Map({
|
|
124
|
-
data: "foo2",
|
|
125
|
-
id: 2
|
|
126
|
-
}), Immutable.Map({
|
|
127
|
-
data: "foo3",
|
|
128
|
-
id: 3
|
|
129
|
-
}), Immutable.Map({
|
|
130
|
-
data: "foo7",
|
|
131
|
-
id: 7
|
|
132
|
-
})]));
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("getCurrentTotalResultsCount should return the total count for the current params of the provided name", function () {
|
|
136
|
-
(0, _chai.expect)(getCurrentTotalResultsCount(paginator, "foo=bar")).to.equal(42);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("getCurrentTotalResultsCount should return 0 if current page url is undefined for the provided name", function () {
|
|
140
|
-
(0, _chai.expect)(getCurrentTotalResultsCount(paginator, "name3")).to.equal(0);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("isPageFetching should return whether the current page is fetching or not for the provided name", function () {
|
|
144
|
-
(0, _chai.expect)(isPageFetching(paginator, "foo=bar", 1)).to.equal(false);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("isPageFetched should return whether the current page is fetched or not for the provided name", function () {
|
|
148
|
-
(0, _chai.expect)(isPageFetched(paginator, "foo=bar", 1)).to.equal(true);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("isPageFetched should return whether the current page is fetched or not for the provided name", function () {
|
|
152
|
-
(0, _chai.expect)(isPageFetched(paginator, "foo=bar", 4)).to.equal(false);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("getCurrentView should return 1 if there is no view point", function () {
|
|
156
|
-
(0, _chai.expect)(getCurrentView(paginator, "foo=bat")).to.equal(1);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("getCurrentView should return the value if it exists", function () {
|
|
160
|
-
(0, _chai.expect)(getCurrentView(paginator, "foo=bar")).to.equal(2);
|
|
161
|
-
});
|
|
162
|
-
});
|
package/lib/__tests__/setup.js
DELETED
package/src/Info.jsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type InfoPropTypes = {
|
|
5
|
-
shown: number;
|
|
6
|
-
total: number;
|
|
7
|
-
one: string;
|
|
8
|
-
all: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
import React from "react";
|
|
12
|
-
import { words as x25Words } from "x25/utility";
|
|
13
|
-
|
|
14
|
-
import words from "./words";
|
|
15
|
-
|
|
16
|
-
const getNumberForm = (value : number, one : string, all : string) : string => {
|
|
17
|
-
if (value === 1) {
|
|
18
|
-
return `1 ${one}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return `${x25Words.getNumberTense(value)} ${all}`;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const Info = ({ shown, total, one, all } : InfoPropTypes) => (
|
|
25
|
-
<div className="text-muted">
|
|
26
|
-
{`${words.Showing} `}
|
|
27
|
-
{
|
|
28
|
-
(shown === total) ? `${words.All} - ` : `${shown} ${words.Of}`
|
|
29
|
-
}
|
|
30
|
-
{` ${getNumberForm(total, one, all)}`}
|
|
31
|
-
</div>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
export default Info;
|
package/src/LoadDataItem.jsx
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
|
|
5
|
-
type LoadDataItemPropTypes = {
|
|
6
|
-
isFetching: bool;
|
|
7
|
-
fetched: bool;
|
|
8
|
-
id: string;
|
|
9
|
-
hasError: bool;
|
|
10
|
-
data: any;
|
|
11
|
-
children: React.Node;
|
|
12
|
-
shouldFetch: any;
|
|
13
|
-
|
|
14
|
-
fetchItem: () => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type OwnProps = {
|
|
18
|
-
id: string;
|
|
19
|
-
settings: {
|
|
20
|
-
selectors: any;
|
|
21
|
-
dataItemURL: string;
|
|
22
|
-
endpoint: string;
|
|
23
|
-
manageEntity: any;
|
|
24
|
-
normalizeDataItem: any;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
import { connect } from "react-redux";
|
|
29
|
-
|
|
30
|
-
// import {
|
|
31
|
-
// useLocation,
|
|
32
|
-
// useNavigate,
|
|
33
|
-
// useParams,
|
|
34
|
-
// } from "react-router-dom";
|
|
35
|
-
|
|
36
|
-
// const withRouter = (Component) => {
|
|
37
|
-
// const ComponentWithRouterProp = (props) => {
|
|
38
|
-
// const location = useLocation();
|
|
39
|
-
// const navigate = useNavigate();
|
|
40
|
-
// const params = useParams();
|
|
41
|
-
|
|
42
|
-
// return (
|
|
43
|
-
// <Component
|
|
44
|
-
// {...props}
|
|
45
|
-
// router={{
|
|
46
|
-
// location,
|
|
47
|
-
// navigate,
|
|
48
|
-
// params,
|
|
49
|
-
// }}
|
|
50
|
-
// />
|
|
51
|
-
// );
|
|
52
|
-
// };
|
|
53
|
-
|
|
54
|
-
// return ComponentWithRouterProp;
|
|
55
|
-
// };
|
|
56
|
-
|
|
57
|
-
import { fetchItem as fetchItemAction } from "./actions";
|
|
58
|
-
|
|
59
|
-
import { LargeErrorMessage, LoadingMessage } from "x25/Messages";
|
|
60
|
-
import words from "./words";
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
mapStateToProps = (state : any, { settings : { selectors }, id } : OwnProps) => ({
|
|
64
|
-
data : selectors.getItem(state, id),
|
|
65
|
-
hasError : selectors.getItemHasError(state, id),
|
|
66
|
-
fetched : selectors.getItemIsFetched(state, id),
|
|
67
|
-
isFetching : selectors.getIsFetchingItemInfo(state, id),
|
|
68
|
-
shouldFetch : selectors.getShouldFetchItemInfo(state, id),
|
|
69
|
-
}),
|
|
70
|
-
mapDispatchToProps = (dispatch : any, { id, settings } : OwnProps) => ({
|
|
71
|
-
fetchItem () {
|
|
72
|
-
dispatch(fetchItemAction({
|
|
73
|
-
...settings,
|
|
74
|
-
id,
|
|
75
|
-
}));
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const LoadDataItem = (props : LoadDataItemPropTypes) => {
|
|
80
|
-
const { children, data, isFetching, shouldFetch, hasError, fetchItem } = props;
|
|
81
|
-
|
|
82
|
-
React.useEffect(() => {
|
|
83
|
-
if (shouldFetch) {
|
|
84
|
-
fetchItem();
|
|
85
|
-
}
|
|
86
|
-
}, [
|
|
87
|
-
shouldFetch,
|
|
88
|
-
isFetching,
|
|
89
|
-
hasError,
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
if (isFetching) {
|
|
93
|
-
return (
|
|
94
|
-
<LoadingMessage message={words.LoadingData} />
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (hasError) {
|
|
99
|
-
return (
|
|
100
|
-
<LargeErrorMessage
|
|
101
|
-
message={words.ThereWasAProblem}
|
|
102
|
-
onRetry={fetchItem}
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (data.size === 0) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
children
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export default connect(mapStateToProps, mapDispatchToProps)(LoadDataItem);
|
package/src/LoadingButton.jsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { ErrorMessage, LoadingMessage } from "x25/Messages";
|
|
5
|
-
|
|
6
|
-
type LoadingButtonPropTypes = {
|
|
7
|
-
isFetching: bool;
|
|
8
|
-
hasProblems: bool;
|
|
9
|
-
|
|
10
|
-
onLoadMoreClick: () => void;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
import words from "./words";
|
|
14
|
-
|
|
15
|
-
class LoadingButton extends React.Component<LoadingButtonPropTypes> {
|
|
16
|
-
props: LoadingButtonPropTypes;
|
|
17
|
-
|
|
18
|
-
shouldComponentUpdate (nextProps : LoadingButtonPropTypes) {
|
|
19
|
-
const { hasProblems, isFetching } = this.props;
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
hasProblems !== nextProps.hasProblems ||
|
|
23
|
-
isFetching !== nextProps.isFetching
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render () {
|
|
28
|
-
const { isFetching, hasProblems, onLoadMoreClick } = this.props;
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div className="text-center my-2">
|
|
32
|
-
{
|
|
33
|
-
hasProblems ? (
|
|
34
|
-
<ErrorMessage message={words.ThereWasAProblem} />
|
|
35
|
-
) : null
|
|
36
|
-
}
|
|
37
|
-
{
|
|
38
|
-
isFetching ? (
|
|
39
|
-
<LoadingMessage message={words.LoadingData} sm />
|
|
40
|
-
) : (
|
|
41
|
-
<button
|
|
42
|
-
className="btn btn-outline-info d-print-none"
|
|
43
|
-
disabled={isFetching}
|
|
44
|
-
onClick={onLoadMoreClick}
|
|
45
|
-
type="button">
|
|
46
|
-
{isFetching ? words.Loading : words.LoadMore}
|
|
47
|
-
</button>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default LoadingButton;
|
package/src/actions.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type { Action, EndPointCb } from "./types";
|
|
4
|
-
|
|
5
|
-
type RequestPageArgsTypes = {
|
|
6
|
-
endpoint: string;
|
|
7
|
-
endpointCb: EndPointCb;
|
|
8
|
-
manageEntity: any;
|
|
9
|
-
resultsKey: string;
|
|
10
|
-
totalKey: string;
|
|
11
|
-
pageArgName: string;
|
|
12
|
-
idKey: string;
|
|
13
|
-
page: number;
|
|
14
|
-
token: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type ReceivePageArgsTypes = {
|
|
18
|
-
endpoint: string;
|
|
19
|
-
endpointCb: EndPointCb;
|
|
20
|
-
manageEntity: any;
|
|
21
|
-
pageArgName: string;
|
|
22
|
-
idKey: string;
|
|
23
|
-
page: number;
|
|
24
|
-
token: string;
|
|
25
|
-
items: Array<any>;
|
|
26
|
-
total: number;
|
|
27
|
-
error: bool;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
import agent from "superagent";
|
|
31
|
-
|
|
32
|
-
const requestPage = ({
|
|
33
|
-
endpoint,
|
|
34
|
-
endpointCb,
|
|
35
|
-
manageEntity,
|
|
36
|
-
resultsKey,
|
|
37
|
-
totalKey,
|
|
38
|
-
pageArgName,
|
|
39
|
-
idKey,
|
|
40
|
-
page,
|
|
41
|
-
token,
|
|
42
|
-
} : RequestPageArgsTypes) : Action => ({
|
|
43
|
-
type : "@@redux-paginator-immutable/REQUEST_PAGE",
|
|
44
|
-
meta : {
|
|
45
|
-
endpoint,
|
|
46
|
-
endpointCb,
|
|
47
|
-
manageEntity,
|
|
48
|
-
resultsKey,
|
|
49
|
-
totalKey,
|
|
50
|
-
pageArgName,
|
|
51
|
-
idKey,
|
|
52
|
-
},
|
|
53
|
-
payload: {
|
|
54
|
-
page,
|
|
55
|
-
token,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const receivePage = ({
|
|
60
|
-
endpoint,
|
|
61
|
-
endpointCb,
|
|
62
|
-
manageEntity,
|
|
63
|
-
pageArgName,
|
|
64
|
-
idKey,
|
|
65
|
-
page,
|
|
66
|
-
token,
|
|
67
|
-
items,
|
|
68
|
-
error,
|
|
69
|
-
total,
|
|
70
|
-
} : ReceivePageArgsTypes) : Action => ({
|
|
71
|
-
type : "@@redux-paginator-immutable/RECEIVE_PAGE",
|
|
72
|
-
meta : {
|
|
73
|
-
endpoint,
|
|
74
|
-
endpointCb,
|
|
75
|
-
manageEntity,
|
|
76
|
-
pageArgName,
|
|
77
|
-
idKey,
|
|
78
|
-
},
|
|
79
|
-
payload: {
|
|
80
|
-
page,
|
|
81
|
-
token,
|
|
82
|
-
items,
|
|
83
|
-
error,
|
|
84
|
-
total,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const resetView = (endpoint : string, token : string) : Action => ({
|
|
89
|
-
type : "@@redux-paginator-immutable/RESET_VIEW",
|
|
90
|
-
meta : {
|
|
91
|
-
endpoint,
|
|
92
|
-
},
|
|
93
|
-
payload: {
|
|
94
|
-
token,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const changeView = (endpoint : string, {
|
|
99
|
-
token,
|
|
100
|
-
view,
|
|
101
|
-
} : { token : string, view : number }) : Action => ({
|
|
102
|
-
type : "@@redux-paginator-immutable/CHANGE_VIEW",
|
|
103
|
-
meta : {
|
|
104
|
-
endpoint,
|
|
105
|
-
},
|
|
106
|
-
payload: {
|
|
107
|
-
token,
|
|
108
|
-
view,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const clearData = (endpoint : string) : Action => ({
|
|
113
|
-
type : "@@redux-paginator-immutable/CLEAR_DATA",
|
|
114
|
-
meta : {
|
|
115
|
-
endpoint,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// data info
|
|
121
|
-
|
|
122
|
-
type FetchDataItem = {
|
|
123
|
-
dataItemURL: string;
|
|
124
|
-
endpoint: string;
|
|
125
|
-
normalizeDataItem: any;
|
|
126
|
-
id: string;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const fetchDataItemRequest = ({ dataItemURL, normalizeDataItem, id } : FetchDataItem) : Promise<*> => (
|
|
130
|
-
new Promise((resolve, reject) => (
|
|
131
|
-
agent.
|
|
132
|
-
get(`${dataItemURL}/${id}`).
|
|
133
|
-
set("Accept", "application/json").
|
|
134
|
-
end(normalizeDataItem(resolve, reject))
|
|
135
|
-
)) : Promise<any>
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
export const fetchItem = (things : FetchDataItem) : any => ({
|
|
139
|
-
type : "@@redux-paginator-immutable/FETCH_ITEM_DATA",
|
|
140
|
-
payload : fetchDataItemRequest(things),
|
|
141
|
-
meta : {
|
|
142
|
-
id : things.id,
|
|
143
|
-
endpoint : things.endpoint,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
export default {
|
|
148
|
-
clearData,
|
|
149
|
-
requestPage,
|
|
150
|
-
receivePage,
|
|
151
|
-
resetView,
|
|
152
|
-
changeView,
|
|
153
|
-
};
|
package/src/agent.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
/* eslint-disable no-bitwise*/
|
|
3
|
-
|
|
4
|
-
type FetchPageArgs = {
|
|
5
|
-
endpoint: string;
|
|
6
|
-
pageArgName: string;
|
|
7
|
-
page: number;
|
|
8
|
-
token: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
import agent from "superagent";
|
|
12
|
-
import qs from "query-string";
|
|
13
|
-
|
|
14
|
-
export const buildSuffix = (pageArgName : string, page : number, params : string) => {
|
|
15
|
-
const parsedParams = qs.parse(params);
|
|
16
|
-
let
|
|
17
|
-
finalParsedParams = {},
|
|
18
|
-
startString = "";
|
|
19
|
-
|
|
20
|
-
for (const key of Object.keys(parsedParams)) {
|
|
21
|
-
if (parsedParams[key] === null) {
|
|
22
|
-
startString += key;
|
|
23
|
-
} else {
|
|
24
|
-
finalParsedParams = {
|
|
25
|
-
...finalParsedParams,
|
|
26
|
-
[key]: parsedParams[key],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
startString = startString === "" ? "?" : `${startString}?`;
|
|
31
|
-
|
|
32
|
-
if (Object.keys(finalParsedParams).length > 0 && qs.extract(params) !== "") {
|
|
33
|
-
startString = params.replace(qs.extract(params), "");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return startString + qs.stringify({
|
|
37
|
-
...finalParsedParams,
|
|
38
|
-
[pageArgName]: page,
|
|
39
|
-
}, { encode: false }).replace(startString, "");
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const fetchPage = ({ endpoint, pageArgName, page, token } : FetchPageArgs) => {
|
|
43
|
-
const
|
|
44
|
-
suffix = buildSuffix(pageArgName, page, token),
|
|
45
|
-
url = endpoint + suffix;
|
|
46
|
-
|
|
47
|
-
const promise : any = new Promise((resolve : any, reject : any) => agent.
|
|
48
|
-
get(url).
|
|
49
|
-
end((err : any, res : any) => err ? reject(err) : resolve(res))
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
return promise.then((res : { body : any }) => ({
|
|
53
|
-
response: res.body,
|
|
54
|
-
}));
|
|
55
|
-
};
|
package/src/createDataReducer.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
/* eslint-disable max-lines-per-function, */
|
|
3
|
-
|
|
4
|
-
import type { PaginatorSettings } from "./types";
|
|
5
|
-
|
|
6
|
-
import { createSelector } from "reselect";
|
|
7
|
-
import * as Immutable from "immutable";
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
Use to create a complex list where you need more information about
|
|
11
|
-
the item. For instance, if you DO need to fetch more data or to
|
|
12
|
-
manipulate it
|
|
13
|
-
*/
|
|
14
|
-
const createDataReducer = ({ key } : PaginatorSettings) => {
|
|
15
|
-
const
|
|
16
|
-
getItems = (state : any) => state.getIn([
|
|
17
|
-
"entities",
|
|
18
|
-
key,
|
|
19
|
-
]),
|
|
20
|
-
getItem = createSelector(
|
|
21
|
-
getItems,
|
|
22
|
-
(state, id) => id,
|
|
23
|
-
(data, id) => data.get(id) || Immutable.Map()
|
|
24
|
-
),
|
|
25
|
-
getItemsList = createSelector(
|
|
26
|
-
getItems,
|
|
27
|
-
(data) => data.map((current) => current.get("Data")).toList()
|
|
28
|
-
),
|
|
29
|
-
getItemData = createSelector(
|
|
30
|
-
getItems,
|
|
31
|
-
(state, id) => id,
|
|
32
|
-
(data, id) => {
|
|
33
|
-
if (typeof data === "undefined") {
|
|
34
|
-
return Immutable.Map();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return data.getIn([
|
|
38
|
-
id,
|
|
39
|
-
"Data",
|
|
40
|
-
]);
|
|
41
|
-
}
|
|
42
|
-
),
|
|
43
|
-
getItemHasError = createSelector(
|
|
44
|
-
getItem,
|
|
45
|
-
(data) => {
|
|
46
|
-
if (typeof data === "undefined") {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return data.get("error") === true;
|
|
51
|
-
}
|
|
52
|
-
),
|
|
53
|
-
getIsFetchingItemInfo = createSelector(
|
|
54
|
-
getItem,
|
|
55
|
-
(data) => {
|
|
56
|
-
if (typeof data === "undefined") {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return data.get("fetching");
|
|
61
|
-
}
|
|
62
|
-
),
|
|
63
|
-
getItemIsFetched = createSelector(
|
|
64
|
-
getItem,
|
|
65
|
-
(data) => {
|
|
66
|
-
if (typeof data === "undefined") {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return data.get("fetched");
|
|
71
|
-
}
|
|
72
|
-
),
|
|
73
|
-
getShouldFetchItemInfo = createSelector(
|
|
74
|
-
getIsFetchingItemInfo,
|
|
75
|
-
getItemIsFetched,
|
|
76
|
-
getItemHasError,
|
|
77
|
-
(isFetching, isFetched, hasError) => (
|
|
78
|
-
!isFetched && !isFetching && !hasError
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
getItems,
|
|
84
|
-
getItem,
|
|
85
|
-
getItemsList,
|
|
86
|
-
getItemData,
|
|
87
|
-
getItemHasError,
|
|
88
|
-
getIsFetchingItemInfo,
|
|
89
|
-
getItemIsFetched,
|
|
90
|
-
getShouldFetchItemInfo,
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export default createDataReducer;
|