@marktiderman/genesis-ui-native 3.0.0 → 3.1.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/dist/data/index.d.ts +7 -2
- package/dist/data/index.js +19 -4
- package/dist/data/index.js.map +1 -1
- package/package.json +51 -3
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +45 -0
- package/src/data/resource-view/mapping.ts +18 -1
- package/src/data/resource-view/use-native-resource-view.ts +18 -6
package/dist/data/index.d.ts
CHANGED
|
@@ -274,6 +274,10 @@ interface NativeFormField {
|
|
|
274
274
|
required: boolean;
|
|
275
275
|
/** Shown as text, never as an input, and never sent. */
|
|
276
276
|
readOnly: boolean;
|
|
277
|
+
/** From the contract: the column takes null. Unset when the contract doesn't say. */
|
|
278
|
+
nullable?: boolean;
|
|
279
|
+
/** From the contract: the column has a default (or is generated). */
|
|
280
|
+
hasDefault?: boolean;
|
|
277
281
|
max?: number;
|
|
278
282
|
options?: {
|
|
279
283
|
value: string;
|
|
@@ -306,14 +310,15 @@ declare function writableValues<T extends Row$3>(view: AnyResourceView<T>, mode:
|
|
|
306
310
|
declare function validateValues(fields: readonly NativeFormField[], values: Readonly<Record<string, unknown>>, messages: NativeResourceViewMessages): Record<string, string>;
|
|
307
311
|
|
|
308
312
|
type Row$2 = Record<string, unknown>;
|
|
309
|
-
type Filter = Readonly<Record<string, string | number | boolean | null>>;
|
|
313
|
+
type Filter = Readonly<Record<string, string | number | boolean | null | readonly (string | number)[]>>;
|
|
310
314
|
/** How long typing waits before the search goes to the server. */
|
|
311
315
|
declare const SEARCH_DEBOUNCE_MS = 300;
|
|
312
316
|
interface NativeResourceViewOptions<T extends Row$2 = Row$2> {
|
|
313
317
|
/** A tab the view defines: its server filter. */
|
|
314
318
|
preset?: string;
|
|
315
319
|
/**
|
|
316
|
-
*
|
|
320
|
+
* Filters sent to the server (`{ client_id: id }`); `null` means "is empty" and a list means
|
|
321
|
+
* "any of" (`{ status: ["open", "blocked"] }`, sent as `in`; a create never takes a list). A create
|
|
317
322
|
* also saves every non-null value here (a tab's filter too), even for read-only fields such as
|
|
318
323
|
* a required link: they come from the screen, never from an input. An edit never sends them.
|
|
319
324
|
*/
|
package/dist/data/index.js
CHANGED
|
@@ -1123,6 +1123,8 @@ function formFieldsFor(view, mode) {
|
|
|
1123
1123
|
display: f.display,
|
|
1124
1124
|
required: !readOnly && f.required,
|
|
1125
1125
|
readOnly,
|
|
1126
|
+
...typeof f.field.nullable === "boolean" ? { nullable: f.field.nullable } : {},
|
|
1127
|
+
...f.field.hasDefault || f.field.generated ? { hasDefault: true } : {},
|
|
1126
1128
|
...f.max !== void 0 ? { max: f.max } : {},
|
|
1127
1129
|
...options ? { options } : {},
|
|
1128
1130
|
...f.field.references ? { references: f.field.references } : {},
|
|
@@ -1144,10 +1146,17 @@ function writableValues(view, mode, fields, values, dirty) {
|
|
|
1144
1146
|
if (field.readOnly || !writable.has(field.key)) continue;
|
|
1145
1147
|
if (dirty && !dirty.has(field.key)) continue;
|
|
1146
1148
|
const value = values[field.key];
|
|
1147
|
-
|
|
1149
|
+
if (value !== "" && value !== void 0 || field.required) {
|
|
1150
|
+
out[field.key] = value;
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
if (field.nullable === void 0) out[field.key] = null;
|
|
1154
|
+
else if (TEXT_KINDS.has(field.kind) && !field.nullable && !(mode === "create" && field.hasDefault)) out[field.key] = "";
|
|
1155
|
+
else if (mode === "edit") out[field.key] = null;
|
|
1148
1156
|
}
|
|
1149
1157
|
return out;
|
|
1150
1158
|
}
|
|
1159
|
+
var TEXT_KINDS = /* @__PURE__ */ new Set(["text", "email", "url", "textarea"]);
|
|
1151
1160
|
function validateValues(fields, values, messages) {
|
|
1152
1161
|
const errors = {};
|
|
1153
1162
|
for (const field of shownFields(fields, values)) {
|
|
@@ -1388,13 +1397,15 @@ function DateField({
|
|
|
1388
1397
|
var SEARCH_DEBOUNCE_MS = 300;
|
|
1389
1398
|
function filterParams(filter) {
|
|
1390
1399
|
return Object.entries(filter ?? {}).map(
|
|
1391
|
-
([field, value]) => value === null ? { field, operator: "is_null" } : { field, operator: "eq", value }
|
|
1400
|
+
([field, value]) => value === null ? { field, operator: "is_null" } : Array.isArray(value) ? { field, operator: "in", value: [...value] } : { field, operator: "eq", value }
|
|
1392
1401
|
);
|
|
1393
1402
|
}
|
|
1394
1403
|
function screenValues(...filters) {
|
|
1395
1404
|
const out = {};
|
|
1396
1405
|
for (const filter of filters) {
|
|
1397
|
-
for (const [field, value] of Object.entries(filter ?? {}))
|
|
1406
|
+
for (const [field, value] of Object.entries(filter ?? {})) {
|
|
1407
|
+
if (value !== null && !Array.isArray(value)) out[field] = value;
|
|
1408
|
+
}
|
|
1398
1409
|
}
|
|
1399
1410
|
return out;
|
|
1400
1411
|
}
|
|
@@ -1416,7 +1427,11 @@ function useNativeResourceView(view, options = {}) {
|
|
|
1416
1427
|
const tab = preset ? view.definition.presets?.[preset] : void 0;
|
|
1417
1428
|
if (preset && !tab) throw new Error(`NativeResourceView(${view.resource}): no preset "${preset}"`);
|
|
1418
1429
|
const tabFilter = tab?.filter;
|
|
1419
|
-
const
|
|
1430
|
+
const filterKey = JSON.stringify(filter ?? {});
|
|
1431
|
+
const defaultFilters = useMemo(
|
|
1432
|
+
() => [...filterParams(tabFilter), ...filterParams(JSON.parse(filterKey))],
|
|
1433
|
+
[tabFilter, filterKey]
|
|
1434
|
+
);
|
|
1420
1435
|
const createKey = JSON.stringify(screenValues(tabFilter, filter));
|
|
1421
1436
|
const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
|
|
1422
1437
|
const sorts = useMemo(() => serverSorts(view), [view]);
|