redux-clerk2 2.0.11 → 2.0.16

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.
@@ -137,21 +137,20 @@ var Create = exports.Create = function (_BaseAction) {
137
137
 
138
138
  if (response.data.success) {
139
139
  successHandler(response.data.data || [], null, response.data.updates || []);
140
-
141
140
  message = response.data.message;
142
141
 
143
142
  if (settings.notification !== undefined) {
144
- if (settings.notification.type !== undefined && settings.notification.type === "notification") {
143
+ if (settings.notification.type !== undefined && settings.notification.type === 'notification') {
145
144
  dispatch(notify({
146
145
  title: settings.notification.title,
147
146
  message: settings.notification.message !== undefined ? settings.notification.message : message,
148
- type: "notification",
149
- kind: settings.notification.kind !== undefined ? settings.notification.kind : "success"
147
+ type: 'notification',
148
+ kind: settings.notification.kind !== undefined ? settings.notification.kind : 'success'
150
149
  }));
151
150
  } else {
152
151
  dispatch(notify({
153
152
  title: settings.notification.title !== undefined ? settings.notification.title : message, //response.data.message,
154
- kind: settings.notification.kind !== undefined ? settings.notification.kind : "success"
153
+ kind: settings.notification.kind !== undefined ? settings.notification.kind : 'success'
155
154
  }));
156
155
  }
157
156
  }
@@ -162,8 +161,8 @@ var Create = exports.Create = function (_BaseAction) {
162
161
  dispatch(notify({
163
162
  title: settings.error.title,
164
163
  message: message || settings.error.message,
165
- type: "notification",
166
- kind: settings.error.kind !== undefined ? settings.error.kind : "error"
164
+ type: 'notification',
165
+ kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
167
166
  }));
168
167
  }
169
168
  return response.data;
@@ -174,17 +173,18 @@ var Create = exports.Create = function (_BaseAction) {
174
173
  errorHandler(error);
175
174
 
176
175
  if (error && error.response && error.response.status && error.response.status !== 401) {
177
- if (settings.error.type !== undefined && settings.error.type === "notification") {
176
+
177
+ if (settings.error.type !== undefined && settings.error.type === 'notification') {
178
178
  dispatch(notify({
179
179
  title: settings.error.title,
180
- message: settings.error.message !== undefined ? settings.error.message : error.response.data.message,
181
- type: "notification",
182
- kind: settings.error.kind !== undefined ? settings.error.kind : "error"
180
+ message: error.response.data.message ? error.response.data.message : settings.error.message !== undefined ? settings.error.message : '',
181
+ type: 'notification',
182
+ kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
183
183
  }));
184
184
  } else {
185
185
  dispatch(notify({
186
- title: settings.error.title !== undefined ? settings.error.title : error.response.data.message,
187
- kind: settings.error.kind !== undefined ? settings.error.kind : "error"
186
+ title: error.response.data.message ? error.response.data.message : settings.error.title !== undefined ? settings.error.title : '',
187
+ kind: settings.error.kind !== undefined ? settings.error.kind : 'error'
188
188
  }));
189
189
  }
190
190
  }
@@ -147,11 +147,11 @@ var Fetch = exports.Fetch = function (_BaseAction) {
147
147
  }
148
148
 
149
149
  var parameters = _extends({
150
- page: params.page || 1,
151
- query: params.query || undefined,
152
- order: params.order || undefined,
150
+ page: params && params.page || 1,
151
+ query: params && params.query || undefined,
152
+ order: params && params.order || undefined,
153
153
  sort: sort_order || undefined,
154
- limit: params.limit || 10
154
+ limit: params && params.limit || 10
155
155
  }, additionalData.filters);
156
156
  apiparams = _pickBy(parameters, _identity);
157
157
 
@@ -95,7 +95,9 @@ var start = exports.start = function start(state, action) {
95
95
  state = state.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
96
96
  error: false,
97
97
  errorMessage: null,
98
- isSaving: true
98
+ isSaving: true,
99
+ isFetching: false,
100
+ isFetchingSingle: false
99
101
  })));
100
102
  //}
101
103
  return state;
@@ -125,7 +127,9 @@ var start = exports.start = function start(state, action) {
125
127
  map.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
126
128
  error: false,
127
129
  errorMessage: null,
128
- isSaving: true
130
+ isSaving: true,
131
+ isFetching: false,
132
+ isFetchingSingle: false
129
133
  })));
