saasufy-components 7.12.0 → 7.13.0
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/README.md +1 -0
- package/collection-reducer.js +31 -8
- package/collection-viewer.js +30 -8
- package/model-viewer.js +31 -9
- package/package.json +3 -3
- package/styles.css +12 -0
package/README.md
CHANGED
|
@@ -312,6 +312,7 @@ In addition to the slots shown above, the `collection-viewer` also supports the
|
|
|
312
312
|
- `page-number`: This is typically a `div` element to display the current page number. Alternatively, it can be an `input-provider` element to allow the user to manually type in the page number.
|
|
313
313
|
- `first-item`: This should be a `template` element. It can be used to inject an element just above the first record. This can be useful to render the `collection-viewer` as a table with a heading above table rows.
|
|
314
314
|
- `last-item`: This should be a `template` element. It can be used to inject an element just after the last record.
|
|
315
|
+
- `error`: This can be used to display an error message if the required data cannot be loaded. The `Error` object can be accessed inside the template via the syntax: `$CollectionName.error` (substitute `CollectionName` with your `collection-type` or, if set, your `type-alias` preceded by a dollar sign). For example, the error message for a `Chat` collection will be `$Chat.error.message`.
|
|
315
316
|
|
|
316
317
|
**Attributes**
|
|
317
318
|
|
package/collection-reducer.js
CHANGED
|
@@ -76,8 +76,7 @@ class CollectionReducer extends SocketConsumer {
|
|
|
76
76
|
'collection-page-offset',
|
|
77
77
|
'collection-get-count',
|
|
78
78
|
'max-show-loader',
|
|
79
|
-
'type-alias'
|
|
80
|
-
'hide-error-logs'
|
|
79
|
+
'type-alias'
|
|
81
80
|
];
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -136,6 +135,27 @@ class CollectionReducer extends SocketConsumer {
|
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
138
|
+
renderError(error) {
|
|
139
|
+
let viewportSlot = this.shadowRoot.querySelector('slot[name="viewport"]');
|
|
140
|
+
if (!viewportSlot) return;
|
|
141
|
+
|
|
142
|
+
let viewportNode = viewportSlot.assignedNodes()[0];
|
|
143
|
+
if (!viewportNode) return;
|
|
144
|
+
|
|
145
|
+
this.activeLoader = null;
|
|
146
|
+
|
|
147
|
+
let errorTemplate = this.shadowRoot.querySelector('slot[name="error"]').assignedNodes()[0];
|
|
148
|
+
if (errorTemplate) {
|
|
149
|
+
let type = this.getAttribute('type-alias') || this.getAttribute('collection-type');
|
|
150
|
+
let errorItemString = renderTemplate(
|
|
151
|
+
errorTemplate.innerHTML,
|
|
152
|
+
{ [`$${type}`]: { error } },
|
|
153
|
+
this.socket
|
|
154
|
+
);
|
|
155
|
+
viewportNode.innerHTML = errorItemString;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
139
159
|
renderReduction() {
|
|
140
160
|
let viewportSlot = this.shadowRoot.querySelector('slot[name="viewport"]');
|
|
141
161
|
if (!viewportSlot) return;
|
|
@@ -192,7 +212,7 @@ class CollectionReducer extends SocketConsumer {
|
|
|
192
212
|
let collectionPageSize = this.getAttribute('collection-page-size');
|
|
193
213
|
let collectionPageOffset = this.getAttribute('collection-page-offset');
|
|
194
214
|
let collectionGetCount = this.hasAttribute('collection-get-count');
|
|
195
|
-
|
|
215
|
+
|
|
196
216
|
let collectionReloadDelay = Number(
|
|
197
217
|
this.getAttribute('collection-reload-delay') || DEFAULT_RELOAD_DELAY
|
|
198
218
|
);
|
|
@@ -217,6 +237,7 @@ class CollectionReducer extends SocketConsumer {
|
|
|
217
237
|
<slot name="loader"></slot>
|
|
218
238
|
<slot name="item"></slot>
|
|
219
239
|
<slot name="no-item"></slot>
|
|
240
|
+
<slot name="error"></slot>
|
|
220
241
|
<slot name="viewport"></slot>
|
|
221
242
|
<slot name="previous-page"></slot>
|
|
222
243
|
<slot name="page-number"></slot>
|
|
@@ -252,15 +273,17 @@ class CollectionReducer extends SocketConsumer {
|
|
|
252
273
|
}
|
|
253
274
|
})();
|
|
254
275
|
|
|
255
|
-
|
|
256
|
-
(
|
|
257
|
-
|
|
276
|
+
(async () => {
|
|
277
|
+
for await (let { error } of this.collection.listener('error')) {
|
|
278
|
+
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
279
|
+
if (!hideErrorLogs) {
|
|
258
280
|
console.error(
|
|
259
281
|
`Collection reducer encountered an error: ${error.message}`
|
|
260
282
|
);
|
|
261
283
|
}
|
|
262
|
-
|
|
263
|
-
|
|
284
|
+
this.renderError(error);
|
|
285
|
+
}
|
|
286
|
+
})();
|
|
264
287
|
}
|
|
265
288
|
}
|
|
266
289
|
|
package/collection-viewer.js
CHANGED
|
@@ -165,8 +165,7 @@ class CollectionViewer extends SocketConsumer {
|
|
|
165
165
|
'collection-disable-realtime',
|
|
166
166
|
'auto-reset-page-offset',
|
|
167
167
|
'max-show-loader',
|
|
168
|
-
'type-alias'
|
|
169
|
-
'hide-error-logs'
|
|
168
|
+
'type-alias'
|
|
170
169
|
];
|
|
171
170
|
}
|
|
172
171
|
|
|
@@ -240,6 +239,27 @@ class CollectionViewer extends SocketConsumer {
|
|
|
240
239
|
}
|
|
241
240
|
}
|
|
242
241
|
|
|
242
|
+
renderError(error) {
|
|
243
|
+
let viewportSlot = this.shadowRoot.querySelector('slot[name="viewport"]');
|
|
244
|
+
if (!viewportSlot) return;
|
|
245
|
+
|
|
246
|
+
let viewportNode = viewportSlot.assignedNodes()[0];
|
|
247
|
+
if (!viewportNode) return;
|
|
248
|
+
|
|
249
|
+
this.activeLoader = null;
|
|
250
|
+
|
|
251
|
+
let errorTemplate = this.shadowRoot.querySelector('slot[name="error"]').assignedNodes()[0];
|
|
252
|
+
if (errorTemplate) {
|
|
253
|
+
let type = this.getAttribute('type-alias') || this.getAttribute('collection-type');
|
|
254
|
+
let errorItemString = renderTemplate(
|
|
255
|
+
errorTemplate.innerHTML,
|
|
256
|
+
{ [`$${type}`]: { error } },
|
|
257
|
+
this.socket
|
|
258
|
+
);
|
|
259
|
+
viewportNode.innerHTML = errorItemString;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
243
263
|
renderList() {
|
|
244
264
|
let viewportSlot = this.shadowRoot.querySelector('slot[name="viewport"]');
|
|
245
265
|
if (!viewportSlot) return;
|
|
@@ -330,7 +350,6 @@ class CollectionViewer extends SocketConsumer {
|
|
|
330
350
|
let collectionPageOffset = this.getAttribute('collection-page-offset');
|
|
331
351
|
let collectionGetCount = this.hasAttribute('collection-get-count');
|
|
332
352
|
let collectionDisableRealtime = this.hasAttribute('collection-disable-realtime');
|
|
333
|
-
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
334
353
|
let collectionReloadDelay = Number(
|
|
335
354
|
this.getAttribute('collection-reload-delay') || DEFAULT_RELOAD_DELAY
|
|
336
355
|
);
|
|
@@ -361,6 +380,7 @@ class CollectionViewer extends SocketConsumer {
|
|
|
361
380
|
<slot name="loader"></slot>
|
|
362
381
|
<slot name="item"></slot>
|
|
363
382
|
<slot name="no-item"></slot>
|
|
383
|
+
<slot name="error"></slot>
|
|
364
384
|
<slot name="first-item"></slot>
|
|
365
385
|
<slot name="last-item"></slot>
|
|
366
386
|
<slot name="viewport"></slot>
|
|
@@ -399,15 +419,17 @@ class CollectionViewer extends SocketConsumer {
|
|
|
399
419
|
}
|
|
400
420
|
})();
|
|
401
421
|
|
|
402
|
-
|
|
403
|
-
(
|
|
404
|
-
|
|
422
|
+
(async () => {
|
|
423
|
+
for await (let { error } of this.collection.listener('error')) {
|
|
424
|
+
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
425
|
+
if (!hideErrorLogs) {
|
|
405
426
|
console.error(
|
|
406
427
|
`Collection viewer encountered an error: ${error.message}`
|
|
407
428
|
);
|
|
408
429
|
}
|
|
409
|
-
|
|
410
|
-
|
|
430
|
+
this.renderError(error);
|
|
431
|
+
}
|
|
432
|
+
})();
|
|
411
433
|
}
|
|
412
434
|
}
|
|
413
435
|
|
package/model-viewer.js
CHANGED
|
@@ -35,8 +35,7 @@ class ModelViewer extends SocketConsumer {
|
|
|
35
35
|
'model-id',
|
|
36
36
|
'model-fields',
|
|
37
37
|
'fields-slice-to',
|
|
38
|
-
'type-alias'
|
|
39
|
-
'hide-error-logs'
|
|
38
|
+
'type-alias'
|
|
40
39
|
];
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -52,6 +51,27 @@ class ModelViewer extends SocketConsumer {
|
|
|
52
51
|
return !!Object.values(otherProps).filter(value => value != null).length;
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
renderError(error) {
|
|
55
|
+
let viewportSlot = this.shadowRoot.querySelector('slot[name="viewport"]');
|
|
56
|
+
if (!viewportSlot) return;
|
|
57
|
+
|
|
58
|
+
let viewportNode = viewportSlot.assignedNodes()[0];
|
|
59
|
+
if (!viewportNode) return;
|
|
60
|
+
|
|
61
|
+
this.activeLoader = null;
|
|
62
|
+
|
|
63
|
+
let errorTemplate = this.shadowRoot.querySelector('slot[name="error"]').assignedNodes()[0];
|
|
64
|
+
if (errorTemplate) {
|
|
65
|
+
let type = this.getAttribute('type-alias') || this.getAttribute('model-type');
|
|
66
|
+
let errorItemString = renderTemplate(
|
|
67
|
+
errorTemplate.innerHTML,
|
|
68
|
+
{ [`$${type}`]: { error } },
|
|
69
|
+
this.socket
|
|
70
|
+
);
|
|
71
|
+
viewportNode.innerHTML = errorItemString;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
55
75
|
renderItem() {
|
|
56
76
|
let viewportSlot = this.shadowRoot.querySelector('slot[name="viewport"]');
|
|
57
77
|
if (!viewportSlot) return;
|
|
@@ -102,7 +122,6 @@ class ModelViewer extends SocketConsumer {
|
|
|
102
122
|
let modelId = this.getAttribute('model-id');
|
|
103
123
|
let modelFields = this.getAttribute('model-fields') || '';
|
|
104
124
|
let fieldsSliceTo = this.getAttribute('fields-slice-to') || '';
|
|
105
|
-
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
106
125
|
|
|
107
126
|
let {
|
|
108
127
|
fieldValues: sliceToMap
|
|
@@ -149,6 +168,7 @@ class ModelViewer extends SocketConsumer {
|
|
|
149
168
|
<slot name="loader"></slot>
|
|
150
169
|
<slot name="item"></slot>
|
|
151
170
|
<slot name="no-item"></slot>
|
|
171
|
+
<slot name="error"></slot>
|
|
152
172
|
<slot name="viewport"></slot>
|
|
153
173
|
`;
|
|
154
174
|
|
|
@@ -176,16 +196,18 @@ class ModelViewer extends SocketConsumer {
|
|
|
176
196
|
}
|
|
177
197
|
})();
|
|
178
198
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
199
|
+
(async () => {
|
|
200
|
+
this.modelErrorConsumer = this.model.listener('error').createConsumer();
|
|
201
|
+
for await (let { error } of this.modelErrorConsumer) {
|
|
202
|
+
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
203
|
+
if (!hideErrorLogs) {
|
|
183
204
|
console.error(
|
|
184
205
|
`Model viewer encountered an error: ${error.message}`
|
|
185
206
|
);
|
|
186
207
|
}
|
|
187
|
-
|
|
188
|
-
|
|
208
|
+
this.renderError(error);
|
|
209
|
+
}
|
|
210
|
+
})();
|
|
189
211
|
}
|
|
190
212
|
}
|
|
191
213
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saasufy-components",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.0",
|
|
4
4
|
"description": "Components for Saasufy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"author": "Jonathan Gros-Dubois",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"ag-collection": "^5.3.
|
|
21
|
-
"ag-model": "^3.1.
|
|
20
|
+
"ag-collection": "^5.3.4",
|
|
21
|
+
"ag-model": "^3.1.3",
|
|
22
22
|
"capitalisk-auth-client": "^1.5.1",
|
|
23
23
|
"socketcluster-client": "^19.2.3",
|
|
24
24
|
"uuid": "^8.3.2"
|
package/styles.css
CHANGED
|
@@ -215,6 +215,18 @@ collection-viewer > [slot=next-page] {
|
|
|
215
215
|
gap: 5px;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
.container-column {
|
|
219
|
+
display: flex;
|
|
220
|
+
flex-direction: column;
|
|
221
|
+
box-sizing: border-box;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.container-row {
|
|
225
|
+
display: flex;
|
|
226
|
+
flex-direction: row;
|
|
227
|
+
box-sizing: border-box;
|
|
228
|
+
}
|
|
229
|
+
|
|
218
230
|
.container-vertical {
|
|
219
231
|
display: flex;
|
|
220
232
|
flex-direction: column;
|