@parhelia/localization 0.4.12884 → 0.4.13030
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/LICENSE +1 -1
- package/dist/LocalizeItemCommand.d.ts.map +1 -1
- package/dist/LocalizeItemCommand.js +1 -0
- package/dist/LocalizeItemDialog.d.ts.map +1 -1
- package/dist/LocalizeItemDialog.js +9 -3
- package/dist/LocalizeItemUtils.d.ts +1 -0
- package/dist/LocalizeItemUtils.d.ts.map +1 -1
- package/dist/LocalizeItemUtils.js +44 -18
- package/dist/api/discovery.d.ts +17 -3
- package/dist/api/discovery.d.ts.map +1 -1
- package/dist/api/discovery.js +35 -14
- package/dist/hooks/useTranslationWizard.d.ts.map +1 -1
- package/dist/hooks/useTranslationWizard.js +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/services/translationService.d.ts +43 -27
- package/dist/services/translationService.d.ts.map +1 -1
- package/dist/services/translationService.js +36 -32
- package/dist/services/translationSettingsService.d.ts +79 -0
- package/dist/services/translationSettingsService.d.ts.map +1 -0
- package/dist/services/translationSettingsService.js +68 -0
- package/dist/settings/ExcludedContentTypeDialog.d.ts +12 -0
- package/dist/settings/ExcludedContentTypeDialog.d.ts.map +1 -0
- package/dist/settings/ExcludedContentTypeDialog.js +29 -0
- package/dist/settings/TranslationProviderDialog.d.ts +18 -0
- package/dist/settings/TranslationProviderDialog.d.ts.map +1 -0
- package/dist/settings/TranslationProviderDialog.js +105 -0
- package/dist/settings/TranslationServicesPanel.d.ts +14 -4
- package/dist/settings/TranslationServicesPanel.d.ts.map +1 -1
- package/dist/settings/TranslationServicesPanel.js +186 -263
- package/dist/setup/LocalizationSetupStep.d.ts.map +1 -1
- package/dist/setup/LocalizationSetupStep.js +14 -33
- package/dist/sidebar/TranslationSidebar.d.ts.map +1 -1
- package/dist/sidebar/TranslationSidebar.js +35 -14
- package/dist/steps/ItemSelectionTree.d.ts.map +1 -1
- package/dist/steps/ItemSelectionTree.js +130 -43
- package/dist/steps/ProviderStep.d.ts.map +1 -1
- package/dist/steps/ProviderStep.js +54 -42
- package/dist/steps/ServiceLanguageSelectionStep.d.ts.map +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.js +32 -9
- package/dist/steps/types.d.ts +7 -1
- package/dist/steps/types.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.d.ts +36 -0
- package/dist/translation-center/TranslationBatches.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.js +200 -77
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationSidebar.d.ts","sourceRoot":"","sources":["../../src/sidebar/TranslationSidebar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TranslationSidebar.d.ts","sourceRoot":"","sources":["../../src/sidebar/TranslationSidebar.tsx"],"names":[],"mappings":"AAmBA,wBAAgB,kBAAkB,uCAwPjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, useEditContext, SimpleTable, confirmCreateVersion, Progress, } from "@parhelia/core";
|
|
2
|
+
import { Button, useEditContext, SimpleTable, confirmCreateVersion, Progress, LanguageIcon, } from "@parhelia/core";
|
|
3
3
|
import { getTranslationStatus } from "../services/translationService";
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
import { localizeItemCommand } from "../LocalizeItemCommand";
|
|
@@ -28,20 +28,33 @@ export function TranslationSidebar() {
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
const languageName = (language) => {
|
|
31
|
-
return (_jsxs("div", { className: "flex items-center gap-2 text-neutral-grey-100", children: [_jsx(
|
|
32
|
-
};
|
|
33
|
-
const loadTranslationStatus = async () => {
|
|
34
|
-
if (!item)
|
|
35
|
-
return;
|
|
36
|
-
const status = await getTranslationStatus(item.descriptor.id);
|
|
37
|
-
setTranslationStatus(status.data || []);
|
|
31
|
+
return (_jsxs("div", { className: "flex items-center gap-2 text-neutral-grey-100", children: [_jsx(LanguageIcon, { language: language, flagClassName: "h-[15px] w-5 shrink-0", globeClassName: "h-5 w-5" }), _jsx("span", { className: "font-normal", children: language.name })] }, language.languageCode));
|
|
38
32
|
};
|
|
33
|
+
// W12 phase 3 wave 15 (agentactor lane): keyed on the stable socket-listener registration and
|
|
34
|
+
// the item coordinate, not on the edit context (rebuilt on every revision, focus, selection,
|
|
35
|
+
// caret and socket message): each rebuild blanked the status table and the live progress bars
|
|
36
|
+
// and asked the server for the status again.
|
|
37
|
+
const addSocketMessageListener = editContext.addSocketMessageListener;
|
|
39
38
|
useEffect(() => {
|
|
40
|
-
|
|
39
|
+
let cancelled = false;
|
|
40
|
+
let request = 0;
|
|
41
|
+
const descriptor = item?.descriptor;
|
|
42
|
+
setTranslationStatus(null);
|
|
41
43
|
setTranslationProgress(new Map());
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
44
|
+
if (!descriptor?.database)
|
|
45
|
+
return;
|
|
46
|
+
const loadTranslationStatus = async () => {
|
|
47
|
+
const sequence = ++request;
|
|
48
|
+
const status = await getTranslationStatus(descriptor);
|
|
49
|
+
if (!cancelled && sequence === request)
|
|
50
|
+
setTranslationStatus((status.data || []).filter((row) => row.store === descriptor.database && row.itemId === descriptor.id));
|
|
51
|
+
};
|
|
52
|
+
void loadTranslationStatus();
|
|
53
|
+
const removeSocketMessageListener = addSocketMessageListener((message) => {
|
|
54
|
+
if (cancelled ||
|
|
55
|
+
message.payload?.store !== descriptor.database ||
|
|
56
|
+
message.payload?.itemId !== descriptor.id)
|
|
57
|
+
return;
|
|
45
58
|
if (message.type === "translation-started" ||
|
|
46
59
|
message.type === "translation-finished" ||
|
|
47
60
|
message.type === "translation-error") {
|
|
@@ -66,8 +79,16 @@ export function TranslationSidebar() {
|
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
});
|
|
69
|
-
return
|
|
70
|
-
|
|
82
|
+
return () => {
|
|
83
|
+
cancelled = true;
|
|
84
|
+
removeSocketMessageListener();
|
|
85
|
+
};
|
|
86
|
+
}, [
|
|
87
|
+
addSocketMessageListener,
|
|
88
|
+
item?.descriptor.database,
|
|
89
|
+
item?.descriptor.id,
|
|
90
|
+
item?.descriptor.language,
|
|
91
|
+
]);
|
|
71
92
|
const languageData = languages.map((x) => {
|
|
72
93
|
const progress = translationProgress.get(x.languageCode);
|
|
73
94
|
const status = translationStatus?.find((y) => y.targetLanguage === x.languageCode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemSelectionTree.d.ts","sourceRoot":"","sources":["../../src/steps/ItemSelectionTree.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"ItemSelectionTree.d.ts","sourceRoot":"","sources":["../../src/steps/ItemSelectionTree.tsx"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,eAAe,EAOrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAOrD,KAAK,sBAAsB,GAAG;IAC5B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC/C,WAAW,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B,CAAC;AAoFF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,QAAe,EACf,sBAAsB,EACtB,MAAY,GACb,EAAE,sBAAsB,+BAkfxB"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { ItemCollectionEditor, } from "@parhelia/core";
|
|
3
|
+
import { ContentStoreSelect, FormField, ItemCollectionEditor, Select, getLanguages, useContentModel, } from "@parhelia/core";
|
|
4
4
|
import { streamSubitemCount } from "../api/discovery";
|
|
5
|
-
|
|
6
|
-
"0de95ae4-41ab-4d01-9eb0-67441b7c2450", // Content
|
|
7
|
-
"b701850a-cb8a-4943-b2bc-dddb1238c103", // Forms
|
|
8
|
-
"3d6658d8-a0bf-4e75-b3e2-d050fabcf4e1", // Media Library
|
|
9
|
-
];
|
|
5
|
+
import { translationDescriptorKey as itemKey, translationItem, } from "../services/translationService";
|
|
10
6
|
const NO_WRITE_ACCESS_TITLE = "You don't have write access to this item, so it can't be translated.";
|
|
11
7
|
/**
|
|
12
8
|
* Only items the user may write can receive a translation (the backend
|
|
@@ -22,6 +18,7 @@ function fullItemFromDescriptor(descriptor) {
|
|
|
22
18
|
language: descriptor.language,
|
|
23
19
|
version: descriptor.version,
|
|
24
20
|
descriptor: {
|
|
21
|
+
database: descriptor.database,
|
|
25
22
|
id: descriptor.id,
|
|
26
23
|
language: descriptor.language,
|
|
27
24
|
version: descriptor.version,
|
|
@@ -56,6 +53,7 @@ function fullItemFromDescriptor(descriptor) {
|
|
|
56
53
|
function fullItemToWithSubtree(item, includeSubitems) {
|
|
57
54
|
return {
|
|
58
55
|
descriptor: {
|
|
56
|
+
database: item.descriptor.database,
|
|
59
57
|
id: item.descriptor?.id ?? item.id,
|
|
60
58
|
language: item.descriptor?.language ?? item.language,
|
|
61
59
|
version: item.descriptor?.version ?? item.version,
|
|
@@ -69,9 +67,13 @@ function fullItemToWithSubtree(item, includeSubitems) {
|
|
|
69
67
|
};
|
|
70
68
|
}
|
|
71
69
|
export function ItemSelectionTree({ data, setData, editContext, isActive = true, onSelectionValidChange, height = 360, }) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const model = useContentModel();
|
|
71
|
+
const [store, setStore] = useState(editContext.currentItemDescriptor?.database ??
|
|
72
|
+
data.items[0]?.descriptor.database ??
|
|
73
|
+
"");
|
|
74
|
+
const [language, setLanguage] = useState(editContext?.currentItemDescriptor?.language ??
|
|
75
|
+
data.items[0]?.descriptor.language ??
|
|
76
|
+
"");
|
|
75
77
|
// Seed selection: prefer previously saved tree items, then discoveredItems,
|
|
76
78
|
// then the wizard's initial `items`. Default includeSubitems = legacy flag.
|
|
77
79
|
const initialItems = useMemo(() => {
|
|
@@ -109,9 +111,9 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
109
111
|
const itemCacheRef = useRef(new Map());
|
|
110
112
|
if (itemCacheRef.current.size === 0) {
|
|
111
113
|
for (const it of data.items)
|
|
112
|
-
itemCacheRef.current.set(it.
|
|
114
|
+
itemCacheRef.current.set(itemKey(it.descriptor), it);
|
|
113
115
|
for (const it of data.discoveredItems || [])
|
|
114
|
-
itemCacheRef.current.set(it.
|
|
116
|
+
itemCacheRef.current.set(itemKey(it.descriptor), it);
|
|
115
117
|
}
|
|
116
118
|
// Build a combined idPath that expands every parent of the current
|
|
117
119
|
// selection (but not the items themselves). ContentTree's parser
|
|
@@ -119,7 +121,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
119
121
|
const expandIdPath = useMemo(() => {
|
|
120
122
|
const segments = [];
|
|
121
123
|
for (const entry of items) {
|
|
122
|
-
const cached = itemCacheRef.current.get(entry.descriptor
|
|
124
|
+
const cached = itemCacheRef.current.get(itemKey(entry.descriptor));
|
|
123
125
|
const idPath = cached?.idPath;
|
|
124
126
|
if (!idPath)
|
|
125
127
|
continue;
|
|
@@ -133,17 +135,70 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
133
135
|
return undefined;
|
|
134
136
|
return "/" + segments.join("/");
|
|
135
137
|
}, [items]);
|
|
136
|
-
const commitToWizard = useCallback((nextItems) => {
|
|
138
|
+
const commitToWizard = useCallback((nextItems, sourceLanguage = language) => {
|
|
137
139
|
const cache = itemCacheRef.current;
|
|
138
|
-
const discovered = nextItems.map((entry) => cache.get(entry.descriptor
|
|
140
|
+
const discovered = nextItems.map((entry) => cache.get(itemKey(entry.descriptor)) ??
|
|
139
141
|
fullItemFromDescriptor(entry.descriptor));
|
|
140
142
|
setData({
|
|
141
143
|
...data,
|
|
142
144
|
selectionTreeItems: nextItems,
|
|
143
145
|
discoveredItems: discovered,
|
|
144
146
|
includeSubitems: nextItems.some((i) => i.includeSubitems),
|
|
147
|
+
sourceLanguage: sourceLanguage || undefined,
|
|
145
148
|
});
|
|
146
|
-
}, [data, setData]);
|
|
149
|
+
}, [data, setData, language]);
|
|
150
|
+
// Only stores the user may write can receive a translation. With a single
|
|
151
|
+
// one there is nothing to choose: it is preselected and the picker hidden.
|
|
152
|
+
const writableStores = useMemo(() => (model?.stores ?? []).filter((candidate) => candidate.canWrite), [model?.stores]);
|
|
153
|
+
const onlyStore = writableStores.length === 1 ? writableStores[0] : undefined;
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (onlyStore && !store)
|
|
156
|
+
setStore(onlyStore.id);
|
|
157
|
+
}, [onlyStore, store]);
|
|
158
|
+
// The locales the chosen store declares: the only valid source languages.
|
|
159
|
+
// Null while loading (or with no store), so the current choice is kept.
|
|
160
|
+
const [storeLanguages, setStoreLanguages] = useState(null);
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
setStoreLanguages(null);
|
|
163
|
+
if (!store)
|
|
164
|
+
return;
|
|
165
|
+
let cancelled = false;
|
|
166
|
+
getLanguages(store)
|
|
167
|
+
.then((res) => {
|
|
168
|
+
if (!cancelled)
|
|
169
|
+
setStoreLanguages(Array.isArray(res.data) ? res.data : []);
|
|
170
|
+
})
|
|
171
|
+
.catch((error) => {
|
|
172
|
+
console.error("Failed to load languages:", error);
|
|
173
|
+
if (!cancelled)
|
|
174
|
+
setStoreLanguages([]);
|
|
175
|
+
});
|
|
176
|
+
return () => {
|
|
177
|
+
cancelled = true;
|
|
178
|
+
};
|
|
179
|
+
}, [store]);
|
|
180
|
+
// The selected items carry the source language as their coordinate, so a
|
|
181
|
+
// new source relabels them (subitem discovery reads it from there too).
|
|
182
|
+
const handleLanguageChange = useCallback((nextLanguage) => {
|
|
183
|
+
setLanguage(nextLanguage);
|
|
184
|
+
setSelectedInTree([]);
|
|
185
|
+
const next = items.map((entry) => ({
|
|
186
|
+
...entry,
|
|
187
|
+
descriptor: { ...entry.descriptor, language: nextLanguage },
|
|
188
|
+
}));
|
|
189
|
+
setItems(next);
|
|
190
|
+
commitToWizard(next, nextLanguage);
|
|
191
|
+
}, [items, commitToWizard]);
|
|
192
|
+
// A store that does not declare the current source language (another
|
|
193
|
+
// store picked, or a seed in a language the store lacks) clears it.
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
// An empty list is a failed read, not a store without languages.
|
|
196
|
+
if (!storeLanguages?.length || !language)
|
|
197
|
+
return;
|
|
198
|
+
if (storeLanguages.some((entry) => entry.languageCode === language))
|
|
199
|
+
return;
|
|
200
|
+
handleLanguageChange("");
|
|
201
|
+
}, [storeLanguages, language, handleLanguageChange]);
|
|
147
202
|
// Commit current state on first mount so wizard data reflects the seed.
|
|
148
203
|
const didInitialCommitRef = useRef(false);
|
|
149
204
|
useEffect(() => {
|
|
@@ -167,7 +222,9 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
167
222
|
const inFlightRef = useRef(new Map());
|
|
168
223
|
useEffect(() => {
|
|
169
224
|
const inFlight = inFlightRef.current;
|
|
170
|
-
const enabledIds = new Set(items
|
|
225
|
+
const enabledIds = new Set(items
|
|
226
|
+
.filter((it) => it.includeSubitems)
|
|
227
|
+
.map((it) => itemKey(it.descriptor)));
|
|
171
228
|
// Cancel any streams whose items no longer have the flag on.
|
|
172
229
|
for (const [id, ctrl] of inFlight) {
|
|
173
230
|
if (!enabledIds.has(id)) {
|
|
@@ -183,9 +240,9 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
183
240
|
.filter((it) => it.includeSubitems)
|
|
184
241
|
.map((it) => it.descriptor)
|
|
185
242
|
.filter((d) => {
|
|
186
|
-
if (inFlight.has(d
|
|
243
|
+
if (inFlight.has(itemKey(d)))
|
|
187
244
|
return false;
|
|
188
|
-
const c = subitemCounts[d
|
|
245
|
+
const c = subitemCounts[itemKey(d)];
|
|
189
246
|
if (c === undefined || c === "error")
|
|
190
247
|
return true;
|
|
191
248
|
if (c === "loading")
|
|
@@ -197,30 +254,37 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
197
254
|
setSubitemCounts((prev) => {
|
|
198
255
|
const next = { ...prev };
|
|
199
256
|
for (const d of toStart)
|
|
200
|
-
next[d
|
|
257
|
+
next[itemKey(d)] = "loading";
|
|
201
258
|
return next;
|
|
202
259
|
});
|
|
203
260
|
for (const descriptor of toStart) {
|
|
204
261
|
const controller = new AbortController();
|
|
205
|
-
|
|
262
|
+
const key = itemKey(descriptor);
|
|
263
|
+
inFlight.set(key, controller);
|
|
206
264
|
void (async () => {
|
|
207
265
|
try {
|
|
208
|
-
const finalCount = await streamSubitemCount({
|
|
266
|
+
const finalCount = await streamSubitemCount({ ...translationItem(descriptor), language: descriptor.language }, ({ count, complete, refusal }) => {
|
|
267
|
+
if (controller.signal.aborted)
|
|
268
|
+
return;
|
|
269
|
+
// multi-cms cfsmall (A15): the store's refusal on the last line travels with the count to the badge.
|
|
209
270
|
setSubitemCounts((prev) => ({
|
|
210
271
|
...prev,
|
|
211
|
-
[
|
|
272
|
+
[key]: refusal
|
|
273
|
+
? { count, complete, refusal }
|
|
274
|
+
: { count, complete },
|
|
212
275
|
}));
|
|
213
276
|
}, { sessionId, signal: controller.signal });
|
|
214
277
|
// Backend may close the stream without explicitly sending
|
|
215
278
|
// complete=true on the last line — mark complete on a clean exit.
|
|
279
|
+
if (controller.signal.aborted)
|
|
280
|
+
return;
|
|
216
281
|
setSubitemCounts((prev) => {
|
|
217
|
-
const existing = prev[
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
: finalCount;
|
|
282
|
+
const existing = prev[key];
|
|
283
|
+
if (existing && typeof existing === "object")
|
|
284
|
+
return { ...prev, [key]: { ...existing, complete: true } };
|
|
221
285
|
return {
|
|
222
286
|
...prev,
|
|
223
|
-
[
|
|
287
|
+
[key]: { count: finalCount, complete: true },
|
|
224
288
|
};
|
|
225
289
|
});
|
|
226
290
|
}
|
|
@@ -229,15 +293,15 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
229
293
|
return;
|
|
230
294
|
setSubitemCounts((prev) => {
|
|
231
295
|
// Don't overwrite a partial count with "error" — keep what we have.
|
|
232
|
-
const existing = prev[
|
|
296
|
+
const existing = prev[key];
|
|
233
297
|
if (existing && typeof existing === "object")
|
|
234
298
|
return prev;
|
|
235
|
-
return { ...prev, [
|
|
299
|
+
return { ...prev, [key]: "error" };
|
|
236
300
|
});
|
|
237
301
|
}
|
|
238
302
|
finally {
|
|
239
|
-
if (inFlight.get(
|
|
240
|
-
inFlight.delete(
|
|
303
|
+
if (inFlight.get(key) === controller) {
|
|
304
|
+
inFlight.delete(key);
|
|
241
305
|
}
|
|
242
306
|
}
|
|
243
307
|
})();
|
|
@@ -257,10 +321,11 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
257
321
|
if (!id)
|
|
258
322
|
return;
|
|
259
323
|
const cache = itemCacheRef.current;
|
|
260
|
-
if (cache.has(
|
|
324
|
+
if (cache.has(itemKey(node)))
|
|
261
325
|
return;
|
|
262
326
|
const anyNode = node;
|
|
263
|
-
cache.set(
|
|
327
|
+
cache.set(itemKey(node), fullItemFromDescriptor({
|
|
328
|
+
database: node.database,
|
|
264
329
|
id,
|
|
265
330
|
language: node.language ?? language,
|
|
266
331
|
version: node.version ?? 1,
|
|
@@ -278,10 +343,12 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
278
343
|
const source = itemsToAdd ?? selectedInTree;
|
|
279
344
|
if (!source || source.length === 0)
|
|
280
345
|
return;
|
|
281
|
-
const existing = new Set(items.map((i) => i.descriptor
|
|
346
|
+
const existing = new Set(items.map((i) => itemKey(i.descriptor)));
|
|
282
347
|
const next = [...items];
|
|
283
|
-
for (const
|
|
284
|
-
|
|
348
|
+
for (const candidate of source) {
|
|
349
|
+
// A tree node belongs to the store the tree browses.
|
|
350
|
+
const node = { ...candidate, database: candidate.database ?? store };
|
|
351
|
+
if (!node.id || !node.database || existing.has(itemKey(node)))
|
|
285
352
|
continue;
|
|
286
353
|
if (!isWritable(node))
|
|
287
354
|
continue;
|
|
@@ -289,6 +356,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
289
356
|
cacheTreeNode(node);
|
|
290
357
|
next.push({
|
|
291
358
|
descriptor: {
|
|
359
|
+
database: node.database,
|
|
292
360
|
id: node.id,
|
|
293
361
|
language: node.language ?? language,
|
|
294
362
|
version: node.version ?? 1,
|
|
@@ -299,16 +367,18 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
299
367
|
},
|
|
300
368
|
includeSubitems: false,
|
|
301
369
|
});
|
|
302
|
-
existing.add(node
|
|
370
|
+
existing.add(itemKey(node));
|
|
303
371
|
}
|
|
304
372
|
setItems(next);
|
|
305
373
|
commitToWizard(next);
|
|
306
374
|
setSelectedInTree([]);
|
|
307
375
|
setSelectedFromList([]);
|
|
308
|
-
}, [items, selectedInTree, language, cacheTreeNode, commitToWizard]);
|
|
376
|
+
}, [items, selectedInTree, store, language, cacheTreeNode, commitToWizard]);
|
|
309
377
|
const handleAddItem = useCallback(async (item) => {
|
|
310
378
|
const id = item.id;
|
|
311
|
-
if (!id ||
|
|
379
|
+
if (!id ||
|
|
380
|
+
!item.database ||
|
|
381
|
+
items.some((i) => itemKey(i.descriptor) === itemKey(item)))
|
|
312
382
|
return;
|
|
313
383
|
if (!isWritable(item))
|
|
314
384
|
return;
|
|
@@ -317,6 +387,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
317
387
|
...items,
|
|
318
388
|
{
|
|
319
389
|
descriptor: {
|
|
390
|
+
database: item.database,
|
|
320
391
|
id,
|
|
321
392
|
language: item.language ?? language,
|
|
322
393
|
version: item.version ?? 1,
|
|
@@ -333,8 +404,8 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
333
404
|
setSelectedFromList([]);
|
|
334
405
|
}, [items, language, cacheTreeNode, commitToWizard]);
|
|
335
406
|
const handleRemoveFromList = useCallback(() => {
|
|
336
|
-
const ids = new Set(selectedFromList.map((i) => i.descriptor
|
|
337
|
-
const next = items.filter((i) => !ids.has(i.descriptor
|
|
407
|
+
const ids = new Set(selectedFromList.map((i) => itemKey(i.descriptor)));
|
|
408
|
+
const next = items.filter((i) => !ids.has(itemKey(i.descriptor)));
|
|
338
409
|
setItems(next);
|
|
339
410
|
commitToWizard(next);
|
|
340
411
|
setSelectedFromList([]);
|
|
@@ -350,5 +421,21 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
350
421
|
setItems(next);
|
|
351
422
|
commitToWizard(next);
|
|
352
423
|
}, [items, commitToWizard]);
|
|
353
|
-
|
|
424
|
+
// A bounded column: the pickers keep their height and the editor takes the
|
|
425
|
+
// rest, so the tree and the list scroll inside it, never the whole step.
|
|
426
|
+
return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "mb-3 flex shrink-0 flex-wrap gap-4 px-6 pt-4", children: [!onlyStore && (_jsx(FormField, { label: "Content store", className: "w-64", children: _jsx(ContentStoreSelect, { "data-testid": "translation-content-store", value: store, placeholder: "Select a store", onValueChange: (value) => {
|
|
427
|
+
setStore(value);
|
|
428
|
+
setSelectedInTree([]);
|
|
429
|
+
}, stores: writableStores }) })), _jsx(FormField, { label: "Source language", className: "w-64", children: _jsx(Select, { "data-testid": "translation-source-language", value: language, placeholder: store ? "Select a language" : "Select a store first", disabled: !store, loading: !!store && storeLanguages === null, onValueChange: handleLanguageChange, searchable: (storeLanguages?.length ?? 0) > 8, options: (storeLanguages ?? []).map((entry) => ({
|
|
430
|
+
value: entry.languageCode,
|
|
431
|
+
label: entry.name || entry.languageCode,
|
|
432
|
+
description: entry.name && entry.name !== entry.languageCode
|
|
433
|
+
? entry.languageCode
|
|
434
|
+
: undefined,
|
|
435
|
+
})) }) })] }), store && language ? (_jsx("div", { className: "min-h-0 flex-1", children: _jsx(ItemCollectionEditor, { items: items, selectedInTree: selectedInTree, onSelectedInTreeChange: setSelectedInTree, selectedFromList: selectedFromList, onSelectedFromListChange: setSelectedFromList, onAddToList: handleAddToList, onRemoveFromList: handleRemoveFromList, onAddItem: handleAddItem, onRemoveItem: handleRemoveItem, onToggleSubitems: handleToggleSubitems, language: language, database: store, rootItemIds: model?.roots
|
|
436
|
+
.filter((root) => root.storeId === store &&
|
|
437
|
+
(root.kind === "content" || root.kind === "media"))
|
|
438
|
+
.map((root) => root.id), hideRootNodes: false, isItemSelectable: isWritable, unselectableItemTitle: NO_WRITE_ACCESS_TITLE, selectedItemsLabel: "Items to Translate", emptyMessage: "No items selected", emptyHint: "Browse or search to add items", height: height, subitemCounts: subitemCounts, subitemCountKey: itemKey, expandIdPath: expandIdPath, localStorageKey: "translation-wizard.itemCollectionSplitter", treeSearchContainerClassName: "border-b-0 p-0 pb-3", frameless: true }) })) : (_jsx("p", { className: "text-neutral-grey-50 px-6 text-sm", children: onlyStore
|
|
439
|
+
? "Select a source language to choose translation items."
|
|
440
|
+
: "Select a content store and source language to choose translation items." }))] }));
|
|
354
441
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderStep.d.ts","sourceRoot":"","sources":["../../src/steps/ProviderStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAUf,OAAO,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"ProviderStep.d.ts","sourceRoot":"","sources":["../../src/steps/ProviderStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAUf,OAAO,EAAE,oBAAoB,EAAyB,MAAM,SAAS,CAAC;AAStE,wBAAgB,YAAY,CAAC,EAC3B,QAAe,EACf,IAAI,EACJ,OAAO,EACP,eAAe,EACf,WAAW,GACZ,EAAE,oBAAoB,qBAiZtB"}
|
|
@@ -4,6 +4,7 @@ import { Button, Input, Label, Select, Spinner, Textarea, } from "@parhelia/core
|
|
|
4
4
|
import { RotateCcw } from "lucide-react";
|
|
5
5
|
import { WizardStepShell } from "./WizardStepShell";
|
|
6
6
|
import { suggestBatchName } from "../api/discovery";
|
|
7
|
+
import { translationItem } from "../services/translationService";
|
|
7
8
|
const PROMPT_CUSTOMIZATION_TYPE = "replace";
|
|
8
9
|
const ResetIcon = (props) => React.createElement(RotateCcw, props);
|
|
9
10
|
export function ProviderStep({ isActive = true, data, setData, onStepCompleted, editContext, }) {
|
|
@@ -15,17 +16,29 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
15
16
|
// it with a fresh AI suggestion.
|
|
16
17
|
const userTouchedNameRef = useRef(!!data.batchName);
|
|
17
18
|
const dataRef = useRef(data);
|
|
18
|
-
|
|
19
|
+
const lastDataPropRef = useRef(data);
|
|
20
|
+
if (lastDataPropRef.current !== data) {
|
|
21
|
+
lastDataPropRef.current = data;
|
|
19
22
|
dataRef.current = data;
|
|
20
|
-
}
|
|
23
|
+
}
|
|
24
|
+
// This step has several asynchronous writers (name suggestion, prompt
|
|
25
|
+
// debounce, provider selection). Serialize them through one current-data
|
|
26
|
+
// ref so a late writer cannot rebuild wizard state from an older render and
|
|
27
|
+
// erase a newer checkbox/provider choice.
|
|
28
|
+
const commitData = useCallback((update) => {
|
|
29
|
+
const current = dataRef.current;
|
|
30
|
+
const next = update(current);
|
|
31
|
+
if (next === current)
|
|
32
|
+
return;
|
|
33
|
+
dataRef.current = next;
|
|
34
|
+
setData(next);
|
|
35
|
+
}, [setData]);
|
|
21
36
|
// Push name changes back into wizard data (debounced via simple equality).
|
|
22
37
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
setData((current) => (current.batchName ?? "") === batchName
|
|
38
|
+
commitData((current) => (current.batchName ?? "") === batchName
|
|
26
39
|
? current
|
|
27
40
|
: { ...current, batchName });
|
|
28
|
-
}, [batchName,
|
|
41
|
+
}, [batchName, commitData]);
|
|
29
42
|
// Auto-suggest a name when the step becomes active and the user hasn't
|
|
30
43
|
// already provided/edited one. Fires once per item+language combination so
|
|
31
44
|
// navigating away and back doesn't re-fetch.
|
|
@@ -36,13 +49,17 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
36
49
|
return;
|
|
37
50
|
if (userTouchedNameRef.current)
|
|
38
51
|
return;
|
|
39
|
-
const
|
|
40
|
-
? data.selectionTreeItems.map((s) => s.descriptor
|
|
41
|
-
: data.items.map((i) => i.descriptor
|
|
52
|
+
const descriptors = (data.selectionTreeItems && data.selectionTreeItems.length > 0
|
|
53
|
+
? data.selectionTreeItems.map((s) => s.descriptor)
|
|
54
|
+
: data.items.map((i) => i.descriptor)).filter(Boolean);
|
|
42
55
|
const langs = [...data.targetLanguages].sort();
|
|
43
|
-
if (
|
|
56
|
+
if (descriptors.length === 0 ||
|
|
57
|
+
langs.length === 0 ||
|
|
58
|
+
descriptors.some((d) => !d.database || !d.language))
|
|
44
59
|
return;
|
|
45
|
-
const
|
|
60
|
+
const items = descriptors.map(translationItem);
|
|
61
|
+
const language = descriptors[0].language;
|
|
62
|
+
const key = JSON.stringify({ items, language, langs });
|
|
46
63
|
if (lastSuggestionKeyRef.current === key)
|
|
47
64
|
return;
|
|
48
65
|
lastSuggestionKeyRef.current = key;
|
|
@@ -51,7 +68,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
51
68
|
void (async () => {
|
|
52
69
|
try {
|
|
53
70
|
const includeSubitems = !!data.selectionTreeItems?.some((s) => s.includeSubitems);
|
|
54
|
-
const name = await suggestBatchName({
|
|
71
|
+
const name = await suggestBatchName({ items, language, targetLanguages: langs, includeSubitems }, sessionId);
|
|
55
72
|
if (cancelled || userTouchedNameRef.current)
|
|
56
73
|
return;
|
|
57
74
|
if (name)
|
|
@@ -76,9 +93,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
76
93
|
const hasInitializedRef = useRef(false);
|
|
77
94
|
const lastProviderRef = useRef(data.translationProvider);
|
|
78
95
|
const updateTimerRef = useRef(null);
|
|
79
|
-
|
|
80
|
-
customPromptRef.current = customPrompt;
|
|
81
|
-
}, [customPrompt]);
|
|
96
|
+
customPromptRef.current = customPrompt;
|
|
82
97
|
const selectedProvider = useMemo(() => data.translationProviders.find((p) => p.name === data.translationProvider), [data.translationProviders, data.translationProvider]);
|
|
83
98
|
const serviceData = useMemo(() => {
|
|
84
99
|
if (!data.serviceCustomData || !data.translationProvider)
|
|
@@ -133,7 +148,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
133
148
|
}, [data.translationProvider, isActive, onStepCompleted]);
|
|
134
149
|
const handleProviderChange = (e) => {
|
|
135
150
|
const newProvider = e.target.value;
|
|
136
|
-
|
|
151
|
+
commitData((current) => {
|
|
137
152
|
const newServiceCustomData = new Map();
|
|
138
153
|
current.serviceCustomData?.forEach((value, key) => {
|
|
139
154
|
if (key !== "AI" || newProvider === "AI") {
|
|
@@ -149,10 +164,9 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
149
164
|
};
|
|
150
165
|
const handleCustomPromptToggle = (enabled) => {
|
|
151
166
|
const prompt = defaultPrompt || "";
|
|
152
|
-
if (enabled)
|
|
167
|
+
if (enabled)
|
|
153
168
|
setCustomPrompt(prompt);
|
|
154
|
-
|
|
155
|
-
setData((current) => {
|
|
169
|
+
commitData((current) => {
|
|
156
170
|
const newServiceCustomData = new Map(current.serviceCustomData || new Map());
|
|
157
171
|
if (enabled) {
|
|
158
172
|
newServiceCustomData.set(current.translationProvider, {
|
|
@@ -175,36 +189,34 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
175
189
|
};
|
|
176
190
|
const updateParentData = useCallback(() => {
|
|
177
191
|
const trimmedCustomPrompt = customPromptRef.current.trim();
|
|
178
|
-
|
|
179
|
-
|
|
192
|
+
commitData((current) => {
|
|
193
|
+
const provider = current.translationProvider;
|
|
194
|
+
if (!provider)
|
|
195
|
+
return current;
|
|
196
|
+
const currentServiceData = current.serviceCustomData?.get(provider);
|
|
197
|
+
// The toggle itself owns disabling/removal. A delayed prompt sync must
|
|
198
|
+
// never delete a choice made after its timer was scheduled.
|
|
199
|
+
if (currentServiceData?.enableCustomPrompt !== true)
|
|
200
|
+
return current;
|
|
201
|
+
const nextServiceData = {
|
|
202
|
+
enableCustomPrompt: true,
|
|
203
|
+
customPrompt: trimmedCustomPrompt,
|
|
204
|
+
promptCustomizationType: PROMPT_CUSTOMIZATION_TYPE,
|
|
205
|
+
};
|
|
206
|
+
const isSame = currentServiceData?.enableCustomPrompt === true &&
|
|
207
|
+
(currentServiceData.customPrompt || "") === trimmedCustomPrompt &&
|
|
208
|
+
currentServiceData.promptCustomizationType ===
|
|
209
|
+
PROMPT_CUSTOMIZATION_TYPE;
|
|
210
|
+
if (isSame)
|
|
180
211
|
return current;
|
|
181
212
|
const newServiceCustomData = new Map(current.serviceCustomData || new Map());
|
|
182
|
-
|
|
183
|
-
const isEnabled = currentServiceData?.enableCustomPrompt === true;
|
|
184
|
-
if (isEnabled) {
|
|
185
|
-
const nextServiceData = {
|
|
186
|
-
enableCustomPrompt: true,
|
|
187
|
-
customPrompt: trimmedCustomPrompt,
|
|
188
|
-
promptCustomizationType: PROMPT_CUSTOMIZATION_TYPE,
|
|
189
|
-
};
|
|
190
|
-
const isSame = (currentServiceData.customPrompt || "") === trimmedCustomPrompt &&
|
|
191
|
-
currentServiceData.promptCustomizationType ===
|
|
192
|
-
PROMPT_CUSTOMIZATION_TYPE;
|
|
193
|
-
if (isSame)
|
|
194
|
-
return current;
|
|
195
|
-
newServiceCustomData.set(current.translationProvider, nextServiceData);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
if (!currentServiceData)
|
|
199
|
-
return current;
|
|
200
|
-
newServiceCustomData.delete(current.translationProvider);
|
|
201
|
-
}
|
|
213
|
+
newServiceCustomData.set(provider, nextServiceData);
|
|
202
214
|
return {
|
|
203
215
|
...current,
|
|
204
216
|
serviceCustomData: newServiceCustomData,
|
|
205
217
|
};
|
|
206
218
|
});
|
|
207
|
-
}, [
|
|
219
|
+
}, [commitData]);
|
|
208
220
|
useEffect(() => {
|
|
209
221
|
if (!isActive || !supportsPromptCustomization)
|
|
210
222
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLanguageSelectionStep.d.ts","sourceRoot":"","sources":["../../src/steps/ServiceLanguageSelectionStep.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServiceLanguageSelectionStep.d.ts","sourceRoot":"","sources":["../../src/steps/ServiceLanguageSelectionStep.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,SAAS,CAAC;AAGtE;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAe,EACf,IAAI,EACJ,OAAO,EACP,eAAe,EACf,WAAW,GACZ,EAAE,oBAAoB,+BAoVtB"}
|