@jskit-ai/http-web 0.1.95 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/locales/en.json +112 -0
- package/package.json +8 -7
- 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/composables/crud/crudLookupFieldRuntime.js +4 -1
- 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/useCrudList.js +6 -0
- package/src/client/composables/records/useCrudView.js +6 -0
- 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/test/crudListBulkActionSurface.test.js +1 -1
- package/test/crudListFilterSurface.test.js +2 -2
- package/test/crudScreenComponents.test.js +1 -1
- package/test/exportsContract.test.js +3 -1
- package/test/i18nCatalog.test.js +16 -0
- package/test/translation.test.js +164 -0
- package/test/useCrudListScreen.test.js +3 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createValidationFailure,
|
|
3
|
-
resolveFieldErrors
|
|
4
|
-
} from "@jskit-ai/http-runtime/client";
|
|
1
|
+
import { createValidationFailure } from "@jskit-ai/http-runtime/client";
|
|
5
2
|
import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
|
|
3
|
+
import { toUiFieldErrors } from "../support/errorMessageHelpers.js";
|
|
4
|
+
import { useJskitText } from "../../i18n.js";
|
|
5
|
+
|
|
6
|
+
const { t, text } = useJskitText();
|
|
6
7
|
|
|
7
8
|
function validateOperationInput({
|
|
8
9
|
input,
|
|
9
10
|
rawPayload = {},
|
|
10
11
|
fieldBag = null,
|
|
11
12
|
feedback = null,
|
|
12
|
-
validationMessage = "
|
|
13
|
+
validationMessage = ""
|
|
13
14
|
} = {}) {
|
|
14
15
|
if (!input) {
|
|
15
16
|
return {
|
|
@@ -33,12 +34,16 @@ function validateOperationInput({
|
|
|
33
34
|
throw error;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const fieldErrorCodes = error.fieldErrorCodes || error.details?.fieldErrorCodes;
|
|
38
|
+
const failure = {
|
|
39
|
+
...createValidationFailure({
|
|
40
|
+
error: text(validationMessage) || t("jskit.http.feedback.validationFailed"),
|
|
41
|
+
code: "validation_failed",
|
|
42
|
+
fieldErrors: error?.fieldErrors
|
|
43
|
+
}),
|
|
44
|
+
...(fieldErrorCodes ? { fieldErrorCodes } : {})
|
|
45
|
+
};
|
|
46
|
+
fieldBag?.apply?.(toUiFieldErrors(failure));
|
|
42
47
|
feedback?.error?.(failure, failure.error);
|
|
43
48
|
return {
|
|
44
49
|
ok: false,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { useQueryClient } from "@tanstack/vue-query";
|
|
2
2
|
import { computed, ref } from "vue";
|
|
3
|
-
import { resolveFieldErrors } from "@jskit-ai/http-runtime/client";
|
|
4
3
|
import { validateOperationInput } from "./operationValidationHelpers.js";
|
|
5
4
|
import { watchResourceModelState } from "./modelStateHelpers.js";
|
|
5
|
+
import { toUiFieldErrors } from "../support/errorMessageHelpers.js";
|
|
6
|
+
import { useJskitText } from "../../i18n.js";
|
|
7
|
+
|
|
8
|
+
const { t, text } = useJskitText();
|
|
6
9
|
|
|
7
10
|
function useAddEditCore({
|
|
8
11
|
model,
|
|
@@ -45,7 +48,7 @@ function useAddEditCore({
|
|
|
45
48
|
|
|
46
49
|
// Revalidate without changing server field errors or reporting feedback.
|
|
47
50
|
const result = validateOperationInput({ input, rawPayload: resolveRawPayload() });
|
|
48
|
-
return result.ok ? {} :
|
|
51
|
+
return result.ok ? {} : toUiFieldErrors(result.failure);
|
|
49
52
|
});
|
|
50
53
|
|
|
51
54
|
function resolveRawPayload() {
|
|
@@ -76,7 +79,7 @@ function useAddEditCore({
|
|
|
76
79
|
rawPayload,
|
|
77
80
|
fieldBag,
|
|
78
81
|
feedback: validationFeedback === false ? null : feedback,
|
|
79
|
-
validationMessage:
|
|
82
|
+
validationMessage: text(messages.validation) || t("jskit.http.feedback.validationFailed")
|
|
80
83
|
});
|
|
81
84
|
if (!validationResult.ok) {
|
|
82
85
|
return;
|
|
@@ -117,10 +120,10 @@ function useAddEditCore({
|
|
|
117
120
|
});
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
feedback?.success?.(
|
|
123
|
+
feedback?.success?.(text(messages.saveSuccess) || t("jskit.http.feedback.saved"));
|
|
121
124
|
} catch (error) {
|
|
122
|
-
fieldBag?.apply?.(
|
|
123
|
-
feedback?.error?.(error,
|
|
125
|
+
fieldBag?.apply?.(toUiFieldErrors(error));
|
|
126
|
+
feedback?.error?.(error, text(messages.saveError) || t("jskit.http.feedback.saveFailed"));
|
|
124
127
|
} finally {
|
|
125
128
|
submitting.value = false;
|
|
126
129
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useQueryClient } from "@tanstack/vue-query";
|
|
2
|
-
import { resolveFieldErrors } from "@jskit-ai/http-runtime/client";
|
|
3
2
|
import { validateOperationInput } from "./operationValidationHelpers.js";
|
|
3
|
+
import { toUiFieldErrors } from "../support/errorMessageHelpers.js";
|
|
4
|
+
import { useJskitText } from "../../i18n.js";
|
|
5
|
+
|
|
6
|
+
const { t, text } = useJskitText();
|
|
4
7
|
|
|
5
8
|
function useCommandCore({
|
|
6
9
|
model,
|
|
@@ -47,7 +50,7 @@ function useCommandCore({
|
|
|
47
50
|
rawPayload,
|
|
48
51
|
fieldBag,
|
|
49
52
|
feedback,
|
|
50
|
-
validationMessage:
|
|
53
|
+
validationMessage: text(messages.validation) || t("jskit.http.feedback.validationFailed")
|
|
51
54
|
});
|
|
52
55
|
if (!validationResult.ok) {
|
|
53
56
|
return null;
|
|
@@ -88,11 +91,11 @@ function useCommandCore({
|
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
if (!suppressSuccessMessage) {
|
|
91
|
-
feedback?.success?.(
|
|
94
|
+
feedback?.success?.(text(messages.success) || t("jskit.http.feedback.completed"));
|
|
92
95
|
}
|
|
93
96
|
return response;
|
|
94
97
|
} catch (error) {
|
|
95
|
-
fieldBag?.apply?.(
|
|
98
|
+
fieldBag?.apply?.(toUiFieldErrors(error));
|
|
96
99
|
|
|
97
100
|
if (typeof onRunError === "function") {
|
|
98
101
|
await onRunError(error, {
|
|
@@ -106,7 +109,7 @@ function useCommandCore({
|
|
|
106
109
|
});
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
feedback?.error?.(error,
|
|
112
|
+
feedback?.error?.(error, text(messages.error) || t("jskit.http.feedback.actionFailed"));
|
|
110
113
|
throw error;
|
|
111
114
|
}
|
|
112
115
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
mergeRequestRecoveryQueryMeta
|
|
12
12
|
} from "../support/resourceLoadStateHelpers.js";
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
function buildEndpointReadRequestOptions({
|
|
15
16
|
method = "GET",
|
|
16
17
|
query = null,
|
|
@@ -77,9 +78,10 @@ function useEndpointResource({
|
|
|
77
78
|
queryOptions = null,
|
|
78
79
|
mutationOptions = null,
|
|
79
80
|
requestRecovery = null,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// No label: shell-web's request recovery names the app.
|
|
82
|
+
requestRecoveryLabel = "",
|
|
83
|
+
fallbackLoadError = "jskit.http.resource.loadFailed",
|
|
84
|
+
fallbackSaveError = "jskit.http.resource.saveFailed"
|
|
83
85
|
} = {}) {
|
|
84
86
|
const activeClient = client || getHttpWebClient();
|
|
85
87
|
if (!activeClient || typeof activeClient.request !== "function") {
|
|
@@ -162,8 +164,8 @@ function useEndpointResource({
|
|
|
162
164
|
const isRefetching = computed(() => Boolean(isFetching.value && !isInitialLoading.value));
|
|
163
165
|
const isLoading = computed(() => Boolean(isInitialLoading.value || isFetching.value));
|
|
164
166
|
const isSaving = computed(() => Boolean(mutation.isPending.value));
|
|
165
|
-
const loadError = computed(() => toQueryErrorMessage(query.error.value, fallbackLoadError
|
|
166
|
-
const saveError = computed(() => toQueryErrorMessage(mutation.error.value, fallbackSaveError
|
|
167
|
+
const loadError = computed(() => toQueryErrorMessage(query.error.value, fallbackLoadError));
|
|
168
|
+
const saveError = computed(() => toQueryErrorMessage(mutation.error.value, fallbackSaveError));
|
|
167
169
|
|
|
168
170
|
async function reload() {
|
|
169
171
|
return query.refetch();
|
|
@@ -4,6 +4,9 @@ import { asPlainObject } from "../support/scopeHelpers.js";
|
|
|
4
4
|
import { resolveEnabledRef, resolveTextRef } from "../support/refValueHelpers.js";
|
|
5
5
|
import { usePagedCollection } from "../usePagedCollection.js";
|
|
6
6
|
import { mergeRequestRecoveryQueryMeta } from "../support/resourceLoadStateHelpers.js";
|
|
7
|
+
import { useJskitText } from "../../i18n.js";
|
|
8
|
+
|
|
9
|
+
const { t } = useJskitText();
|
|
7
10
|
|
|
8
11
|
const DEFAULT_LIST_LIMIT = 20;
|
|
9
12
|
|
|
@@ -64,8 +67,8 @@ function useListCore({
|
|
|
64
67
|
requestOptions = null,
|
|
65
68
|
queryOptions = null,
|
|
66
69
|
requestRecovery = null,
|
|
67
|
-
requestRecoveryLabel = "
|
|
68
|
-
fallbackLoadError = "
|
|
70
|
+
requestRecoveryLabel = t("jskit.http.list.label"),
|
|
71
|
+
fallbackLoadError = t("jskit.http.list.loadFailed")
|
|
69
72
|
} = {}) {
|
|
70
73
|
const activeClient = client || getHttpWebClient();
|
|
71
74
|
if (!activeClient || typeof activeClient.request !== "function") {
|
|
@@ -65,7 +65,7 @@ function useUiFeedback({
|
|
|
65
65
|
|
|
66
66
|
function error(errorValue, fallbackMessage = "") {
|
|
67
67
|
messageType.value = "error";
|
|
68
|
-
message.value = toUiErrorMessage(errorValue, fallbackMessage
|
|
68
|
+
message.value = toUiErrorMessage(errorValue, fallbackMessage);
|
|
69
69
|
if (!message.value) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import { watchResourceModelState } from "./modelStateHelpers.js";
|
|
3
|
+
import { useJskitText } from "../../i18n.js";
|
|
4
|
+
|
|
5
|
+
const { t } = useJskitText();
|
|
3
6
|
|
|
4
7
|
function normalizeStatusList(value) {
|
|
5
8
|
if (Array.isArray(value)) {
|
|
@@ -15,7 +18,7 @@ function useViewCore({
|
|
|
15
18
|
canView,
|
|
16
19
|
mapLoadedToModel,
|
|
17
20
|
notFoundStatuses = [404],
|
|
18
|
-
notFoundMessage = "
|
|
21
|
+
notFoundMessage = ""
|
|
19
22
|
} = {}) {
|
|
20
23
|
const statusList = normalizeStatusList(notFoundStatuses);
|
|
21
24
|
watchResourceModelState({
|
|
@@ -55,7 +58,7 @@ function useViewCore({
|
|
|
55
58
|
return "";
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
return String(notFoundMessage || "
|
|
61
|
+
return String(notFoundMessage || t("jskit.http.crud.recordNotFound"));
|
|
59
62
|
});
|
|
60
63
|
|
|
61
64
|
const loadError = computed(() => {
|
|
@@ -1,26 +1,42 @@
|
|
|
1
|
-
import { isGenericHttpErrorMessage } from "@jskit-ai/http-runtime/client";
|
|
1
|
+
import { isGenericHttpErrorMessage, resolveFieldErrors } from "@jskit-ai/http-runtime/client";
|
|
2
|
+
import { useJskitText } from "../../i18n.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
const { t, text, serverMessage, fieldErrorMessages } = useJskitText();
|
|
5
|
+
|
|
6
|
+
// An error's message in the user's language: its code or messageCode when the
|
|
7
|
+
// English it carries is JSKIT's English for that code, otherwise as sent. A
|
|
8
|
+
// caller's specific fallback copy still wins over generic transport wording.
|
|
9
|
+
// Fallbacks may be message keys, rendered in the language active when shown.
|
|
10
|
+
function toUiErrorMessage(error, fallbackMessage = "", defaultMessage = "") {
|
|
11
|
+
const normalizedFallback = text(fallbackMessage).trim();
|
|
5
12
|
const normalizedMessage = String(error?.message || "").trim();
|
|
6
13
|
if (normalizedMessage && !isGenericHttpErrorMessage(error)) {
|
|
7
|
-
return
|
|
14
|
+
return serverMessage(error).trim();
|
|
8
15
|
}
|
|
9
16
|
if (normalizedFallback) {
|
|
10
17
|
return normalizedFallback;
|
|
11
18
|
}
|
|
12
19
|
if (normalizedMessage) {
|
|
13
|
-
return
|
|
20
|
+
return serverMessage(error).trim();
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
return
|
|
23
|
+
return text(defaultMessage).trim() || t("jskit.http.feedback.requestFailed");
|
|
17
24
|
}
|
|
18
25
|
|
|
19
|
-
function toQueryErrorMessage(error, fallbackMessage = "", defaultMessage = "
|
|
26
|
+
function toQueryErrorMessage(error, fallbackMessage = "", defaultMessage = "") {
|
|
20
27
|
return error ? toUiErrorMessage(error, fallbackMessage, defaultMessage) : "";
|
|
21
28
|
}
|
|
22
29
|
|
|
30
|
+
// Field errors in the user's language, field by field under the same rule.
|
|
31
|
+
function toUiFieldErrors(error) {
|
|
32
|
+
return fieldErrorMessages({
|
|
33
|
+
fieldErrors: resolveFieldErrors(error),
|
|
34
|
+
fieldErrorCodes: error?.fieldErrorCodes || error?.details?.fieldErrorCodes
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
export {
|
|
24
39
|
toQueryErrorMessage,
|
|
25
|
-
toUiErrorMessage
|
|
40
|
+
toUiErrorMessage,
|
|
41
|
+
toUiFieldErrors
|
|
26
42
|
};
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
normalizeUniqueTextList
|
|
5
5
|
} from "@jskit-ai/kernel/shared/support/normalize";
|
|
6
6
|
import { asPlainObject } from "./scopeHelpers.js";
|
|
7
|
+
import { useJskitText } from "../../i18n.js";
|
|
8
|
+
|
|
9
|
+
const { t, text } = useJskitText();
|
|
7
10
|
|
|
8
11
|
const DEFAULT_LIST_SEARCH_DEBOUNCE_MS = 250;
|
|
9
12
|
const DEFAULT_LIST_SEARCH_MIN_LENGTH = 1;
|
|
@@ -21,7 +24,7 @@ function normalizeListSearchConfig(value = {}) {
|
|
|
21
24
|
enabled: source.enabled === true,
|
|
22
25
|
mode,
|
|
23
26
|
queryParam: normalizeText(source.queryParam) || "q",
|
|
24
|
-
label: normalizeText(source.label) || "
|
|
27
|
+
label: normalizeText(text(source.label)) || t("jskit.http.list.search"),
|
|
25
28
|
placeholder: normalizeText(source.placeholder),
|
|
26
29
|
initialQuery: normalizeText(source.initialQuery),
|
|
27
30
|
debounceMs: normalizeInteger(source.debounceMs, {
|
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
resolveAccessModeEnabled
|
|
7
7
|
} from "./support/scopeHelpers.js";
|
|
8
8
|
import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
|
|
9
|
+
import { useJskitText } from "../i18n.js";
|
|
10
|
+
|
|
11
|
+
const { t } = useJskitText();
|
|
9
12
|
|
|
10
13
|
function asPermissionList(value) {
|
|
11
14
|
if (Array.isArray(value)) {
|
|
@@ -51,7 +54,7 @@ function useAccess({
|
|
|
51
54
|
if (!queryEnabled.value || hasPlacementPermissions.value) {
|
|
52
55
|
return "";
|
|
53
56
|
}
|
|
54
|
-
return "
|
|
57
|
+
return t("jskit.http.access.permissionsUnavailable");
|
|
55
58
|
});
|
|
56
59
|
const awaitingPlacementPermissions = computed(() => queryEnabled.value && !hasPlacementPermissions.value);
|
|
57
60
|
|
|
@@ -22,7 +22,7 @@ function useCommand({
|
|
|
22
22
|
resource: commandResource = null,
|
|
23
23
|
transport = null,
|
|
24
24
|
placementSource = "http-web.command",
|
|
25
|
-
fallbackRunError = "
|
|
25
|
+
fallbackRunError = "jskit.http.feedback.actionFailed",
|
|
26
26
|
fieldErrorKeys = [],
|
|
27
27
|
clearOnRouteChange = true,
|
|
28
28
|
model,
|
|
@@ -80,9 +80,10 @@ function useCommand({
|
|
|
80
80
|
onRunError,
|
|
81
81
|
suppressSuccessMessage: Boolean(suppressSuccessMessage),
|
|
82
82
|
messages: {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
// Keys, rendered when shown so they follow a language switch.
|
|
84
|
+
validation: "jskit.http.feedback.fixInvalidValues",
|
|
85
|
+
success: "jskit.http.feedback.completed",
|
|
86
|
+
error: String(fallbackRunError || "jskit.http.feedback.actionFailed"),
|
|
86
87
|
...(messages && typeof messages === "object" ? messages : {})
|
|
87
88
|
}
|
|
88
89
|
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { computed, unref } from "vue";
|
|
2
2
|
import { useRoute } from "vue-router";
|
|
3
3
|
import { useCrudAddEdit } from "./records/useCrudAddEdit.js";
|
|
4
|
+
import { useJskitText } from "../i18n.js";
|
|
5
|
+
|
|
6
|
+
const { t, text } = useJskitText();
|
|
4
7
|
|
|
5
8
|
function normalizeProvidedScreen(screen = null) {
|
|
6
9
|
return screen && typeof screen === "object" && !Array.isArray(screen)
|
|
@@ -13,7 +16,7 @@ function useCrudAddEditScreen({
|
|
|
13
16
|
mode = "new",
|
|
14
17
|
title = "",
|
|
15
18
|
subtitle = "",
|
|
16
|
-
saveLabel = "
|
|
19
|
+
saveLabel = "",
|
|
17
20
|
cancelTo = "",
|
|
18
21
|
resource = null,
|
|
19
22
|
operationName = "",
|
|
@@ -48,7 +51,7 @@ function useCrudAddEditScreen({
|
|
|
48
51
|
const resolvedMode = computed(() => String(unref(mode) || "new").trim() || "new");
|
|
49
52
|
const resolvedTitle = computed(() => String(unref(title) || "").trim());
|
|
50
53
|
const resolvedSubtitle = computed(() => String(unref(subtitle) || "").trim());
|
|
51
|
-
const resolvedSaveLabel = computed(() => String(unref(saveLabel) || "
|
|
54
|
+
const resolvedSaveLabel = computed(() => String(text(unref(saveLabel)) || "").trim() || t("jskit.http.actions.save"));
|
|
52
55
|
const resolvedCancelTo = computed(() => unref(cancelTo));
|
|
53
56
|
|
|
54
57
|
function resolveCancelTo(target = resolvedCancelTo.value) {
|
|
@@ -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 };
|