@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
|
@@ -27,8 +27,9 @@ function normalizeQueryKeyPrefix(value = []) {
|
|
|
27
27
|
return normalizedValue ? [normalizedValue] : [];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** @param {import("../types.js").CrudListParentTitleOptions} options */
|
|
30
31
|
function useCrudListParentTitle({
|
|
31
|
-
listRuntime
|
|
32
|
+
listRuntime,
|
|
32
33
|
resource = {},
|
|
33
34
|
recordIdParam = "recordId",
|
|
34
35
|
queryKeyPrefix = ["http-web", "crud-list-parent-title"],
|
|
@@ -37,7 +38,7 @@ function useCrudListParentTitle({
|
|
|
37
38
|
notFoundMessage = t("jskit.http.crud.parent.notFound"),
|
|
38
39
|
route = null,
|
|
39
40
|
viewRuntimeFactory = useView
|
|
40
|
-
}
|
|
41
|
+
}) {
|
|
41
42
|
const sourceRoute = route && typeof route === "object" ? route : useRoute();
|
|
42
43
|
const parentDescriptor = computed(() => {
|
|
43
44
|
const descriptor = resolveCrudListParentDescriptor({
|
|
@@ -81,11 +82,11 @@ function useCrudListParentTitle({
|
|
|
81
82
|
if (!descriptor?.apiUrlTemplate) {
|
|
82
83
|
return false;
|
|
83
84
|
}
|
|
84
|
-
if (Boolean(listRuntime
|
|
85
|
+
if (Boolean(listRuntime.isInitialLoading) || normalizeText(listRuntime.loadError)) {
|
|
85
86
|
return false;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
const items = Array.isArray(listRuntime
|
|
89
|
+
const items = Array.isArray(listRuntime.items) ? listRuntime.items : [];
|
|
89
90
|
if (items.length < 1) {
|
|
90
91
|
return true;
|
|
91
92
|
}
|
|
@@ -118,12 +119,12 @@ function useCrudListParentTitle({
|
|
|
118
119
|
return "";
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
const parentRecordTitle = resolveCrudListParentRecordTitle(parentView
|
|
122
|
+
const parentRecordTitle = resolveCrudListParentRecordTitle(parentView.record || {}, descriptor);
|
|
122
123
|
if (parentRecordTitle && shouldLoadParentRecord.value) {
|
|
123
124
|
return parentRecordTitle;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
const listTitle = resolveCrudListParentTitleFromItems(listRuntime
|
|
127
|
+
const listTitle = resolveCrudListParentTitleFromItems(listRuntime.items, descriptor);
|
|
127
128
|
if (listTitle) {
|
|
128
129
|
return listTitle;
|
|
129
130
|
}
|
|
@@ -143,9 +144,9 @@ function useCrudListParentTitle({
|
|
|
143
144
|
title,
|
|
144
145
|
descriptor: parentDescriptor,
|
|
145
146
|
shouldLoadParentRecord,
|
|
146
|
-
record: computed(() => parentView
|
|
147
|
-
isLoading: computed(() => Boolean(parentView
|
|
148
|
-
loadError: computed(() => normalizeText(parentView
|
|
147
|
+
record: computed(() => parentView.record || null),
|
|
148
|
+
isLoading: computed(() => Boolean(parentView.isLoading)),
|
|
149
|
+
loadError: computed(() => normalizeText(parentView.loadError))
|
|
149
150
|
});
|
|
150
151
|
}
|
|
151
152
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { computed, ref } from "vue";
|
|
2
2
|
import { defineCrudListRowActions } from "../rowActions.js";
|
|
3
|
+
import { emptyRecord } from "./support/scopeHelpers.js";
|
|
3
4
|
import {
|
|
4
5
|
normalizeListActionKey,
|
|
5
6
|
resolveListActionBaseContext,
|
|
6
|
-
|
|
7
|
+
resolveListActionFlag,
|
|
8
|
+
resolveListRecordId,
|
|
9
|
+
selectListRecordId
|
|
7
10
|
} from "../support/crudListActionSupport.js";
|
|
8
11
|
|
|
9
12
|
function createExecutionKey(actionKey = "", recordId = "", index = 0) {
|
|
@@ -13,9 +16,13 @@ function createExecutionKey(actionKey = "", recordId = "", index = 0) {
|
|
|
13
16
|
].join(":");
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @param {import("../types.js").CrudListRowActionDefinition[]} [actions]
|
|
21
|
+
* @param {import("../types.js").CrudListActionOptions} [options]
|
|
22
|
+
*/
|
|
16
23
|
function useCrudListRowActions(actions = [], {
|
|
17
|
-
resolveRecordId =
|
|
18
|
-
resolveContext =
|
|
24
|
+
resolveRecordId = selectListRecordId,
|
|
25
|
+
resolveContext = emptyRecord
|
|
19
26
|
} = {}) {
|
|
20
27
|
const normalizedActions = defineCrudListRowActions(actions);
|
|
21
28
|
const executingKeys = ref([]);
|
|
@@ -41,14 +48,11 @@ function useCrudListRowActions(actions = [], {
|
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
function resolveActionFlag(action = {}, flagKey = "", record = {}, index = 0, fallback = false) {
|
|
44
|
-
const flag = action
|
|
45
|
-
if (typeof flag === "function") {
|
|
46
|
-
return Boolean(flag(createActionContext(action, record, index)));
|
|
47
|
-
}
|
|
51
|
+
const flag = action[flagKey];
|
|
48
52
|
if (flag === undefined || flag === null) {
|
|
49
53
|
return fallback;
|
|
50
54
|
}
|
|
51
|
-
return Boolean(flag);
|
|
55
|
+
return Boolean(resolveListActionFlag(flag, () => createActionContext(action, record, index)));
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
function isActionVisible(actionOrKey = "", record = {}, index = 0) {
|
|
@@ -96,7 +100,7 @@ function useCrudListRowActions(actions = [], {
|
|
|
96
100
|
|
|
97
101
|
async function execute(actionOrKey = "", record = {}, index = 0) {
|
|
98
102
|
const action = findAction(actionOrKey);
|
|
99
|
-
if (!action ||
|
|
103
|
+
if (!action || !action.run || isActionDisabled(action, record, index)) {
|
|
100
104
|
return null;
|
|
101
105
|
}
|
|
102
106
|
|
|
@@ -109,7 +113,7 @@ function useCrudListRowActions(actions = [], {
|
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
return
|
|
116
|
+
return {
|
|
113
117
|
actions: normalizedActions,
|
|
114
118
|
hasActions,
|
|
115
119
|
executingKeys,
|
|
@@ -122,7 +126,7 @@ function useCrudListRowActions(actions = [], {
|
|
|
122
126
|
visibleActionsFor,
|
|
123
127
|
hasVisibleActionsFor,
|
|
124
128
|
execute
|
|
125
|
-
}
|
|
129
|
+
};
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
export { useCrudListRowActions };
|
|
@@ -9,6 +9,9 @@ import { useJskitText } from "../i18n.js";
|
|
|
9
9
|
|
|
10
10
|
const { t } = useJskitText();
|
|
11
11
|
|
|
12
|
+
const NO_LIST_FILTERS = Object.freeze({});
|
|
13
|
+
const NO_LIST_ACTIONS = Object.freeze([]);
|
|
14
|
+
|
|
12
15
|
function buildCrudListActionContext(records, client) {
|
|
13
16
|
return Object.freeze({
|
|
14
17
|
records,
|
|
@@ -97,11 +100,8 @@ function normalizeSyntheticDisplayRowGroups(syntheticRows = null) {
|
|
|
97
100
|
});
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
function createCrudListDisplayRow(record
|
|
101
|
-
const
|
|
102
|
-
? records.resolveRowKey
|
|
103
|
-
: (_record, fallbackIndex) => fallbackIndex;
|
|
104
|
-
const recordKey = String(resolveRowKey(record, index) || index);
|
|
103
|
+
function createCrudListDisplayRow(record, index, records) {
|
|
104
|
+
const recordKey = String(records.resolveRowKey(record, index) || index);
|
|
105
105
|
return Object.freeze({
|
|
106
106
|
key: `record:${recordKey}`,
|
|
107
107
|
recordKey,
|
|
@@ -113,29 +113,30 @@ function createCrudListDisplayRow(record = {}, index = 0, records = {}) {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/** @param {import("../types.js").CrudListScreenOptions} options */
|
|
116
117
|
function useCrudListScreen({
|
|
117
|
-
client
|
|
118
|
-
resource
|
|
118
|
+
client,
|
|
119
|
+
resource,
|
|
119
120
|
resourceNamespace = "resource",
|
|
120
121
|
apiSuffix = "",
|
|
121
122
|
recordIdParam = "recordId",
|
|
122
|
-
recordIdSelector
|
|
123
|
+
recordIdSelector,
|
|
123
124
|
titleFallbackFieldKey = "",
|
|
124
125
|
viewUrlTemplate = "",
|
|
125
126
|
editUrlTemplate = "",
|
|
126
127
|
newUrlTemplate = "",
|
|
127
128
|
recordChangedEvents = [],
|
|
128
|
-
listFilters =
|
|
129
|
-
listBulkActions
|
|
130
|
-
listRowActions =
|
|
129
|
+
listFilters = NO_LIST_FILTERS,
|
|
130
|
+
listBulkActions,
|
|
131
|
+
listRowActions = NO_LIST_ACTIONS,
|
|
131
132
|
syntheticRows = null,
|
|
132
133
|
routeQueryBlacklist = Object.freeze(["include", "cursor", "limit"]),
|
|
133
|
-
requestQueryParams
|
|
134
|
-
requestFieldsets
|
|
134
|
+
requestQueryParams,
|
|
135
|
+
requestFieldsets,
|
|
135
136
|
readEnabled = true,
|
|
136
137
|
requestRecoveryLabel = t("jskit.http.crud.records"),
|
|
137
138
|
fallbackLoadError = t("jskit.http.crud.list.loadFailed")
|
|
138
|
-
}
|
|
139
|
+
}) {
|
|
139
140
|
const crudHttpClient = resolveCrudHttpClient(resource, { client });
|
|
140
141
|
const filterRuntime = useCrudListFilters(listFilters);
|
|
141
142
|
const normalizedRecordChangedEvents = Array.isArray(recordChangedEvents)
|
|
@@ -215,7 +216,7 @@ function useCrudListScreen({
|
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
return
|
|
219
|
+
return {
|
|
219
220
|
records,
|
|
220
221
|
listFilters,
|
|
221
222
|
filterRuntime,
|
|
@@ -229,7 +230,7 @@ function useCrudListScreen({
|
|
|
229
230
|
hasEditUrl: records.hasEditUrl,
|
|
230
231
|
resolveRecordTitle,
|
|
231
232
|
formatListCardValue: formatCrudListCardValue
|
|
232
|
-
}
|
|
233
|
+
};
|
|
233
234
|
}
|
|
234
235
|
|
|
235
236
|
const __testables = Object.freeze({
|
|
@@ -6,8 +6,9 @@ import { useJskitText } from "../i18n.js";
|
|
|
6
6
|
|
|
7
7
|
const { t } = useJskitText();
|
|
8
8
|
|
|
9
|
+
/** @param {import("../types.js").CrudViewScreenOptions} options */
|
|
9
10
|
function useCrudViewScreen({
|
|
10
|
-
resource
|
|
11
|
+
resource,
|
|
11
12
|
resourceNamespace = "resource",
|
|
12
13
|
apiUrlTemplate = "",
|
|
13
14
|
recordIdParam = "recordId",
|
|
@@ -15,14 +16,14 @@ function useCrudViewScreen({
|
|
|
15
16
|
listUrlTemplate = "",
|
|
16
17
|
editUrlTemplate = "",
|
|
17
18
|
recordChangedEvent = "",
|
|
18
|
-
requestQueryParams
|
|
19
|
-
requestFieldsets
|
|
19
|
+
requestQueryParams,
|
|
20
|
+
requestFieldsets,
|
|
20
21
|
readEnabled = true,
|
|
21
22
|
queryKeyFactory = null,
|
|
22
23
|
requestRecoveryLabel = t("jskit.http.crud.record"),
|
|
23
24
|
fallbackLoadError = t("jskit.http.crud.view.loadFailed"),
|
|
24
25
|
notFoundMessage = t("jskit.http.crud.recordNotFound")
|
|
25
|
-
}
|
|
26
|
+
}) {
|
|
26
27
|
const route = useRoute();
|
|
27
28
|
const normalizedResourceNamespace = String(resourceNamespace || "resource").trim() || "resource";
|
|
28
29
|
const defaultQueryKeyFactory = (surfaceId = "", workspaceSlug = "") => [
|
|
@@ -37,7 +38,7 @@ function useCrudViewScreen({
|
|
|
37
38
|
apiUrlTemplate,
|
|
38
39
|
recordIdParam,
|
|
39
40
|
includeRecordIdInQueryKey: true,
|
|
40
|
-
queryKeyFactory:
|
|
41
|
+
queryKeyFactory: queryKeyFactory ?? defaultQueryKeyFactory,
|
|
41
42
|
requestQueryParams,
|
|
42
43
|
requestFieldsets,
|
|
43
44
|
readEnabled,
|
|
@@ -68,12 +69,12 @@ function useCrudViewScreen({
|
|
|
68
69
|
const listLocation = computed(() => resolveRouteLocation(listUrlTemplate));
|
|
69
70
|
const editLocation = computed(() => resolveRouteLocation(editUrlTemplate));
|
|
70
71
|
|
|
71
|
-
return
|
|
72
|
+
return {
|
|
72
73
|
view,
|
|
73
74
|
recordTitle,
|
|
74
75
|
listLocation,
|
|
75
76
|
editLocation
|
|
76
|
-
}
|
|
77
|
+
};
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
export { useCrudViewScreen };
|
|
@@ -16,6 +16,9 @@ function defaultGetNextPageParam(lastPage) {
|
|
|
16
16
|
return lastPage?.nextCursor ?? null;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// The first page has no cursor.
|
|
20
|
+
const FIRST_PAGE_PARAM = null;
|
|
21
|
+
|
|
19
22
|
function normalizeQueryKeyValue(queryKey = null) {
|
|
20
23
|
const resolved = unref(queryKey);
|
|
21
24
|
if (Array.isArray(resolved)) {
|
|
@@ -52,30 +55,18 @@ function trimInfinitePagesToFirst(data = null) {
|
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
/** @param {import("../types.js").PagedCollectionOptions} options */
|
|
55
59
|
function usePagedCollection({
|
|
56
60
|
queryKey,
|
|
57
61
|
enabled = true,
|
|
58
|
-
initialPageParam =
|
|
62
|
+
initialPageParam = FIRST_PAGE_PARAM,
|
|
59
63
|
queryFn,
|
|
60
64
|
getNextPageParam = defaultGetNextPageParam,
|
|
61
65
|
selectItems = defaultSelectItems,
|
|
62
|
-
dedupeBy
|
|
66
|
+
dedupeBy,
|
|
63
67
|
queryOptions = null,
|
|
64
68
|
fallbackLoadError = t("jskit.http.list.loadFailed")
|
|
65
|
-
}
|
|
66
|
-
if (typeof queryFn !== "function") {
|
|
67
|
-
throw new TypeError("usePagedCollection requires queryFn().");
|
|
68
|
-
}
|
|
69
|
-
if (typeof getNextPageParam !== "function") {
|
|
70
|
-
throw new TypeError("usePagedCollection requires getNextPageParam().");
|
|
71
|
-
}
|
|
72
|
-
if (typeof selectItems !== "function") {
|
|
73
|
-
throw new TypeError("usePagedCollection requires selectItems().");
|
|
74
|
-
}
|
|
75
|
-
if (dedupeBy != null && typeof dedupeBy !== "function") {
|
|
76
|
-
throw new TypeError("usePagedCollection dedupeBy must be a function when provided.");
|
|
77
|
-
}
|
|
78
|
-
|
|
69
|
+
}) {
|
|
79
70
|
const queryClient = useQueryClient();
|
|
80
71
|
const queryEnabled = computed(() => resolveEnabledRef(enabled));
|
|
81
72
|
const normalizedQueryKey = computed(() => normalizeQueryKeyValue(queryKey));
|
|
@@ -161,7 +152,7 @@ function usePagedCollection({
|
|
|
161
152
|
queryClient.setQueryData(key, (data) => trimInfinitePagesToFirst(data));
|
|
162
153
|
}
|
|
163
154
|
|
|
164
|
-
return
|
|
155
|
+
return {
|
|
165
156
|
query,
|
|
166
157
|
pages,
|
|
167
158
|
items,
|
|
@@ -175,7 +166,7 @@ function usePagedCollection({
|
|
|
175
166
|
reload,
|
|
176
167
|
loadMore,
|
|
177
168
|
trimToFirstPage
|
|
178
|
-
}
|
|
169
|
+
};
|
|
179
170
|
}
|
|
180
171
|
|
|
181
172
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, nextTick, unref } from "vue";
|
|
1
|
+
import { computed, nextTick, toValue, unref } from "vue";
|
|
2
2
|
import { useQueryClient } from "@tanstack/vue-query";
|
|
3
3
|
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
4
4
|
import { useRealtimeEvent } from "@jskit-ai/realtime/client/composables/useRealtimeEvent";
|
|
@@ -41,7 +41,7 @@ function resolveOperationRealtimeOptions({
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function toQueryKeyList(value) {
|
|
44
|
-
const resolved =
|
|
44
|
+
const resolved = toValue(value);
|
|
45
45
|
if (!Array.isArray(resolved) || resolved.length < 1) {
|
|
46
46
|
return [];
|
|
47
47
|
}
|
|
@@ -90,13 +90,14 @@ async function refreshQueriesWithoutCancelling(queryClient, queryKey) {
|
|
|
90
90
|
.map((query) => refetchAfterCurrentRead(queryClient, query)));
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/** @param {import("../types.js").RealtimeQueryInvalidationOptions} options */
|
|
93
94
|
function useRealtimeQueryInvalidation({
|
|
94
95
|
event = "",
|
|
95
96
|
enabled = true,
|
|
96
|
-
matches
|
|
97
|
+
matches,
|
|
97
98
|
queryKey = null,
|
|
98
|
-
onEvent
|
|
99
|
-
}
|
|
99
|
+
onEvent
|
|
100
|
+
}) {
|
|
100
101
|
const queryClient = useQueryClient();
|
|
101
102
|
const normalizedEvent = computed(() => normalizeText(unref(event)));
|
|
102
103
|
const active = computed(() => resolveEnabledRef(enabled) && Boolean(normalizedEvent.value));
|
|
@@ -106,7 +107,8 @@ function useRealtimeQueryInvalidation({
|
|
|
106
107
|
enabled: active,
|
|
107
108
|
matches,
|
|
108
109
|
onEvent: async (context) => {
|
|
109
|
-
|
|
110
|
+
// readable-check: allow method-probe - optional operation: with no onEvent the refresh starts in the same tick as the event
|
|
111
|
+
if (onEvent) {
|
|
110
112
|
await onEvent(context);
|
|
111
113
|
}
|
|
112
114
|
|
|
@@ -117,11 +119,12 @@ function useRealtimeQueryInvalidation({
|
|
|
117
119
|
}
|
|
118
120
|
});
|
|
119
121
|
|
|
120
|
-
return
|
|
122
|
+
return {
|
|
121
123
|
active: listener.active
|
|
122
|
-
}
|
|
124
|
+
};
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
/** @param {import("../types.js").OperationRealtimeOptions} [options] */
|
|
125
128
|
function useOperationRealtime({
|
|
126
129
|
realtime = null,
|
|
127
130
|
queryKey = null,
|
|
@@ -152,8 +155,7 @@ function useOperationRealtime({
|
|
|
152
155
|
return null;
|
|
153
156
|
}
|
|
154
157
|
|
|
155
|
-
const
|
|
156
|
-
const onEvent = typeof source.onEvent === "function" ? source.onEvent : null;
|
|
158
|
+
const { matches, onEvent } = source;
|
|
157
159
|
const resolvedQueryKey = Object.hasOwn(source, "queryKey") ? source.queryKey : queryKey;
|
|
158
160
|
const active = computed(() => {
|
|
159
161
|
const sourceEnabled = Object.hasOwn(source, "enabled") ? source.enabled : true;
|
|
@@ -170,9 +172,9 @@ function useOperationRealtime({
|
|
|
170
172
|
})
|
|
171
173
|
);
|
|
172
174
|
|
|
173
|
-
return
|
|
174
|
-
active: computed(() => bindings.some((binding) => Boolean(binding
|
|
175
|
-
}
|
|
175
|
+
return {
|
|
176
|
+
active: computed(() => bindings.some((binding) => Boolean(binding.active.value)))
|
|
177
|
+
};
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
export {
|
|
@@ -24,6 +24,7 @@ function resolveScopedRouteParamNames(placementContext = null, surfaceId = "") {
|
|
|
24
24
|
return extractRouteParamNames(resolveScopedRouteBase(routeBase));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/** @param {import("../types.js").ScopeRuntimeOptions} [options] */
|
|
27
28
|
function useScopeRuntime({
|
|
28
29
|
ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
|
|
29
30
|
surfaceId = "",
|
|
@@ -117,7 +118,7 @@ function useScopeRuntime({
|
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
return
|
|
121
|
+
return {
|
|
121
122
|
normalizedOwnershipFilter,
|
|
122
123
|
requiresScopedRouteParams: requiresScopedRouteParams.value,
|
|
123
124
|
resolvedSurfaceId,
|
|
@@ -132,7 +133,7 @@ function useScopeRuntime({
|
|
|
132
133
|
access: accessRuntime,
|
|
133
134
|
resolveApiPath,
|
|
134
135
|
requireRouteScope
|
|
135
|
-
}
|
|
136
|
+
};
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
export { useScopeRuntime };
|
|
@@ -18,30 +18,32 @@ function createHttpWebClient(options = {}) {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
// readable-check: allow module-state - shared resource: every request on the page goes through the one configured client
|
|
21
22
|
let httpWebClient = createHttpWebClient();
|
|
22
23
|
|
|
24
|
+
// readable-check: allow method-probe - input validation: configureHttpWebClient takes a ready client or the options to create one
|
|
25
|
+
function isHttpClient(source) {
|
|
26
|
+
return typeof source.request === "function";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {import("../types.js").HttpClient | Record<string, unknown>} [optionsOrClient]
|
|
31
|
+
* @returns {import("../types.js").HttpClient}
|
|
32
|
+
*/
|
|
23
33
|
function configureHttpWebClient(optionsOrClient = {}) {
|
|
24
34
|
const source = normalizeOptions(optionsOrClient);
|
|
25
|
-
httpWebClient =
|
|
26
|
-
typeof source.request === "function"
|
|
27
|
-
? source
|
|
28
|
-
: createHttpWebClient(source);
|
|
35
|
+
httpWebClient = isHttpClient(source) ? source : createHttpWebClient(source);
|
|
29
36
|
return httpWebClient;
|
|
30
37
|
}
|
|
31
38
|
|
|
39
|
+
/** @returns {import("../types.js").HttpClient} */
|
|
32
40
|
function getHttpWebClient() {
|
|
33
41
|
return httpWebClient;
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
function resetHttpWebClientForTests() {
|
|
37
|
-
httpWebClient = createHttpWebClient();
|
|
38
|
-
return httpWebClient;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
44
|
export {
|
|
42
45
|
configureHttpWebClient,
|
|
43
46
|
createHttpWebClient,
|
|
44
47
|
getHttpWebClient,
|
|
45
|
-
resetHttpWebClientForTests,
|
|
46
48
|
httpWebClient
|
|
47
49
|
};
|
package/src/client/rowActions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
2
|
import { defineCrudListActions } from "./support/crudListActionSupport.js";
|
|
3
3
|
|
|
4
|
+
/** @param {import("./types.js").CrudListRowActionDefinition[]} [actions] */
|
|
4
5
|
function defineCrudListRowActions(actions = []) {
|
|
5
6
|
return defineCrudListActions(actions, {
|
|
6
7
|
name: "defineCrudListRowActions",
|
|
@@ -9,6 +10,7 @@ function defineCrudListRowActions(actions = []) {
|
|
|
9
10
|
label,
|
|
10
11
|
icon: normalizeText(rawAction.icon),
|
|
11
12
|
color: normalizeText(rawAction.color, { fallback: "primary" }),
|
|
13
|
+
// readable-check: allow method-probe - optional operation: a row action with no run shows disabled
|
|
12
14
|
run: typeof rawAction.run === "function" ? rawAction.run : null,
|
|
13
15
|
visible: rawAction.visible,
|
|
14
16
|
disabled: rawAction.disabled,
|
|
@@ -34,21 +34,29 @@ function normalizeListActionKey(actionOrKey = "") {
|
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
? resolveRecordId(record, index)
|
|
40
|
-
: record?.id ?? record?.attributes?.id ?? index;
|
|
41
|
-
return normalizeText(resolvedId);
|
|
37
|
+
function selectListRecordId(record, index) {
|
|
38
|
+
return record.id ?? record.attributes?.id ?? index;
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
function
|
|
45
|
-
|
|
41
|
+
function resolveListRecordId(record, index, resolveRecordId) {
|
|
42
|
+
return normalizeText(resolveRecordId(record, index));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolveListActionBaseContext(resolveContext) {
|
|
46
|
+
const baseContext = resolveContext();
|
|
46
47
|
return baseContext && typeof baseContext === "object" && !Array.isArray(baseContext) ? baseContext : {};
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
// readable-check: allow method-probe - input validation: an action's disabled, visible and loading are each a value or a function of the action's context
|
|
51
|
+
function resolveListActionFlag(flag, resolveFlagContext) {
|
|
52
|
+
return typeof flag === "function" ? flag(resolveFlagContext()) : flag;
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
export {
|
|
50
56
|
defineCrudListActions,
|
|
51
57
|
normalizeListActionKey,
|
|
58
|
+
resolveListActionFlag,
|
|
52
59
|
resolveListRecordId,
|
|
53
|
-
resolveListActionBaseContext
|
|
60
|
+
resolveListActionBaseContext,
|
|
61
|
+
selectListRecordId
|
|
54
62
|
};
|