redux-paginator-immutable 17.0.4 → 17.0.18
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/__tests__/createPaginator.spec.js +2 -2
- package/lib/__tests__/reducers.spec.js +2 -3
- package/lib/__tests__/selectors.spec.js +11 -13
- package/package.json +15 -8
- 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 +98 -0
- package/src/{createItemReducer.js → createItemReducer.ts} +6 -12
- 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} +3 -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/Info.js +0 -37
- package/lib/LoadDataItem.js +0 -110
- package/lib/LoadPaginator.js +0 -216
- package/lib/LoadingButton.js +0 -75
- package/lib/actionTypes.js +0 -16
- package/lib/actions.js +0 -136
- package/lib/agent.js +0 -86
- package/lib/createDataReducer.js +0 -83
- package/lib/createItemReducer.js +0 -36
- package/lib/createPaginator.js +0 -141
- package/lib/index.js +0 -58
- package/lib/paginatorMiddleware.js +0 -102
- package/lib/reducerItemData.js +0 -63
- package/lib/reducerOperations.js +0 -114
- package/lib/reducers.js +0 -87
- package/lib/selectors.js +0 -129
- package/lib/types/actions.js +0 -1
- package/lib/types/index.js +0 -29
- package/lib/types/state.js +0 -1
- package/lib/util.js +0 -73
- package/lib/words.js +0 -15
- package/src/Info.jsx +0 -32
- 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/selectors.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _immutable = require("immutable");
|
|
8
|
-
|
|
9
|
-
var Immutable = _interopRequireWildcard(_immutable);
|
|
10
|
-
|
|
11
|
-
var _reselect = require("reselect");
|
|
12
|
-
|
|
13
|
-
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; } }
|
|
14
|
-
|
|
15
|
-
var pagesSelector = function pagesSelector(state) {
|
|
16
|
-
return state;
|
|
17
|
-
};
|
|
18
|
-
/* eslint-disable no-undefined */
|
|
19
|
-
|
|
20
|
-
var rowsPerPage = 50;
|
|
21
|
-
|
|
22
|
-
var pageSelector = (0, _reselect.createSelector)(pagesSelector, function (state, token) {
|
|
23
|
-
return token;
|
|
24
|
-
}, function (pages, token) {
|
|
25
|
-
return pages.get(token);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
var getAllResults = (0, _reselect.createSelector)(pageSelector, function (state, token, items) {
|
|
29
|
-
return items;
|
|
30
|
-
}, function (page, items) {
|
|
31
|
-
if (typeof page === "undefined") {
|
|
32
|
-
return Immutable.List();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return page.get("ids").map(function (id) {
|
|
36
|
-
return items.get(String(id));
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
var getResultsUpToPage = (0, _reselect.createSelector)(pageSelector, function (state, token, items) {
|
|
41
|
-
return items;
|
|
42
|
-
}, function (state, token, items, target) {
|
|
43
|
-
return target;
|
|
44
|
-
}, function (state, token, items, target, perPage) {
|
|
45
|
-
return perPage || rowsPerPage;
|
|
46
|
-
}, function (page, items, target, perPage) {
|
|
47
|
-
if (typeof page === "undefined") {
|
|
48
|
-
return Immutable.List();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var ids = page.get("ids").slice(0, perPage * target);
|
|
52
|
-
|
|
53
|
-
return ids.map(function (id) {
|
|
54
|
-
return items.get(String(id));
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
var getCurrentTotalResultsCount = (0, _reselect.createSelector)(pageSelector, function (page) {
|
|
59
|
-
if (typeof page === "undefined") {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return page.get("total");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
var isPageFetching = (0, _reselect.createSelector)(pageSelector, function (state, token, target) {
|
|
67
|
-
return target;
|
|
68
|
-
}, function (page, target) {
|
|
69
|
-
if (typeof page === "undefined") {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return page.get("fetching") && target === page.get("page");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
var isPageFetched = (0, _reselect.createSelector)(pageSelector, function (state, token, target) {
|
|
77
|
-
return target;
|
|
78
|
-
}, function (page, target) {
|
|
79
|
-
if (typeof page === "undefined") {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return page.get("fetched") && target <= page.get("page");
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
var hasPageProblems = (0, _reselect.createSelector)(pageSelector, function (page) {
|
|
87
|
-
if (typeof page === "undefined") {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return page.get("error");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
var getCurrentView = (0, _reselect.createSelector)(pageSelector, function (page) {
|
|
95
|
-
if (typeof page === "undefined") {
|
|
96
|
-
return 1;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return page.get("view");
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// these selectors are used for the entire app
|
|
103
|
-
var getPaginatorPaginations = function getPaginatorPaginations(state, name) {
|
|
104
|
-
return state.getIn(["paginations", name]);
|
|
105
|
-
},
|
|
106
|
-
getPaginatorEntities = function getPaginatorEntities(state, name) {
|
|
107
|
-
return state.getIn(["entities", name]);
|
|
108
|
-
},
|
|
109
|
-
getPaginators = (0, _reselect.createSelector)(getPaginatorPaginations, getPaginatorEntities, function (list, entities) {
|
|
110
|
-
return {
|
|
111
|
-
list: list,
|
|
112
|
-
entities: entities
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
exports.default = {
|
|
117
|
-
getAllResults: getAllResults,
|
|
118
|
-
getCurrentTotalResultsCount: getCurrentTotalResultsCount,
|
|
119
|
-
getResultsUpToPage: getResultsUpToPage,
|
|
120
|
-
isPageFetching: isPageFetching,
|
|
121
|
-
isPageFetched: isPageFetched,
|
|
122
|
-
hasPageProblems: hasPageProblems,
|
|
123
|
-
getCurrentView: getCurrentView,
|
|
124
|
-
|
|
125
|
-
// for state
|
|
126
|
-
getPaginatorPaginations: getPaginatorPaginations,
|
|
127
|
-
getPaginatorEntities: getPaginatorEntities,
|
|
128
|
-
getPaginators: getPaginators
|
|
129
|
-
};
|
package/lib/types/actions.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/types/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _actions = require("./actions");
|
|
8
|
-
|
|
9
|
-
Object.keys(_actions).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
Object.defineProperty(exports, key, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function get() {
|
|
14
|
-
return _actions[key];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
var _state = require("./state");
|
|
20
|
-
|
|
21
|
-
Object.keys(_state).forEach(function (key) {
|
|
22
|
-
if (key === "default" || key === "__esModule") return;
|
|
23
|
-
Object.defineProperty(exports, key, {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function get() {
|
|
26
|
-
return _state[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
package/lib/types/state.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/util.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.manageEntity = exports.manipulateItems = exports.manipulateDataItems = exports.manageDataEntity = undefined;
|
|
7
|
-
|
|
8
|
-
var _immutable = require("immutable");
|
|
9
|
-
|
|
10
|
-
var Immutable = _interopRequireWildcard(_immutable);
|
|
11
|
-
|
|
12
|
-
var _reselect = require("reselect");
|
|
13
|
-
|
|
14
|
-
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; } }
|
|
15
|
-
|
|
16
|
-
// simple item
|
|
17
|
-
|
|
18
|
-
/* eslint-disable no-duplicate-imports */
|
|
19
|
-
|
|
20
|
-
var manageEntity = function manageEntity(normalizrEntity) {
|
|
21
|
-
return function (item, state, keyID) {
|
|
22
|
-
// prevent rewrite
|
|
23
|
-
var old = state.get(String(item[keyID]));
|
|
24
|
-
|
|
25
|
-
if (typeof old === "undefined") {
|
|
26
|
-
return Immutable.Map(normalizrEntity(item));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return old;
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
manipulateItems = function manipulateItems() {
|
|
33
|
-
var sortKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "ID";
|
|
34
|
-
return (0, _reselect.createSelector)(function (data) {
|
|
35
|
-
return data;
|
|
36
|
-
}, function (data) {
|
|
37
|
-
return data.sortBy(function (current) {
|
|
38
|
-
return -current.get(sortKey);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// data item
|
|
44
|
-
|
|
45
|
-
var manageDataEntity = function manageDataEntity(normalizrEntity) {
|
|
46
|
-
return function (item, state, keyID) {
|
|
47
|
-
// prevent rewrite
|
|
48
|
-
var old = state.get(String(item[keyID]));
|
|
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;
|
package/lib/words.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var words = {
|
|
7
|
-
ThereWasAProblem: "There was a problem. Try again",
|
|
8
|
-
Showing: "Showing",
|
|
9
|
-
All: "all",
|
|
10
|
-
Of: "of",
|
|
11
|
-
LoadingData: "Loading data...",
|
|
12
|
-
LoadMore: "Load more"
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.default = words;
|
package/src/Info.jsx
DELETED
|
@@ -1,32 +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 } from "x25/utility";
|
|
13
|
-
|
|
14
|
-
const getNumberForm = (value : number, one : string, all : string) : string => {
|
|
15
|
-
if (value === 1) {
|
|
16
|
-
return `1 ${one}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return `${words.getNumberTense(value)} ${all}`;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const Info = ({ shown, total, one, all } : InfoPropTypes) => (
|
|
23
|
-
<div className="text-muted">
|
|
24
|
-
{`${words.Showing} `}
|
|
25
|
-
{
|
|
26
|
-
(shown === total) ? `${words.All} - ` : `${shown} ${words.Of}`
|
|
27
|
-
}
|
|
28
|
-
{` ${getNumberForm(total, one, all)}`}
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
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
|
-
};
|