@jskit-ai/http-web 0.2.8 → 0.2.9
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 +7 -6
- package/src/client/bulkActions.js +2 -0
- package/src/client/components/CrudAddEditScreen.vue +13 -18
- package/src/client/components/CrudDeleteAction.vue +1 -1
- package/src/client/components/CrudListBulkActionSurface.vue +13 -13
- package/src/client/components/CrudListDateFilterControl.vue +2 -2
- package/src/client/components/CrudListFilterControls.vue +4 -4
- package/src/client/components/CrudListFilterSurface.vue +8 -8
- package/src/client/components/CrudListRecordActionMenu.vue +9 -19
- package/src/client/components/CrudListScreen.vue +21 -39
- package/src/client/components/CrudViewScreen.vue +4 -4
- package/src/client/components/SelectField.vue +1 -0
- package/src/client/composables/crud/crudHttpClientSupport.js +10 -10
- package/src/client/composables/crud/crudJsonApiTransportSupport.js +1 -0
- package/src/client/composables/crud/crudLookupFieldRuntime.js +3 -3
- package/src/client/composables/crud/crudSchemaFormHelpers.js +3 -3
- package/src/client/composables/internal/crudListFilterLookupSupport.js +10 -8
- package/src/client/composables/internal/crudListParentTitleSupport.js +2 -2
- package/src/client/composables/internal/useOperationScope.js +7 -5
- package/src/client/composables/records/useAddEdit.js +12 -11
- package/src/client/composables/records/useCrudAddEdit.js +27 -40
- package/src/client/composables/records/useCrudList.js +4 -11
- package/src/client/composables/records/useCrudView.js +4 -10
- package/src/client/composables/records/useList.js +18 -11
- package/src/client/composables/records/useView.js +18 -11
- package/src/client/composables/runtime/addEditUiRuntime.js +10 -17
- package/src/client/composables/runtime/listUiRuntime.js +17 -20
- package/src/client/composables/runtime/modelStateHelpers.js +18 -8
- package/src/client/composables/runtime/operationUiHelpers.js +20 -20
- package/src/client/composables/runtime/operationValidationHelpers.js +10 -5
- package/src/client/composables/runtime/useAddEditCore.js +39 -36
- package/src/client/composables/runtime/useCommandCore.js +33 -32
- package/src/client/composables/runtime/useEndpointResource.js +10 -14
- package/src/client/composables/runtime/useFieldErrorBag.js +3 -2
- package/src/client/composables/runtime/useListCore.js +7 -11
- package/src/client/composables/runtime/useUiFeedback.js +3 -2
- package/src/client/composables/runtime/useViewCore.js +10 -20
- package/src/client/composables/runtime/viewUiRuntime.js +7 -6
- package/src/client/composables/support/listQueryParamSupport.js +6 -10
- package/src/client/composables/support/refValueHelpers.js +2 -6
- package/src/client/composables/support/requestQueryRuntimeSupport.js +2 -2
- package/src/client/composables/support/routeTemplateHelpers.js +13 -12
- package/src/client/composables/support/scopeHelpers.js +5 -4
- package/src/client/composables/useAccess.js +8 -5
- package/src/client/composables/useCommand.js +7 -6
- package/src/client/composables/useCrudAddEditScreen.js +13 -12
- package/src/client/composables/useCrudDeleteAction.js +13 -25
- package/src/client/composables/useCrudListBulkActions.js +18 -14
- package/src/client/composables/useCrudListFilterLookups.js +8 -4
- package/src/client/composables/useCrudListFilters.js +13 -6
- package/src/client/composables/useCrudListParentTitle.js +10 -9
- package/src/client/composables/useCrudListRowActions.js +15 -11
- package/src/client/composables/useCrudListScreen.js +17 -16
- package/src/client/composables/useCrudViewScreen.js +8 -7
- package/src/client/composables/usePagedCollection.js +9 -18
- package/src/client/composables/useRealtimeQueryInvalidation.js +15 -13
- package/src/client/composables/useScopeRuntime.js +3 -2
- package/src/client/lib/httpClient.js +12 -10
- package/src/client/rowActions.js +2 -0
- package/src/client/support/crudListActionSupport.js +16 -8
- package/src/client/types.js +596 -0
- package/test/crudScreenComponents.test.js +4 -2
- package/test/exportsContract.test.js +1 -0
- package/test/requestTransportOptions.test.js +7 -7
- package/test/translation.test.js +3 -0
- package/test/useAddEditCore.test.js +4 -0
- package/test/useCrudDeleteAction.test.js +4 -4
- package/test/viewCoreLoading.test.js +0 -19
|
@@ -20,26 +20,27 @@ import { useJskitText } from "../../i18n.js";
|
|
|
20
20
|
|
|
21
21
|
const { t } = useJskitText();
|
|
22
22
|
|
|
23
|
+
/** @param {import("../../types.js").AddEditOptions} options */
|
|
23
24
|
function useAddEdit({
|
|
24
25
|
ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
|
|
25
26
|
surfaceId = "",
|
|
26
27
|
access = "auto",
|
|
27
28
|
resource = null,
|
|
28
29
|
apiSuffix = "",
|
|
29
|
-
queryKeyFactory
|
|
30
|
+
queryKeyFactory,
|
|
30
31
|
viewPermissions = [],
|
|
31
32
|
savePermissions = [],
|
|
32
33
|
readMethod = "GET",
|
|
33
34
|
readEnabled = true,
|
|
34
35
|
writeMethod = "PATCH",
|
|
35
|
-
client
|
|
36
|
-
transport
|
|
37
|
-
requestRecovery
|
|
36
|
+
client,
|
|
37
|
+
transport,
|
|
38
|
+
requestRecovery,
|
|
38
39
|
requestRecoveryLabel = t("jskit.http.resource.label"),
|
|
39
40
|
placementSource = "http-web.add-edit",
|
|
40
41
|
fallbackLoadError = t("jskit.http.resource.loadFailed"),
|
|
41
42
|
fallbackSaveError = "",
|
|
42
|
-
fieldErrorKeys
|
|
43
|
+
fieldErrorKeys,
|
|
43
44
|
clearOnRouteChange = true,
|
|
44
45
|
model,
|
|
45
46
|
input,
|
|
@@ -48,17 +49,17 @@ function useAddEdit({
|
|
|
48
49
|
buildSavePayload,
|
|
49
50
|
onSaveSuccess,
|
|
50
51
|
validationFeedback = true,
|
|
51
|
-
requestQueryParams
|
|
52
|
+
requestQueryParams,
|
|
52
53
|
recordIdParam = "recordId",
|
|
53
54
|
routeParams = null,
|
|
54
|
-
routeRecordId
|
|
55
|
+
routeRecordId,
|
|
55
56
|
apiUrlTemplate = "",
|
|
56
57
|
viewUrlTemplate = "",
|
|
57
58
|
listUrlTemplate = "",
|
|
58
|
-
saveRecordIdSelector
|
|
59
|
+
saveRecordIdSelector,
|
|
59
60
|
messages = {},
|
|
60
|
-
realtime
|
|
61
|
-
}
|
|
61
|
+
realtime
|
|
62
|
+
}) {
|
|
62
63
|
const route = useRoute();
|
|
63
64
|
const addEditUiRuntime = createAddEditUiRuntime({
|
|
64
65
|
recordIdParam,
|
|
@@ -178,7 +179,7 @@ function useAddEdit({
|
|
|
178
179
|
);
|
|
179
180
|
const loadError = operationScope.loadError(endpointResource.loadError);
|
|
180
181
|
const isLoading = operationScope.isLoading(endpointResource.isLoading);
|
|
181
|
-
const canRetryLoad = computed(() =>
|
|
182
|
+
const canRetryLoad = computed(() => readEnabled !== false);
|
|
182
183
|
|
|
183
184
|
async function refresh() {
|
|
184
185
|
if (!canRetryLoad.value) {
|
|
@@ -100,18 +100,23 @@ function normalizeSaveSuccessOptions(options = {}) {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
function buildFormPayload(model, { fields }) {
|
|
104
|
+
return buildCrudFormPayload(fields, model);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** @param {import("../../types.js").CrudAddEditOptions} options */
|
|
103
108
|
function useCrudAddEdit({
|
|
104
|
-
resource
|
|
109
|
+
resource,
|
|
105
110
|
operationName = "",
|
|
106
111
|
formFields = [],
|
|
107
112
|
addEditOptions = {},
|
|
108
113
|
saveSuccess = {},
|
|
109
114
|
fieldBinding = null,
|
|
110
|
-
createModel =
|
|
111
|
-
buildPayload =
|
|
112
|
-
mapPayloadToModel
|
|
113
|
-
input
|
|
114
|
-
}
|
|
115
|
+
createModel = createCrudFormModel,
|
|
116
|
+
buildPayload = buildFormPayload,
|
|
117
|
+
mapPayloadToModel,
|
|
118
|
+
input
|
|
119
|
+
}) {
|
|
115
120
|
const router = useRouter();
|
|
116
121
|
const route = useRoute();
|
|
117
122
|
const normalizedFields = normalizeCrudFormFields(formFields);
|
|
@@ -137,10 +142,7 @@ function useCrudAddEdit({
|
|
|
137
142
|
const fieldErrorKeys = providedFieldErrorKeys.length > 0 ? providedFieldErrorKeys : defaultFieldErrorKeys;
|
|
138
143
|
const providedModel = normalizedAddEditOptions.model;
|
|
139
144
|
const hasProvidedModel = Boolean(providedModel && typeof providedModel === "object" && !Array.isArray(providedModel));
|
|
140
|
-
const
|
|
141
|
-
? asPlainObject(createModel(normalizedFields))
|
|
142
|
-
: createCrudFormModel(normalizedFields);
|
|
143
|
-
const form = hasProvidedModel ? providedModel : reactive(defaultModel);
|
|
145
|
+
const form = hasProvidedModel ? providedModel : reactive(asPlainObject(createModel(normalizedFields)));
|
|
144
146
|
const boundFieldValues = computed(() => {
|
|
145
147
|
return resolveCrudBoundValues({
|
|
146
148
|
binding: fieldBinding,
|
|
@@ -167,29 +169,23 @@ function useCrudAddEdit({
|
|
|
167
169
|
deep: true
|
|
168
170
|
}
|
|
169
171
|
);
|
|
170
|
-
const buildPayloadOverride = typeof buildPayload === "function" ? buildPayload : null;
|
|
171
|
-
const mapPayloadToModelOverride = typeof mapPayloadToModel === "function" ? mapPayloadToModel : null;
|
|
172
|
-
const onSaveSuccessOverride = typeof normalizedAddEditOptions.onSaveSuccess === "function"
|
|
173
|
-
? normalizedAddEditOptions.onSaveSuccess
|
|
174
|
-
: null;
|
|
175
172
|
const shouldApplyDefaultMapPayload = normalizedAddEditOptions.readEnabled !== false;
|
|
176
173
|
const resolvedInput = input || resource?.operations?.[operationName]?.body || null;
|
|
177
174
|
|
|
178
175
|
function resolveBuildRawPayload(model = {}, context = {}) {
|
|
179
|
-
const payload =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
})
|
|
184
|
-
: buildCrudFormPayload(normalizedFields, model);
|
|
176
|
+
const payload = buildPayload(model, {
|
|
177
|
+
...context,
|
|
178
|
+
fields: normalizedFields
|
|
179
|
+
});
|
|
185
180
|
applyBoundFieldValues(payload);
|
|
186
181
|
|
|
187
182
|
return payload;
|
|
188
183
|
}
|
|
189
184
|
|
|
190
|
-
|
|
185
|
+
// readable-check: allow method-probe - optional operation: without mapPayloadToModel a form maps the payload by its fields, or not at all when it reads nothing
|
|
186
|
+
const effectiveMapLoadedToModel = typeof mapPayloadToModel === "function"
|
|
191
187
|
? (model = {}, payload = {}, context = {}) => {
|
|
192
|
-
|
|
188
|
+
mapPayloadToModel(model, payload, {
|
|
193
189
|
...context,
|
|
194
190
|
fields: normalizedFields
|
|
195
191
|
});
|
|
@@ -202,24 +198,16 @@ function useCrudAddEdit({
|
|
|
202
198
|
}
|
|
203
199
|
: undefined);
|
|
204
200
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
async function handleSaveSuccess(payload, context = {}) {
|
|
208
|
-
if (onSaveSuccessOverride) {
|
|
209
|
-
await onSaveSuccessOverride(payload, context);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const queryClient = context?.queryClient;
|
|
214
|
-
if (queryClient && saveSuccessOptions.invalidateQueryKey?.length > 0) {
|
|
201
|
+
async function handleSaveSuccess(payload, { queryClient }) {
|
|
202
|
+
if (saveSuccessOptions.invalidateQueryKey?.length > 0) {
|
|
215
203
|
await queryClient.invalidateQueries({
|
|
216
204
|
queryKey: saveSuccessOptions.invalidateQueryKey
|
|
217
205
|
});
|
|
218
206
|
}
|
|
219
207
|
|
|
220
208
|
if (saveSuccessOptions.navigateToView) {
|
|
221
|
-
const viewUrl =
|
|
222
|
-
|
|
209
|
+
const viewUrl = addEdit.resolveSavedViewUrl(payload) ||
|
|
210
|
+
addEdit.resolveViewUrl(addEdit.recordId);
|
|
223
211
|
if (viewUrl) {
|
|
224
212
|
await router.push(viewUrl);
|
|
225
213
|
return;
|
|
@@ -230,7 +218,7 @@ function useCrudAddEdit({
|
|
|
230
218
|
return;
|
|
231
219
|
}
|
|
232
220
|
|
|
233
|
-
const listUrl =
|
|
221
|
+
const listUrl = addEdit.resolveParams(saveSuccessOptions.listUrlTemplate);
|
|
234
222
|
if (listUrl) {
|
|
235
223
|
await router.push(listUrl);
|
|
236
224
|
}
|
|
@@ -249,9 +237,8 @@ function useCrudAddEdit({
|
|
|
249
237
|
buildRawPayload: resolveBuildRawPayload,
|
|
250
238
|
mapLoadedToModel: effectiveMapLoadedToModel,
|
|
251
239
|
realtime: resolvedRealtime,
|
|
252
|
-
onSaveSuccess: handleSaveSuccess
|
|
240
|
+
onSaveSuccess: normalizedAddEditOptions.onSaveSuccess ?? handleSaveSuccess
|
|
253
241
|
});
|
|
254
|
-
addEditRuntime = addEdit;
|
|
255
242
|
|
|
256
243
|
function resolveFieldErrors(fieldKey = "") {
|
|
257
244
|
return resolveCrudFieldErrors(addEdit.fieldErrors, fieldKey);
|
|
@@ -259,8 +246,8 @@ function useCrudAddEdit({
|
|
|
259
246
|
|
|
260
247
|
const showFormSkeleton = computed(() => {
|
|
261
248
|
const hasResolvedData = hasResolvedQueryData({
|
|
262
|
-
query: addEdit
|
|
263
|
-
data: addEdit
|
|
249
|
+
query: addEdit.resource.query,
|
|
250
|
+
data: addEdit.resource.data
|
|
264
251
|
});
|
|
265
252
|
|
|
266
253
|
return Boolean(addEdit.isInitialLoading) && !hasResolvedData;
|
|
@@ -2,10 +2,6 @@ import { computed, unref } from "vue";
|
|
|
2
2
|
import { useRoute } from "vue-router";
|
|
3
3
|
import { resolveCrudJsonApiTransport } from "../crud/crudJsonApiTransportSupport.js";
|
|
4
4
|
import { resolveCrudHttpClient } from "../crud/crudHttpClientSupport.js";
|
|
5
|
-
import {
|
|
6
|
-
resolveLookupFieldDisplayValue,
|
|
7
|
-
resolveRecordTitle
|
|
8
|
-
} from "../crud/crudLookupFieldLabelSupport.js";
|
|
9
5
|
import { resolveCrudBoundValues } from "../crud/crudBindingSupport.js";
|
|
10
6
|
import { resolveCrudListParentDescriptor } from "../internal/crudListParentTitleSupport.js";
|
|
11
7
|
import {
|
|
@@ -45,15 +41,16 @@ function resolveCrudParentRequestQueryParams({ resource = {}, route = null, reco
|
|
|
45
41
|
};
|
|
46
42
|
}
|
|
47
43
|
|
|
44
|
+
/** @param {import("../../types.js").CrudListOptions} options */
|
|
48
45
|
function useCrudList({
|
|
49
46
|
resource = null,
|
|
50
47
|
requestQueryParams = null,
|
|
51
48
|
parentBinding = null,
|
|
52
49
|
recordIdParam = "recordId",
|
|
53
50
|
route = null,
|
|
54
|
-
realtime
|
|
51
|
+
realtime,
|
|
55
52
|
...listOptions
|
|
56
|
-
}
|
|
53
|
+
}) {
|
|
57
54
|
const sourceRoute = route && typeof route === "object" ? route : useRoute();
|
|
58
55
|
const boundParentRequestQueryParams = computed(() => {
|
|
59
56
|
return resolveCrudBoundValues({
|
|
@@ -70,7 +67,7 @@ function useCrudList({
|
|
|
70
67
|
})
|
|
71
68
|
});
|
|
72
69
|
});
|
|
73
|
-
|
|
70
|
+
return useList({
|
|
74
71
|
...listOptions,
|
|
75
72
|
client: resolveCrudHttpClient(resource, {
|
|
76
73
|
client: listOptions.client
|
|
@@ -92,10 +89,6 @@ function useCrudList({
|
|
|
92
89
|
};
|
|
93
90
|
}
|
|
94
91
|
});
|
|
95
|
-
|
|
96
|
-
records.resolveFieldDisplay = resolveLookupFieldDisplayValue;
|
|
97
|
-
records.resolveRecordTitle = resolveRecordTitle;
|
|
98
|
-
return records;
|
|
99
92
|
}
|
|
100
93
|
|
|
101
94
|
export { useCrudList };
|
|
@@ -4,20 +4,17 @@ import {
|
|
|
4
4
|
resolveCrudJsonApiTransport
|
|
5
5
|
} from "../crud/crudJsonApiTransportSupport.js";
|
|
6
6
|
import { resolveCrudHttpClient } from "../crud/crudHttpClientSupport.js";
|
|
7
|
-
import {
|
|
8
|
-
resolveLookupFieldDisplayValue,
|
|
9
|
-
resolveRecordTitle
|
|
10
|
-
} from "../crud/crudLookupFieldLabelSupport.js";
|
|
11
7
|
import { resolveCrudBoundValues } from "../crud/crudBindingSupport.js";
|
|
12
8
|
import { asPlainObject } from "../support/scopeHelpers.js";
|
|
13
9
|
import { useView } from "./useView.js";
|
|
14
10
|
|
|
11
|
+
/** @param {import("../../types.js").CrudViewOptions} options */
|
|
15
12
|
function useCrudView({
|
|
16
|
-
resource
|
|
13
|
+
resource,
|
|
17
14
|
paramBinding = null,
|
|
18
15
|
route = null,
|
|
19
16
|
...viewOptions
|
|
20
|
-
}
|
|
17
|
+
}) {
|
|
21
18
|
const sourceRoute = route && typeof route === "object" ? route : useRoute();
|
|
22
19
|
const boundRouteParams = computed(() => {
|
|
23
20
|
return resolveCrudBoundValues({
|
|
@@ -28,7 +25,7 @@ function useCrudView({
|
|
|
28
25
|
})
|
|
29
26
|
});
|
|
30
27
|
});
|
|
31
|
-
|
|
28
|
+
return useView({
|
|
32
29
|
...viewOptions,
|
|
33
30
|
resource,
|
|
34
31
|
client: resolveCrudHttpClient(resource, {
|
|
@@ -39,9 +36,6 @@ function useCrudView({
|
|
|
39
36
|
}),
|
|
40
37
|
routeParams: boundRouteParams
|
|
41
38
|
});
|
|
42
|
-
view.resolveFieldDisplay = resolveLookupFieldDisplayValue;
|
|
43
|
-
view.resolveRecordTitle = resolveRecordTitle;
|
|
44
|
-
return view;
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
export { useCrudView };
|
|
@@ -2,6 +2,10 @@ import { computed, onScopeDispose, proxyRefs, ref, watch } from "vue";
|
|
|
2
2
|
import { useRouter } from "vue-router";
|
|
3
3
|
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
4
4
|
import { ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/kernel/shared/support/visibility";
|
|
5
|
+
import {
|
|
6
|
+
resolveLookupFieldDisplayValue,
|
|
7
|
+
resolveRecordTitle
|
|
8
|
+
} from "../crud/crudLookupFieldLabelSupport.js";
|
|
5
9
|
import { useListCore } from "../runtime/useListCore.js";
|
|
6
10
|
import { useOperationScope } from "../internal/useOperationScope.js";
|
|
7
11
|
import { setupOperationErrorReporting } from "../runtime/operationUiHelpers.js";
|
|
@@ -36,37 +40,38 @@ const { t } = useJskitText();
|
|
|
36
40
|
|
|
37
41
|
const EMPTY_ROUTE_SYNC_QUERY_PARAM_BLACKLIST = Object.freeze([]);
|
|
38
42
|
|
|
43
|
+
/** @param {import("../../types.js").ListOptions} options */
|
|
39
44
|
function useList({
|
|
40
45
|
ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
|
|
41
46
|
surfaceId = "",
|
|
42
47
|
access = "auto",
|
|
43
48
|
apiSuffix = "",
|
|
44
|
-
queryKeyFactory
|
|
49
|
+
queryKeyFactory,
|
|
45
50
|
viewPermissions = [],
|
|
46
51
|
readEnabled = true,
|
|
47
52
|
placementSource = "http-web.list",
|
|
48
53
|
fallbackLoadError = t("jskit.http.list.loadFailed"),
|
|
49
|
-
initialPageParam
|
|
54
|
+
initialPageParam,
|
|
50
55
|
getNextPageParam,
|
|
51
56
|
selectItems,
|
|
52
|
-
client
|
|
53
|
-
transport
|
|
57
|
+
client,
|
|
58
|
+
transport,
|
|
54
59
|
requestOptions,
|
|
55
60
|
queryOptions,
|
|
56
61
|
requestRecovery,
|
|
57
62
|
requestRecoveryLabel = t("jskit.http.list.label"),
|
|
58
|
-
realtime
|
|
63
|
+
realtime,
|
|
59
64
|
recordIdParam = "recordId",
|
|
60
|
-
recordIdSelector
|
|
65
|
+
recordIdSelector,
|
|
61
66
|
viewUrlTemplate = "",
|
|
62
67
|
editUrlTemplate = "",
|
|
63
68
|
search = null,
|
|
64
69
|
queryParams = null,
|
|
65
70
|
routeQueryValueResolvers = null,
|
|
66
|
-
requestQueryParams
|
|
67
|
-
requestFieldsets
|
|
71
|
+
requestQueryParams,
|
|
72
|
+
requestFieldsets,
|
|
68
73
|
syncToRoute = false
|
|
69
|
-
}
|
|
74
|
+
}) {
|
|
70
75
|
const searchConfig = normalizeListSearchConfig(search);
|
|
71
76
|
const routeSyncConfig = normalizeListSyncToRouteConfig(syncToRoute, {
|
|
72
77
|
defaultSearchParam: searchConfig.queryParam
|
|
@@ -339,7 +344,7 @@ function useList({
|
|
|
339
344
|
const nextValue = parseRouteBindingValue(binding, routeQuerySource[binding.key], {
|
|
340
345
|
initial: initialHydration
|
|
341
346
|
});
|
|
342
|
-
const currentValue =
|
|
347
|
+
const currentValue = binding.get();
|
|
343
348
|
if (areQueryParamBindingValuesEqual(currentValue, nextValue)) {
|
|
344
349
|
continue;
|
|
345
350
|
}
|
|
@@ -490,7 +495,9 @@ function useList({
|
|
|
490
495
|
searchLabel: searchConfig.label,
|
|
491
496
|
searchPlaceholder: searchConfig.placeholder,
|
|
492
497
|
isSearchDebouncing,
|
|
493
|
-
activeQueryParamsToken
|
|
498
|
+
activeQueryParamsToken,
|
|
499
|
+
resolveFieldDisplay: resolveLookupFieldDisplayValue,
|
|
500
|
+
resolveRecordTitle
|
|
494
501
|
});
|
|
495
502
|
}
|
|
496
503
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { computed, proxyRefs } from "vue";
|
|
2
2
|
import { useRoute } from "vue-router";
|
|
3
3
|
import { ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/kernel/shared/support/visibility";
|
|
4
|
+
import {
|
|
5
|
+
resolveLookupFieldDisplayValue,
|
|
6
|
+
resolveRecordTitle
|
|
7
|
+
} from "../crud/crudLookupFieldLabelSupport.js";
|
|
4
8
|
import { useViewCore } from "../runtime/useViewCore.js";
|
|
5
9
|
import { useEndpointResource } from "../runtime/useEndpointResource.js";
|
|
6
10
|
import { useOperationScope } from "../internal/useOperationScope.js";
|
|
@@ -13,19 +17,20 @@ import { useJskitText } from "../../i18n.js";
|
|
|
13
17
|
|
|
14
18
|
const { t } = useJskitText();
|
|
15
19
|
|
|
20
|
+
/** @param {import("../../types.js").ViewOptions} options */
|
|
16
21
|
function useView({
|
|
17
|
-
resource
|
|
22
|
+
resource,
|
|
18
23
|
ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
|
|
19
24
|
surfaceId = "",
|
|
20
25
|
access = "auto",
|
|
21
26
|
apiSuffix = "",
|
|
22
|
-
queryKeyFactory
|
|
27
|
+
queryKeyFactory,
|
|
23
28
|
viewPermissions = [],
|
|
24
29
|
readMethod = "GET",
|
|
25
30
|
readEnabled = true,
|
|
26
|
-
client
|
|
27
|
-
transport
|
|
28
|
-
requestRecovery
|
|
31
|
+
client,
|
|
32
|
+
transport,
|
|
33
|
+
requestRecovery,
|
|
29
34
|
requestRecoveryLabel = t("jskit.http.resource.label"),
|
|
30
35
|
placementSource = "http-web.view",
|
|
31
36
|
fallbackLoadError = t("jskit.http.resource.loadFailed"),
|
|
@@ -33,17 +38,17 @@ function useView({
|
|
|
33
38
|
notFoundMessage = t("jskit.http.crud.recordNotFound"),
|
|
34
39
|
model,
|
|
35
40
|
mapLoadedToModel,
|
|
36
|
-
requestQueryParams
|
|
37
|
-
requestFieldsets
|
|
41
|
+
requestQueryParams,
|
|
42
|
+
requestFieldsets,
|
|
38
43
|
recordIdParam = "recordId",
|
|
39
44
|
routeParams = null,
|
|
40
|
-
routeRecordId
|
|
45
|
+
routeRecordId,
|
|
41
46
|
apiUrlTemplate = "",
|
|
42
47
|
listUrlTemplate = "",
|
|
43
48
|
editUrlTemplate = "",
|
|
44
49
|
includeRecordIdInQueryKey = false,
|
|
45
|
-
realtime
|
|
46
|
-
}
|
|
50
|
+
realtime
|
|
51
|
+
}) {
|
|
47
52
|
const route = useRoute();
|
|
48
53
|
const viewUiRuntime = createViewUiRuntime({
|
|
49
54
|
recordIdParam,
|
|
@@ -155,7 +160,9 @@ function useView({
|
|
|
155
160
|
notFoundError: view.notFoundError,
|
|
156
161
|
loadError,
|
|
157
162
|
refresh: view.refresh,
|
|
158
|
-
resource: endpointResource
|
|
163
|
+
resource: endpointResource,
|
|
164
|
+
resolveFieldDisplay: resolveLookupFieldDisplayValue,
|
|
165
|
+
resolveRecordTitle
|
|
159
166
|
});
|
|
160
167
|
}
|
|
161
168
|
|
|
@@ -3,29 +3,22 @@ import { asPlainObject } from "../support/scopeHelpers.js";
|
|
|
3
3
|
import {
|
|
4
4
|
createRouteTemplateResolver,
|
|
5
5
|
normalizeRouteParamName,
|
|
6
|
+
selectRecordId,
|
|
6
7
|
toRouteParamValue
|
|
7
8
|
} from "../support/routeTemplateHelpers.js";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
const sourcePayload = asPlainObject(payload);
|
|
11
|
-
if (typeof saveRecordIdSelector === "function") {
|
|
12
|
-
return toRouteParamValue(saveRecordIdSelector(sourcePayload));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return toRouteParamValue(sourcePayload.id);
|
|
16
|
-
}
|
|
17
|
-
|
|
10
|
+
/** @param {import("../../types.js").AddEditUiRuntimeOptions} options */
|
|
18
11
|
function createAddEditUiRuntime({
|
|
19
12
|
recordIdParam = "recordId",
|
|
20
|
-
routeParams
|
|
21
|
-
routeParamNames
|
|
13
|
+
routeParams,
|
|
14
|
+
routeParamNames,
|
|
22
15
|
routePath = "",
|
|
23
|
-
routeRecordId
|
|
16
|
+
routeRecordId,
|
|
24
17
|
apiUrlTemplate = "",
|
|
25
18
|
viewUrlTemplate = "",
|
|
26
19
|
listUrlTemplate = "",
|
|
27
|
-
saveRecordIdSelector =
|
|
28
|
-
}
|
|
20
|
+
saveRecordIdSelector = selectRecordId
|
|
21
|
+
}) {
|
|
29
22
|
const normalizedRecordIdParam = normalizeRouteParamName(recordIdParam, {
|
|
30
23
|
context: "useAddEdit recordIdParam"
|
|
31
24
|
});
|
|
@@ -60,7 +53,7 @@ function createAddEditUiRuntime({
|
|
|
60
53
|
}
|
|
61
54
|
|
|
62
55
|
function resolveSavedViewUrl(payload = {}) {
|
|
63
|
-
const targetRecordId =
|
|
56
|
+
const targetRecordId = toRouteParamValue(saveRecordIdSelector(asPlainObject(payload)));
|
|
64
57
|
if (!targetRecordId) {
|
|
65
58
|
return "";
|
|
66
59
|
}
|
|
@@ -68,7 +61,7 @@ function createAddEditUiRuntime({
|
|
|
68
61
|
return resolveViewUrl(targetRecordId);
|
|
69
62
|
}
|
|
70
63
|
|
|
71
|
-
return
|
|
64
|
+
return {
|
|
72
65
|
recordId,
|
|
73
66
|
apiSuffix,
|
|
74
67
|
listUrl,
|
|
@@ -76,7 +69,7 @@ function createAddEditUiRuntime({
|
|
|
76
69
|
resolveParams: resolveTemplatePath,
|
|
77
70
|
resolveViewUrl,
|
|
78
71
|
resolveSavedViewUrl
|
|
79
|
-
}
|
|
72
|
+
};
|
|
80
73
|
}
|
|
81
74
|
|
|
82
75
|
export { createAddEditUiRuntime };
|
|
@@ -3,29 +3,22 @@ import { asPlainObject } from "../support/scopeHelpers.js";
|
|
|
3
3
|
import {
|
|
4
4
|
createRouteTemplateResolver,
|
|
5
5
|
normalizeRouteParamName,
|
|
6
|
+
selectRecordId,
|
|
6
7
|
toRouteParamValue
|
|
7
8
|
} from "../support/routeTemplateHelpers.js";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
const item = asPlainObject(record);
|
|
11
|
-
if (typeof recordIdSelector === "function") {
|
|
12
|
-
return toRouteParamValue(recordIdSelector(item));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return toRouteParamValue(item.id);
|
|
16
|
-
}
|
|
17
|
-
|
|
10
|
+
/** @param {import("../../types.js").ListUiRuntimeOptions} options */
|
|
18
11
|
function createListUiRuntime({
|
|
19
12
|
items,
|
|
20
13
|
isInitialLoading,
|
|
21
14
|
recordIdParam = "recordId",
|
|
22
|
-
recordIdSelector =
|
|
23
|
-
routeParams
|
|
24
|
-
routeParamNames
|
|
15
|
+
recordIdSelector = selectRecordId,
|
|
16
|
+
routeParams,
|
|
17
|
+
routeParamNames,
|
|
25
18
|
routePath = "",
|
|
26
19
|
viewUrlTemplate = "",
|
|
27
20
|
editUrlTemplate = ""
|
|
28
|
-
}
|
|
21
|
+
}) {
|
|
29
22
|
const normalizedRecordIdParam = normalizeRouteParamName(recordIdParam, {
|
|
30
23
|
context: "useList recordIdParam"
|
|
31
24
|
});
|
|
@@ -33,8 +26,8 @@ function createListUiRuntime({
|
|
|
33
26
|
const normalizedEditUrlTemplate = String(editUrlTemplate || "").trim();
|
|
34
27
|
const hasViewUrl = Boolean(normalizedViewUrlTemplate);
|
|
35
28
|
const hasEditUrl = Boolean(normalizedEditUrlTemplate);
|
|
36
|
-
const normalizedItems = computed(() => (Array.isArray(items
|
|
37
|
-
const showListSkeleton = computed(() => Boolean(isInitialLoading
|
|
29
|
+
const normalizedItems = computed(() => (Array.isArray(items.value) ? items.value : []));
|
|
30
|
+
const showListSkeleton = computed(() => Boolean(isInitialLoading.value && normalizedItems.value.length < 1));
|
|
38
31
|
|
|
39
32
|
const { resolveTemplatePath } = createRouteTemplateResolver({
|
|
40
33
|
recordIdParam: normalizedRecordIdParam,
|
|
@@ -45,8 +38,12 @@ function createListUiRuntime({
|
|
|
45
38
|
fillRecordId: false
|
|
46
39
|
});
|
|
47
40
|
|
|
41
|
+
function resolveRecordId(record) {
|
|
42
|
+
return toRouteParamValue(recordIdSelector(asPlainObject(record)));
|
|
43
|
+
}
|
|
44
|
+
|
|
48
45
|
function resolveRowKey(record, index) {
|
|
49
|
-
const recordId = resolveRecordId(record
|
|
46
|
+
const recordId = resolveRecordId(record);
|
|
50
47
|
if (recordId) {
|
|
51
48
|
return recordId;
|
|
52
49
|
}
|
|
@@ -59,7 +56,7 @@ function createListUiRuntime({
|
|
|
59
56
|
return "";
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
const recordId = resolveRecordId(record
|
|
59
|
+
const recordId = resolveRecordId(record);
|
|
63
60
|
if (!recordId) {
|
|
64
61
|
return "";
|
|
65
62
|
}
|
|
@@ -74,7 +71,7 @@ function createListUiRuntime({
|
|
|
74
71
|
return "";
|
|
75
72
|
}
|
|
76
73
|
|
|
77
|
-
const recordId = resolveRecordId(record
|
|
74
|
+
const recordId = resolveRecordId(record);
|
|
78
75
|
if (!recordId) {
|
|
79
76
|
return "";
|
|
80
77
|
}
|
|
@@ -84,7 +81,7 @@ function createListUiRuntime({
|
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
83
|
|
|
87
|
-
return
|
|
84
|
+
return {
|
|
88
85
|
hasViewUrl,
|
|
89
86
|
hasEditUrl,
|
|
90
87
|
showListSkeleton,
|
|
@@ -92,7 +89,7 @@ function createListUiRuntime({
|
|
|
92
89
|
resolveRowKey,
|
|
93
90
|
resolveViewUrl,
|
|
94
91
|
resolveEditUrl
|
|
95
|
-
}
|
|
92
|
+
};
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
export { createListUiRuntime };
|
|
@@ -45,16 +45,26 @@ function restoreModelSnapshot(model, snapshot) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function ignoreLoadedPayload() {}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {{
|
|
52
|
+
* resource: Pick<import("../../types.js").EndpointResource, "query" | "data">,
|
|
53
|
+
* model?: object,
|
|
54
|
+
* mapLoadedToModel?: import("../../types.js").MapLoadedToModel,
|
|
55
|
+
* resolveMapContext: () => object
|
|
56
|
+
* }} options
|
|
57
|
+
*/
|
|
48
58
|
function watchResourceModelState({
|
|
49
59
|
resource,
|
|
50
60
|
model,
|
|
51
|
-
mapLoadedToModel,
|
|
52
|
-
resolveMapContext
|
|
53
|
-
}
|
|
61
|
+
mapLoadedToModel = ignoreLoadedPayload,
|
|
62
|
+
resolveMapContext
|
|
63
|
+
}) {
|
|
54
64
|
const modelSnapshot = captureModelSnapshot(model);
|
|
55
65
|
|
|
56
66
|
watch(
|
|
57
|
-
() => resource
|
|
67
|
+
() => resource.query.isPending.value,
|
|
58
68
|
(isPending) => {
|
|
59
69
|
if (!isPending || !modelSnapshot) {
|
|
60
70
|
return;
|
|
@@ -68,14 +78,13 @@ function watchResourceModelState({
|
|
|
68
78
|
);
|
|
69
79
|
|
|
70
80
|
watch(
|
|
71
|
-
() => resource
|
|
81
|
+
() => resource.data.value,
|
|
72
82
|
(payload) => {
|
|
73
|
-
if (!payload
|
|
83
|
+
if (!payload) {
|
|
74
84
|
return;
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
|
|
78
|
-
mapLoadedToModel(model, payload, context);
|
|
87
|
+
mapLoadedToModel(model, payload, resolveMapContext());
|
|
79
88
|
},
|
|
80
89
|
{
|
|
81
90
|
immediate: true
|
|
@@ -84,6 +93,7 @@ function watchResourceModelState({
|
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
export {
|
|
96
|
+
ignoreLoadedPayload,
|
|
87
97
|
captureModelSnapshot,
|
|
88
98
|
restoreModelSnapshot,
|
|
89
99
|
watchResourceModelState
|