@panneau/core 0.6.70-alpha.0 → 0.6.73
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/es/Panneau.js +33 -35
- package/es/components/App.js +5 -5
- package/es/components/Layout.js +4 -3
- package/es/components/Panneau.js +9 -11
- package/es/components/pages/Account.js +2 -1
- package/es/components/pages/ResourceCreate.js +2 -2
- package/es/components/pages/ResourceForm.js +39 -39
- package/es/components/pages/ResourceIndex.js +102 -64
- package/es/lib/ComponentsCollection.js +9 -11
- package/es/lib/ResourceApi.js +4 -4
- package/es/lib/messageWithValues.js +3 -3
- package/es/lib/parseDefinition.js +11 -10
- package/es/lib/react-container/Container.js +7 -6
- package/es/lib/react-container/IntlContainer.js +7 -6
- package/es/lib/react-container/RouterContainer.js +2 -1
- package/es/lib/react-container/StoreContainer.js +5 -5
- package/es/lib/react-container/UrlGenerator.js +6 -5
- package/es/lib/react-container/UrlGeneratorContainer.js +25 -14
- package/es/lib/react-container/configureStore.dev.js +2 -2
- package/es/lib/react-container/withUrlGenerator.js +5 -5
- package/es/lib/requests.js +8 -6
- package/es/lib/withComponentsCollection.js +6 -6
- package/es/lib/withDefinition.js +5 -5
- package/es/lib/withFieldsCollection.js +2 -2
- package/es/lib/withFormsCollection.js +2 -2
- package/es/lib/withLayoutsCollection.js +2 -2
- package/es/lib/withListsCollection.js +2 -2
- package/es/lib/withModalsCollection.js +2 -2
- package/es/lib/withPreviewsCollection.js +2 -2
- package/es/lib/withResourceApi.js +11 -13
- package/es/reducers/AuthReducer.js +3 -3
- package/es/reducers/PanneauReducer.js +4 -4
- package/lib/Panneau.js +35 -36
- package/lib/actions/PanneauActions.js +1 -1
- package/lib/components/App.js +11 -7
- package/lib/components/Layout.js +11 -5
- package/lib/components/Panneau.js +15 -13
- package/lib/components/index.js +4 -4
- package/lib/components/pages/Account.js +9 -4
- package/lib/components/pages/ResourceCreate.js +8 -4
- package/lib/components/pages/ResourceForm.js +47 -42
- package/lib/components/pages/ResourceIndex.js +110 -67
- package/lib/index.js +47 -47
- package/lib/lib/ComponentsCollection.js +9 -11
- package/lib/lib/PropTypes.js +1 -1
- package/lib/lib/ResourceApi.js +4 -4
- package/lib/lib/messageWithValues.js +3 -3
- package/lib/lib/parseDefinition.js +12 -10
- package/lib/lib/react-container/Container.js +14 -8
- package/lib/lib/react-container/IntlContainer.js +14 -8
- package/lib/lib/react-container/RouterContainer.js +2 -1
- package/lib/lib/react-container/StoreContainer.js +11 -7
- package/lib/lib/react-container/UrlGenerator.js +7 -5
- package/lib/lib/react-container/UrlGeneratorContainer.js +25 -14
- package/lib/lib/react-container/configureStore.dev.js +2 -2
- package/lib/lib/react-container/index.js +5 -5
- package/lib/lib/react-container/withUrlGenerator.js +11 -7
- package/lib/lib/requests.js +10 -7
- package/lib/lib/withComponentsCollection.js +12 -8
- package/lib/lib/withDefinition.js +11 -7
- package/lib/lib/withFieldsCollection.js +8 -4
- package/lib/lib/withFormsCollection.js +8 -4
- package/lib/lib/withLayoutsCollection.js +8 -4
- package/lib/lib/withListsCollection.js +8 -4
- package/lib/lib/withModalsCollection.js +8 -4
- package/lib/lib/withPreviewsCollection.js +8 -4
- package/lib/lib/withResourceApi.js +17 -15
- package/lib/reducers/AuthReducer.js +3 -3
- package/lib/reducers/PanneauReducer.js +4 -4
- package/package.json +3 -3
- package/src/components/Panneau.jsx +0 -1
- package/src/components/pages/ResourceIndex.jsx +62 -13
- package/src/lib/react-container/UrlGeneratorContainer.jsx +17 -10
- package/src/styles/pages/resource-index.scss +16 -1
- package/es/components/pages/_ResourceIndexOld.js +0 -459
- package/lib/components/pages/_ResourceIndexOld.js +0 -488
- package/src/components/pages/_ResourceIndexOld.jsx +0 -428
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
7
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
9
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
10
|
-
|
|
11
|
-
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
-
|
|
13
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
-
|
|
15
|
-
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
16
|
-
import React, { Component } from 'react';
|
|
17
|
-
import PropTypes from 'prop-types';
|
|
18
|
-
import { Link } from 'react-router-dom';
|
|
19
|
-
import get from 'lodash/get';
|
|
20
|
-
import isString from 'lodash/isString';
|
|
21
|
-
import isObject from 'lodash/isObject';
|
|
22
|
-
import classNames from 'classnames';
|
|
23
|
-
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
|
24
|
-
import Loading from '../partials/Loading';
|
|
25
|
-
import * as PanneauPropTypes from '../../lib/PropTypes';
|
|
26
|
-
import withResourceApi from '../../lib/withResourceApi';
|
|
27
|
-
import withListsCollection from '../../lib/withListsCollection';
|
|
28
|
-
var styles = {
|
|
29
|
-
"container": "panneau-core-resource-index-container",
|
|
30
|
-
"header": "panneau-core-resource-index-header",
|
|
31
|
-
"cols": "panneau-core-resource-index-cols",
|
|
32
|
-
"col": "panneau-core-resource-index-col",
|
|
33
|
-
"listContainer": "panneau-core-resource-index-listContainer",
|
|
34
|
-
"list": "panneau-core-resource-index-list",
|
|
35
|
-
"filters": "panneau-core-resource-index-filters",
|
|
36
|
-
"loading": "panneau-core-resource-index-loading",
|
|
37
|
-
"inner": "panneau-core-resource-index-inner",
|
|
38
|
-
"middle": "panneau-core-resource-index-middle",
|
|
39
|
-
"alone": "panneau-core-resource-index-alone"
|
|
40
|
-
};
|
|
41
|
-
var messages = defineMessages({
|
|
42
|
-
add: {
|
|
43
|
-
"id": "core.buttons.resources.add",
|
|
44
|
-
"defaultMessage": "Add {name}"
|
|
45
|
-
},
|
|
46
|
-
title: {
|
|
47
|
-
"id": "core.titles.resources.index",
|
|
48
|
-
"defaultMessage": "{name}"
|
|
49
|
-
},
|
|
50
|
-
confirmDelete: {
|
|
51
|
-
"id": "core.resources.index.confirm_delete",
|
|
52
|
-
"defaultMessage": "Are you sure you want to delete this item from {name}?"
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
var propTypes = {
|
|
56
|
-
intl: PanneauPropTypes.intl.isRequired,
|
|
57
|
-
listsCollection: PanneauPropTypes.componentsCollection.isRequired,
|
|
58
|
-
resource: PanneauPropTypes.resource.isRequired,
|
|
59
|
-
resourceApi: PanneauPropTypes.resourceApi.isRequired,
|
|
60
|
-
query: PropTypes.shape({
|
|
61
|
-
page: PropTypes.string
|
|
62
|
-
}),
|
|
63
|
-
items: PropTypes.arrayOf(PropTypes.object),
|
|
64
|
-
title: PanneauPropTypes.message,
|
|
65
|
-
errors: PropTypes.arrayOf(PropTypes.string),
|
|
66
|
-
showAddButton: PropTypes.bool,
|
|
67
|
-
addButtonLabel: PanneauPropTypes.message,
|
|
68
|
-
confirmDeleteMessage: PanneauPropTypes.message,
|
|
69
|
-
getResourceActionUrl: PropTypes.func.isRequired,
|
|
70
|
-
gotoResourceAction: PropTypes.func.isRequired
|
|
71
|
-
};
|
|
72
|
-
var defaultProps = {
|
|
73
|
-
query: null,
|
|
74
|
-
items: null,
|
|
75
|
-
title: messages.title,
|
|
76
|
-
errors: null,
|
|
77
|
-
showAddButton: true,
|
|
78
|
-
addButtonLabel: messages.add,
|
|
79
|
-
confirmDeleteMessage: messages.confirmDelete
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
var ResourceIndexOld = /*#__PURE__*/function (_Component) {
|
|
83
|
-
_inherits(ResourceIndexOld, _Component);
|
|
84
|
-
|
|
85
|
-
var _super = _createSuper(ResourceIndexOld);
|
|
86
|
-
|
|
87
|
-
_createClass(ResourceIndexOld, null, [{
|
|
88
|
-
key: "getDerivedStateFromProps",
|
|
89
|
-
value: function getDerivedStateFromProps(_ref, _ref2) {
|
|
90
|
-
var nextQuery = _ref.query,
|
|
91
|
-
nextErrors = _ref.errors;
|
|
92
|
-
var query = _ref2.query,
|
|
93
|
-
errors = _ref2.errors;
|
|
94
|
-
var queryChanged = nextQuery !== query;
|
|
95
|
-
var errorsChanged = nextErrors !== errors;
|
|
96
|
-
|
|
97
|
-
if (queryChanged || errorsChanged) {
|
|
98
|
-
return {
|
|
99
|
-
query: queryChanged ? nextQuery : query,
|
|
100
|
-
errors: errorsChanged ? nextErrors : errors,
|
|
101
|
-
isLoading: queryChanged
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
}]);
|
|
108
|
-
|
|
109
|
-
function ResourceIndexOld(props) {
|
|
110
|
-
var _this;
|
|
111
|
-
|
|
112
|
-
_classCallCheck(this, ResourceIndexOld);
|
|
113
|
-
|
|
114
|
-
_this = _super.call(this, props);
|
|
115
|
-
_this.onItemsLoaded = _this.onItemsLoaded.bind(_assertThisInitialized(_this));
|
|
116
|
-
_this.onItemsLoadError = _this.onItemsLoadError.bind(_assertThisInitialized(_this));
|
|
117
|
-
_this.onClickAction = _this.onClickAction.bind(_assertThisInitialized(_this));
|
|
118
|
-
_this.onItemDeleted = _this.onItemDeleted.bind(_assertThisInitialized(_this));
|
|
119
|
-
_this.state = {
|
|
120
|
-
isLoading: props.items === null,
|
|
121
|
-
query: null,
|
|
122
|
-
// eslint-disable-line react/no-unused-state
|
|
123
|
-
items: props.items,
|
|
124
|
-
pagination: null,
|
|
125
|
-
errors: props.errors
|
|
126
|
-
};
|
|
127
|
-
return _this;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
_createClass(ResourceIndexOld, [{
|
|
131
|
-
key: "componentDidMount",
|
|
132
|
-
value: function componentDidMount() {
|
|
133
|
-
var items = this.state.items;
|
|
134
|
-
|
|
135
|
-
if (items === null) {
|
|
136
|
-
this.loadItems();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}, {
|
|
140
|
-
key: "componentDidUpdate",
|
|
141
|
-
value: function componentDidUpdate(_ref3, _ref4) {
|
|
142
|
-
var prevQuery = _ref3.query;
|
|
143
|
-
var prevItems = _ref4.items;
|
|
144
|
-
var query = this.props.query;
|
|
145
|
-
var items = this.state.items;
|
|
146
|
-
var itemsChanged = prevItems !== items;
|
|
147
|
-
var queryChanged = prevQuery !== query;
|
|
148
|
-
|
|
149
|
-
if (itemsChanged && items === null || queryChanged) {
|
|
150
|
-
this.loadItems();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}, {
|
|
154
|
-
key: "onItemsLoaded",
|
|
155
|
-
value: function onItemsLoaded(data) {
|
|
156
|
-
if (this.isPaginated()) {
|
|
157
|
-
var items = data.data,
|
|
158
|
-
pagination = _objectWithoutProperties(data, ["data"]);
|
|
159
|
-
|
|
160
|
-
this.setState({
|
|
161
|
-
items: items,
|
|
162
|
-
pagination: pagination,
|
|
163
|
-
isLoading: false
|
|
164
|
-
});
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.setState({
|
|
169
|
-
items: data,
|
|
170
|
-
isLoading: false
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "onItemsLoadError",
|
|
175
|
-
value: function onItemsLoadError(errors) {
|
|
176
|
-
this.setState({
|
|
177
|
-
errors: errors,
|
|
178
|
-
isLoading: false
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}, {
|
|
182
|
-
key: "onClickAction",
|
|
183
|
-
value: function onClickAction(e, action, it) {
|
|
184
|
-
var _this$props = this.props,
|
|
185
|
-
getResourceActionUrl = _this$props.getResourceActionUrl,
|
|
186
|
-
gotoResourceAction = _this$props.gotoResourceAction;
|
|
187
|
-
var useRouter = get(action, 'useRouter', true);
|
|
188
|
-
|
|
189
|
-
switch (action.id) {
|
|
190
|
-
case 'edit':
|
|
191
|
-
case 'show':
|
|
192
|
-
if (useRouter) {
|
|
193
|
-
gotoResourceAction(action.id, it.id);
|
|
194
|
-
} else {
|
|
195
|
-
window.location.href = getResourceActionUrl(action.id);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
break;
|
|
199
|
-
|
|
200
|
-
case 'delete':
|
|
201
|
-
{
|
|
202
|
-
var hasPage = get(action, 'hasPage', false);
|
|
203
|
-
|
|
204
|
-
if (!hasPage) {
|
|
205
|
-
this.deleteItem(it.id);
|
|
206
|
-
} else if (useRouter) {
|
|
207
|
-
gotoResourceAction(action.id, it.id);
|
|
208
|
-
} else {
|
|
209
|
-
window.location.href = getResourceActionUrl(action.id);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
default:
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}, {
|
|
220
|
-
key: "onItemDeleted",
|
|
221
|
-
value: function onItemDeleted(_ref5) {
|
|
222
|
-
var id = _ref5.id;
|
|
223
|
-
this.setState(function (_ref6) {
|
|
224
|
-
var items = _ref6.items;
|
|
225
|
-
return {
|
|
226
|
-
items: items.filter(function (it) {
|
|
227
|
-
return it.id !== id;
|
|
228
|
-
})
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}, {
|
|
233
|
-
key: "isPaginated",
|
|
234
|
-
value: function isPaginated() {
|
|
235
|
-
var resource = this.props.resource;
|
|
236
|
-
return get(resource, 'lists.index.pagination', get(resource, 'lists.pagination', false));
|
|
237
|
-
}
|
|
238
|
-
}, {
|
|
239
|
-
key: "loadItems",
|
|
240
|
-
value: function loadItems() {
|
|
241
|
-
var _this$props2 = this.props,
|
|
242
|
-
resourceApi = _this$props2.resourceApi,
|
|
243
|
-
query = _this$props2.query;
|
|
244
|
-
var params = {};
|
|
245
|
-
|
|
246
|
-
if (this.isPaginated()) {
|
|
247
|
-
var page = query.page || null;
|
|
248
|
-
|
|
249
|
-
if (page !== null) {
|
|
250
|
-
params.page = page;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
resourceApi.index(params).then(this.onItemsLoaded)["catch"](this.onItemsLoadError);
|
|
255
|
-
}
|
|
256
|
-
}, {
|
|
257
|
-
key: "deleteItem",
|
|
258
|
-
value: function deleteItem(id) {
|
|
259
|
-
var _this$props3 = this.props,
|
|
260
|
-
resource = _this$props3.resource,
|
|
261
|
-
resourceApi = _this$props3.resourceApi,
|
|
262
|
-
intl = _this$props3.intl,
|
|
263
|
-
confirmDeleteMessage = _this$props3.confirmDeleteMessage;
|
|
264
|
-
var name = resource.name;
|
|
265
|
-
var confirmMessage = get(resource, 'messages.confirm_delete', confirmDeleteMessage);
|
|
266
|
-
var message = isObject(confirmMessage) && typeof confirmMessage.id !== 'undefined' ? intl.formatMessage(confirmMessage, {
|
|
267
|
-
name: name,
|
|
268
|
-
id: id
|
|
269
|
-
}) : confirmMessage; // eslint-disable-next-line no-alert
|
|
270
|
-
|
|
271
|
-
if (window.confirm(message)) {
|
|
272
|
-
resourceApi.destroy(id).then(this.onItemDeleted);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}, {
|
|
276
|
-
key: "renderAddButton",
|
|
277
|
-
value: function renderAddButton() {
|
|
278
|
-
var _this$props4 = this.props,
|
|
279
|
-
addButtonLabel = _this$props4.addButtonLabel,
|
|
280
|
-
resource = _this$props4.resource,
|
|
281
|
-
getResourceActionUrl = _this$props4.getResourceActionUrl;
|
|
282
|
-
var resourceType = get(resource, 'type', 'default');
|
|
283
|
-
var isTyped = resourceType === 'typed';
|
|
284
|
-
var types = isTyped ? get(resource, 'types', []) : null;
|
|
285
|
-
var buttonMessage = get(resource, 'messages.buttons.resources.add', null);
|
|
286
|
-
var name = get(resource, 'messages.names.a', get(resource, 'messages.name', resource.name));
|
|
287
|
-
var buttonLabel = isString(addButtonLabel) ? addButtonLabel : /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, addButtonLabel, {
|
|
288
|
-
values: {
|
|
289
|
-
name: name
|
|
290
|
-
}
|
|
291
|
-
}));
|
|
292
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
293
|
-
className: classNames({
|
|
294
|
-
'btn-group': true
|
|
295
|
-
})
|
|
296
|
-
}, isTyped ? /*#__PURE__*/React.createElement("button", {
|
|
297
|
-
type: "button",
|
|
298
|
-
className: classNames({
|
|
299
|
-
btn: true,
|
|
300
|
-
'btn-primary': true,
|
|
301
|
-
'dropdown-toggle': isTyped
|
|
302
|
-
}),
|
|
303
|
-
"data-toggle": "dropdown",
|
|
304
|
-
"aria-haspopup": "true",
|
|
305
|
-
"aria-expanded": "false"
|
|
306
|
-
}, buttonMessage !== null ? buttonMessage : buttonLabel, ' ', /*#__PURE__*/React.createElement("span", {
|
|
307
|
-
className: "caret"
|
|
308
|
-
})) : /*#__PURE__*/React.createElement(Link, {
|
|
309
|
-
to: getResourceActionUrl('create'),
|
|
310
|
-
className: classNames({
|
|
311
|
-
btn: true,
|
|
312
|
-
'btn-primary': true
|
|
313
|
-
})
|
|
314
|
-
}, buttonMessage !== null ? buttonMessage : buttonLabel), isTyped ? /*#__PURE__*/React.createElement("div", {
|
|
315
|
-
className: "dropdown-menu"
|
|
316
|
-
}, types.map(function (_ref7) {
|
|
317
|
-
var id = _ref7.id,
|
|
318
|
-
label = _ref7.label;
|
|
319
|
-
return /*#__PURE__*/React.createElement(Link, {
|
|
320
|
-
key: "add-button-".concat(id),
|
|
321
|
-
to: "".concat(getResourceActionUrl('create'), "?type=").concat(id),
|
|
322
|
-
className: "dropdown-item"
|
|
323
|
-
}, label);
|
|
324
|
-
})) : null);
|
|
325
|
-
}
|
|
326
|
-
}, {
|
|
327
|
-
key: "renderHeader",
|
|
328
|
-
value: function renderHeader() {
|
|
329
|
-
var _classNames2;
|
|
330
|
-
|
|
331
|
-
var _this$props5 = this.props,
|
|
332
|
-
resource = _this$props5.resource,
|
|
333
|
-
title = _this$props5.title,
|
|
334
|
-
showAddButton = _this$props5.showAddButton;
|
|
335
|
-
var message = get(resource, 'messages.titles.resources.index', null);
|
|
336
|
-
var name = get(resource, 'messages.names.plural', get(resource, 'messages.name', resource.name));
|
|
337
|
-
var defaultTitle = isString(title) ? title : /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, title, {
|
|
338
|
-
values: {
|
|
339
|
-
name: name
|
|
340
|
-
}
|
|
341
|
-
}));
|
|
342
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
343
|
-
className: classNames(_defineProperty({
|
|
344
|
-
'py-4': true
|
|
345
|
-
}, styles.header, true))
|
|
346
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
347
|
-
className: styles.cols
|
|
348
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
349
|
-
className: styles.col
|
|
350
|
-
}, /*#__PURE__*/React.createElement("h1", {
|
|
351
|
-
className: classNames([styles.title, 'mb-0', 'mt-0'])
|
|
352
|
-
}, message !== null ? message : defaultTitle)), /*#__PURE__*/React.createElement("div", {
|
|
353
|
-
className: classNames((_classNames2 = {}, _defineProperty(_classNames2, styles.col, true), _defineProperty(_classNames2, 'text-right', true), _classNames2))
|
|
354
|
-
}, showAddButton ? this.renderAddButton() : null)), this.renderErrors());
|
|
355
|
-
}
|
|
356
|
-
}, {
|
|
357
|
-
key: "renderErrors",
|
|
358
|
-
value: function renderErrors() {
|
|
359
|
-
var errors = this.state.errors;
|
|
360
|
-
var errorsClassNames = classNames(_defineProperty({}, styles.errors, true));
|
|
361
|
-
/* eslint-disable react/no-array-index-key */
|
|
362
|
-
|
|
363
|
-
return errors !== null && errors.length > 1 ? /*#__PURE__*/React.createElement("div", {
|
|
364
|
-
className: errorsClassNames
|
|
365
|
-
}, /*#__PURE__*/React.createElement("ul", null, errors.map(function (error, index) {
|
|
366
|
-
return /*#__PURE__*/React.createElement("li", {
|
|
367
|
-
key: "error-".concat(index)
|
|
368
|
-
}, error);
|
|
369
|
-
}))) : null;
|
|
370
|
-
/* eslint-enable react/no-array-index-key */
|
|
371
|
-
}
|
|
372
|
-
}, {
|
|
373
|
-
key: "renderList",
|
|
374
|
-
value: function renderList() {
|
|
375
|
-
var _this$props6 = this.props,
|
|
376
|
-
resource = _this$props6.resource,
|
|
377
|
-
listsCollection = _this$props6.listsCollection;
|
|
378
|
-
var items = this.state.items;
|
|
379
|
-
var list = get(resource, 'lists.index', get(resource, 'lists', {}));
|
|
380
|
-
|
|
381
|
-
var type = list.type,
|
|
382
|
-
listProps = _objectWithoutProperties(list, ["type"]);
|
|
383
|
-
|
|
384
|
-
var ListComponent = listsCollection.getComponent(type || 'table');
|
|
385
|
-
var listClassNames = classNames(_defineProperty({}, styles.list, true));
|
|
386
|
-
return ListComponent !== null ? /*#__PURE__*/React.createElement("div", {
|
|
387
|
-
className: listClassNames
|
|
388
|
-
}, /*#__PURE__*/React.createElement(ListComponent, _extends({
|
|
389
|
-
items: items || [],
|
|
390
|
-
onClickAction: this.onClickAction
|
|
391
|
-
}, listProps))) : null;
|
|
392
|
-
} // eslint-disable-next-line class-methods-use-this
|
|
393
|
-
|
|
394
|
-
}, {
|
|
395
|
-
key: "renderPagination",
|
|
396
|
-
value: function renderPagination() {
|
|
397
|
-
var _this$props7 = this.props,
|
|
398
|
-
getResourceActionUrl = _this$props7.getResourceActionUrl,
|
|
399
|
-
listsCollection = _this$props7.listsCollection;
|
|
400
|
-
var pagination = this.state.pagination;
|
|
401
|
-
var Pagination = listsCollection.getComponent('pagination');
|
|
402
|
-
return /*#__PURE__*/React.createElement(Pagination, {
|
|
403
|
-
total: pagination.total,
|
|
404
|
-
perPage: pagination.per_page,
|
|
405
|
-
currentPage: pagination.current_page,
|
|
406
|
-
lastPage: pagination.last_page,
|
|
407
|
-
url: getResourceActionUrl('index')
|
|
408
|
-
});
|
|
409
|
-
} // eslint-disable-next-line class-methods-use-this
|
|
410
|
-
|
|
411
|
-
}, {
|
|
412
|
-
key: "renderLoading",
|
|
413
|
-
value: function renderLoading() {
|
|
414
|
-
var _classNames5;
|
|
415
|
-
|
|
416
|
-
var items = this.state.items;
|
|
417
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
418
|
-
className: classNames((_classNames5 = {}, _defineProperty(_classNames5, styles.loading, true), _defineProperty(_classNames5, styles.alone, items === null), _classNames5))
|
|
419
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
420
|
-
className: styles.inner
|
|
421
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
422
|
-
className: styles.middle
|
|
423
|
-
}, /*#__PURE__*/React.createElement(Loading, {
|
|
424
|
-
loading: true
|
|
425
|
-
}))));
|
|
426
|
-
}
|
|
427
|
-
}, {
|
|
428
|
-
key: "render",
|
|
429
|
-
value: function render() {
|
|
430
|
-
var _this$state = this.state,
|
|
431
|
-
items = _this$state.items,
|
|
432
|
-
pagination = _this$state.pagination,
|
|
433
|
-
isLoading = _this$state.isLoading;
|
|
434
|
-
var containerClassNames = classNames(_defineProperty({}, styles.container, true));
|
|
435
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
436
|
-
className: containerClassNames
|
|
437
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
438
|
-
className: "container"
|
|
439
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
440
|
-
className: "row justify-content-md-center"
|
|
441
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
442
|
-
className: "col-lg-8"
|
|
443
|
-
}, this.renderHeader(), /*#__PURE__*/React.createElement("div", {
|
|
444
|
-
className: styles.listContainer
|
|
445
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
446
|
-
className: styles.list
|
|
447
|
-
}, items !== null ? this.renderList() : null), isLoading ? this.renderLoading() : null), pagination !== null && pagination.last_page > 1 ? this.renderPagination() : null))));
|
|
448
|
-
}
|
|
449
|
-
}]);
|
|
450
|
-
|
|
451
|
-
return ResourceIndexOld;
|
|
452
|
-
}(Component);
|
|
453
|
-
|
|
454
|
-
ResourceIndexOld.propTypes = propTypes;
|
|
455
|
-
ResourceIndexOld.defaultProps = defaultProps;
|
|
456
|
-
var WithResourceApi = withResourceApi()(ResourceIndexOld);
|
|
457
|
-
var WithListsCollectionContainer = withListsCollection()(WithResourceApi);
|
|
458
|
-
var WithIntlContainer = injectIntl(WithListsCollectionContainer);
|
|
459
|
-
export default WithIntlContainer;
|