130
134
  } else {
131
135
  // Optimistically update the record
@@ -62,7 +62,9 @@ var start = exports.start = function start(state, action) {
62
62
  state = state.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
63
63
  error: false,
64
64
  errorMessage: null,
65
- isSaving: true
65
+ isSaving: true,
66
+ isFetching: false,
67
+ isFetchingSingle: false
66
68
  })));
67
69
 
68
70
  return state;
@@ -102,7 +104,9 @@ var start = exports.start = function start(state, action) {
102
104
  map.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
103
105
  error: false,
104
106
  errorMessage: null,
105
- isSaving: true
107
+ isSaving: true,
108
+ isFetching: false,
109
+ isFetchingSingle: false
106
110
  })));
107
111
  });
108
112
  }
@@ -33,7 +33,7 @@ var uniqEs6 = function uniqEs6(arrArg) {
33
33
  * @return {Immutable.Map} - updated state
34
34
  */
35
35
  var start = exports.start = function start(state, action) {
36
- var params = actions.params;
36
+ var params = action.params;
37
37
  return state.withMutations(function (map) {
38
38
 
39
39
  // Add additional data if provided
@@ -29,7 +29,9 @@ var start = exports.start = function start(state, action) {
29
29
  map.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
30
30
  error: false,
31
31
  errorMessage: null,
32
- isSaving: true
32
+ isSaving: true,
33
+ isFetching: false,
34
+ isFetchingSingle: false
33
35
  })));
34
36
  }
35
37
  });
@@ -86,7 +88,13 @@ var success = exports.success = function success(state, action) {
86
88
  map.set('raw', state.get('raw').merge(newRecord));
87
89
 
88
90
  // Add new record to instance array using permanent uid
89
- map.setIn(['instances', action.instance, 'data'], map.getIn(['instances', action.instance, 'data']).push(uid));
91
+ var instanceData = map.getIn(['instances', action.instance, 'data'], (0, _immutable.List)());
92
+ // Check if key already present in instance
93
+ if (!(instanceData.indexOf(uid) !== -1)) {
94
+ map.setIn(['instances', action.instance, 'data'], instanceData.push(uid));
95
+ }
96
+ // OLD method
97
+ //map.setIn(['instances', action.instance, 'data'], map.getIn(['instances', action.instance, 'data']).push(uid));
90
98
 
91
99
  // UPDATE TOTAL COUNT FOR THIS INSTANCE
92
100
  map.setIn(['instances', action.instance, 'additionalData', 'total'], map.getIn(['instances', action.instance, 'additionalData', 'total']) + 1);
@@ -63,7 +63,9 @@ var start = exports.start = function start(state, action) {
63
63
  state = state.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
64
64
  error: false,
65
65
  errorMessage: null,
66
- isDeleting: true
66
+ isDeleting: true,
67
+ isFetching: false,
68
+ isFetchingSingle: false
67
69
  })));
68
70
 
69
71
  return state;
@@ -64,7 +64,9 @@ var start = exports.start = function start(state, action) {
64
64
  state = state.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
65
65
  error: false,
66
66
  errorMessage: null,
67
- isSaving: true
67
+ isSaving: true,
68
+ isFetching: false,
69
+ isFetchingSingle: false
68
70
  })));
69
71
 
70
72
  return state;
@@ -100,7 +102,9 @@ var start = exports.start = function start(state, action) {
100
102
  map.mergeIn(['instances', action.instance, 'additionalData'], _immutable2.default.fromJS(_extends({}, action.additionalData, {
101
103
  error: false,
102
104
  errorMessage: null,
103
- isSaving: true
105
+ isSaving: true,
106
+ isFetching: false,
107
+ isFetchingSingle: false
104
108
  })));
105
109
  });
106
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redux-clerk2",
3
- "version": "2.0.11",
3
+ "version": "2.0.16",
4
4
  "description": "Redux Clerk handles the async CRUD in your Redux App.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -143,61 +143,33 @@ export class Create extends BaseAction {
143
143
 
