@antelopejs/dms 0.23.0 → 0.23.1-next.1028.g8526d04
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/frontend-vue/layers/dms-core/app/build/composables/user/tablePreferences.ts +96 -107
- package/frontend-vue/layers/dms-core/app/composables/data-types/useDataType.ts +31 -11
- package/frontend-vue/layers/dms-core/app/composables/realtime/useSseStream.ts +1 -1
- package/frontend-vue/layers/dms-core/app/composables/realtime/useUserRealtime.ts +5 -3
- package/frontend-vue/layers/dms-core/app/composables/user/usePreferences.ts +1 -0
- package/frontend-vue/layers/dms-core/app/types/page.ts +2 -2
- package/frontend-vue/layers/dms-core/app/types/watch.ts +3 -2
- package/frontend-vue/layers/dms-core/app/utils/query-validation.ts +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/sortable/SortableList.vue +1 -0
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuImport.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuRoot.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/chart/apexRawOptions.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/form/repeaterTable.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/form/useFormModel.ts +38 -24
- package/frontend-vue/layers/dms-ui/app/build/composables/table/useTableConfigClipboard.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewArrival.ts +3 -6
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewDisplays.ts +1 -4
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewFilters.ts +2 -5
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewPersistence.ts +20 -20
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewSorting.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewTabs.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewTypes.ts +0 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewViews.ts +1 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/usePersistedPagination.ts +3 -6
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTablePreferences.ts +57 -25
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTableViews.ts +2 -9
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/linkedArrival.ts +11 -6
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputRepeater.vue +2 -1
- package/frontend-vue/layers/dms-ui/app/components/form/components/KeyValue.vue +2 -1
- package/frontend-vue/layers/dms-ui/app/composables/form/types/props.ts +3 -7
- package/frontend-vue/layers/dms-ui/app/composables/form/types/value.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/form/useForm.ts +3 -2
- package/frontend-vue/layers/dms-ui/app/entries/composables/form/useFormModel.ts +1 -0
- package/frontend-vue/package.json +0 -1
- package/package.json +5 -6
|
@@ -1,23 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
PaginationState,
|
|
3
|
+
SortingState,
|
|
4
|
+
VisibilityState,
|
|
5
|
+
} from "@tanstack/vue-table";
|
|
2
6
|
import { isBranch, type PreferencesTree } from "./preferencesCookie";
|
|
3
7
|
import { isNumber, isString } from "../../../utils/type-check";
|
|
4
8
|
|
|
9
|
+
/** @internal A filter of a table view, as `TableFilter` shapes it. */
|
|
10
|
+
export interface FilterEntry {
|
|
11
|
+
accessorKey: string;
|
|
12
|
+
value?: unknown;
|
|
13
|
+
mode: string;
|
|
14
|
+
pinned?: boolean;
|
|
15
|
+
initialValue?: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
5
18
|
/**
|
|
6
19
|
* @internal
|
|
7
20
|
* The state of a table view that the server render reads to list and draw
|
|
8
|
-
* the right rows: kept in the preferences cookie, compactly.
|
|
21
|
+
* the right rows: kept in the preferences cookie, compactly. Each field maps
|
|
22
|
+
* to the type of its value.
|
|
9
23
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
export interface ServerTableValues {
|
|
25
|
+
sorting: SortingState;
|
|
26
|
+
columnFilters: FilterEntry[];
|
|
27
|
+
columnVisibility: VisibilityState;
|
|
28
|
+
pagination: PaginationState;
|
|
29
|
+
paginationScope: string;
|
|
30
|
+
activeTab: string;
|
|
31
|
+
viewMode: string;
|
|
32
|
+
activeView: string;
|
|
33
|
+
linkScope: string;
|
|
34
|
+
shownLink: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @internal The fields kept in the preferences cookie. */
|
|
38
|
+
export type ServerTableField = keyof ServerTableValues;
|
|
21
39
|
|
|
22
40
|
/**
|
|
23
41
|
* @internal
|
|
@@ -92,53 +110,27 @@ export const tablePreferenceId = (
|
|
|
92
110
|
.padStart(TABLE_ID_LENGTH, "0")
|
|
93
111
|
.slice(0, TABLE_ID_LENGTH);
|
|
94
112
|
|
|
95
|
-
interface SortEntry {
|
|
96
|
-
id: string;
|
|
97
|
-
desc: boolean;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
interface FilterEntry {
|
|
101
|
-
accessorKey: string;
|
|
102
|
-
value?: unknown;
|
|
103
|
-
mode: string;
|
|
104
|
-
pinned?: boolean;
|
|
105
|
-
initialValue?: unknown;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
interface PaginationEntry {
|
|
109
|
-
pageIndex: number;
|
|
110
|
-
pageSize: number;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
113
|
/**
|
|
114
114
|
* @internal
|
|
115
|
-
* How a server field is kept: its key in the table's
|
|
116
|
-
* form. `encode` gets the field's default so that it
|
|
117
|
-
* differs from it; a value whose form equals the default's
|
|
115
|
+
* How a server field's value of type `V` is kept: its key in the table's
|
|
116
|
+
* entry, and its compact form. `encode` gets the field's default so that it
|
|
117
|
+
* can keep only what differs from it; a value whose form equals the default's
|
|
118
|
+
* is not written. `decode` throws on a stored value that is not a `V`'s form.
|
|
118
119
|
*/
|
|
119
|
-
export interface ServerFieldCodec {
|
|
120
|
+
export interface ServerFieldCodec<V> {
|
|
120
121
|
key: string;
|
|
121
|
-
encode: (
|
|
122
|
-
|
|
123
|
-
defaultValue: PreferencesTree[string],
|
|
124
|
-
) => PreferencesTree[string];
|
|
125
|
-
decode: (
|
|
126
|
-
stored: PreferencesTree[string],
|
|
127
|
-
defaultValue: PreferencesTree[string],
|
|
128
|
-
) => PreferencesTree[string];
|
|
122
|
+
encode: (value: V, defaultValue: V | undefined) => PreferencesTree[string];
|
|
123
|
+
decode: (stored: PreferencesTree[string], defaultValue: V | undefined) => V;
|
|
129
124
|
}
|
|
130
125
|
|
|
131
|
-
const encodeSorting: ServerFieldCodec["encode"] = (value) => {
|
|
132
|
-
const
|
|
133
|
-
const tokens = sorts.map(
|
|
126
|
+
const encodeSorting: ServerFieldCodec<SortingState>["encode"] = (value) => {
|
|
127
|
+
const tokens = value.map(
|
|
134
128
|
(sort) => `${sort.desc ? DESCENDING_PREFIX : ""}${sort.id}`,
|
|
135
129
|
);
|
|
136
130
|
return tokens.length === 1 ? tokens[0] : tokens;
|
|
137
131
|
};
|
|
138
132
|
|
|
139
|
-
const decodeSorting = (
|
|
140
|
-
stored: Parameters<ServerFieldCodec["decode"]>[0],
|
|
141
|
-
): SortEntry[] => {
|
|
133
|
+
const decodeSorting = (stored: PreferencesTree[string]): SortingState => {
|
|
142
134
|
const tokens = isString(stored) ? [stored] : stored;
|
|
143
135
|
if (!Array.isArray(tokens)) throw new TypeError("sorting");
|
|
144
136
|
return tokens.map((token: string) => ({
|
|
@@ -147,26 +139,22 @@ const decodeSorting = (
|
|
|
147
139
|
}));
|
|
148
140
|
};
|
|
149
141
|
|
|
150
|
-
const isSameValue = (
|
|
151
|
-
left
|
|
152
|
-
right: Parameters<ServerFieldCodec["encode"]>[0],
|
|
153
|
-
): boolean => JSON.stringify(left) === JSON.stringify(right);
|
|
142
|
+
const isSameValue = <V>(left: V, right: V): boolean =>
|
|
143
|
+
JSON.stringify(left) === JSON.stringify(right);
|
|
154
144
|
|
|
155
|
-
const encodeFilters: ServerFieldCodec["encode"] = (value) =>
|
|
156
|
-
|
|
145
|
+
const encodeFilters: ServerFieldCodec<FilterEntry[]>["encode"] = (value) =>
|
|
146
|
+
value
|
|
157
147
|
.filter(
|
|
158
|
-
(filter
|
|
148
|
+
(filter) =>
|
|
159
149
|
!filter.pinned || !isSameValue(filter.value, filter.initialValue),
|
|
160
150
|
)
|
|
161
|
-
.map((filter
|
|
151
|
+
.map((filter) =>
|
|
162
152
|
filter.mode === DEFAULT_FILTER_MODE
|
|
163
153
|
? [filter.accessorKey, filter.value ?? null]
|
|
164
154
|
: [filter.accessorKey, filter.value ?? null, filter.mode],
|
|
165
155
|
);
|
|
166
156
|
|
|
167
|
-
const decodeFilters = (
|
|
168
|
-
stored: Parameters<ServerFieldCodec["decode"]>[0],
|
|
169
|
-
): FilterEntry[] => {
|
|
157
|
+
const decodeFilters = (stored: PreferencesTree[string]): FilterEntry[] => {
|
|
170
158
|
if (!Array.isArray(stored)) throw new TypeError("columnFilters");
|
|
171
159
|
return stored.map(([accessorKey, value, mode]: unknown[]) => ({
|
|
172
160
|
accessorKey: String(accessorKey),
|
|
@@ -175,12 +163,12 @@ const decodeFilters = (
|
|
|
175
163
|
}));
|
|
176
164
|
};
|
|
177
165
|
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const defaults =
|
|
183
|
-
return Object.entries(
|
|
166
|
+
const encodeVisibility: ServerFieldCodec<VisibilityState>["encode"] = (
|
|
167
|
+
value,
|
|
168
|
+
defaultValue,
|
|
169
|
+
) => {
|
|
170
|
+
const defaults = defaultValue ?? {};
|
|
171
|
+
return Object.entries(value)
|
|
184
172
|
.filter(([column, isShown]) => isShown !== (defaults[column] ?? true))
|
|
185
173
|
.map(
|
|
186
174
|
([column, isShown]) =>
|
|
@@ -188,27 +176,26 @@ const encodeVisibility: ServerFieldCodec["encode"] = (value, defaultValue) => {
|
|
|
188
176
|
);
|
|
189
177
|
};
|
|
190
178
|
|
|
191
|
-
const decodeVisibility: ServerFieldCodec["decode"] = (
|
|
179
|
+
const decodeVisibility: ServerFieldCodec<VisibilityState>["decode"] = (
|
|
180
|
+
stored,
|
|
181
|
+
defaultValue,
|
|
182
|
+
) => {
|
|
192
183
|
if (!Array.isArray(stored)) throw new TypeError("columnVisibility");
|
|
193
|
-
const changes = stored.map((token: string) => [
|
|
184
|
+
const changes = stored.map((token: string): [string, boolean] => [
|
|
194
185
|
token.slice(1),
|
|
195
186
|
token.startsWith(SHOWN_PREFIX),
|
|
196
187
|
]);
|
|
197
|
-
return { ...
|
|
188
|
+
return { ...defaultValue, ...Object.fromEntries(changes) };
|
|
198
189
|
};
|
|
199
190
|
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const encodePagination: ServerFieldCodec["encode"] = (value) => {
|
|
204
|
-
if (!isPaginationEntry(value)) return undefined;
|
|
191
|
+
const encodePagination: ServerFieldCodec<PaginationState>["encode"] = (
|
|
192
|
+
value,
|
|
193
|
+
) => {
|
|
205
194
|
const { pageIndex, pageSize } = value;
|
|
206
195
|
return pageIndex === FIRST_PAGE_INDEX ? pageSize : [pageSize, pageIndex];
|
|
207
196
|
};
|
|
208
197
|
|
|
209
|
-
const decodePagination = (
|
|
210
|
-
stored: Parameters<ServerFieldCodec["decode"]>[0],
|
|
211
|
-
): PaginationEntry => {
|
|
198
|
+
const decodePagination = (stored: PreferencesTree[string]): PaginationState => {
|
|
212
199
|
const pair: unknown[] = Array.isArray(stored)
|
|
213
200
|
? stored
|
|
214
201
|
: [stored, FIRST_PAGE_INDEX];
|
|
@@ -219,10 +206,13 @@ const decodePagination = (
|
|
|
219
206
|
return { pageIndex, pageSize };
|
|
220
207
|
};
|
|
221
208
|
|
|
222
|
-
const
|
|
209
|
+
const stringField = (key: string): ServerFieldCodec<string> => ({
|
|
223
210
|
key,
|
|
224
211
|
encode: (value) => value,
|
|
225
|
-
decode: (stored) =>
|
|
212
|
+
decode: (stored) => {
|
|
213
|
+
if (!isString(stored)) throw new TypeError(key);
|
|
214
|
+
return stored;
|
|
215
|
+
},
|
|
226
216
|
});
|
|
227
217
|
|
|
228
218
|
/**
|
|
@@ -231,7 +221,7 @@ const plainField = (key: string): ServerFieldCodec => ({
|
|
|
231
221
|
* `"-name"`, a filter `["status", "open"]`, a hidden column `"-email"`, a
|
|
232
222
|
* page size `50`.
|
|
233
223
|
*/
|
|
234
|
-
export const SERVER_TABLE_FIELDS
|
|
224
|
+
export const SERVER_TABLE_FIELDS = {
|
|
235
225
|
sorting: { key: "s", encode: encodeSorting, decode: decodeSorting },
|
|
236
226
|
columnFilters: { key: "f", encode: encodeFilters, decode: decodeFilters },
|
|
237
227
|
columnVisibility: {
|
|
@@ -240,30 +230,26 @@ export const SERVER_TABLE_FIELDS: Record<ServerTableField, ServerFieldCodec> = {
|
|
|
240
230
|
decode: decodeVisibility,
|
|
241
231
|
},
|
|
242
232
|
pagination: { key: "p", encode: encodePagination, decode: decodePagination },
|
|
243
|
-
paginationScope:
|
|
244
|
-
activeTab:
|
|
245
|
-
viewMode:
|
|
246
|
-
activeView:
|
|
247
|
-
linkScope:
|
|
248
|
-
shownLink:
|
|
233
|
+
paginationScope: stringField("q"),
|
|
234
|
+
activeTab: stringField("t"),
|
|
235
|
+
viewMode: stringField("d"),
|
|
236
|
+
activeView: stringField("w"),
|
|
237
|
+
linkScope: stringField("l"),
|
|
238
|
+
shownLink: stringField("k"),
|
|
239
|
+
} satisfies {
|
|
240
|
+
[F in ServerTableField]: ServerFieldCodec<ServerTableValues[F]>;
|
|
249
241
|
};
|
|
250
242
|
|
|
251
|
-
/** @internal Whether `field` is kept in the cookie. */
|
|
252
|
-
export const isServerTableField = (
|
|
253
|
-
field: TableField,
|
|
254
|
-
): field is ServerTableField => Object.hasOwn(SERVER_TABLE_FIELDS, field);
|
|
255
|
-
|
|
256
243
|
/**
|
|
257
244
|
* @internal
|
|
258
245
|
* `value`'s form in the entry, or `undefined` when it equals the default's
|
|
259
246
|
* and is not to be written.
|
|
260
247
|
*/
|
|
261
|
-
export const encodeServerField = (
|
|
262
|
-
|
|
263
|
-
value:
|
|
264
|
-
defaultValue:
|
|
265
|
-
):
|
|
266
|
-
const codec = SERVER_TABLE_FIELDS[field];
|
|
248
|
+
export const encodeServerField = <V>(
|
|
249
|
+
codec: ServerFieldCodec<V>,
|
|
250
|
+
value: V | undefined,
|
|
251
|
+
defaultValue: V | undefined,
|
|
252
|
+
): PreferencesTree[string] => {
|
|
267
253
|
if (value === undefined) return undefined;
|
|
268
254
|
const encoded = codec.encode(value, defaultValue);
|
|
269
255
|
const encodedDefault =
|
|
@@ -273,26 +259,29 @@ export const encodeServerField = (
|
|
|
273
259
|
return isSameValue(encoded, encodedDefault) ? undefined : encoded;
|
|
274
260
|
};
|
|
275
261
|
|
|
276
|
-
/**
|
|
277
|
-
|
|
278
|
-
|
|
262
|
+
/**
|
|
263
|
+
* @internal
|
|
264
|
+
* The value `entry` keeps under `codec`, else `defaultValue`: also when
|
|
265
|
+
* what it keeps is not a form the codec reads.
|
|
266
|
+
*/
|
|
267
|
+
export const decodeServerField = <V, D extends V | undefined>(
|
|
268
|
+
codec: ServerFieldCodec<V>,
|
|
279
269
|
entry: CompactTableEntry | undefined,
|
|
280
|
-
defaultValue:
|
|
281
|
-
):
|
|
282
|
-
const codec = SERVER_TABLE_FIELDS[field];
|
|
270
|
+
defaultValue: D,
|
|
271
|
+
): V | D => {
|
|
283
272
|
const stored = entry?.[codec.key];
|
|
284
273
|
if (stored === undefined) return defaultValue;
|
|
285
274
|
try {
|
|
286
|
-
return codec.decode(stored, defaultValue)
|
|
275
|
+
return codec.decode(stored, defaultValue);
|
|
287
276
|
} catch {
|
|
288
277
|
return defaultValue;
|
|
289
278
|
}
|
|
290
279
|
};
|
|
291
280
|
|
|
292
281
|
/** @internal Whether `value` is the field's default, not to be written. */
|
|
293
|
-
export const isDefaultValue = (
|
|
294
|
-
value:
|
|
295
|
-
defaultValue:
|
|
282
|
+
export const isDefaultValue = <V>(
|
|
283
|
+
value: V | undefined,
|
|
284
|
+
defaultValue: V | undefined,
|
|
296
285
|
): boolean => value === undefined || isSameValue(value, defaultValue);
|
|
297
286
|
|
|
298
287
|
const localKey = (id: string): string => `${LOCAL_TABLE_KEY_PREFIX}${id}`;
|
|
@@ -10,30 +10,47 @@ export type RecordWithDefault<T> = Record<string, T> & { default: T };
|
|
|
10
10
|
* Keys of a data type's `formatter` record: `default` (required), `cell` (a
|
|
11
11
|
* shorter grid rendering), `empty` (drawn instead of the fallback for a
|
|
12
12
|
* null/undefined value), and one per compare mode for filter chips.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Value - What a field of the row holds, the formatted one included.
|
|
15
|
+
* @typeParam Options - The options of the field's control.
|
|
16
|
+
* @typeParam Display - What the formatter draws.
|
|
13
17
|
*/
|
|
14
|
-
export type DataTypeFormatter
|
|
15
|
-
|
|
18
|
+
export type DataTypeFormatter<
|
|
19
|
+
Value = unknown,
|
|
20
|
+
Options = unknown,
|
|
21
|
+
Display = unknown,
|
|
22
|
+
> = (
|
|
23
|
+
value: Value,
|
|
16
24
|
locale: string,
|
|
17
|
-
options?:
|
|
18
|
-
row?: Record<string,
|
|
19
|
-
) =>
|
|
25
|
+
options?: Options,
|
|
26
|
+
row?: Record<string, Value>,
|
|
27
|
+
) => Display;
|
|
20
28
|
|
|
21
29
|
/**
|
|
22
30
|
* Reshapes a server value into its form-state representation.
|
|
23
31
|
* Must be idempotent: form reset re-applies the mapper to values that
|
|
24
32
|
* may already be mapped (e.g. restored from a submit-success snapshot).
|
|
33
|
+
*
|
|
34
|
+
* @typeParam Value - The field's value, as served and as held.
|
|
35
|
+
* @typeParam Options - The options of the field's control.
|
|
25
36
|
*/
|
|
26
|
-
export type BeforeStateMapper =
|
|
37
|
+
export type BeforeStateMapper<Value = unknown, Options = unknown> = (
|
|
38
|
+
value: Value,
|
|
39
|
+
options?: Options,
|
|
40
|
+
) => Value;
|
|
27
41
|
|
|
28
42
|
/**
|
|
29
43
|
* Whether two values of a data type are the same value, whatever shape each
|
|
30
44
|
* comes in: a form compares the value it loaded from the server with the one
|
|
31
45
|
* its control holds through it, to tell an edited field from an untouched one.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam Value - The field's value, as served and as held.
|
|
48
|
+
* @typeParam Options - The options of the field's control.
|
|
32
49
|
*/
|
|
33
|
-
export type DataTypeValueComparer = (
|
|
34
|
-
left:
|
|
35
|
-
right:
|
|
36
|
-
options?:
|
|
50
|
+
export type DataTypeValueComparer<Value = unknown, Options = unknown> = (
|
|
51
|
+
left: Value,
|
|
52
|
+
right: Value,
|
|
53
|
+
options?: Options,
|
|
37
54
|
) => boolean;
|
|
38
55
|
|
|
39
56
|
/**
|
|
@@ -42,7 +59,10 @@ export type DataTypeValueComparer = (
|
|
|
42
59
|
* input refuses `"0"`, a date range wants its two days. The filter itself
|
|
43
60
|
* keeps its text, so the query is unchanged.
|
|
44
61
|
*/
|
|
45
|
-
export type DataTypeFilterEditorValue =
|
|
62
|
+
export type DataTypeFilterEditorValue<Value = unknown> = (
|
|
63
|
+
text: string,
|
|
64
|
+
mode: string,
|
|
65
|
+
) => Value;
|
|
46
66
|
|
|
47
67
|
/**
|
|
48
68
|
* Where the rows a value names are read: the `select` route of the table a
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
isString,
|
|
14
14
|
isUndefined,
|
|
15
15
|
} from "../../utils/type-check";
|
|
16
|
-
import { isJsonObject } from "../../build/utils/json";
|
|
16
|
+
import { isJsonObject, type JsonObject } from "../../build/utils/json";
|
|
17
17
|
import { isRecord } from "../../build/utils/record";
|
|
18
18
|
import type { JsonValue } from "../../types/json";
|
|
19
19
|
|
|
@@ -161,14 +161,16 @@ const isSnapshotEntry = (
|
|
|
161
161
|
const isSnapshotEvent = (
|
|
162
162
|
eventName: string,
|
|
163
163
|
data: RealtimeFrameData,
|
|
164
|
-
): data is RealtimeSnapshotEvent =>
|
|
164
|
+
): data is RealtimeSnapshotEvent & JsonObject =>
|
|
165
165
|
eventName === SNAPSHOT_EVENT &&
|
|
166
166
|
isRecord(data) &&
|
|
167
167
|
isString(data.topic) &&
|
|
168
168
|
Array.isArray(data.entries) &&
|
|
169
169
|
data.entries.every(isSnapshotEntry);
|
|
170
170
|
|
|
171
|
-
const isRealtimeEvent = (
|
|
171
|
+
const isRealtimeEvent = (
|
|
172
|
+
data: RealtimeFrameData,
|
|
173
|
+
): data is RealtimeEvent & JsonObject =>
|
|
172
174
|
!!data &&
|
|
173
175
|
isObject(data) &&
|
|
174
176
|
isString(data.topic) &&
|
|
@@ -69,6 +69,7 @@ export const usePreferences = () => {
|
|
|
69
69
|
|
|
70
70
|
const getPreference = <T = unknown>(keyPath: string, defaultValue?: T): T => {
|
|
71
71
|
const value = readAt(tree.value, keyPath.split("."));
|
|
72
|
+
// SAFETY: Holds while the preferences cookie was written by this version and each caller names as T the type its setPreference writes under keyPath: the tree is that cookie decoded, so the value read back has that type or is undefined.
|
|
72
73
|
return (value === undefined ? defaultValue : value) as T;
|
|
73
74
|
};
|
|
74
75
|
|
|
@@ -190,11 +190,11 @@ export interface QuickActionsPayload {
|
|
|
190
190
|
actions: Record<string, QuickActionInfo>;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
export interface ComponentChild<T = object> {
|
|
193
|
+
export interface ComponentChild<T = object, Extra = unknown> {
|
|
194
194
|
id: string;
|
|
195
195
|
component: ComponentInfo<T>;
|
|
196
196
|
slot?: string;
|
|
197
|
-
[key: string]:
|
|
197
|
+
[key: string]: string | ComponentInfo<T> | Extra | undefined;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
export interface ComponentInfo<T = object> {
|
|
@@ -5,10 +5,11 @@ export const ComponentId = {
|
|
|
5
5
|
SELF: "$component:self",
|
|
6
6
|
} as const;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** A watch action, run against the state of the component that watches: `Value` is what that state holds per key. */
|
|
9
|
+
export type WatchActionFunction<Value = unknown> = (
|
|
9
10
|
action: WatchAction,
|
|
10
11
|
eventData: ComponentEventData,
|
|
11
|
-
componentState: Ref<Record<string,
|
|
12
|
+
componentState: Ref<Record<string, Value>>,
|
|
12
13
|
) => void;
|
|
13
14
|
|
|
14
15
|
export interface WatchActionCondition {
|
|
@@ -12,9 +12,10 @@ export function validateRequiredQueryParams(
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** The route a validation reads: `Value` is what each query entry holds. */
|
|
16
|
+
export interface ValidationRouteContext<Value = unknown> {
|
|
17
|
+
query: Record<string, Value>;
|
|
18
|
+
params: Record<string, Value>;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export type ValidationFunction = (route: ValidationRouteContext) => boolean;
|
|
@@ -106,6 +106,7 @@ const { option } = useSortable(root, list, {
|
|
|
106
106
|
emit("change", { moved: { element, oldIndex, newIndex } });
|
|
107
107
|
},
|
|
108
108
|
onAdd: (event: SortableEvent) => {
|
|
109
|
+
// SAFETY: Holds while only onStart writes sharedDragged, under its list's group, with an element of that list, and lists of one group hold the same Item type: the group prop is the contract that makes them exchange items.
|
|
109
110
|
const element = sharedDragged.get(draggedKey()) as Item | undefined;
|
|
110
111
|
const { newIndex } = event;
|
|
111
112
|
if (element === undefined || newIndex === undefined) return;
|
|
@@ -34,7 +34,7 @@ const appConfig = useDmsAppConfig();
|
|
|
34
34
|
const tableSharedData =
|
|
35
35
|
injectLocal<ShallowRef<TableSharedData<T>>>("tableSharedData");
|
|
36
36
|
|
|
37
|
-
const { exportConfig } = useTableConfigClipboard
|
|
37
|
+
const { exportConfig } = useTableConfigClipboard();
|
|
38
38
|
|
|
39
39
|
const navItems = computed((): NavItem[] => {
|
|
40
40
|
const capabilities = tableSharedData?.value?.activeCapabilities.value;
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
} from "../../../../../dms-core/app/utils/type-check";
|
|
7
7
|
import type { UseApexChartInput } from "../../../composables/chart/useApexChart.types";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** An options tree for Apex, one entry per key: `Value` is what an entry holds. */
|
|
10
|
+
export type RawOptionSection<Value = unknown> = Record<string, Value>;
|
|
10
11
|
|
|
11
12
|
/** A value an override is written as: JSON, or the text itself when it is not JSON. */
|
|
12
13
|
type RawOptionJson =
|
|
@@ -11,7 +11,7 @@ export interface RepeaterTableColumn {
|
|
|
11
11
|
id: string;
|
|
12
12
|
label?: string;
|
|
13
13
|
type?: string;
|
|
14
|
-
component: ComponentInfo
|
|
14
|
+
component: ComponentInfo<ComponentOptionsData>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/** Where a relation column reads the rows its values name. */
|
|
@@ -31,7 +31,7 @@ export function renderableColumn(
|
|
|
31
31
|
compareModes: [],
|
|
32
32
|
filterComponents: {},
|
|
33
33
|
|
|
34
|
-
inputComponent: column.component
|
|
34
|
+
inputComponent: column.component,
|
|
35
35
|
};
|
|
36
36
|
return { id: column.id, type };
|
|
37
37
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { onMounted, unref } from "vue";
|
|
3
|
-
import { jsonSchemaToZod } from "json-schema-to-zod";
|
|
4
3
|
import type { FormProps } from "../../../composables/form/types";
|
|
5
4
|
import { FormEvents } from "../../../composables/form/types/events";
|
|
6
5
|
import type {
|
|
@@ -48,9 +47,14 @@ const INTERNAL_STATE_KEYS = new Set([
|
|
|
48
47
|
|
|
49
48
|
function isFormFieldValue(value: unknown): value is FormFieldValue {
|
|
50
49
|
if (value === null || isString(value) || isNumber(value)) return true;
|
|
51
|
-
if (isBoolean(value)) return true;
|
|
50
|
+
if (isBoolean(value) || value instanceof Date) return true;
|
|
52
51
|
if (Array.isArray(value)) return value.every(isFormFieldValue);
|
|
53
|
-
return
|
|
52
|
+
return (
|
|
53
|
+
isPlainObject(value) &&
|
|
54
|
+
Object.values(value).every(
|
|
55
|
+
(entry) => entry === undefined || isFormFieldValue(entry),
|
|
56
|
+
)
|
|
57
|
+
);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
function parseClonedValue(json: string): FormFieldValue {
|
|
@@ -69,7 +73,12 @@ export function cloneFormValue(value: StateValue): FormFieldValue | undefined {
|
|
|
69
73
|
/** The record a form loaded, cloned by value; what is not a plain record clones to none. */
|
|
70
74
|
export function cloneRecordValues(record: FormData): FormData {
|
|
71
75
|
const cloned = parseClonedValue(JSON.stringify(record));
|
|
72
|
-
|
|
76
|
+
if (!isPlainObject(cloned)) return {};
|
|
77
|
+
const values: FormData = {};
|
|
78
|
+
for (const [key, value] of Object.entries(cloned)) {
|
|
79
|
+
if (value !== undefined) values[key] = value;
|
|
80
|
+
}
|
|
81
|
+
return values;
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
/**
|
|
@@ -142,13 +151,10 @@ export function createBaseValidationSchema(
|
|
|
142
151
|
): z.ZodObject<Record<string, z.ZodTypeAny>> {
|
|
143
152
|
if (!schema) return z.object({});
|
|
144
153
|
try {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return zodObjectSchema.parse(
|
|
150
|
-
new Function("z", `"use strict"; return (${zodCode})`)(z),
|
|
151
|
-
);
|
|
154
|
+
const built = zodObjectSchema.parse(z.fromJSONSchema(schema));
|
|
155
|
+
return schema.additionalProperties === false
|
|
156
|
+
? built.loose()
|
|
157
|
+
: z.object(built.shape);
|
|
152
158
|
} catch {
|
|
153
159
|
return z.object({});
|
|
154
160
|
}
|
|
@@ -167,23 +173,27 @@ export function resolveSubmitTarget(
|
|
|
167
173
|
return url === undefined ? { missing: "token" } : { url };
|
|
168
174
|
}
|
|
169
175
|
|
|
176
|
+
/** The values a form's state holds per field, as its inputs read them. */
|
|
177
|
+
export type FormStateValues = { [key: string]: StateValue };
|
|
178
|
+
|
|
179
|
+
/** `data` with each field's value reshaped by its data type's `beforeStateMapper`. */
|
|
170
180
|
export function processBeforeStateMappers(
|
|
171
181
|
data: FormData,
|
|
172
182
|
fields: FormFieldOrGroup[],
|
|
173
183
|
getDataType: (type: string) => DataType | undefined,
|
|
174
|
-
):
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
if (!field.type ||
|
|
184
|
+
): FormStateValues {
|
|
185
|
+
const values = new Map<string, StateValue>(Object.entries({ ...data }));
|
|
186
|
+
for (const field of flattenFields(fields)) {
|
|
187
|
+
const value = values.get(field.id);
|
|
188
|
+
if (!field.type || value === undefined) continue;
|
|
179
189
|
const dataType = getDataType(field.type);
|
|
180
190
|
if (!dataType?.beforeStateMapper) continue;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
field.component.options,
|
|
184
|
-
)
|
|
191
|
+
values.set(
|
|
192
|
+
field.id,
|
|
193
|
+
dataType.beforeStateMapper(value, field.component.options),
|
|
194
|
+
);
|
|
185
195
|
}
|
|
186
|
-
return
|
|
196
|
+
return Object.fromEntries(values);
|
|
187
197
|
}
|
|
188
198
|
|
|
189
199
|
/** A cleared list submits an empty list; other cleared fields submit null. */
|
|
@@ -294,7 +304,11 @@ export function collectSubmitData(
|
|
|
294
304
|
const initial = context.initialValues?.[field.id];
|
|
295
305
|
if (context.onlyChanged && isSameValue(field, value, initial)) continue;
|
|
296
306
|
if (!isClearedField(field, value)) {
|
|
297
|
-
|
|
307
|
+
const submitted = submittedFieldValue(field, value);
|
|
308
|
+
const sent = isFormFieldValue(submitted)
|
|
309
|
+
? submitted
|
|
310
|
+
: cloneFormValue(submitted);
|
|
311
|
+
if (sent !== undefined) fieldData[field.id] = sent;
|
|
298
312
|
continue;
|
|
299
313
|
}
|
|
300
314
|
if (field.disabled || context.disabled?.has(field.id)) continue;
|
|
@@ -302,7 +316,7 @@ export function collectSubmitData(
|
|
|
302
316
|
fieldData[field.id] = clearedFieldValue(initial);
|
|
303
317
|
}
|
|
304
318
|
return {
|
|
305
|
-
...
|
|
319
|
+
...context.submitDefaults,
|
|
306
320
|
...fieldData,
|
|
307
321
|
};
|
|
308
322
|
}
|
|
@@ -332,7 +346,7 @@ export function fieldValuesOfSubmitDefaults(
|
|
|
332
346
|
if (!submitDefaults) return values;
|
|
333
347
|
for (const { id } of fields) {
|
|
334
348
|
if (id in submitDefaults) {
|
|
335
|
-
values[id] = submitDefaults[id]
|
|
349
|
+
values[id] = submitDefaults[id];
|
|
336
350
|
}
|
|
337
351
|
}
|
|
338
352
|
return values;
|
|
@@ -108,9 +108,9 @@ const decodeConfig = (code: string): SerializedTableConfig => {
|
|
|
108
108
|
return parsed;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
export const useTableConfigClipboard =
|
|
111
|
+
export const useTableConfigClipboard = () => {
|
|
112
112
|
const tableSharedData =
|
|
113
|
-
injectLocal<ShallowRef<TableSharedData<
|
|
113
|
+
injectLocal<ShallowRef<TableSharedData<Data>>>("tableSharedData");
|
|
114
114
|
const toast = useToast();
|
|
115
115
|
const { t } = useI18n();
|
|
116
116
|
const presenter = useApiErrorPresenter();
|
|
@@ -33,12 +33,9 @@ export function useTableViewArrival<T extends Data>(
|
|
|
33
33
|
urlScope,
|
|
34
34
|
queryParamFilters,
|
|
35
35
|
isVisit: pageArrivalKind() === "visit",
|
|
36
|
-
rememberedTab: keptPreferences.get
|
|
37
|
-
keptLinkScope: keptPreferences.get
|
|
38
|
-
|
|
39
|
-
undefined,
|
|
40
|
-
),
|
|
41
|
-
shownLink: keptPreferences.get<string | undefined>("shownLink", undefined),
|
|
36
|
+
rememberedTab: keptPreferences.get("activeTab", ALL_TAB_ID),
|
|
37
|
+
keptLinkScope: keptPreferences.get("linkScope", undefined),
|
|
38
|
+
shownLink: keptPreferences.get("shownLink", undefined),
|
|
42
39
|
});
|
|
43
40
|
const tablePreferences = linkFollowingPreferences(
|
|
44
41
|
isLinked ? linkedArrivalPreferences(keptPreferences) : keptPreferences,
|
|
@@ -47,10 +47,7 @@ export function useTableViewDisplayOptions<T extends Data>(
|
|
|
47
47
|
? declaredGroupedOptions
|
|
48
48
|
: undefined;
|
|
49
49
|
|
|
50
|
-
const persistedDisplay = tablePreferences.get
|
|
51
|
-
"viewMode",
|
|
52
|
-
defaultDisplay,
|
|
53
|
-
);
|
|
50
|
+
const persistedDisplay = tablePreferences.get("viewMode", defaultDisplay);
|
|
54
51
|
|
|
55
52
|
const isDefaultDisplayStandalone =
|
|
56
53
|
resolvedDisplay(defaultDisplay)?.capabilities?.header === false;
|
|
@@ -86,7 +86,7 @@ export function useTableViewPinnedFilters<T extends Data>(
|
|
|
86
86
|
) {
|
|
87
87
|
const { tablePreferences } = scope.arrival;
|
|
88
88
|
const { defaultFilters } = scope.configuration;
|
|
89
|
-
const savedFilters = tablePreferences.get
|
|
89
|
+
const savedFilters = tablePreferences.get("columnFilters", []);
|
|
90
90
|
|
|
91
91
|
const buildPinnedFilters = (): TableFilter[] =>
|
|
92
92
|
(defaultFilters || []).map((def) => {
|
|
@@ -136,10 +136,7 @@ export function useTableViewFilterState<T extends Data>(
|
|
|
136
136
|
const { offeredDisplayIds, fallbackDisplayId } = scope.displayOptions;
|
|
137
137
|
const columnFilters = ref<TableFilter[]>(initialFilters);
|
|
138
138
|
const columnVisibility = ref<VisibilityState>(
|
|
139
|
-
tablePreferences.get
|
|
140
|
-
"columnVisibility",
|
|
141
|
-
initialVisibility,
|
|
142
|
-
),
|
|
139
|
+
tablePreferences.get("columnVisibility", initialVisibility),
|
|
143
140
|
);
|
|
144
141
|
const columnSizing = ref<ColumnSizingState>({});
|
|
145
142
|
tablePreferences.restore("columnSizing", columnSizing);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { watchDebounced } from "@vueuse/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MaybeRef, Ref } from "vue";
|
|
3
|
+
import type { TableField } from "#dms-core/app/entries/composables/user/tablePreferences";
|
|
4
|
+
import type { TablePreferenceValues } from "./useTablePreferences";
|
|
3
5
|
import type { TableViewScope } from "./tableViewScope";
|
|
4
6
|
|
|
5
7
|
export function useTableViewStatePersistence<T extends Data>(
|
|
@@ -33,24 +35,11 @@ export function useTableViewStatePersistence<T extends Data>(
|
|
|
33
35
|
const { kanbanGroupBy, defaultKanbanGroupBy, density, defaultDensity } =
|
|
34
36
|
scope.displayPreferences;
|
|
35
37
|
const { groupedGroupBy, defaultGroupedGroupBy } = scope.groupingOptions;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
]),
|
|
42
|
-
["columnFilters", columnFilters, []],
|
|
43
|
-
["columnVisibility", columnVisibility, initialVisibility],
|
|
44
|
-
["filtersOpen", filtersRowOpen, hasEmptyDefaultFilter],
|
|
45
|
-
["activeTab", activeTabId, ALL_TAB_ID],
|
|
46
|
-
["viewMode", activeDisplayId, displayDefault],
|
|
47
|
-
["columnOrder", columnOrder, []],
|
|
48
|
-
["kanbanGroupBy", kanbanGroupBy, defaultKanbanGroupBy],
|
|
49
|
-
["groupedGroupBy", groupedGroupBy, defaultGroupedGroupBy],
|
|
50
|
-
["density", density, defaultDensity],
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
tableStatePreferences.forEach(([field, state, defaultValue]) => {
|
|
38
|
+
const persist = <F extends TableField>(
|
|
39
|
+
field: F,
|
|
40
|
+
state: Ref<TablePreferenceValues[F]>,
|
|
41
|
+
defaultValue: MaybeRef<TablePreferenceValues[F]>,
|
|
42
|
+
) => {
|
|
54
43
|
watch(
|
|
55
44
|
state,
|
|
56
45
|
(newValue) => {
|
|
@@ -58,7 +47,18 @@ export function useTableViewStatePersistence<T extends Data>(
|
|
|
58
47
|
},
|
|
59
48
|
{ deep: true },
|
|
60
49
|
);
|
|
61
|
-
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (!reorderConfig) persist("sorting", sorting, defaultSortState);
|
|
53
|
+
persist("columnFilters", columnFilters, []);
|
|
54
|
+
persist("columnVisibility", columnVisibility, initialVisibility);
|
|
55
|
+
persist("filtersOpen", filtersRowOpen, hasEmptyDefaultFilter);
|
|
56
|
+
persist("activeTab", activeTabId, ALL_TAB_ID);
|
|
57
|
+
persist("viewMode", activeDisplayId, displayDefault);
|
|
58
|
+
persist("columnOrder", columnOrder, []);
|
|
59
|
+
persist("kanbanGroupBy", kanbanGroupBy, defaultKanbanGroupBy);
|
|
60
|
+
persist("groupedGroupBy", groupedGroupBy, defaultGroupedGroupBy);
|
|
61
|
+
persist("density", density, defaultDensity);
|
|
62
62
|
return {};
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -115,7 +115,7 @@ export function useTableViewDefaultSorting<T extends Data>(
|
|
|
115
115
|
reorderConfig
|
|
116
116
|
? defaultSortState
|
|
117
117
|
: sortingOrDefault(
|
|
118
|
-
tablePreferences.get
|
|
118
|
+
tablePreferences.get("sorting", defaultSortState),
|
|
119
119
|
declaredSortableIds,
|
|
120
120
|
defaultSortState,
|
|
121
121
|
),
|
|
@@ -34,7 +34,7 @@ export function useTableViewTabs<T extends Data>(
|
|
|
34
34
|
|
|
35
35
|
const activeTabId = ref<string>(
|
|
36
36
|
readTableUrlTab(route.query, urlScope) ??
|
|
37
|
-
tablePreferences.get
|
|
37
|
+
tablePreferences.get("activeTab", ALL_TAB_ID),
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
const hasConfiguredAllTab = (tabs ?? []).some((tab) => tab.id === ALL_TAB_ID);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { TableViewConfig } from "../../../composables/table-view/types";
|
|
2
|
-
import { type Ref } from "vue";
|
|
3
|
-
import type { TableField } from "#dms-core/app/entries/composables/user/tablePreferences";
|
|
4
2
|
import type { TableViewLiveHoldOptions } from "#dms-core/app/types/live";
|
|
5
3
|
export interface RealtimePresenceActor {
|
|
6
4
|
id: string;
|
|
@@ -10,7 +8,6 @@ export interface RealtimePresenceActor {
|
|
|
10
8
|
since?: number;
|
|
11
9
|
}
|
|
12
10
|
export type RealtimePresenceMap = Record<string, RealtimePresenceActor[]>;
|
|
13
|
-
export type TableStatePreference = [TableField, Ref<unknown>, unknown];
|
|
14
11
|
export type TableViewSetupProps<T extends Data> = TableViewConfig<T> & {
|
|
15
12
|
realtimeTopic?: string | string[];
|
|
16
13
|
liveHold?: boolean | TableViewLiveHoldOptions;
|
|
@@ -107,8 +107,7 @@ export function useTableViewMobileDisplay<T extends Data>(
|
|
|
107
107
|
activeView,
|
|
108
108
|
isDisplayChosen: () =>
|
|
109
109
|
isDefaultDisplayStandalone ||
|
|
110
|
-
tablePreferences.get
|
|
111
|
-
undefined,
|
|
110
|
+
tablePreferences.get("viewMode", undefined) !== undefined,
|
|
112
111
|
});
|
|
113
112
|
return {};
|
|
114
113
|
}
|
package/frontend-vue/layers/dms-ui/app/build/composables/table-view/usePersistedPagination.ts
CHANGED
|
@@ -36,12 +36,9 @@ export function usePersistedPagination(
|
|
|
36
36
|
const scopeKey = computed(() =>
|
|
37
37
|
hashText(JSON.stringify(options.scope() ?? null)),
|
|
38
38
|
);
|
|
39
|
-
const stored = preferences.get
|
|
39
|
+
const stored = preferences.get("pagination", defaults);
|
|
40
40
|
|
|
41
|
-
const storedScope = preferences.get
|
|
42
|
-
"paginationScope",
|
|
43
|
-
scopeKey.value,
|
|
44
|
-
);
|
|
41
|
+
const storedScope = preferences.get("paginationScope", scopeKey.value);
|
|
45
42
|
const pagination = ref<PaginationState>(
|
|
46
43
|
storedScope === scopeKey.value ? stored : firstPage(stored),
|
|
47
44
|
);
|
|
@@ -59,7 +56,7 @@ export function usePersistedPagination(
|
|
|
59
56
|
([value, scope]) => {
|
|
60
57
|
preferences.set("pagination", value, defaults);
|
|
61
58
|
const isFirstPage = value.pageIndex === FIRST_PAGE_INDEX;
|
|
62
|
-
preferences.set
|
|
59
|
+
preferences.set(
|
|
63
60
|
"paginationScope",
|
|
64
61
|
isFirstPage ? undefined : scope,
|
|
65
62
|
undefined,
|
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import { getCurrentInstance, onMounted, type Ref } from "vue";
|
|
2
|
+
import type { ColumnSizingState } from "@tanstack/vue-table";
|
|
2
3
|
import {
|
|
3
4
|
type CompactTableEntry,
|
|
4
5
|
decodeServerField,
|
|
5
6
|
encodeServerField,
|
|
6
7
|
isDefaultValue,
|
|
7
|
-
isServerTableField,
|
|
8
8
|
type LocalTableField,
|
|
9
9
|
readLocalTableEntry,
|
|
10
10
|
SERVER_TABLE_FIELDS,
|
|
11
|
-
type
|
|
11
|
+
type ServerFieldCodec,
|
|
12
|
+
type ServerTableValues,
|
|
12
13
|
type TableField,
|
|
13
14
|
TABLES_PREFERENCE_KEY,
|
|
14
15
|
tablePreferenceId,
|
|
15
16
|
writeLocalTableEntry,
|
|
16
17
|
} from "#dms-core/app/entries/composables/user/tablePreferences";
|
|
18
|
+
import type { TableDensity } from "../../components/table/Table.types";
|
|
19
|
+
import type { UserTableView } from "./utils/views";
|
|
20
|
+
|
|
21
|
+
/** The state of a table view that only the browser draws, by field. */
|
|
22
|
+
export interface LocalTableValues extends Record<LocalTableField, unknown> {
|
|
23
|
+
columnOrder: string[];
|
|
24
|
+
columnSizing: ColumnSizingState;
|
|
25
|
+
density: TableDensity;
|
|
26
|
+
filtersOpen: boolean;
|
|
27
|
+
kanbanGroupBy: string;
|
|
28
|
+
groupedGroupBy: string;
|
|
29
|
+
userViews: UserTableView[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The type of the value each preference field keeps. */
|
|
33
|
+
export type TablePreferenceValues = ServerTableValues & LocalTableValues;
|
|
17
34
|
|
|
18
35
|
/**
|
|
19
36
|
* The preferences of one table view. A field the server render needs
|
|
@@ -23,21 +40,33 @@ import {
|
|
|
23
40
|
*/
|
|
24
41
|
export interface TablePreferences {
|
|
25
42
|
/** A server field's stored value, else `defaultValue`; a local field's default. */
|
|
26
|
-
get: <
|
|
43
|
+
get: <F extends TableField, D extends TablePreferenceValues[F] | undefined>(
|
|
44
|
+
field: F,
|
|
45
|
+
defaultValue: D,
|
|
46
|
+
) => TablePreferenceValues[F] | D;
|
|
27
47
|
/** Stores `value`, or forgets the field when `value` is its default. */
|
|
28
|
-
set: <
|
|
48
|
+
set: <F extends TableField>(
|
|
49
|
+
field: F,
|
|
50
|
+
value: TablePreferenceValues[F] | undefined,
|
|
51
|
+
defaultValue: TablePreferenceValues[F] | undefined,
|
|
52
|
+
) => void;
|
|
29
53
|
/**
|
|
30
54
|
* Sets `state` to the local field's stored value once the table is
|
|
31
55
|
* mounted, unless `isValid` refuses it or `state` already holds it: the
|
|
32
56
|
* server and the hydrating client render the default, so no mismatch.
|
|
33
57
|
*/
|
|
34
|
-
restore: <
|
|
35
|
-
field:
|
|
36
|
-
state: Ref<
|
|
37
|
-
isValid?: (value:
|
|
58
|
+
restore: <F extends LocalTableField>(
|
|
59
|
+
field: F,
|
|
60
|
+
state: Ref<TablePreferenceValues[F]>,
|
|
61
|
+
isValid?: (value: TablePreferenceValues[F]) => boolean,
|
|
38
62
|
) => void;
|
|
39
63
|
}
|
|
40
64
|
|
|
65
|
+
/** The codec of each server field; a local field has none. */
|
|
66
|
+
const SERVER_CODECS: {
|
|
67
|
+
[F in TableField]?: ServerFieldCodec<TablePreferenceValues[F]>;
|
|
68
|
+
} = SERVER_TABLE_FIELDS;
|
|
69
|
+
|
|
41
70
|
type StoredValue = ReturnType<typeof readLocalTableEntry>[string];
|
|
42
71
|
|
|
43
72
|
/** A table state `restore` fills, with the check its caller gave it. */
|
|
@@ -74,14 +103,14 @@ function useServerTableEntry(id: string) {
|
|
|
74
103
|
removePreference(isLastEntry ? TABLES_PREFERENCE_KEY : path);
|
|
75
104
|
};
|
|
76
105
|
|
|
77
|
-
const set = (
|
|
78
|
-
|
|
79
|
-
value:
|
|
80
|
-
defaultValue:
|
|
106
|
+
const set = <V>(
|
|
107
|
+
codec: ServerFieldCodec<V>,
|
|
108
|
+
value: V | undefined,
|
|
109
|
+
defaultValue: V | undefined,
|
|
81
110
|
) => {
|
|
82
|
-
const { key } =
|
|
111
|
+
const { key } = codec;
|
|
83
112
|
const next = { ...entry() };
|
|
84
|
-
const encoded = encodeServerField(
|
|
113
|
+
const encoded = encodeServerField(codec, value, defaultValue);
|
|
85
114
|
if (JSON.stringify(next[key]) === JSON.stringify(encoded)) return;
|
|
86
115
|
if (encoded === undefined) Reflect.deleteProperty(next, key);
|
|
87
116
|
else next[key] = encoded;
|
|
@@ -101,9 +130,9 @@ function useServerTableEntry(id: string) {
|
|
|
101
130
|
|
|
102
131
|
const setLocalField = (
|
|
103
132
|
id: string,
|
|
104
|
-
field:
|
|
105
|
-
value:
|
|
106
|
-
defaultValue:
|
|
133
|
+
field: TableField,
|
|
134
|
+
value: TablePreferenceValues[TableField] | undefined,
|
|
135
|
+
defaultValue: TablePreferenceValues[TableField] | undefined,
|
|
107
136
|
) => {
|
|
108
137
|
const entry = readLocalTableEntry(id);
|
|
109
138
|
if (isDefaultValue(value, defaultValue)) {
|
|
@@ -142,14 +171,17 @@ export function useTablePreferences(
|
|
|
142
171
|
}
|
|
143
172
|
|
|
144
173
|
return {
|
|
145
|
-
get: (field, defaultValue) =>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
174
|
+
get: (field, defaultValue) => {
|
|
175
|
+
const codec = SERVER_CODECS[field];
|
|
176
|
+
return codec
|
|
177
|
+
? decodeServerField(codec, server.entry(), defaultValue)
|
|
178
|
+
: defaultValue;
|
|
179
|
+
},
|
|
180
|
+
set: (field, value, defaultValue) => {
|
|
181
|
+
const codec = SERVER_CODECS[field];
|
|
182
|
+
if (codec) server.set(codec, value, defaultValue);
|
|
183
|
+
else setLocalField(id, field, value, defaultValue);
|
|
184
|
+
},
|
|
153
185
|
restore: (field, state, isValid) => {
|
|
154
186
|
const target: RestoreTarget = { state, isValid };
|
|
155
187
|
pending.push({ field, apply: (value) => restoreInto(target, value) });
|
|
@@ -214,10 +214,7 @@ function arriveTableViews(context: ReturnType<typeof createTableViewState>) {
|
|
|
214
214
|
} = context;
|
|
215
215
|
|
|
216
216
|
const urlView = readTableUrlKey(route.query, urlScope, VIEW_URL_KEY);
|
|
217
|
-
const persistedViewId = preferences.get
|
|
218
|
-
"activeView",
|
|
219
|
-
undefined,
|
|
220
|
-
);
|
|
217
|
+
const persistedViewId = preferences.get("activeView", undefined);
|
|
221
218
|
let isUrlViewUnavailable = false;
|
|
222
219
|
let isUrlViewPending = false;
|
|
223
220
|
let isOpenedOnArrival = false;
|
|
@@ -255,11 +252,7 @@ function arriveTableViews(context: ReturnType<typeof createTableViewState>) {
|
|
|
255
252
|
};
|
|
256
253
|
|
|
257
254
|
const keepActiveView = () =>
|
|
258
|
-
preferences.set
|
|
259
|
-
"activeView",
|
|
260
|
-
keptViewId(activeViewId.value),
|
|
261
|
-
undefined,
|
|
262
|
-
);
|
|
255
|
+
preferences.set("activeView", keptViewId(activeViewId.value), undefined);
|
|
263
256
|
|
|
264
257
|
onMounted(() => {
|
|
265
258
|
arriveOnceMounted();
|
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
type TableField,
|
|
6
6
|
} from "#dms-core/app/entries/composables/user/tablePreferences";
|
|
7
7
|
import type { QueryParamFilters } from "../../../../composables/table-view/types/config";
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
TablePreferences,
|
|
10
|
+
TablePreferenceValues,
|
|
11
|
+
} from "../useTablePreferences";
|
|
9
12
|
import { RECORD_URL_KEY } from "./recordLink";
|
|
10
13
|
import { readTableUrlKey, type TableUrlScope, writeTableUrlKey } from "./views";
|
|
11
14
|
|
|
@@ -214,11 +217,13 @@ export function isLinkedVisit(visit: TableLinkVisit): boolean {
|
|
|
214
217
|
}
|
|
215
218
|
|
|
216
219
|
/** A kept field of the listing state, with its value shown and default. */
|
|
217
|
-
export type KeptListingField =
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
]
|
|
220
|
+
export type KeptListingField = {
|
|
221
|
+
[F in TableField]: [
|
|
222
|
+
field: F,
|
|
223
|
+
value: TablePreferenceValues[F] | undefined,
|
|
224
|
+
defaultValue: TablePreferenceValues[F] | undefined,
|
|
225
|
+
];
|
|
226
|
+
}[TableField];
|
|
222
227
|
|
|
223
228
|
/** What `linkFollowingPreferences` reads the table's link state from. */
|
|
224
229
|
export interface LinkFollowingOptions {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { ComponentInfo } from "#dms-core/app/types/page";
|
|
3
|
+
import type { ComponentOptionsData } from "#dms-core/app/types/component";
|
|
3
4
|
import { EYEBROW_CLASS } from "../../../build/utils/eyebrow";
|
|
4
5
|
import {
|
|
5
6
|
formBusInjectionKey,
|
|
@@ -20,7 +21,7 @@ interface RepeaterColumn {
|
|
|
20
21
|
id: string;
|
|
21
22
|
label?: string;
|
|
22
23
|
type?: string;
|
|
23
|
-
component: ComponentInfo
|
|
24
|
+
component: ComponentInfo<ComponentOptionsData>;
|
|
24
25
|
required?: boolean;
|
|
25
26
|
/** The cell's value in a row added or created to reach `min`. */
|
|
26
27
|
defaultValue?: FormFieldValue;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { ComponentInfo } from "#dms-core/app/types/page";
|
|
3
|
+
import type { ComponentOptionsData } from "#dms-core/app/types/component";
|
|
3
4
|
import { useControlError } from "../../../composables/form/useControlError";
|
|
4
5
|
import {
|
|
5
6
|
type KeyValueRow,
|
|
@@ -11,7 +12,7 @@ import DmsInputRepeater from "./InputRepeater.vue";
|
|
|
11
12
|
|
|
12
13
|
interface KeyValueColumn {
|
|
13
14
|
type?: string;
|
|
14
|
-
component: ComponentInfo
|
|
15
|
+
component: ComponentInfo<ComponentOptionsData>;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
interface KeyValueProps {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { z } from "zod";
|
|
2
2
|
import type { FormFieldOrGroup, FormSection, FormSectionNav } from "./field";
|
|
3
3
|
import type { FormSubmitResponse } from "./api";
|
|
4
4
|
import type { FormData } from "./value";
|
|
5
|
-
import type { validateFormState } from "../../../build/composables/form/formValidation";
|
|
6
5
|
import type {
|
|
7
6
|
FormKind,
|
|
8
7
|
FormSaveMode,
|
|
@@ -54,14 +53,11 @@ export interface FormProps extends FormComponentProps {
|
|
|
54
53
|
backTo?: string;
|
|
55
54
|
successMessage?: string;
|
|
56
55
|
errorMessage?: string;
|
|
57
|
-
schema?:
|
|
56
|
+
schema?: z.core.JSONSchema.BaseSchema;
|
|
58
57
|
watchActions?: WatchAction[];
|
|
59
58
|
onSuccessCallback?: (response?: FormSubmitResponse, data?: FormData) => void;
|
|
60
59
|
fieldsOrientation?: "horizontal" | "vertical";
|
|
61
|
-
submitDefaults?:
|
|
62
|
-
string,
|
|
63
|
-
Parameters<typeof validateFormState>[1][string]
|
|
64
|
-
>;
|
|
60
|
+
submitDefaults?: FormData;
|
|
65
61
|
containerId?: string;
|
|
66
62
|
redirectOnSuccess?: string;
|
|
67
63
|
/** Field of the loaded row a page form names in the breadcrumb. */
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
collectSubmitData,
|
|
23
23
|
computeResetState,
|
|
24
24
|
processBeforeStateMappers,
|
|
25
|
+
type FormStateValues,
|
|
25
26
|
resolveFormFieldErrors,
|
|
26
27
|
resolveSubmitTarget,
|
|
27
28
|
snapshotFormState,
|
|
@@ -257,7 +258,7 @@ function createSavedForm(context: ReturnType<typeof createFormNotices>) {
|
|
|
257
258
|
};
|
|
258
259
|
|
|
259
260
|
/** Applies the saved record without clearing the saved flag in the watcher. */
|
|
260
|
-
const applyStoredRecord = async (stored:
|
|
261
|
+
const applyStoredRecord = async (stored: FormStateValues): Promise<void> => {
|
|
261
262
|
lifecycle.isApplyingSavedRecord = true;
|
|
262
263
|
Object.assign(state.value, stored);
|
|
263
264
|
options.onSaved?.();
|
|
@@ -267,7 +268,7 @@ function createSavedForm(context: ReturnType<typeof createFormNotices>) {
|
|
|
267
268
|
|
|
268
269
|
/** Re-reads a saved record, keeping intervening edits or failed-read values. */
|
|
269
270
|
const refreshSavedRecord = async (): Promise<void> => {
|
|
270
|
-
let stored:
|
|
271
|
+
let stored: FormStateValues | undefined;
|
|
271
272
|
try {
|
|
272
273
|
stored = await loadRecord();
|
|
273
274
|
} catch {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../build/composables/form/useFormModel";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1-next.1028.g8526d04",
|
|
4
4
|
"description": "AntelopeJS DMS. Plug in your PostgreSQL, MySQL, MariaDB, MongoDB or RethinkDB database and your coding agent builds a back office and analytics dashboard as typed TypeScript. Real-time updates on the data the DMS manages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"frontend-vue",
|
|
49
49
|
"!frontend-vue/tests",
|
|
50
50
|
"!frontend-vue/jsconfig.json",
|
|
51
|
-
"!frontend-vue/.oxlint-pending",
|
|
52
51
|
"!frontend-vue/scripts/eslint-globals.mjs",
|
|
53
52
|
"!frontend-vue/scripts/layer-auto-imports.mjs",
|
|
54
53
|
"!frontend-vue/vitest.config.ts",
|
|
@@ -89,6 +88,8 @@
|
|
|
89
88
|
"@antelopejs/interface-data-api": ">=0.8.0 <0.9.0",
|
|
90
89
|
"@antelopejs/interface-database": ">=0.4.0 <0.5.0",
|
|
91
90
|
"@antelopejs/interface-database-decorators": ">=0.5.2 <0.6.0",
|
|
91
|
+
"@antelopejs/interface-dms": "^0.16.0",
|
|
92
|
+
"@antelopejs/interface-dms-builder": "^0.6.2",
|
|
92
93
|
"@antelopejs/interface-email": ">=0.2.1 <0.3.0",
|
|
93
94
|
"@antelopejs/interface-file-storage": ">=0.1.4 <0.2.0",
|
|
94
95
|
"@csstools/css-tokenizer": "4.0.0",
|
|
@@ -110,9 +111,7 @@
|
|
|
110
111
|
"striptags": "^3.2.0",
|
|
111
112
|
"ts-morph": "^28.0.0",
|
|
112
113
|
"ua-parser-js": "^2.0.9",
|
|
113
|
-
"zod": "^4.5.0"
|
|
114
|
-
"@antelopejs/interface-dms": "^0.16.0",
|
|
115
|
-
"@antelopejs/interface-dms-builder": "^0.6.2"
|
|
114
|
+
"zod": "^4.5.0"
|
|
116
115
|
},
|
|
117
116
|
"devDependencies": {
|
|
118
117
|
"@antelopejs/api": "~1.7.8",
|
|
@@ -212,7 +211,7 @@
|
|
|
212
211
|
"optional": true
|
|
213
212
|
}
|
|
214
213
|
},
|
|
215
|
-
"gitHead": "
|
|
214
|
+
"gitHead": "8526d0478a0279bf524974dec2953210fd6a5d35",
|
|
216
215
|
"scripts": {
|
|
217
216
|
"build": "pnpm --filter @antelopejs/interface-dms --filter @antelopejs/interface-dms-builder build && rimraf dist && antelopejs-tsc && tsc-alias && tsc -p e2e/tsconfig.types.json",
|
|
218
217
|
"dev": "ajs project run --inspect -w -p playground",
|