@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
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
} from "@jskit-ai/resource-crud-core/shared/crudLookup";
|
|
8
8
|
import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface/registry";
|
|
9
9
|
import { useList } from "../records/useList.js";
|
|
10
|
-
import {
|
|
11
|
-
resolveLookupItemLabel,
|
|
12
|
-
resolveLookupFieldDisplayValue
|
|
13
|
-
} from "./crudLookupFieldLabelSupport.js";
|
|
10
|
+
import { resolveLookupItemLabel } from "./crudLookupFieldLabelSupport.js";
|
|
14
11
|
import { inferCrudLookupJsonApiTransport } from "./crudJsonApiTransportSupport.js";
|
|
15
12
|
import { asPlainObject } from "../support/scopeHelpers.js";
|
|
13
|
+
import { useJskitText } from "../../i18n.js";
|
|
14
|
+
|
|
15
|
+
const { t } = useJskitText();
|
|
16
16
|
|
|
17
17
|
function normalizeQueryKeyPrefix(value) {
|
|
18
18
|
const source = Array.isArray(value) ? value : [];
|
|
@@ -45,22 +45,16 @@ function createSelectedLookupItem(selectedValue, selectedRecord = {}, entry = {}
|
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
key: entry.fieldKey,
|
|
57
|
-
relation: entry.relation
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
const label = displayValue == null || displayValue === "" ? value : displayValue;
|
|
48
|
+
// Without a hydrated label the only title would be the raw id; leave the
|
|
49
|
+
// selected value unlisted so the field shows its loading or unavailable state.
|
|
50
|
+
const label = resolveLookupItemLabel(hydratedLookup, entry.labelKey);
|
|
51
|
+
if (!label) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
61
55
|
return {
|
|
62
56
|
value,
|
|
63
|
-
label
|
|
57
|
+
label,
|
|
64
58
|
record: hydratedLookup
|
|
65
59
|
};
|
|
66
60
|
}
|
|
@@ -129,7 +123,7 @@ function createCrudLookupFieldRuntime({
|
|
|
129
123
|
placementSource: normalizedPlacementSourcePrefix
|
|
130
124
|
? `${normalizedPlacementSourcePrefix}.${key}`
|
|
131
125
|
: `lookup.${key}`,
|
|
132
|
-
fallbackLoadError:
|
|
126
|
+
fallbackLoadError: t("jskit.http.crud.lookup.optionsLoadFailed", { path: apiPath }),
|
|
133
127
|
recordIdParam: normalizedRecordIdParam,
|
|
134
128
|
recordIdSelector: (item = {}) => item[valueKey],
|
|
135
129
|
viewUrlTemplate: "",
|
|
@@ -141,16 +135,7 @@ function createCrudLookupFieldRuntime({
|
|
|
141
135
|
fieldKey: key,
|
|
142
136
|
lookupContainerKey: relationLookupContainerKey,
|
|
143
137
|
valueKey,
|
|
144
|
-
labelKey
|
|
145
|
-
relation: Object.freeze({
|
|
146
|
-
kind: "lookup",
|
|
147
|
-
namespace,
|
|
148
|
-
...(explicitApiPath ? { apiPath: explicitApiPath } : {}),
|
|
149
|
-
...(relationSurfaceId ? { surfaceId: relationSurfaceId } : {}),
|
|
150
|
-
containerKey: relationLookupContainerKey,
|
|
151
|
-
valueKey,
|
|
152
|
-
...(labelKey ? { labelKey } : {})
|
|
153
|
-
})
|
|
138
|
+
labelKey
|
|
154
139
|
}));
|
|
155
140
|
}
|
|
156
141
|
|
|
@@ -2,6 +2,9 @@ import { normalizeText, normalizeUniqueTextList } from "@jskit-ai/kernel/shared/
|
|
|
2
2
|
import { CRUD_LIST_FILTER_TYPE_RECORD_ID_MANY } from "@jskit-ai/resource-crud-core/shared/crudListFilters";
|
|
3
3
|
import { resolveLookupItemLabel } from "../crud/crudLookupFieldLabelSupport.js";
|
|
4
4
|
import { asPlainObject } from "../support/scopeHelpers.js";
|
|
5
|
+
import { useJskitText } from "../../i18n.js";
|
|
6
|
+
|
|
7
|
+
const { t } = useJskitText();
|
|
5
8
|
|
|
6
9
|
function normalizeLookupQueryKeyPrefix(value = []) {
|
|
7
10
|
const source = Array.isArray(value) ? value : [];
|
|
@@ -129,10 +132,10 @@ function mergeSelectedLookupOptions(options = [], selectedValues = [], cachedOpt
|
|
|
129
132
|
);
|
|
130
133
|
}
|
|
131
134
|
|
|
132
|
-
function resolveLookupOptionLabel(options = [], cachedOptions = new Map(), value = "", fallback = "
|
|
135
|
+
function resolveLookupOptionLabel(options = [], cachedOptions = new Map(), value = "", fallback = "") {
|
|
133
136
|
const normalizedValue = normalizeText(value);
|
|
134
137
|
if (!normalizedValue) {
|
|
135
|
-
return normalizeText(fallback) || "
|
|
138
|
+
return normalizeText(fallback) || t("jskit.http.crud.filters.option");
|
|
136
139
|
}
|
|
137
140
|
|
|
138
141
|
const matchingOption = (Array.isArray(options) ? options : [])
|
|
@@ -147,8 +150,8 @@ function resolveLookupOptionLabel(options = [], cachedOptions = new Map(), value
|
|
|
147
150
|
return String(cachedOption.label);
|
|
148
151
|
}
|
|
149
152
|
|
|
150
|
-
const normalizedFallback = normalizeText(fallback) || "
|
|
151
|
-
return
|
|
153
|
+
const normalizedFallback = normalizeText(fallback) || t("jskit.http.crud.filters.option");
|
|
154
|
+
return t("jskit.http.crud.filters.optionValue", { label: normalizedFallback, value: normalizedValue });
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
export {
|
|
@@ -7,6 +7,9 @@ import { buildCrudFieldContractMap } from "@jskit-ai/resource-crud-core/shared/c
|
|
|
7
7
|
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
8
8
|
import { resolveLookupFieldDisplayValue, resolveRecordTitle } from "../crud/crudLookupFieldLabelSupport.js";
|
|
9
9
|
import { resolveRouteParamNamesInOrder, toRouteParamValue } from "../support/routeTemplateHelpers.js";
|
|
10
|
+
import { useJskitText } from "../../i18n.js";
|
|
11
|
+
|
|
12
|
+
const { t } = useJskitText();
|
|
10
13
|
|
|
11
14
|
function singularizeLabel(value = "") {
|
|
12
15
|
const normalizedValue = normalizeText(value);
|
|
@@ -50,7 +53,7 @@ function resolveEntityLabel(routeParamKey = "", relationNamespace = "") {
|
|
|
50
53
|
return namespaceLabel;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
return "
|
|
56
|
+
return t("jskit.http.crud.record");
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
function resolveLookupFieldMeta(resource = {}, fieldKey = "") {
|
|
@@ -155,10 +158,10 @@ function resolveCrudListParentRecordTitle(record = {}, descriptor = null) {
|
|
|
155
158
|
return resolvedTitle;
|
|
156
159
|
}
|
|
157
160
|
|
|
158
|
-
const entityLabel = normalizeText(descriptor?.entityLabel) || "
|
|
161
|
+
const entityLabel = normalizeText(descriptor?.entityLabel) || t("jskit.http.crud.record");
|
|
159
162
|
const recordId = toRouteParamValue(record?.id);
|
|
160
163
|
if (recordId) {
|
|
161
|
-
return
|
|
164
|
+
return t("jskit.http.crud.parent.recordWithId", { label: entityLabel, id: recordId });
|
|
162
165
|
}
|
|
163
166
|
|
|
164
167
|
return "";
|
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
} from "../support/scopeHelpers.js";
|
|
17
17
|
import { createRequestQueryRuntime } from "../support/requestQueryRuntimeSupport.js";
|
|
18
18
|
import { resolveRouteParamNamesInOrder } from "../support/routeTemplateHelpers.js";
|
|
19
|
+
import { useJskitText } from "../../i18n.js";
|
|
20
|
+
|
|
21
|
+
const { t } = useJskitText();
|
|
19
22
|
|
|
20
23
|
function useAddEdit({
|
|
21
24
|
ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
|
|
@@ -32,9 +35,9 @@ function useAddEdit({
|
|
|
32
35
|
client = null,
|
|
33
36
|
transport = null,
|
|
34
37
|
requestRecovery = null,
|
|
35
|
-
requestRecoveryLabel = "
|
|
38
|
+
requestRecoveryLabel = t("jskit.http.resource.label"),
|
|
36
39
|
placementSource = "http-web.add-edit",
|
|
37
|
-
fallbackLoadError = "
|
|
40
|
+
fallbackLoadError = t("jskit.http.resource.loadFailed"),
|
|
38
41
|
fallbackSaveError = "",
|
|
39
42
|
fieldErrorKeys = [],
|
|
40
43
|
clearOnRouteChange = true,
|
|
@@ -87,9 +90,10 @@ function useAddEdit({
|
|
|
87
90
|
const routeContext = operationScope.routeContext;
|
|
88
91
|
const resolvedMessages = {
|
|
89
92
|
...resolveResourceMessages(resource, {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
// Keys, rendered when shown so they follow a language switch.
|
|
94
|
+
validation: "jskit.http.feedback.fixInvalidValues",
|
|
95
|
+
saveSuccess: "jskit.http.feedback.saved",
|
|
96
|
+
saveError: "jskit.http.feedback.saveFailed"
|
|
93
97
|
}),
|
|
94
98
|
...(messages && typeof messages === "object" ? messages : {})
|
|
95
99
|
};
|
|
@@ -97,7 +101,9 @@ function useAddEdit({
|
|
|
97
101
|
// fallbackSaveError, otherwise the resolved resource/messages saveError.
|
|
98
102
|
const effectiveMessages = {
|
|
99
103
|
...resolvedMessages,
|
|
100
|
-
saveError: String(fallbackSaveError || "").trim() ||
|
|
104
|
+
saveError: String(fallbackSaveError || "").trim() ||
|
|
105
|
+
String(resolvedMessages.saveError || "").trim() ||
|
|
106
|
+
"jskit.http.feedback.saveFailed"
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
const canView = operationScope.permissionGate("view");
|
|
@@ -188,7 +194,7 @@ function useAddEdit({
|
|
|
188
194
|
dedupeWindowMs: 0,
|
|
189
195
|
loadActionFactory: () => canRetryLoad.value
|
|
190
196
|
? {
|
|
191
|
-
label: "
|
|
197
|
+
label: t("jskit.http.actions.retry"),
|
|
192
198
|
dismissOnRun: true,
|
|
193
199
|
handler() {
|
|
194
200
|
void refresh();
|
|
@@ -30,6 +30,9 @@ import {
|
|
|
30
30
|
import {
|
|
31
31
|
resolveRouteParamNamesInOrder,
|
|
32
32
|
} from "../support/routeTemplateHelpers.js";
|
|
33
|
+
import { useJskitText } from "../../i18n.js";
|
|
34
|
+
|
|
35
|
+
const { t } = useJskitText();
|
|
33
36
|
|
|
34
37
|
const EMPTY_ROUTE_SYNC_QUERY_PARAM_BLACKLIST = Object.freeze([]);
|
|
35
38
|
|
|
@@ -42,7 +45,7 @@ function useList({
|
|
|
42
45
|
viewPermissions = [],
|
|
43
46
|
readEnabled = true,
|
|
44
47
|
placementSource = "http-web.list",
|
|
45
|
-
fallbackLoadError = "
|
|
48
|
+
fallbackLoadError = t("jskit.http.list.loadFailed"),
|
|
46
49
|
initialPageParam = null,
|
|
47
50
|
getNextPageParam,
|
|
48
51
|
selectItems,
|
|
@@ -51,7 +54,7 @@ function useList({
|
|
|
51
54
|
requestOptions,
|
|
52
55
|
queryOptions,
|
|
53
56
|
requestRecovery,
|
|
54
|
-
requestRecoveryLabel = "
|
|
57
|
+
requestRecoveryLabel = t("jskit.http.list.label"),
|
|
55
58
|
realtime = null,
|
|
56
59
|
recordIdParam = "recordId",
|
|
57
60
|
recordIdSelector = null,
|
|
@@ -453,7 +456,7 @@ function useList({
|
|
|
453
456
|
loadError,
|
|
454
457
|
dedupeWindowMs: 0,
|
|
455
458
|
loadActionFactory: () => ({
|
|
456
|
-
label: "
|
|
459
|
+
label: t("jskit.http.actions.retry"),
|
|
457
460
|
dismissOnRun: true,
|
|
458
461
|
handler() {
|
|
459
462
|
void list.reload();
|
|
@@ -9,6 +9,9 @@ import { createViewUiRuntime } from "../runtime/viewUiRuntime.js";
|
|
|
9
9
|
import { createRequestQueryRuntime } from "../support/requestQueryRuntimeSupport.js";
|
|
10
10
|
import { resolveRouteParamNamesInOrder } from "../support/routeTemplateHelpers.js";
|
|
11
11
|
import { resolveOperationRealtimeOptions } from "../useRealtimeQueryInvalidation.js";
|
|
12
|
+
import { useJskitText } from "../../i18n.js";
|
|
13
|
+
|
|
14
|
+
const { t } = useJskitText();
|
|
12
15
|
|
|
13
16
|
function useView({
|
|
14
17
|
resource = null,
|
|
@@ -23,11 +26,11 @@ function useView({
|
|
|
23
26
|
client = null,
|
|
24
27
|
transport = null,
|
|
25
28
|
requestRecovery = null,
|
|
26
|
-
requestRecoveryLabel = "
|
|
29
|
+
requestRecoveryLabel = t("jskit.http.resource.label"),
|
|
27
30
|
placementSource = "http-web.view",
|
|
28
|
-
fallbackLoadError = "
|
|
31
|
+
fallbackLoadError = t("jskit.http.resource.loadFailed"),
|
|
29
32
|
notFoundStatuses = [404],
|
|
30
|
-
notFoundMessage = "
|
|
33
|
+
notFoundMessage = t("jskit.http.crud.recordNotFound"),
|
|
31
34
|
model,
|
|
32
35
|
mapLoadedToModel,
|
|
33
36
|
requestQueryParams = null,
|
|
@@ -130,7 +133,7 @@ function useView({
|
|
|
130
133
|
notFoundError: view.notFoundError,
|
|
131
134
|
dedupeWindowMs: 0,
|
|
132
135
|
loadActionFactory: () => ({
|
|
133
|
-
label: "
|
|
136
|
+
label: t("jskit.http.actions.retry"),
|
|
134
137
|
dismissOnRun: true,
|
|
135
138
|
handler() {
|
|
136
139
|
void view.refresh();
|
|
@@ -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) {
|