144
144
  if (response.data.success) {
145
145
  successHandler(response.data.data || [], null, response.data.updates || []);
146
-
147
146
  message = response.data.message;
148
-
149
- if (settings.notification !== undefined) {
150
- if (
151
- settings.notification.type !== undefined &&
152
- settings.notification.type === "notification"
153
- ) {
154
- dispatch(
155
- notify({
156
- title: settings.notification.title,
157
- message:
158
- settings.notification.message !== undefined
159
- ? settings.notification.message
160
- : message,
161
- type: "notification",
162
- kind:
163
- settings.notification.kind !== undefined
164
- ? settings.notification.kind
165
- : "success"
166
- })
167
- );
168
- } else {
169
- dispatch(
170
- notify({
171
- title:
172
- settings.notification.title !== undefined
173
- ? settings.notification.title
174
- : message, //response.data.message,
175
- kind:
176
- settings.notification.kind !== undefined
177
- ? settings.notification.kind
178
- : "success"
179
- })
180
- );
181
- }
147
+
148
+ if(settings.notification !== undefined ){
149
+ if(settings.notification.type !== undefined && settings.notification.type === 'notification'){
150
+ dispatch(notify({
151
+ title: settings.notification.title,
152
+ message: (settings.notification.message !== undefined)?settings.notification.message:message,
153
+ type: 'notification',
154
+ kind: (settings.notification.kind !== undefined)?settings.notification.kind:'success'
155
+ }));
156
+ }else{
157
+ dispatch(notify({
158
+ title: (settings.notification.title !== undefined)?settings.notification.title:message,//response.data.message,
159
+ kind: (settings.notification.kind !== undefined)?settings.notification.kind:'success'
160
+ }));
161
+ }
182
162
  }
183
163
  } else {
184
164
  errorHandler(response.data.error);
185
- message =
186
- response.data.error.message !== undefined
187
- ? response.data.error.message
188
- : response.data.error;
189
-
190
- dispatch(
191
- notify({
165
+ message = (response.data.error.message !== undefined) ? response.data.error.message : response.data.error;
166
+
167
+ dispatch(notify({
192
168
  title: settings.error.title,
193
169
  message: message || settings.error.message,
194
- type: "notification",
195
- kind:
196
- settings.error.kind !== undefined
197
- ? settings.error.kind
198
- : "error"
199
- })
200
- );
170
+ type: 'notification',
171
+ kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
172
+ }));
201
173
  }
202
174
  return response.data;
203
175
  })
@@ -208,39 +180,21 @@ export class Create extends BaseAction {
208
180
  errorHandler(error);
209
181
 
210
182
  if(error && error.response && error.response.status && error.response.status !== 401 ){
211
- if (
212
- settings.error.type !== undefined &&
213
- settings.error.type === "notification"
214
- ) {
215
- dispatch(
216
- notify({
183
+
184
+ if(settings.error.type !== undefined && settings.error.type === 'notification'){
185
+ dispatch(notify({
217
186
  title: settings.error.title,
218
- message:
219
- settings.error.message !== undefined
220
- ? settings.error.message
221
- : error.response.data.message,
222
- type: "notification",
223
- kind:
224
- settings.error.kind !== undefined
225
- ? settings.error.kind
226
- : "error"
227
- })
228
- );
229
- } else {
230
- dispatch(
231
- notify({
232
- title:
233
- settings.error.title !== undefined
234
- ? settings.error.title
235
- : error.response.data.message,
236
- kind:
237
- settings.error.kind !== undefined
238
- ? settings.error.kind
239
- : "error"
240
- })
241
- );
242
- }
187
+ message: error.response.data.message ? error.response.data.message : (settings.error.message !== undefined)?settings.error.message:'',
188
+ type: 'notification',
189
+ kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
190
+ }));
191
+ }else{
192
+ dispatch(notify({
193
+ title: error.response.data.message ? error.response.data.message : (settings.error.title !== undefined)?settings.error.title:'',
194
+ kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
195
+ }));
243
196
  }
197
+ }
244
198
  })
245
199
  );
246
200
  } else {
@@ -124,11 +124,11 @@ export class Fetch extends BaseAction {
124
124
  }
125
125
 
126
126
  const parameters = {
127
- page: params.page || 1
128
- ,query: params.query || undefined
129
- ,order: params.order || undefined
127
+ page: params && params.page || 1
128
+ ,query: params && params.query || undefined
129
+ ,order: params && params.order || undefined
130
130
  ,sort: sort_order || undefined
131
- ,limit: params.limit || 10
131
+ ,limit: params && params.limit || 10
132
132
  ,...additionalData.filters
133
133
  }
134
134
  apiparams = _pickBy(parameters, _identity);
@@ -153,7 +153,7 @@ export class Update extends BaseAction {
153
153
  kind: (settings.error.kind !== undefined)?settings.error.kind:'error'
154
154
  }));
