@nauticana/sail 0.5.0 → 0.5.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauticana/sail",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Metadata-driven Angular component library for CRUD admin frontends backed by the keel Go backend. Tables, forms, navigation, OTP/2FA/social auth, billing.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -50,7 +50,7 @@ export class TableSearch extends BaseForm implements OnInit {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
this.editableRecord = this.
|
|
53
|
+
this.editableRecord = this.emptySearchRecord();
|
|
54
54
|
this.searchColumns = this.getDisplayedColumns();
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -63,7 +63,33 @@ export class TableSearch extends BaseForm implements OnInit {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
onClear() {
|
|
66
|
-
this.editableRecord = this.
|
|
66
|
+
this.editableRecord = this.emptySearchRecord();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Search-form variant of `emptyRecord()`. Boolean columns are forced to
|
|
71
|
+
* null so an unmodified Search click does not coerce filters from the
|
|
72
|
+
* table's HasDefault value (e.g. an `is_primary` column with a `FALSE`
|
|
73
|
+
* default would otherwise have the form submit `?IsPrimary=false` and
|
|
74
|
+
* silently exclude every primary-flag row).
|
|
75
|
+
*
|
|
76
|
+
* The user opts into a boolean filter by clicking the checkbox: first
|
|
77
|
+
* click sets it to `true`, a second click sets it to `false`, and the
|
|
78
|
+
* Clear button resets back to `null` (no filter). `buildSearchTerms`
|
|
79
|
+
* already skips `null` / `undefined` values, so the URL only carries
|
|
80
|
+
* filters the user explicitly toggled.
|
|
81
|
+
*/
|
|
82
|
+
private emptySearchRecord(): any {
|
|
83
|
+
const rec = this.emptyRecord();
|
|
84
|
+
const tableDef = this.cacheService.getTableDefinition(this.tableName);
|
|
85
|
+
if (tableDef?.Columns) {
|
|
86
|
+
for (const col of tableDef.Columns) {
|
|
87
|
+
if (col.DataType === 'boolean') {
|
|
88
|
+
rec[col.PascalName] = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return rec;
|
|
67
93
|
}
|
|
68
94
|
|
|
69
95
|
onAddRecord() {
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { HttpErrorResponse, HttpInterceptorFn, HttpResponse } from '@angular/common/http';
|
|
2
2
|
import { catchError, map, throwError } from 'rxjs';
|
|
3
3
|
|
|
4
|
+
// Detect a final response event by structural shape rather than
|
|
5
|
+
// `event instanceof HttpResponse`. Bundling can produce two distinct
|
|
6
|
+
// HttpResponse class identities — the one captured inside sail's compiled
|
|
7
|
+
// module and the one the host app's HttpClient emits — and instanceof
|
|
8
|
+
// then silently returns false. The structural check (presence of `body`
|
|
9
|
+
// + a callable `clone` + a successful `status`) is robust to that and
|
|
10
|
+
// still correctly skips intermediate events like HttpHeaderResponse and
|
|
11
|
+
// HttpProgressEvent.
|
|
12
|
+
function isFinalResponse(e: unknown): e is HttpResponse<unknown> {
|
|
13
|
+
if (!e || typeof e !== 'object') return false;
|
|
14
|
+
const r = e as { type?: number; body?: unknown; clone?: unknown; status?: number };
|
|
15
|
+
// HttpEventType.Response === 4. Filtering by type is the most reliable
|
|
16
|
+
// gate (HttpResponse and HttpHeaderResponse have different type values
|
|
17
|
+
// and only HttpResponse carries `body`).
|
|
18
|
+
return r.type === 4
|
|
19
|
+
&& 'body' in r
|
|
20
|
+
&& typeof r.clone === 'function'
|
|
21
|
+
&& typeof r.status === 'number';
|
|
22
|
+
}
|
|
23
|
+
|
|
4
24
|
export const apiResponseInterceptor: HttpInterceptorFn = (req, next) => {
|
|
5
25
|
return next(req).pipe(
|
|
6
26
|
map(event => {
|
|
7
|
-
if (event
|
|
27
|
+
if (isFinalResponse(event)) {
|
|
8
28
|
const body = event.body as Record<string, unknown> | null;
|
|
9
|
-
if (body && 'data' in body) {
|
|
29
|
+
if (body && typeof body === 'object' && 'data' in body) {
|
|
10
30
|
return event.clone({ body: body['data'] });
|
|
11
31
|
}
|
|
12
32
|
}
|