@jskit-ai/http-web 0.1.96 → 0.2.1
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/CHANGELOG.md +96 -0
- package/fixtures/select-field/App.vue +56 -0
- package/fixtures/select-field/index.html +12 -0
- package/fixtures/select-field/main.js +24 -0
- package/fixtures/select-field/vite.config.mjs +15 -0
- package/locales/en.json +115 -0
- package/package.json +13 -7
- package/patterns/crud-screen-set/PATTERN.md +46 -0
- package/src/client/components/CrudAddEditScreen.vue +10 -4
- package/src/client/components/CrudDeleteAction.vue +10 -7
- package/src/client/components/CrudListBulkActionSurface.vue +19 -7
- package/src/client/components/CrudListDateFilterControl.vue +10 -5
- package/src/client/components/CrudListFilterControls.vue +25 -17
- package/src/client/components/CrudListFilterSurface.vue +14 -7
- package/src/client/components/CrudListRecordActionMenu.vue +17 -5
- package/src/client/components/CrudListScreen.vue +31 -18
- package/src/client/components/CrudViewScreen.vue +17 -7
- package/src/client/components/SelectField.vue +55 -0
- package/src/client/composables/crud/crudLookupFieldRuntime.js +14 -29
- package/src/client/composables/internal/crudListFilterLookupSupport.js +7 -4
- package/src/client/composables/internal/crudListParentTitleSupport.js +6 -3
- package/src/client/composables/records/useAddEdit.js +13 -7
- package/src/client/composables/records/useList.js +6 -3
- package/src/client/composables/records/useView.js +7 -4
- package/src/client/composables/runtime/operationValidationHelpers.js +16 -11
- package/src/client/composables/runtime/useAddEditCore.js +9 -6
- package/src/client/composables/runtime/useCommandCore.js +8 -5
- package/src/client/composables/runtime/useEndpointResource.js +7 -5
- package/src/client/composables/runtime/useListCore.js +5 -2
- package/src/client/composables/runtime/useUiFeedback.js +1 -1
- package/src/client/composables/runtime/useViewCore.js +5 -2
- package/src/client/composables/support/errorMessageHelpers.js +24 -8
- package/src/client/composables/support/listSearchSupport.js +4 -1
- package/src/client/composables/useAccess.js +4 -1
- package/src/client/composables/useCommand.js +5 -4
- package/src/client/composables/useCrudAddEditScreen.js +5 -2
- package/src/client/composables/useCrudDeleteAction.js +6 -3
- package/src/client/composables/useCrudListFilterLookups.js +6 -3
- package/src/client/composables/useCrudListFilters.js +5 -1
- package/src/client/composables/useCrudListParentTitle.js +5 -2
- package/src/client/composables/useCrudListScreen.js +8 -5
- package/src/client/composables/useCrudViewScreen.js +7 -4
- package/src/client/composables/usePagedCollection.js +5 -2
- package/src/client/composables/useScopeRuntime.js +7 -1
- package/src/client/i18n.js +8 -0
- package/src/client/support/crudListDateFilterSupport.js +18 -9
- package/src/client/support/selectFieldSupport.js +71 -0
- package/test/crudListBulkActionSurface.test.js +1 -1
- package/test/crudListFilterSurface.test.js +2 -2
- package/test/crudLookupFieldRuntime.test.js +42 -0
- package/test/crudScreenComponents.test.js +1 -1
- package/test/exportsContract.test.js +4 -1
- package/test/i18nCatalog.test.js +16 -0
- package/test/selectField.browser.test.js +63 -0
- package/test/selectFieldSupport.test.js +68 -0
- package/test/translation.test.js +164 -0
|
@@ -5,6 +5,9 @@ import { resolveCrudJsonApiTransport } from "./crud/crudJsonApiTransportSupport.
|
|
|
5
5
|
import { resolveCrudHttpClient } from "./crud/crudHttpClientSupport.js";
|
|
6
6
|
import { toQueryErrorMessage } from "./support/errorMessageHelpers.js";
|
|
7
7
|
import { useCommand } from "./useCommand.js";
|
|
8
|
+
import { createTextError, useJskitText } from "../i18n.js";
|
|
9
|
+
|
|
10
|
+
const { t } = useJskitText();
|
|
8
11
|
|
|
9
12
|
function requireCrudDeleteOperation(resource = null) {
|
|
10
13
|
const operation = resource?.operations?.delete;
|
|
@@ -41,7 +44,7 @@ function useCrudDeleteAction({
|
|
|
41
44
|
access = "auto",
|
|
42
45
|
client = null,
|
|
43
46
|
router: routerOverride = null,
|
|
44
|
-
fallbackDeleteError = "
|
|
47
|
+
fallbackDeleteError = t("jskit.http.crud.delete.failed")
|
|
45
48
|
} = {}) {
|
|
46
49
|
const resolvedScreen = requireCrudViewScreen(screen);
|
|
47
50
|
const deleteOperation = requireCrudDeleteOperation(resource);
|
|
@@ -64,7 +67,7 @@ function useCrudDeleteAction({
|
|
|
64
67
|
async function handleDeleteSuccess(_response, context = {}) {
|
|
65
68
|
const listLocation = resolveListLocation(resolvedScreen);
|
|
66
69
|
if (!listLocation) {
|
|
67
|
-
throw
|
|
70
|
+
throw createTextError("jskit.http.crud.delete.listRouteUnavailable");
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
isOpen.value = false;
|
|
@@ -81,7 +84,7 @@ function useCrudDeleteAction({
|
|
|
81
84
|
error.value = toQueryErrorMessage(
|
|
82
85
|
cause,
|
|
83
86
|
fallbackDeleteError,
|
|
84
|
-
"
|
|
87
|
+
t("jskit.http.crud.delete.failed")
|
|
85
88
|
);
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
resolveLookupOptionLabel
|
|
17
17
|
} from "./internal/crudListFilterLookupSupport.js";
|
|
18
18
|
import { inferCrudLookupJsonApiTransport } from "./crud/crudJsonApiTransportSupport.js";
|
|
19
|
+
import { useJskitText } from "../i18n.js";
|
|
20
|
+
|
|
21
|
+
const { t, text } = useJskitText();
|
|
19
22
|
|
|
20
23
|
function useCrudListFilterLookups(
|
|
21
24
|
definitions = {},
|
|
@@ -69,7 +72,7 @@ function useCrudListFilterLookups(
|
|
|
69
72
|
placementSource: normalizedPlacementSourcePrefix
|
|
70
73
|
? `${normalizedPlacementSourcePrefix}.${filter.key}`
|
|
71
74
|
: `crud.list-filter.lookup.${filter.key}`,
|
|
72
|
-
fallbackLoadError:
|
|
75
|
+
fallbackLoadError: t("jskit.http.crud.filters.optionsLoadFailed", { path: filter.lookup.apiSuffix }),
|
|
73
76
|
recordIdParam,
|
|
74
77
|
recordIdSelector: (item = {}) => item[filter.lookup.valueKey || "id"],
|
|
75
78
|
viewUrlTemplate: "",
|
|
@@ -106,7 +109,7 @@ function useCrudListFilterLookups(
|
|
|
106
109
|
isLoading: computed(() => {
|
|
107
110
|
return Boolean(runtime.isInitialLoading || runtime.isFetching || runtime.isSearchDebouncing);
|
|
108
111
|
}),
|
|
109
|
-
resolveLabel(value, fallback = filter.label || "
|
|
112
|
+
resolveLabel(value, fallback = text(filter.label) || t("jskit.http.crud.filters.option")) {
|
|
110
113
|
return resolveLookupOptionLabel(options.value, cachedOptions.value, value, fallback);
|
|
111
114
|
},
|
|
112
115
|
setSearch(value = "") {
|
|
@@ -134,7 +137,7 @@ function useCrudListFilterLookups(
|
|
|
134
137
|
setLookupSearch(filterKey = "", value = "") {
|
|
135
138
|
resolveLookup(filterKey)?.setSearch(value);
|
|
136
139
|
},
|
|
137
|
-
resolveLookupLabel(filterKey = "", value = "", fallback = "
|
|
140
|
+
resolveLookupLabel(filterKey = "", value = "", fallback = t("jskit.http.crud.filters.option")) {
|
|
138
141
|
return resolveLookup(filterKey)?.resolveLabel(value, fallback)
|
|
139
142
|
|| resolveLookupOptionLabel([], new Map(), value, fallback);
|
|
140
143
|
}
|
|
@@ -17,6 +17,9 @@ import {
|
|
|
17
17
|
CRUD_LIST_FILTER_TYPE_FLAG
|
|
18
18
|
} from "@jskit-ai/resource-crud-core/shared/crudListFilters";
|
|
19
19
|
import { formatCrudListDateFilterChipLabel } from "../support/crudListDateFilterSupport.js";
|
|
20
|
+
import { useJskitText } from "../i18n.js";
|
|
21
|
+
|
|
22
|
+
const { text } = useJskitText();
|
|
20
23
|
|
|
21
24
|
function normalizeFunctionMap(value = {}) {
|
|
22
25
|
const source = value && typeof value === "object" && !Array.isArray(value)
|
|
@@ -173,9 +176,10 @@ function resolveAtomicValueLabel(filter = {}, value = "", labelResolvers = {}) {
|
|
|
173
176
|
});
|
|
174
177
|
}
|
|
175
178
|
|
|
179
|
+
// A filter label may be a message key; dates use the active language.
|
|
176
180
|
function formatDefaultChipLabel(filter = {}, chipValue, labelResolvers = {}) {
|
|
177
181
|
return formatCrudListDateFilterChipLabel(filter, chipValue)
|
|
178
|
-
|| formatCrudListFilterDefaultChipLabel(filter, chipValue, {
|
|
182
|
+
|| formatCrudListFilterDefaultChipLabel({ ...filter, label: text(filter.label) }, chipValue, {
|
|
179
183
|
resolveAtomicValue(value) {
|
|
180
184
|
return resolveAtomicValueLabel(filter, value, labelResolvers);
|
|
181
185
|
}
|
|
@@ -12,6 +12,9 @@ import {
|
|
|
12
12
|
resolveCrudListParentRecordTitle,
|
|
13
13
|
resolveCrudListParentTitleFromItems
|
|
14
14
|
} from "./internal/crudListParentTitleSupport.js";
|
|
15
|
+
import { useJskitText } from "../i18n.js";
|
|
16
|
+
|
|
17
|
+
const { t } = useJskitText();
|
|
15
18
|
|
|
16
19
|
function normalizeQueryKeyPrefix(value = []) {
|
|
17
20
|
if (Array.isArray(value)) {
|
|
@@ -30,8 +33,8 @@ function useCrudListParentTitle({
|
|
|
30
33
|
recordIdParam = "recordId",
|
|
31
34
|
queryKeyPrefix = ["http-web", "crud-list-parent-title"],
|
|
32
35
|
placementSource = "http-web.crud-list-parent-title",
|
|
33
|
-
fallbackLoadError = "
|
|
34
|
-
notFoundMessage = "
|
|
36
|
+
fallbackLoadError = t("jskit.http.crud.parent.loadFailed"),
|
|
37
|
+
notFoundMessage = t("jskit.http.crud.parent.notFound"),
|
|
35
38
|
route = null,
|
|
36
39
|
viewRuntimeFactory = useView
|
|
37
40
|
} = {}) {
|
|
@@ -5,6 +5,9 @@ import { useCrudListFilters } from "./useCrudListFilters.js";
|
|
|
5
5
|
import { useCrudListRowActions } from "./useCrudListRowActions.js";
|
|
6
6
|
import { resolveCrudHttpClient } from "./crud/crudHttpClientSupport.js";
|
|
7
7
|
import { resolveRecordTitle as resolveCrudRecordTitle } from "./crud/crudLookupFieldLabelSupport.js";
|
|
8
|
+
import { useJskitText } from "../i18n.js";
|
|
9
|
+
|
|
10
|
+
const { t } = useJskitText();
|
|
8
11
|
|
|
9
12
|
function buildCrudListActionContext(records, client) {
|
|
10
13
|
return Object.freeze({
|
|
@@ -19,10 +22,10 @@ function formatCrudListCardValue(value) {
|
|
|
19
22
|
return "-";
|
|
20
23
|
}
|
|
21
24
|
if (value === true) {
|
|
22
|
-
return "
|
|
25
|
+
return t("jskit.http.crud.yes");
|
|
23
26
|
}
|
|
24
27
|
if (value === false) {
|
|
25
|
-
return "
|
|
28
|
+
return t("jskit.http.crud.no");
|
|
26
29
|
}
|
|
27
30
|
return value;
|
|
28
31
|
}
|
|
@@ -130,8 +133,8 @@ function useCrudListScreen({
|
|
|
130
133
|
requestQueryParams = null,
|
|
131
134
|
requestFieldsets = null,
|
|
132
135
|
readEnabled = true,
|
|
133
|
-
requestRecoveryLabel = "
|
|
134
|
-
fallbackLoadError = "
|
|
136
|
+
requestRecoveryLabel = t("jskit.http.crud.records"),
|
|
137
|
+
fallbackLoadError = t("jskit.http.crud.list.loadFailed")
|
|
135
138
|
} = {}) {
|
|
136
139
|
const crudHttpClient = resolveCrudHttpClient(resource, { client });
|
|
137
140
|
const filterRuntime = useCrudListFilters(listFilters);
|
|
@@ -208,7 +211,7 @@ function useCrudListScreen({
|
|
|
208
211
|
function resolveRecordTitle(record) {
|
|
209
212
|
return resolveCrudRecordTitle(record, {
|
|
210
213
|
fallbackKey: titleFallbackFieldKey,
|
|
211
|
-
defaultValue: "
|
|
214
|
+
defaultValue: t("jskit.http.crud.record")
|
|
212
215
|
});
|
|
213
216
|
}
|
|
214
217
|
|
|
@@ -2,6 +2,9 @@ import { computed, unref } from "vue";
|
|
|
2
2
|
import { useRoute } from "vue-router";
|
|
3
3
|
import { useCrudView } from "./records/useCrudView.js";
|
|
4
4
|
import { resolveRecordTitle } from "./crud/crudLookupFieldLabelSupport.js";
|
|
5
|
+
import { useJskitText } from "../i18n.js";
|
|
6
|
+
|
|
7
|
+
const { t } = useJskitText();
|
|
5
8
|
|
|
6
9
|
function useCrudViewScreen({
|
|
7
10
|
resource = null,
|
|
@@ -16,9 +19,9 @@ function useCrudViewScreen({
|
|
|
16
19
|
requestFieldsets = null,
|
|
17
20
|
readEnabled = true,
|
|
18
21
|
queryKeyFactory = null,
|
|
19
|
-
requestRecoveryLabel = "
|
|
20
|
-
fallbackLoadError = "
|
|
21
|
-
notFoundMessage = "
|
|
22
|
+
requestRecoveryLabel = t("jskit.http.crud.record"),
|
|
23
|
+
fallbackLoadError = t("jskit.http.crud.view.loadFailed"),
|
|
24
|
+
notFoundMessage = t("jskit.http.crud.recordNotFound")
|
|
22
25
|
} = {}) {
|
|
23
26
|
const route = useRoute();
|
|
24
27
|
const normalizedResourceNamespace = String(resourceNamespace || "resource").trim() || "resource";
|
|
@@ -53,7 +56,7 @@ function useCrudViewScreen({
|
|
|
53
56
|
const recordTitle = computed(() =>
|
|
54
57
|
resolveRecordTitle(view.record, {
|
|
55
58
|
fallbackKey: titleFallbackFieldKey,
|
|
56
|
-
defaultValue: "
|
|
59
|
+
defaultValue: t("jskit.http.crud.record")
|
|
57
60
|
})
|
|
58
61
|
);
|
|
59
62
|
|
|
@@ -4,6 +4,9 @@ import { asPlainObject } from "./support/scopeHelpers.js";
|
|
|
4
4
|
import { resolveEnabledRef } from "./support/refValueHelpers.js";
|
|
5
5
|
import { toQueryErrorMessage } from "./support/errorMessageHelpers.js";
|
|
6
6
|
import { mergeQueryMeta } from "./support/resourceLoadStateHelpers.js";
|
|
7
|
+
import { useJskitText } from "../i18n.js";
|
|
8
|
+
|
|
9
|
+
const { t } = useJskitText();
|
|
7
10
|
|
|
8
11
|
function defaultSelectItems(page) {
|
|
9
12
|
return Array.isArray(page?.items) ? page.items : [];
|
|
@@ -58,7 +61,7 @@ function usePagedCollection({
|
|
|
58
61
|
selectItems = defaultSelectItems,
|
|
59
62
|
dedupeBy = null,
|
|
60
63
|
queryOptions = null,
|
|
61
|
-
fallbackLoadError = "
|
|
64
|
+
fallbackLoadError = t("jskit.http.list.loadFailed")
|
|
62
65
|
} = {}) {
|
|
63
66
|
if (typeof queryFn !== "function") {
|
|
64
67
|
throw new TypeError("usePagedCollection requires queryFn().");
|
|
@@ -135,7 +138,7 @@ function usePagedCollection({
|
|
|
135
138
|
const isLoading = computed(() => Boolean(isInitialLoading.value || isFetching.value));
|
|
136
139
|
const isLoadingMore = computed(() => Boolean(query.isFetchingNextPage.value));
|
|
137
140
|
const hasMore = computed(() => Boolean(query.hasNextPage.value));
|
|
138
|
-
const loadError = computed(() => toQueryErrorMessage(query.error.value, fallbackLoadError, "
|
|
141
|
+
const loadError = computed(() => toQueryErrorMessage(query.error.value, fallbackLoadError, t("jskit.http.list.loadFailed")));
|
|
139
142
|
|
|
140
143
|
async function reload() {
|
|
141
144
|
return query.refetch();
|
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
resolveApiSuffix
|
|
16
16
|
} from "./support/scopeHelpers.js";
|
|
17
17
|
import { extractRouteParamNames, toRouteParamValue } from "./support/routeTemplateHelpers.js";
|
|
18
|
+
import { useJskitText } from "../i18n.js";
|
|
19
|
+
|
|
20
|
+
const { t } = useJskitText();
|
|
18
21
|
|
|
19
22
|
function resolveScopedRouteParamNames(placementContext = null, surfaceId = "") {
|
|
20
23
|
const routeBase = resolveSurfaceDefinitionFromPlacementContext(placementContext, surfaceId)?.routeBase || "/";
|
|
@@ -78,7 +81,10 @@ function useScopeRuntime({
|
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
const missingParams = missingScopedRouteParamNames.value.join(", ");
|
|
81
|
-
return
|
|
84
|
+
return t("jskit.http.access.routeParamsRequired", {
|
|
85
|
+
params: missingParams,
|
|
86
|
+
surface: resolvedSurfaceId.value || "<unknown>"
|
|
87
|
+
});
|
|
82
88
|
});
|
|
83
89
|
|
|
84
90
|
const accessRuntime = useAccess({
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createTextError, registerJskitMessages, useJskitText } from "@jskit-ai/kernel/client/i18n";
|
|
2
|
+
import en from "../../locales/en.json" with { type: "json" };
|
|
3
|
+
|
|
4
|
+
// http-web's English, registered on import so its screens and composables
|
|
5
|
+
// translate in fixtures and tests as well as in a bootstrapped app.
|
|
6
|
+
registerJskitMessages(en);
|
|
7
|
+
|
|
8
|
+
export { createTextError, useJskitText };
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { useJskitText } from "../i18n.js";
|
|
2
|
+
|
|
3
|
+
const { t, text, formatDate } = useJskitText();
|
|
1
4
|
const DATE_ONLY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/u;
|
|
5
|
+
const DATE_DISPLAY_OPTIONS = Object.freeze({
|
|
6
|
+
year: "numeric",
|
|
7
|
+
month: "short",
|
|
8
|
+
day: "numeric"
|
|
9
|
+
});
|
|
2
10
|
|
|
3
11
|
function parseDateOnlyValue(value = "") {
|
|
4
12
|
const match = DATE_ONLY_PATTERN.exec(String(value || "").trim());
|
|
@@ -51,21 +59,22 @@ function formatDateOnlyDisplay(value = "", { locale = undefined } = {}) {
|
|
|
51
59
|
return "";
|
|
52
60
|
}
|
|
53
61
|
|
|
62
|
+
// An explicit locale (the date picker's) wins; otherwise the app's active
|
|
63
|
+
// language, or the browser default when the app has no vue-i18n.
|
|
54
64
|
try {
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
day: "numeric"
|
|
59
|
-
}).format(date);
|
|
65
|
+
return locale
|
|
66
|
+
? new Intl.DateTimeFormat(locale, DATE_DISPLAY_OPTIONS).format(date)
|
|
67
|
+
: formatDate(date, DATE_DISPLAY_OPTIONS);
|
|
60
68
|
} catch {
|
|
61
69
|
return formatDateOnlyValue(date);
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
function formatCrudListDateFilterChipLabel(filter = {}, rawValue, { locale = undefined } = {}) {
|
|
74
|
+
const label = text(filter.label);
|
|
66
75
|
if (filter.type === "date") {
|
|
67
76
|
const dateLabel = formatDateOnlyDisplay(rawValue, { locale }) || String(rawValue || "");
|
|
68
|
-
return dateLabel ?
|
|
77
|
+
return dateLabel ? t("jskit.http.crud.filters.chipDate", { label, date: dateLabel }) : "";
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
if (filter.type !== "dateRange") {
|
|
@@ -75,12 +84,12 @@ function formatCrudListDateFilterChipLabel(filter = {}, rawValue, { locale = und
|
|
|
75
84
|
const from = formatDateOnlyDisplay(rawValue?.from, { locale }) || String(rawValue?.from || "");
|
|
76
85
|
const to = formatDateOnlyDisplay(rawValue?.to, { locale }) || String(rawValue?.to || "");
|
|
77
86
|
if (from && to) {
|
|
78
|
-
return
|
|
87
|
+
return t("jskit.http.crud.filters.chipRange", { label, from, to });
|
|
79
88
|
}
|
|
80
89
|
if (from) {
|
|
81
|
-
return
|
|
90
|
+
return t("jskit.http.crud.filters.chipFrom", { label, from });
|
|
82
91
|
}
|
|
83
|
-
return to ?
|
|
92
|
+
return to ? t("jskit.http.crud.filters.chipTo", { label, to }) : "";
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
export {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useJskitText } from "../i18n.js";
|
|
2
|
+
|
|
3
|
+
// Display rules for SelectField. Vuetify titles a model value missing from `items` with the raw
|
|
4
|
+
// value itself, so a stored id ("53") flashes while options load. Here a missing value shows the last
|
|
5
|
+
// title this field saw for it; otherwise it is hidden while `loading` and reads "Unavailable option" once
|
|
6
|
+
// the options have settled. The stored value is never changed by display alone.
|
|
7
|
+
const { t } = useJskitText();
|
|
8
|
+
const unavailableOption = Symbol("unavailable option");
|
|
9
|
+
|
|
10
|
+
// Mirrors Vuetify's item-title/item-value lookup: a key path, a function, or the primitive item.
|
|
11
|
+
function readOption(item, key, fallback) {
|
|
12
|
+
if (typeof key === "function") {
|
|
13
|
+
const value = key(item, fallback);
|
|
14
|
+
return value === undefined ? fallback : value;
|
|
15
|
+
}
|
|
16
|
+
if (item === null || typeof item !== "object" || key == null) {
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
19
|
+
const value = (Array.isArray(key) ? key : String(key).split(".")).reduce((source, part) => source?.[part], item);
|
|
20
|
+
return value === undefined ? fallback : value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function optionTitle(item, itemTitle) {
|
|
24
|
+
return item?.[unavailableOption] ? item.title : readOption(item, itemTitle, item);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function optionValue(item, itemTitle, itemValue) {
|
|
28
|
+
return item?.[unavailableOption] ? item.value : readOption(item, itemValue, readOption(item, itemTitle, item));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function selectedValues(modelValue, multiple) {
|
|
32
|
+
if (multiple) {
|
|
33
|
+
return modelValue == null ? [] : [].concat(modelValue);
|
|
34
|
+
}
|
|
35
|
+
return modelValue == null || modelValue === "" ? [] : [modelValue];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// `seen` (value → item) is the field's memory of titles, so a search that narrows the options
|
|
39
|
+
// does not blank a value chosen earlier.
|
|
40
|
+
function selectionFieldState(field, seen) {
|
|
41
|
+
const { modelValue, items = [], itemTitle = "title", itemValue = "value", multiple = false, returnObject = false } = field;
|
|
42
|
+
if (returnObject) {
|
|
43
|
+
// The model is the option itself and carries its own title.
|
|
44
|
+
return { modelValue, items, hiddenValues: [] };
|
|
45
|
+
}
|
|
46
|
+
const listed = new Set();
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
const value = optionValue(item, itemTitle, itemValue);
|
|
49
|
+
listed.add(value);
|
|
50
|
+
seen.set(value, item);
|
|
51
|
+
}
|
|
52
|
+
const missing = selectedValues(modelValue, multiple).filter((value) => !listed.has(value));
|
|
53
|
+
const remembered = missing.filter((value) => seen.has(value)).map((value) => seen.get(value));
|
|
54
|
+
const unresolved = missing.filter((value) => !seen.has(value));
|
|
55
|
+
if (field.loading && unresolved.length) {
|
|
56
|
+
return {
|
|
57
|
+
modelValue: multiple ? [].concat(modelValue).filter((value) => !unresolved.includes(value)) : null,
|
|
58
|
+
items: [...items, ...remembered],
|
|
59
|
+
hiddenValues: unresolved
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const title = t("jskit.http.selectField.unavailableOption");
|
|
63
|
+
const unavailable = unresolved.map((value) => ({ [unavailableOption]: true, title, value }));
|
|
64
|
+
return {
|
|
65
|
+
modelValue,
|
|
66
|
+
items: missing.length ? [...items, ...remembered, ...unavailable] : items,
|
|
67
|
+
hiddenValues: []
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { optionTitle, optionValue, selectionFieldState };
|
|
@@ -20,7 +20,7 @@ test("CrudListBulkActionSurface stays adaptive and runtime-owned", async () => {
|
|
|
20
20
|
assert.match(source, /hasActions/);
|
|
21
21
|
assert.match(source, /hasSelection/);
|
|
22
22
|
assert.match(source, /v-menu/);
|
|
23
|
-
assert.match(source, /
|
|
23
|
+
assert.match(source, /jskit\.http\.crud\.bulk\.actions/);
|
|
24
24
|
assert.match(source, /min-height:\s*48px/);
|
|
25
25
|
assert.doesNotMatch(source, /useCrudList\(/);
|
|
26
26
|
assert.doesNotMatch(source, /apiSuffix|repository|server/);
|
|
@@ -71,8 +71,8 @@ test("CrudListDateFilterControl composes stable Vuetify picker components access
|
|
|
71
71
|
assert.match(source, /v-bind="\{ \.\.\.attrs, \.\.\.activatorProps \}"/);
|
|
72
72
|
assert.match(source, /\["Enter", " ", "ArrowDown"\]/);
|
|
73
73
|
assert.match(source, /role="dialog"/);
|
|
74
|
-
assert.match(source, />\s
|
|
75
|
-
assert.match(source, />\s
|
|
74
|
+
assert.match(source, />\s*\{\{ t\("jskit\.http\.actions\.clear"\) \}\}\s*</u);
|
|
75
|
+
assert.match(source, />\s*\{\{ t\("jskit\.http\.actions\.close"\) \}\}\s*</u);
|
|
76
76
|
assert.doesNotMatch(source, /VDateInput|vuetify\/labs|type="date"/);
|
|
77
77
|
|
|
78
78
|
const { descriptor, errors: parseErrors } = parse(source, { filename: componentPath });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { registerHooks } from "node:module";
|
|
2
3
|
import test from "node:test";
|
|
3
4
|
import {
|
|
4
5
|
resolveLookupItemLabel,
|
|
@@ -6,6 +7,26 @@ import {
|
|
|
6
7
|
resolveRecordTitle
|
|
7
8
|
} from "../src/client/composables/crud/crudLookupFieldLabelSupport.js";
|
|
8
9
|
|
|
10
|
+
// The lookup list is the first page of services, which does not contain the selected service 53.
|
|
11
|
+
const useListUrl = new URL("../src/client/composables/records/useList.js", import.meta.url).href;
|
|
12
|
+
const hooks = registerHooks({
|
|
13
|
+
load(url, context, nextLoad) {
|
|
14
|
+
if (url !== useListUrl) return nextLoad(url, context);
|
|
15
|
+
return {
|
|
16
|
+
format: "module",
|
|
17
|
+
shortCircuit: true,
|
|
18
|
+
source: "export const useList = () => ({ items: [{ id: 7, name: 'Bath' }] });"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const { createCrudLookupFieldRuntime } = await import("../src/client/composables/crud/crudLookupFieldRuntime.js");
|
|
23
|
+
hooks.deregister();
|
|
24
|
+
|
|
25
|
+
const serviceFormFields = [{
|
|
26
|
+
key: "serviceId",
|
|
27
|
+
relation: { kind: "lookup", namespace: "services", valueKey: "id", labelKey: "name" }
|
|
28
|
+
}];
|
|
29
|
+
|
|
9
30
|
test("resolveLookupItemLabel composes name + surname", () => {
|
|
10
31
|
assert.equal(
|
|
11
32
|
resolveLookupItemLabel(
|
|
@@ -262,3 +283,24 @@ test("resolveLookupFieldDisplayValue supports scalar lookup descriptor arguments
|
|
|
262
283
|
"Harbor Vet"
|
|
263
284
|
);
|
|
264
285
|
});
|
|
286
|
+
|
|
287
|
+
test("lookup items never title the selected value with its raw id", () => {
|
|
288
|
+
const { resolveLookupItems } = createCrudLookupFieldRuntime({ formFields: serviceFormFields });
|
|
289
|
+
const listed = [{ value: "7", label: "Bath", record: { id: 7, name: "Bath" } }];
|
|
290
|
+
|
|
291
|
+
assert.deepEqual(resolveLookupItems("serviceId", { selectedValue: 53, selectedRecord: { serviceId: 53 } }), listed);
|
|
292
|
+
assert.deepEqual(
|
|
293
|
+
resolveLookupItems("serviceId", {
|
|
294
|
+
selectedValue: 53,
|
|
295
|
+
selectedRecord: { serviceId: 53, lookups: { serviceId: { id: 53 } } }
|
|
296
|
+
}),
|
|
297
|
+
listed
|
|
298
|
+
);
|
|
299
|
+
assert.deepEqual(
|
|
300
|
+
resolveLookupItems("serviceId", {
|
|
301
|
+
selectedValue: 53,
|
|
302
|
+
selectedRecord: { serviceId: 53, lookups: { serviceId: { id: 53, name: "Daycare - One Day" } } }
|
|
303
|
+
}),
|
|
304
|
+
[{ value: "53", label: "Daycare - One Day", record: { id: 53, name: "Daycare - One Day" } }, ...listed]
|
|
305
|
+
);
|
|
306
|
+
});
|
|
@@ -95,7 +95,7 @@ test("CRUD screen components own list/view/form chrome centrally", async () => {
|
|
|
95
95
|
listSource,
|
|
96
96
|
/@media \(min-width: 960px\)[\s\S]*\.crud-list-cards\s*\{\s*display:\s*none;[\s\S]*\.crud-list-table\s*\{\s*display:\s*block;[\s\S]*\.crud-list-fab\s*\{\s*display:\s*none;/
|
|
97
97
|
);
|
|
98
|
-
assert.match(listSource,
|
|
98
|
+
assert.match(listSource, /:button-label="t\('jskit\.http\.actions\.more'\)"/);
|
|
99
99
|
assert.match(listSource, /selectableRows/);
|
|
100
100
|
assert.match(
|
|
101
101
|
listSource,
|
|
@@ -21,6 +21,7 @@ test("http-web exports are explicit and aligned with production and generated us
|
|
|
21
21
|
"./client/components/CrudListFilterSurface",
|
|
22
22
|
"./client/components/CrudListScreen",
|
|
23
23
|
"./client/components/CrudViewScreen",
|
|
24
|
+
"./client/components/SelectField",
|
|
24
25
|
"./client/bulkActions",
|
|
25
26
|
"./client/filters",
|
|
26
27
|
"./client/rowActions",
|
|
@@ -49,7 +50,9 @@ test("http-web exports are explicit and aligned with production and generated us
|
|
|
49
50
|
"./client/crudHttpClient",
|
|
50
51
|
"./client/lib/httpClient",
|
|
51
52
|
"./client/lib/permissions",
|
|
52
|
-
"./client/support/contractGuards"
|
|
53
|
+
"./client/support/contractGuards",
|
|
54
|
+
// The generated client bootstrap registers every package's English catalog.
|
|
55
|
+
"./locales/en.json"
|
|
53
56
|
]
|
|
54
57
|
});
|
|
55
58
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
|
|
6
|
+
|
|
7
|
+
const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
|
|
9
|
+
|
|
10
|
+
test("http-web English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "http-web")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { chromium, expect } from "@playwright/test";
|
|
6
|
+
import { createChromiumLaunchOptions, startViteFixture, stopProcess } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
7
|
+
|
|
8
|
+
const FIELDS = Object.freeze(["Service", "Retired service", "Extras"]);
|
|
9
|
+
|
|
10
|
+
function field(page, label) {
|
|
11
|
+
return page.locator(".v-input").filter({ has: page.getByText(label, { exact: true }) });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function readModels(page) {
|
|
15
|
+
return JSON.parse(await page.getByTestId("select-field-models").textContent());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function assertNoStoredIdShown(page) {
|
|
19
|
+
for (const label of FIELDS) {
|
|
20
|
+
const words = (await field(page, label).innerText()).split(/\s+/u);
|
|
21
|
+
assert.ok(!words.some((word) => /^\d+$/u.test(word)), `${label} shows a stored id: ${words.join(" ")}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
test("SelectField never shows a stored id while options load and titles unmatched values afterwards", {
|
|
26
|
+
skip: process.env.JSKIT_HTTP_WEB_SELECT_FIELD_BROWSER === "1"
|
|
27
|
+
? false
|
|
28
|
+
: "set JSKIT_HTTP_WEB_SELECT_FIELD_BROWSER=1 to run the select field browser regression",
|
|
29
|
+
timeout: 120_000
|
|
30
|
+
}, async () => {
|
|
31
|
+
const runtime = await startViteFixture({ fixtureRoot: fileURLToPath(new URL("../fixtures/select-field/", import.meta.url)) });
|
|
32
|
+
let browser = null;
|
|
33
|
+
try {
|
|
34
|
+
browser = await chromium.launch(createChromiumLaunchOptions());
|
|
35
|
+
const page = await browser.newPage({ baseURL: runtime.baseURL });
|
|
36
|
+
const errors = [];
|
|
37
|
+
page.on("pageerror", (error) => errors.push(error.message));
|
|
38
|
+
await page.goto("/", { waitUntil: "networkidle" });
|
|
39
|
+
|
|
40
|
+
// Options are still loading: unresolved values are hidden and the fields show their loading state.
|
|
41
|
+
await expect(field(page, "Extras")).toContainText("Bath");
|
|
42
|
+
await assertNoStoredIdShown(page);
|
|
43
|
+
for (const label of FIELDS) {
|
|
44
|
+
await expect(field(page, label).locator(".v-field--loading")).toHaveCount(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Removing the visible chip keeps the value hidden while its options load.
|
|
48
|
+
await field(page, "Extras").locator(".v-chip__close").click();
|
|
49
|
+
assert.deepEqual(await readModels(page), { service: 53, retired: 99, serviceIds: [53] });
|
|
50
|
+
|
|
51
|
+
await page.evaluate(() => window.releaseOptions());
|
|
52
|
+
await expect(field(page, "Service")).toContainText("Daycare - One Day");
|
|
53
|
+
await expect(field(page, "Retired service")).toContainText("Unavailable option");
|
|
54
|
+
await expect(field(page, "Extras")).toContainText("Daycare - One Day");
|
|
55
|
+
await expect(page.locator(".v-field--loading")).toHaveCount(0);
|
|
56
|
+
await assertNoStoredIdShown(page);
|
|
57
|
+
assert.deepEqual(await readModels(page), { service: 53, retired: 99, serviceIds: [53] });
|
|
58
|
+
assert.deepEqual(errors, []);
|
|
59
|
+
} finally {
|
|
60
|
+
await browser?.close();
|
|
61
|
+
await stopProcess(runtime);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { optionTitle, optionValue, selectionFieldState } from "../src/client/support/selectFieldSupport.js";
|
|
4
|
+
|
|
5
|
+
const services = [
|
|
6
|
+
{ value: 7, label: "Bath" },
|
|
7
|
+
{ value: 53, label: "Daycare - One Day" }
|
|
8
|
+
];
|
|
9
|
+
const field = { itemTitle: "label", itemValue: "value" };
|
|
10
|
+
const titles = (state) => state.items.map((item) => optionTitle(item, field.itemTitle));
|
|
11
|
+
|
|
12
|
+
test("an unresolved value is hidden while options load, never shown as its id", () => {
|
|
13
|
+
const state = selectionFieldState({ ...field, modelValue: 53, items: [], loading: true }, new Map());
|
|
14
|
+
|
|
15
|
+
assert.equal(state.modelValue, null);
|
|
16
|
+
assert.deepEqual(state.items, []);
|
|
17
|
+
assert.deepEqual(state.hiddenValues, [53]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("a listed value keeps its own option and title", () => {
|
|
21
|
+
const state = selectionFieldState({ ...field, modelValue: 53, items: services, loading: true }, new Map());
|
|
22
|
+
|
|
23
|
+
assert.equal(state.modelValue, 53);
|
|
24
|
+
assert.equal(state.items, services);
|
|
25
|
+
assert.deepEqual(state.hiddenValues, []);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("an unmatched value reads Unavailable option once options settle and keeps its stored value", () => {
|
|
29
|
+
const state = selectionFieldState({ ...field, modelValue: 99, items: services }, new Map());
|
|
30
|
+
|
|
31
|
+
assert.equal(state.modelValue, 99);
|
|
32
|
+
assert.deepEqual(titles(state), ["Bath", "Daycare - One Day", "Unavailable option"]);
|
|
33
|
+
assert.equal(optionValue(state.items[2], field.itemTitle, field.itemValue), 99);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("a remembered title survives a narrowed option list", () => {
|
|
37
|
+
const seen = new Map();
|
|
38
|
+
selectionFieldState({ ...field, modelValue: 53, items: services }, seen);
|
|
39
|
+
const narrowed = selectionFieldState({ ...field, modelValue: 53, items: [services[0]], loading: true }, seen);
|
|
40
|
+
|
|
41
|
+
assert.equal(narrowed.modelValue, 53);
|
|
42
|
+
assert.deepEqual(titles(narrowed), ["Bath", "Daycare - One Day"]);
|
|
43
|
+
assert.deepEqual(narrowed.hiddenValues, []);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("multiple selections hide only their unresolved values while loading", () => {
|
|
47
|
+
const state = selectionFieldState(
|
|
48
|
+
{ ...field, multiple: true, modelValue: [7, 99], items: [services[0]], loading: true },
|
|
49
|
+
new Map()
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
assert.deepEqual(state.modelValue, [7]);
|
|
53
|
+
assert.deepEqual(state.hiddenValues, [99]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("item-title and item-value follow Vuetify key paths, functions, and primitive items", () => {
|
|
57
|
+
assert.equal(optionTitle({ service: { name: "Bath" } }, "service.name"), "Bath");
|
|
58
|
+
assert.equal(optionTitle({ name: "Bath" }, (item) => item.name.toUpperCase()), "BATH");
|
|
59
|
+
assert.equal(optionValue("Bath", "title", "value"), "Bath");
|
|
60
|
+
assert.equal(optionValue({ title: "Bath" }, "title", "value"), "Bath");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("returnObject models pass through unchanged", () => {
|
|
64
|
+
const modelValue = { value: 99, label: "Grooming" };
|
|
65
|
+
const state = selectionFieldState({ ...field, returnObject: true, modelValue, items: services, loading: true }, new Map());
|
|
66
|
+
|
|
67
|
+
assert.deepEqual(state, { modelValue, items: services, hiddenValues: [] });
|
|
68
|
+
});
|