155
155
  }
156
- }
156
+ }
157
157
  });
158
158
 
159
159
  }else{
@@ -81,6 +81,8 @@ export const start = (state, action) => {
81
81
  error: false,
82
82
  errorMessage: null,
83
83
  isSaving: true,
84
+ isFetching: false,
85
+ isFetchingSingle: false,
84
86
  })));
85
87
  //}
86
88
  return state;
@@ -112,6 +114,8 @@ export const start = (state, action) => {
112
114
  error: false,
113
115
  errorMessage: null,
114
116
  isSaving: true,
117
+ isFetching: false,
118
+ isFetchingSingle: false,
115
119
  })));
116
120
 
117
121
  }
@@ -49,6 +49,8 @@ export const start = (state, action) => {
49
49
  error: false,
50
50
  errorMessage: null,
51
51
  isSaving: true,
52
+ isFetching: false,
53
+ isFetchingSingle: false,
52
54
  })));
53
55
 
54
56
  return state;
@@ -89,7 +91,9 @@ export const start = (state, action) => {
89
91
  map.mergeIn(['instances', action.instance, 'additionalData'], Immutable.fromJS(Object.assign({}, action.additionalData, {
90
92
  error: false,
91
93
  errorMessage: null,
92
- isSaving: true
94
+ isSaving: true,
95
+ isFetching: false,
96
+ isFetchingSingle: false,
93
97
  })));
94
98
 
95
99
  })
@@ -16,7 +16,7 @@ const uniqEs6 = (arrArg) => {
16
16
  * @return {Immutable.Map} - updated state
17
17
  */
18
18
  export const start = (state, action) => {
19
- const params = actions.params;
19
+ const params = action.params;
20
20
  return state.withMutations(map => {
21
21
 
22
22
  // Add additional data if provided
@@ -17,6 +17,8 @@ export const start = (state, action) => {
17
17
  error: false,
18
18
  errorMessage: null,
19
19
  isSaving: true,
20
+ isFetching: false,
21
+ isFetchingSingle: false,
20
22
  })));
21
23
  }
22
24
  })
