redux-clerk2 2.0.16 → 2.0.17

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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
6
  exports.Perform = undefined;
7
7
 
@@ -31,205 +31,207 @@ var uuidv1 = require('uuid/v1');
31
31
  */
32
32
 
33
33
  var Perform = exports.Perform = function (_BaseAction) {
34
- _inherits(Perform, _BaseAction);
35
-
36
- /**
37
- * Create an instance of the bulk action.
38
- * @param {Object} config - The configuration for the action.
39
- */
40
- function Perform(config) {
41
- _classCallCheck(this, Perform);
42
-
43
- var _this = _possibleConstructorReturn(this, (Perform.__proto__ || Object.getPrototypeOf(Perform)).call(this, 'perform', config));
44
-
45
- _this.do = function (instance, record) {
46
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
47
- var _this$config = _this.config,
48
- uidField = _this$config.uidField,
49
- performer = _this$config.performer,
50
- actionSettings = _this$config.actionSettings,
51
- api = _this$config.api,
52
- notificationActions = _this$config.notificationActions,
53
- normalizationSettings = _this$config.normalizationSettings;
54
-
55
- //console.log('actionSettings', actionSettings);
56
- //console.log('api', api);
57
- //console.log('notificationAction', notificationAction);
58
-
59
- // Extend fetch options
60
-
61
- options = _extends({}, _this.defaultOptions, options);
62
-
63
- // Make sure record is an immutable map
64
- record = _immutable2.default.Iterable.isIterable(record) ? record : _immutable2.default.fromJS(record);
65
-
66
- // Validate instance key
67
- _this.validateInstance(instance);
68
-
69
- /*if(List.isList(record)){
70
- // ADD uids to new items
71
- record = record.map(item =>
72
- item.get(uidField) === undefined ? item.set("tmpid", uuidv1()) : item
73
- );
74
- }else{
75
- record.get(uidField) === undefined ? record.set("tmpid", uuidv1()) : record
76
- }*/
77
-
78
- return function (dispatch) {
79
-
80
- // Create data object to be dispatched with actions
81
- var isAsync = options.isAsync !== undefined ? options.isAsync : typeof performer === 'function' || actionSettings !== undefined;
82
- var data = { instance: instance, record: record, uidField: uidField, isAsync: isAsync, options: options, normalizationSettings: normalizationSettings };
83
- var msguid = uuidv1();
84
-
85
- // Call BaseAction.start with dispatch and the action data
86
- _this.start(dispatch, data);
87
-
88
- //console.log('action bulk:', data);
89
-
90
- if (actionSettings !== undefined && isAsync) {
91
- var notify = notificationActions.notify,
92
- notifyDismiss = notificationActions.notifyDismiss;
93
- // Extend config options
94
-
95
- var settings = _extends({}, actionSettings.default, actionSettings.performer);
96
- //console.log(settings);
97
- var displayLoading = settings.loading !== undefined && settings.loading !== '' ? true : false;
98
- var displayNotification = settings.notification !== undefined && settings.notification.type === 'notification' ? true : false;
99
- var displayMessage = settings.notification !== undefined && !displayNotification ? true : false;
100
-
101
- if (displayLoading) {
102
- dispatch(notify({
103
- id: msguid,
104
- title: settings.loading !== undefined ? settings.loading : 'Please wait',
105
- kind: 'loading'
106
- }));
107
- }
108
-
109
- //console.log('auto performer action');
110
- var successHandler = _this.success.bind(_this, dispatch, data);
111
- var errorHandler = _this.error.bind(_this, dispatch, data);
112
-
113
- var url = settings.url;
114
-
115
- var activeProperty = localStorage.activeProperty !== undefined && localStorage.activeProperty !== 'undefined' ? JSON.parse(localStorage.activeProperty) : null;
116
- var propertycode = activeProperty !== null ? activeProperty.propertycode : null;
117
-
118
- if (options && options.property_id) {
119
- var properties = localStorage.properties !== undefined && localStorage.properties !== 'undefined' ? JSON.parse(localStorage.properties) : [];
120
- var overrideProperty = properties.find(function (property) {
121
- return property.id === options.property_id;
122
- });
123
- if (overrideProperty && overrideProperty.propertycode) {
124
- propertycode = overrideProperty.propertycode;
125
- }
126
- }
127
-
128
- if (propertycode !== null) {
129
- url = settings.url.replace(/#@propertycode@#/i, propertycode);
130
- }
131
-
132
- //console.log(`options`, options);
133
-
134
- if (options.url) {
135
- url = url + '/' + options.url;
136
- }
137
-
138
- //return api.put(url, record.toJSON())
139
- return api({ method: options.method || 'get', url: url, data: record.toJSON() }).then(function (response) {
140
- if (displayLoading) {
141
- dispatch(notifyDismiss(msguid));
142
- }
143
-
144
- var message = '';
145
-
146
- if (response.data.success) {
147
- successHandler(response.data.data || [], null, response.data.updates || []);
148
- message = response.data.message;
149
-
150
- if (displayNotification) {
151
- dispatch(notify({
152
- title: settings.notification.title,
153
- message: settings.notification.message !== undefined ? settings.notification.message : message,
154
- type: 'notification',
155
- kind: settings.notification.kind !== undefined ? settings.notification.kind : 'success'
156
- }));
157
- } else if (displayMessage) {
158
- dispatch(notify({
159
- title: settings.notification.title !== undefined ? settings.notification.title : message,
160
- kind: settings.notification.kind !== undefined ? settings.notification.kind : 'success'
161
- }));
162
- }
163
- } else {
164
- errorHandler(response.data.error);
165
- message = response.data.error.message !== undefined ? response.data.error.message : response.data.error;
166
-
167
- dispatch(notify({
168
- title: settings.error.title,
169
- message: message || settings.error.message,
170
- type: 'notification',
171
- kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
172
- }));
173
- }
174
- return response.data;
175
- }).catch(function (error) {
176
- if (displayLoading) {
177
- dispatch(notifyDismiss(msguid));
178
- }
179
- errorHandler(error);
180
-
181
- if (error && error.response && error.response.status && error.response.status !== 401) {
182
-
183
- if (settings.error.type !== undefined && settings.error.type === 'notification') {
184
- dispatch(notify({
185
- title: settings.error.title,
186
- message: settings.error.message !== undefined ? settings.error.message : error.response.data.message,
187
- type: 'notification',
188
- kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
189
- }));
190
- } else {
191
- dispatch(notify({
192
- title: settings.error.title !== undefined ? settings.error.title : error.response.data.message,
193
- kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
194
- }));
195
- }
196
- }
197
- });
198
- } else {
199
- // If config.performer is provided, call it
200
- //if(isAsync) {
201
- // Prepare BaseAction.success and BaseAction.error handlers
202
- // by currying with dispatch
203
- var success = _this.success.bind(_this, dispatch, data);
204
- var error = _this.error.bind(_this, dispatch, data);
205
- return success(record || []);
206
- // Call performer
207
- //return performer(record, success, error);
208
- //}
209
- }
210
- };
211
- };
212
-
213
- return _this;
214
- }
215
-
216
- /**
217
- * Default options for the fetch action.
218
- */
219
-
220
-
221
- /**
222
- * Generate an action creator with the provided data.
223
- * @param {Object} record - item being updated.
224
- *
225
- * @returns {Function} - Returns the perform action thunk.
226
- */
227
-
228
-
229
- return Perform;
34
+ _inherits(Perform, _BaseAction);
35
+
36
+ /**
37
+ * Create an instance of the bulk action.
38
+ * @param {Object} config - The configuration for the action.
39
+ */
40
+ function Perform(config) {
41
+ _classCallCheck(this, Perform);
42
+
43
+ var _this = _possibleConstructorReturn(this, (Perform.__proto__ || Object.getPrototypeOf(Perform)).call(this, 'perform', config));
44
+
45
+ _this.do = function (instance, record) {
46
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
47
+ var _this$config = _this.config,
48
+ uidField = _this$config.uidField,
49
+ performer = _this$config.performer,
50
+ actionSettings = _this$config.actionSettings,
51
+ api = _this$config.api,
52
+ notificationActions = _this$config.notificationActions,
53
+ normalizationSettings = _this$config.normalizationSettings;
54
+
55
+ //console.log('actionSettings', actionSettings);
56
+ //console.log('api', api);
57
+ //console.log('notificationAction', notificationAction);
58
+
59
+ // Extend fetch options
60
+
61
+ options = _extends({}, _this.defaultOptions, options);
62
+
63
+ // Make sure record is an immutable map
64
+ record = _immutable2.default.Iterable.isIterable(record) ? record : _immutable2.default.fromJS(record);
65
+
66
+ // Validate instance key
67
+ _this.validateInstance(instance);
68
+
69
+ /*if(List.isList(record)){
70
+ // ADD uids to new items
71
+ record = record.map(item =>
72
+ item.get(uidField) === undefined ? item.set("tmpid", uuidv1()) : item
73
+ );
74
+ }else{
75
+ record.get(uidField) === undefined ? record.set("tmpid", uuidv1()) : record
76
+ }*/
77
+
78
+ return function (dispatch) {
79
+
80
+ // Create data object to be dispatched with actions
81
+ var isAsync = options.isAsync !== undefined ? options.isAsync : typeof performer === 'function' || actionSettings !== undefined;
82
+ var data = { instance: instance, record: record, uidField: uidField, isAsync: isAsync, options: options, normalizationSettings: normalizationSettings };
83
+ var msguid = uuidv1();
84
+
85
+ // Call BaseAction.start with dispatch and the action data
86
+ _this.start(dispatch, data);
87
+
88
+ //console.log('action bulk:', data);
89
+
90
+ if (actionSettings !== undefined && isAsync) {
91
+ var notify = notificationActions.notify,
92
+ notifyDismiss = notificationActions.notifyDismiss;
93
+ // Extend config options
94
+
95
+ var settings = _extends({}, actionSettings.default, actionSettings.performer);
96
+ //console.log(settings);
97
+ var displayLoading = settings.loading !== undefined && settings.loading !== '' ? true : false;
98
+ var displayNotification = settings.notification !== undefined && settings.notification.type === 'notification' ? true : false;
99
+ var displayMessage = settings.notification !== undefined && !displayNotification ? true : false;
100
+
101
+ if (displayLoading) {
102
+ dispatch(notify({
103
+ id: msguid,
104
+ title: settings.loading !== undefined ? settings.loading : 'Please wait',
105
+ kind: 'loading'
106
+ }));
107
+ }
108
+
109
+ //console.log('auto performer action');
110
+ var successHandler = _this.success.bind(_this, dispatch, data);
111
+ var errorHandler = _this.error.bind(_this, dispatch, data);
112
+
113
+ var url = settings.url;
114
+
115
+ var activeProperty = localStorage.activeProperty !== undefined && localStorage.activeProperty !== 'undefined' ? JSON.parse(localStorage.activeProperty) : null;
116
+ var propertycode = activeProperty !== null ? activeProperty.propertycode : null;
117
+
118
+ if (options && options.property_id) {
119
+ var properties = localStorage.properties !== undefined && localStorage.properties !== 'undefined' ? JSON.parse(localStorage.properties) : [];
120
+ var overrideProperty = properties.find(function (property) {
121
+ return property.id === options.property_id;
122
+ });
123
+ if (overrideProperty && overrideProperty.propertycode) {
124
+ propertycode = overrideProperty.propertycode;
125
+ }
126
+ }
127
+
128
+ if (propertycode !== null) {
129
+ url = settings.url.replace(/#@propertycode@#/i, propertycode);
130
+ }
131
+
132
+ //console.log(`options`, options);
133
+
134
+ if (options.url) {
135
+ url = url + '/' + options.url;
136
+ }
137
+
138
+ //return api.put(url, record.toJSON())
139
+ return api({ method: options.method || 'get', url: url, data: record.toJSON() }).then(function (response) {
140
+ if (displayLoading) {
141
+ dispatch(notifyDismiss(msguid));
142
+ }
143
+
144
+ var message = '';
145
+
146
+ if (response.data.success) {
147
+ successHandler(response.data.data || [], null, response.data.updates || []);
148
+ message = response.data.message;
149
+
150
+ if (settings.notification !== undefined) {
151
+ if (settings.notification.type !== undefined && settings.notification.type === 'notification') {
152
+ dispatch(notify({
153
+ title: settings.notification.title,
154
+ message: settings.notification.message !== undefined ? settings.notification.message : message,
155
+ type: 'notification',
156
+ kind: settings.notification.kind !== undefined ? settings.notification.kind : 'success'
157
+ }));
158
+ } else {
159
+ dispatch(notify({
160
+ title: settings.notification.title !== undefined ? settings.notification.title : message, //response.data.message,
161
+ kind: settings.notification.kind !== undefined ? settings.notification.kind : 'success'
162
+ }));
163
+ }
164
+ }
165
+ } else {
166
+ errorHandler(response.data.error);
167
+ message = response.data.error.message !== undefined ? response.data.error.message : response.data.error;
168
+
169
+ dispatch(notify({
170
+ title: settings.error.title,
171
+ message: message || settings.error.message,
172
+ type: 'notification',
173
+ kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
174
+ }));
175
+ }
176
+ return response.data;
177
+ }).catch(function (error) {
178
+ if (displayLoading) {
179
+ dispatch(notifyDismiss(msguid));
180
+ }
181
+ errorHandler(error);
182
+
183
+ if (error && error.response && error.response.status && error.response.status !== 401) {
184
+
185
+ if (settings.error.type !== undefined && settings.error.type === 'notification') {
186
+ dispatch(notify({
187
+ title: settings.error.title,
188
+ message: error.response.data.message ? error.response.data.message : settings.error.message !== undefined ? settings.error.message : '',
189
+ type: 'notification',
190
+ kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
191
+ }));
192
+ } else {
193
+ dispatch(notify({
194
+ title: error.response.data.message ? error.response.data.message : settings.error.title !== undefined ? settings.error.title : '',
195
+ kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
196
+ }));
197
+ }
198
+ }
199
+ });
200
+ } else {
201
+ // If config.performer is provided, call it
202
+ //if(isAsync) {
203
+ // Prepare BaseAction.success and BaseAction.error handlers
204
+ // by currying with dispatch
205
+ var success = _this.success.bind(_this, dispatch, data);
206
+ var error = _this.error.bind(_this, dispatch, data);
207
+ return success(record || []);
208
+ // Call performer
209
+ //return performer(record, success, error);
210
+ //}
211
+ }
212
+ };
213
+ };
214
+
215
+ return _this;
216
+ }
217
+
218
+ /**
219
+ * Default options for the fetch action.
220
+ */
221
+
222
+
223
+ /**
224
+ * Generate an action creator with the provided data.
225
+ * @param {Object} record - item being updated.
226
+ *
227
+ * @returns {Function} - Returns the perform action thunk.
228
+ */
229
+
230
+
231
+ return Perform;
230
232
  }(_BaseAction3.default);
231
233
 
232
234
  Perform.defaultOptions = {
233
- appendResponse: true,
234
- normalizeResponse: false,
235
- property_id: null };
235
+ appendResponse: true,
236
+ normalizeResponse: false,
237
+ property_id: null };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redux-clerk2",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "description": "Redux Clerk handles the async CRUD in your Redux App.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -126,30 +126,32 @@ export class Perform extends BaseAction {
126
126
  successHandler(response.data.data || [], null, response.data.updates || []);
127
127
  message = response.data.message;
128
128
 
129
- if(displayNotification){
130
- dispatch(notify({
131
- title: settings.notification.title,
132
- message: (settings.notification.message !== undefined)?settings.notification.message:message,
133
- type: 'notification',
134
- kind: (settings.notification.kind !== undefined)?settings.notification.kind:'success'
135
- }));
136
- }else if(displayMessage){
137
- dispatch(notify({
138
- title: (settings.notification.title !== undefined)?settings.notification.title:message,
139
- kind: (settings.notification.kind !== undefined)?settings.notification.kind:'success'
140
- }));
141
- }
129
+ if(settings.notification !== undefined ){
130
+ if(settings.notification.type !== undefined && settings.notification.type === 'notification'){
131
+ dispatch(notify({
132
+ title: settings.notification.title,
133
+ message: (settings.notification.message !== undefined)?settings.notification.message:message,
134
+ type: 'notification',
135
+ kind: (settings.notification.kind !== undefined)?settings.notification.kind:'success'
136
+ }));
137
+ }else{
138
+ dispatch(notify({
139
+ title: (settings.notification.title !== undefined)?settings.notification.title:message,//response.data.message,
140
+ kind: (settings.notification.kind !== undefined)?settings.notification.kind:'success'
141
+ }));
142
+ }
143
+ }
142
144
 
143
145
  }else{
144
146
  errorHandler(response.data.error);
145
147
  message = (response.data.error.message !== undefined)?response.data.error.message:response.data.error;
146
148
 
147
149
  dispatch(notify({
148
- title: settings.error.title,
149
- message: message || settings.error.message,
150
- type: 'notification',
151
- kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
152
- }));
150
+ title: settings.error.title,
151
+ message: message || settings.error.message,
152
+ type: 'notification',
153
+ kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
154
+ }));
153
155
  }
154
156
  return response.data;
155
157
  })
@@ -164,13 +166,13 @@ export class Perform extends BaseAction {
164
166
  if(settings.error.type !== undefined && settings.error.type === 'notification'){
165
167
  dispatch(notify({
166
168
  title: settings.error.title,
167
- message: (settings.error.message !== undefined)?settings.error.message:error.response.data.message,
169
+ message: error.response.data.message ? error.response.data.message : (settings.error.message !== undefined)?settings.error.message:'',
168
170
  type: 'notification',
169
171
  kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
170
172
  }));
171
173
  }else{
172
174
  dispatch(notify({
173
- title: (settings.error.title !== undefined)?settings.error.title:error.response.data.message,
175
+ title: error.response.data.message ? error.response.data.message : (settings.error.title !== undefined)?settings.error.title:'',
174
176
  kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
175
177
  }));
176
178
  }