@@ -73,7 +75,13 @@ export const start = (state, action) => {
73
75
  map.set('raw', state.get('raw').merge(newRecord))
74
76
 
75
77
  // Add new record to instance array using permanent uid
76
- map.setIn(['instances', action.instance, 'data'], map.getIn(['instances', action.instance, 'data']).push(uid));
78
+ const instanceData = map.getIn(['instances', action.instance, 'data'], List());
79
+ // Check if key already present in instance
80
+ if(!instanceData.includes(uid)){
81
+ map.setIn(['instances', action.instance, 'data'], instanceData.push(uid));
82
+ }
83
+ // OLD method
84
+ //map.setIn(['instances', action.instance, 'data'], map.getIn(['instances', action.instance, 'data']).push(uid));
77
85
 
78
86
  // UPDATE TOTAL COUNT FOR THIS INSTANCE
79
87
  map.setIn(['instances', action.instance, 'additionalData', 'total'], map.getIn(['instances', action.instance, 'additionalData', 'total']) + 1 );
@@ -51,7 +51,9 @@ export const start = (state, action) => {
51
51
  state = state.mergeIn(['instances', action.instance, 'additionalData'], Immutable.fromJS(Object.assign({}, action.additionalData, {
52
52
  error: false,
53
53
  errorMessage: null,
54
- isDeleting: true
54
+ isDeleting: true,
55
+ isFetching: false,
56
+ isFetchingSingle: false,
55
57
  })));
56
58
 
57
59
  return state;
@@ -54,7 +54,9 @@ export const start = (state, action) => {
54
54
  state = state.mergeIn(['instances', action.instance, 'additionalData'], Immutable.fromJS(Object.assign({}, action.additionalData, {
55
55
  error: false,
56
56
  errorMessage: null,
57
- isSaving: true
57
+ isSaving: true,
58
+ isFetching: false,
59
+ isFetchingSingle: false,
58
60
  })));
59
61
 
60
62
  return state;
@@ -92,7 +94,9 @@ export const start = (state, action) => {
92
94
  map.mergeIn(['instances', action.instance, 'additionalData'], Immutable.fromJS(Object.assign({}, action.additionalData, {
93
95
  error: false,
94
96
  errorMessage: null,
95
- isSaving: true
97
+ isSaving: true,
98
+ isFetching: false,
99
+ isFetchingSingle: false,
96
100
  })));
97
101
 
98
102
  })
package/CHANGELOG.md DELETED
@@ -1,79 +0,0 @@
1
- ## 1.0.0
2
- ###### _August 10, 2017_
3
-
4
- - Convert responseData to Immutable data structure before adding to store ([#51](https://github.com/GetAmbassador/redux-clerk/pull/51))
5
-
6
- ## 1.0.0-rc.4
7
- ###### _May 2, 2017_
8
-
9
- - Accept responseData in handleSuccess for the update action ([#48](https://github.com/GetAmbassador/redux-clerk/pull/48))
10
- - Update docs to reflect optional optimism ([#47](https://github.com/GetAmbassador/redux-clerk/pull/47))
11
-
12
- ## 1.0.0-rc.3
13
- ###### _April 10, 2017_
14
-
15
- - Cast all raw ids to strings ([#44](https://github.com/GetAmbassador/redux-clerk/pull/44))
16
- - Update selectors to handle optional optimism ([#43](https://github.com/GetAmbassador/redux-clerk/pull/43))
17
- - Make optimistic updates optional ([#41](https://github.com/GetAmbassador/redux-clerk/pull/41))
18
-
19
- ## 1.0.0-rc.2
20
- ###### _March 23, 2017_
21
-
22
- - Added pre action hooks ([#38](https://github.com/GetAmbassador/redux-clerk/pull/38))
23
-
24
- ## 1.0.0-rc.1
25
- ###### _March 22, 2017_
26
-
27
- - Added post action hooks ([#36](https://github.com/GetAmbassador/redux-clerk/pull/36))
28
- - Rename delete action to remove to avoid reserved word conflicts ([#35](https://github.com/GetAmbassador/redux-clerk/pull/35))
29
-
30
- ## 0.3.0
31
- ###### _March 15, 2017_
32
-
33
- - Fetch response will now deep merge response data into raw data ([#33](https://github.com/GetAmbassador/redux-clerk/pull/33))
34
-
35
- ## 0.2.8
36
- ###### _February 21, 2017_
37
-
38
- - Cast uid to int in record selector ([#31](https://github.com/GetAmbassador/redux-clerk/pull/31))
39
-
40
- ## 0.2.7
41
- ###### _February 16, 2017_
42
-
43
- - Added the get selector ([#29](https://github.com/GetAmbassador/redux-clerk/pull/29))
44
-
45
- ## 0.2.6
46
- ###### _January 11, 2017_
47
-
48
- - Added the datasetProperty selector ([#27](https://github.com/GetAmbassador/redux-clerk/pull/27))
49
-
50
- ## 0.2.5
51
- ###### _January 3, 2017_
52
-
53
- - Return Map instead of List for empty dataset ([#25](https://github.com/GetAmbassador/redux-clerk/pull/25))
54
- - Ensure data is properly converted between actions and reducers ([#24](https://github.com/GetAmbassador/redux-clerk/pull/24))
55
-
56
- ## 0.2.4
57
- ###### _December 15, 2016_
58
-
59
- - uidField option has been removed for the reducer (it is not longer needed) ([#22](https://github.com/GetAmbassador/redux-clerk/pull/22))
60
-
61
- ## 0.2.3
62
- ###### _December 14, 2016_
63
-
64
- - Records are now added while updating if not already in state ([#20](https://github.com/GetAmbassador/redux-clerk/pull/20))
65
-
66
- ## 0.2.2
67
- ###### _December 13, 2016_
68
-
69
- - Added the ability to return fetch response as an object or array ([#18](https://github.com/GetAmbassador/redux-clerk/pull/18))
70
-
71
- ## 0.2.1
72
- ###### _December 7, 2016_
73
-
74
- - Added the ability to pass additional data with fetch, create and delete actions ([#16](https://github.com/GetAmbassador/redux-clerk/pull/16))
75
-
76
- ## 0.2.0
77
- ###### _December 5, 2016_
78
-
79
- - Initial Release