@parhelia/localization 0.4.13049 → 0.4.13170
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 +0 -1
- package/dist/LocalizeItemDialog.d.ts.map +1 -1
- package/dist/LocalizeItemDialog.js +3 -9
- package/dist/LocalizeItemUtils.d.ts +0 -1
- package/dist/LocalizeItemUtils.d.ts.map +1 -1
- package/dist/LocalizeItemUtils.js +24 -45
- package/dist/api/discovery.d.ts +3 -17
- package/dist/api/discovery.d.ts.map +1 -1
- package/dist/api/discovery.js +14 -35
- package/dist/hooks/useTranslationWizard.d.ts.map +1 -1
- package/dist/hooks/useTranslationWizard.js +2 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/services/translationService.d.ts +27 -43
- package/dist/services/translationService.d.ts.map +1 -1
- package/dist/services/translationService.js +32 -36
- package/dist/settings/TranslationServicesPanel.d.ts +4 -14
- package/dist/settings/TranslationServicesPanel.d.ts.map +1 -1
- package/dist/settings/TranslationServicesPanel.js +263 -186
- package/dist/setup/LocalizationSetupStep.d.ts.map +1 -1
- package/dist/setup/LocalizationSetupStep.js +33 -14
- package/dist/sidebar/TranslationSidebar.d.ts.map +1 -1
- package/dist/sidebar/TranslationSidebar.js +14 -35
- package/dist/steps/ItemSelectionTree.d.ts +2 -2
- package/dist/steps/ItemSelectionTree.d.ts.map +1 -1
- package/dist/steps/ItemSelectionTree.js +47 -132
- package/dist/steps/ProviderStep.d.ts.map +1 -1
- package/dist/steps/ProviderStep.js +42 -55
- package/dist/steps/ServiceLanguageSelectionStep.d.ts +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.d.ts.map +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.js +176 -127
- package/dist/steps/types.d.ts +3 -3
- package/dist/steps/types.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.d.ts +0 -37
- package/dist/translation-center/TranslationBatches.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.js +78 -214
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/services/translationSettingsService.d.ts +0 -79
- package/dist/services/translationSettingsService.d.ts.map +0 -1
- package/dist/services/translationSettingsService.js +0 -68
- package/dist/settings/ExcludedContentTypeDialog.d.ts +0 -12
- package/dist/settings/ExcludedContentTypeDialog.d.ts.map +0 -1
- package/dist/settings/ExcludedContentTypeDialog.js +0 -29
- package/dist/settings/TranslationProviderDialog.d.ts +0 -18
- package/dist/settings/TranslationProviderDialog.d.ts.map +0 -1
- package/dist/settings/TranslationProviderDialog.js +0 -105
|
@@ -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":"AAkBA,wBAAgB,kBAAkB,uCA8NjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, useEditContext, SimpleTable, confirmCreateVersion, Progress,
|
|
2
|
+
import { Button, useEditContext, SimpleTable, confirmCreateVersion, Progress, } from "@parhelia/core";
|
|
3
3
|
import { getTranslationStatus } from "../services/translationService";
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
import { localizeItemCommand } from "../LocalizeItemCommand";
|
|
@@ -28,33 +28,20 @@ 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(
|
|
31
|
+
return (_jsxs("div", { className: "flex items-center gap-2 text-neutral-grey-100", children: [_jsx("img", { src: language.icon, className: "h-5 rounded-sm", alt: language.languageCode }), _jsx("span", { className: "font-normal", children: language.name })] }, language.languageCode));
|
|
32
|
+
};
|
|
33
|
+
const loadTranslationStatus = async () => {
|
|
34
|
+
if (!item)
|
|
35
|
+
return;
|
|
36
|
+
const status = await getTranslationStatus(item.descriptor.id);
|
|
37
|
+
setTranslationStatus(status.data || []);
|
|
32
38
|
};
|
|
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;
|
|
38
39
|
useEffect(() => {
|
|
39
|
-
|
|
40
|
-
let request = 0;
|
|
41
|
-
const descriptor = item?.descriptor;
|
|
42
|
-
setTranslationStatus(null);
|
|
40
|
+
loadTranslationStatus();
|
|
43
41
|
setTranslationProgress(new Map());
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
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;
|
|
42
|
+
}, [editContext.currentItemDescriptor?.id]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const removeSocketMessageListener = editContext.addSocketMessageListener((message) => {
|
|
58
45
|
if (message.type === "translation-started" ||
|
|
59
46
|
message.type === "translation-finished" ||
|
|
60
47
|
message.type === "translation-error") {
|
|
@@ -79,16 +66,8 @@ export function TranslationSidebar() {
|
|
|
79
66
|
}
|
|
80
67
|
}
|
|
81
68
|
});
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
removeSocketMessageListener();
|
|
85
|
-
};
|
|
86
|
-
}, [
|
|
87
|
-
addSocketMessageListener,
|
|
88
|
-
item?.descriptor.database,
|
|
89
|
-
item?.descriptor.id,
|
|
90
|
-
item?.descriptor.language,
|
|
91
|
-
]);
|
|
69
|
+
return removeSocketMessageListener;
|
|
70
|
+
}, [editContext, setTranslationProgress]);
|
|
92
71
|
const languageData = languages.map((x) => {
|
|
93
72
|
const progress = translationProgress.get(x.languageCode);
|
|
94
73
|
const status = translationStatus?.find((y) => y.targetLanguage === x.languageCode);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type EditContextType } from "@parhelia/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { TranslationWizardData } from "./types";
|
|
3
3
|
type ItemSelectionTreeProps = {
|
|
4
4
|
data: TranslationWizardData;
|
|
5
|
-
setData:
|
|
5
|
+
setData: (data: TranslationWizardData) => void;
|
|
6
6
|
editContext: EditContextType;
|
|
7
7
|
isActive?: boolean;
|
|
8
8
|
onSelectionValidChange?: (valid: boolean) => void;
|
|
@@ -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,EAEL,KAAK,eAAe,EAMrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGrD,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;AAuFF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,QAAe,EACf,sBAAsB,EACtB,MAAY,GACb,EAAE,sBAAsB,+BA0WxB"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { ItemCollectionEditor, } from "@parhelia/core";
|
|
4
4
|
import { streamSubitemCount } from "../api/discovery";
|
|
5
|
-
|
|
5
|
+
const TRANSLATION_ROOT_ITEM_IDS = [
|
|
6
|
+
"0de95ae4-41ab-4d01-9eb0-67441b7c2450", // Content
|
|
7
|
+
"b701850a-cb8a-4943-b2bc-dddb1238c103", // Forms
|
|
8
|
+
"3d6658d8-a0bf-4e75-b3e2-d050fabcf4e1", // Media Library
|
|
9
|
+
];
|
|
6
10
|
const NO_WRITE_ACCESS_TITLE = "You don't have write access to this item, so it can't be translated.";
|
|
7
11
|
/**
|
|
8
12
|
* Only items the user may write can receive a translation (the backend
|
|
@@ -18,7 +22,6 @@ function fullItemFromDescriptor(descriptor) {
|
|
|
18
22
|
language: descriptor.language,
|
|
19
23
|
version: descriptor.version,
|
|
20
24
|
descriptor: {
|
|
21
|
-
database: descriptor.database,
|
|
22
25
|
id: descriptor.id,
|
|
23
26
|
language: descriptor.language,
|
|
24
27
|
version: descriptor.version,
|
|
@@ -53,7 +56,6 @@ function fullItemFromDescriptor(descriptor) {
|
|
|
53
56
|
function fullItemToWithSubtree(item, includeSubitems) {
|
|
54
57
|
return {
|
|
55
58
|
descriptor: {
|
|
56
|
-
database: item.descriptor.database,
|
|
57
59
|
id: item.descriptor?.id ?? item.id,
|
|
58
60
|
language: item.descriptor?.language ?? item.language,
|
|
59
61
|
version: item.descriptor?.version ?? item.version,
|
|
@@ -67,14 +69,9 @@ function fullItemToWithSubtree(item, includeSubitems) {
|
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
export function ItemSelectionTree({ data, setData, editContext, isActive = true, onSelectionValidChange, height = 360, }) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"");
|
|
74
|
-
const preferredLanguage = data.sourceLanguage ||
|
|
75
|
-
editContext?.currentItemDescriptor?.language ||
|
|
76
|
-
data.items[0]?.descriptor.language ||
|
|
77
|
-
"";
|
|
72
|
+
const language = useMemo(() => editContext?.item?.language ??
|
|
73
|
+
editContext?.currentItemDescriptor?.language ??
|
|
74
|
+
"en", [editContext?.item?.language, editContext?.currentItemDescriptor?.language]);
|
|
78
75
|
// Seed selection: prefer previously saved tree items, then discoveredItems,
|
|
79
76
|
// then the wizard's initial `items`. Default includeSubitems = legacy flag.
|
|
80
77
|
const initialItems = useMemo(() => {
|
|
@@ -102,17 +99,19 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
102
99
|
const [subitemCounts, setSubitemCounts] = useState(() => data.subitemCounts ?? {});
|
|
103
100
|
// Mirror local subitemCounts into wizardData so later steps (e.g. the
|
|
104
101
|
// Start Translation button) can show a live total.
|
|
102
|
+
const dataRef = useRef(data);
|
|
103
|
+
dataRef.current = data;
|
|
105
104
|
useEffect(() => {
|
|
106
|
-
setData(
|
|
105
|
+
setData({ ...dataRef.current, subitemCounts });
|
|
107
106
|
}, [subitemCounts, setData]);
|
|
108
107
|
// Keep a cache of the richest FullItem we've ever seen for each id so we
|
|
109
108
|
// can rebuild discoveredItems without re-fetching.
|
|
110
109
|
const itemCacheRef = useRef(new Map());
|
|
111
110
|
if (itemCacheRef.current.size === 0) {
|
|
112
111
|
for (const it of data.items)
|
|
113
|
-
itemCacheRef.current.set(
|
|
112
|
+
itemCacheRef.current.set(it.id, it);
|
|
114
113
|
for (const it of data.discoveredItems || [])
|
|
115
|
-
itemCacheRef.current.set(
|
|
114
|
+
itemCacheRef.current.set(it.id, it);
|
|
116
115
|
}
|
|
117
116
|
// Build a combined idPath that expands every parent of the current
|
|
118
117
|
// selection (but not the items themselves). ContentTree's parser
|
|
@@ -120,7 +119,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
120
119
|
const expandIdPath = useMemo(() => {
|
|
121
120
|
const segments = [];
|
|
122
121
|
for (const entry of items) {
|
|
123
|
-
const cached = itemCacheRef.current.get(
|
|
122
|
+
const cached = itemCacheRef.current.get(entry.descriptor.id);
|
|
124
123
|
const idPath = cached?.idPath;
|
|
125
124
|
if (!idPath)
|
|
126
125
|
continue;
|
|
@@ -136,70 +135,15 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
136
135
|
}, [items]);
|
|
137
136
|
const commitToWizard = useCallback((nextItems) => {
|
|
138
137
|
const cache = itemCacheRef.current;
|
|
139
|
-
const discovered = nextItems.map((entry) => cache.get(
|
|
138
|
+
const discovered = nextItems.map((entry) => cache.get(entry.descriptor.id) ??
|
|
140
139
|
fullItemFromDescriptor(entry.descriptor));
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
setData((current) => ({
|
|
144
|
-
...current,
|
|
140
|
+
setData({
|
|
141
|
+
...data,
|
|
145
142
|
selectionTreeItems: nextItems,
|
|
146
143
|
discoveredItems: discovered,
|
|
147
144
|
includeSubitems: nextItems.some((i) => i.includeSubitems),
|
|
148
|
-
}));
|
|
149
|
-
}, [setData]);
|
|
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. Null while loading (or with no
|
|
159
|
-
// store), so the preferred language 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
145
|
});
|
|
176
|
-
|
|
177
|
-
cancelled = true;
|
|
178
|
-
};
|
|
179
|
-
}, [store]);
|
|
180
|
-
// The tree browses in the source language chosen in the Languages step,
|
|
181
|
-
// else the editor's language; a store that declares neither is browsed in
|
|
182
|
-
// its first language. An empty list is a failed read, not a store without
|
|
183
|
-
// languages.
|
|
184
|
-
const language = !storeLanguages?.length ||
|
|
185
|
-
storeLanguages.some((entry) => entry.languageCode === preferredLanguage)
|
|
186
|
-
? preferredLanguage
|
|
187
|
-
: storeLanguages[0].languageCode;
|
|
188
|
-
// The selected items carry the source language as their coordinate, so a
|
|
189
|
-
// new source relabels them (subitem discovery reads it from there too).
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
if (!language)
|
|
192
|
-
return;
|
|
193
|
-
if (items.every((entry) => entry.descriptor.language === language))
|
|
194
|
-
return;
|
|
195
|
-
setSelectedInTree([]);
|
|
196
|
-
const next = items.map((entry) => ({
|
|
197
|
-
...entry,
|
|
198
|
-
descriptor: { ...entry.descriptor, language },
|
|
199
|
-
}));
|
|
200
|
-
setItems(next);
|
|
201
|
-
commitToWizard(next);
|
|
202
|
-
}, [language, items, commitToWizard]);
|
|
146
|
+
}, [data, setData]);
|
|
203
147
|
// Commit current state on first mount so wizard data reflects the seed.
|
|
204
148
|
const didInitialCommitRef = useRef(false);
|
|
205
149
|
useEffect(() => {
|
|
@@ -223,9 +167,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
223
167
|
const inFlightRef = useRef(new Map());
|
|
224
168
|
useEffect(() => {
|
|
225
169
|
const inFlight = inFlightRef.current;
|
|
226
|
-
const enabledIds = new Set(items
|
|
227
|
-
.filter((it) => it.includeSubitems)
|
|
228
|
-
.map((it) => itemKey(it.descriptor)));
|
|
170
|
+
const enabledIds = new Set(items.filter((it) => it.includeSubitems).map((it) => it.descriptor.id));
|
|
229
171
|
// Cancel any streams whose items no longer have the flag on.
|
|
230
172
|
for (const [id, ctrl] of inFlight) {
|
|
231
173
|
if (!enabledIds.has(id)) {
|
|
@@ -241,9 +183,9 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
241
183
|
.filter((it) => it.includeSubitems)
|
|
242
184
|
.map((it) => it.descriptor)
|
|
243
185
|
.filter((d) => {
|
|
244
|
-
if (inFlight.has(
|
|
186
|
+
if (inFlight.has(d.id))
|
|
245
187
|
return false;
|
|
246
|
-
const c = subitemCounts[
|
|
188
|
+
const c = subitemCounts[d.id];
|
|
247
189
|
if (c === undefined || c === "error")
|
|
248
190
|
return true;
|
|
249
191
|
if (c === "loading")
|
|
@@ -255,37 +197,30 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
255
197
|
setSubitemCounts((prev) => {
|
|
256
198
|
const next = { ...prev };
|
|
257
199
|
for (const d of toStart)
|
|
258
|
-
next[
|
|
200
|
+
next[d.id] = "loading";
|
|
259
201
|
return next;
|
|
260
202
|
});
|
|
261
203
|
for (const descriptor of toStart) {
|
|
262
204
|
const controller = new AbortController();
|
|
263
|
-
|
|
264
|
-
inFlight.set(key, controller);
|
|
205
|
+
inFlight.set(descriptor.id, controller);
|
|
265
206
|
void (async () => {
|
|
266
207
|
try {
|
|
267
|
-
const finalCount = await streamSubitemCount({
|
|
268
|
-
if (controller.signal.aborted)
|
|
269
|
-
return;
|
|
270
|
-
// multi-cms cfsmall (A15): the store's refusal on the last line travels with the count to the badge.
|
|
208
|
+
const finalCount = await streamSubitemCount({ itemId: descriptor.id, language: descriptor.language }, ({ count, complete }) => {
|
|
271
209
|
setSubitemCounts((prev) => ({
|
|
272
210
|
...prev,
|
|
273
|
-
[
|
|
274
|
-
? { count, complete, refusal }
|
|
275
|
-
: { count, complete },
|
|
211
|
+
[descriptor.id]: { count, complete },
|
|
276
212
|
}));
|
|
277
213
|
}, { sessionId, signal: controller.signal });
|
|
278
214
|
// Backend may close the stream without explicitly sending
|
|
279
215
|
// complete=true on the last line — mark complete on a clean exit.
|
|
280
|
-
if (controller.signal.aborted)
|
|
281
|
-
return;
|
|
282
216
|
setSubitemCounts((prev) => {
|
|
283
|
-
const existing = prev[
|
|
284
|
-
|
|
285
|
-
|
|
217
|
+
const existing = prev[descriptor.id];
|
|
218
|
+
const count = existing && typeof existing === "object"
|
|
219
|
+
? existing.count
|
|
220
|
+
: finalCount;
|
|
286
221
|
return {
|
|
287
222
|
...prev,
|
|
288
|
-
[
|
|
223
|
+
[descriptor.id]: { count, complete: true },
|
|
289
224
|
};
|
|
290
225
|
});
|
|
291
226
|
}
|
|
@@ -294,15 +229,15 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
294
229
|
return;
|
|
295
230
|
setSubitemCounts((prev) => {
|
|
296
231
|
// Don't overwrite a partial count with "error" — keep what we have.
|
|
297
|
-
const existing = prev[
|
|
232
|
+
const existing = prev[descriptor.id];
|
|
298
233
|
if (existing && typeof existing === "object")
|
|
299
234
|
return prev;
|
|
300
|
-
return { ...prev, [
|
|
235
|
+
return { ...prev, [descriptor.id]: "error" };
|
|
301
236
|
});
|
|
302
237
|
}
|
|
303
238
|
finally {
|
|
304
|
-
if (inFlight.get(
|
|
305
|
-
inFlight.delete(
|
|
239
|
+
if (inFlight.get(descriptor.id) === controller) {
|
|
240
|
+
inFlight.delete(descriptor.id);
|
|
306
241
|
}
|
|
307
242
|
}
|
|
308
243
|
})();
|
|
@@ -322,11 +257,10 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
322
257
|
if (!id)
|
|
323
258
|
return;
|
|
324
259
|
const cache = itemCacheRef.current;
|
|
325
|
-
if (cache.has(
|
|
260
|
+
if (cache.has(id))
|
|
326
261
|
return;
|
|
327
262
|
const anyNode = node;
|
|
328
|
-
cache.set(
|
|
329
|
-
database: node.database,
|
|
263
|
+
cache.set(id, fullItemFromDescriptor({
|
|
330
264
|
id,
|
|
331
265
|
language: node.language ?? language,
|
|
332
266
|
version: node.version ?? 1,
|
|
@@ -344,12 +278,10 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
344
278
|
const source = itemsToAdd ?? selectedInTree;
|
|
345
279
|
if (!source || source.length === 0)
|
|
346
280
|
return;
|
|
347
|
-
const existing = new Set(items.map((i) =>
|
|
281
|
+
const existing = new Set(items.map((i) => i.descriptor.id));
|
|
348
282
|
const next = [...items];
|
|
349
|
-
for (const
|
|
350
|
-
|
|
351
|
-
const node = { ...candidate, database: candidate.database ?? store };
|
|
352
|
-
if (!node.id || !node.database || existing.has(itemKey(node)))
|
|
283
|
+
for (const node of source) {
|
|
284
|
+
if (!node.id || existing.has(node.id))
|
|
353
285
|
continue;
|
|
354
286
|
if (!isWritable(node))
|
|
355
287
|
continue;
|
|
@@ -357,7 +289,6 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
357
289
|
cacheTreeNode(node);
|
|
358
290
|
next.push({
|
|
359
291
|
descriptor: {
|
|
360
|
-
database: node.database,
|
|
361
292
|
id: node.id,
|
|
362
293
|
language: node.language ?? language,
|
|
363
294
|
version: node.version ?? 1,
|
|
@@ -368,18 +299,16 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
368
299
|
},
|
|
369
300
|
includeSubitems: false,
|
|
370
301
|
});
|
|
371
|
-
existing.add(
|
|
302
|
+
existing.add(node.id);
|
|
372
303
|
}
|
|
373
304
|
setItems(next);
|
|
374
305
|
commitToWizard(next);
|
|
375
306
|
setSelectedInTree([]);
|
|
376
307
|
setSelectedFromList([]);
|
|
377
|
-
}, [items, selectedInTree,
|
|
308
|
+
}, [items, selectedInTree, language, cacheTreeNode, commitToWizard]);
|
|
378
309
|
const handleAddItem = useCallback(async (item) => {
|
|
379
310
|
const id = item.id;
|
|
380
|
-
if (!id ||
|
|
381
|
-
!item.database ||
|
|
382
|
-
items.some((i) => itemKey(i.descriptor) === itemKey(item)))
|
|
311
|
+
if (!id || items.some((i) => i.descriptor.id === id))
|
|
383
312
|
return;
|
|
384
313
|
if (!isWritable(item))
|
|
385
314
|
return;
|
|
@@ -388,7 +317,6 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
388
317
|
...items,
|
|
389
318
|
{
|
|
390
319
|
descriptor: {
|
|
391
|
-
database: item.database,
|
|
392
320
|
id,
|
|
393
321
|
language: item.language ?? language,
|
|
394
322
|
version: item.version ?? 1,
|
|
@@ -405,8 +333,8 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
405
333
|
setSelectedFromList([]);
|
|
406
334
|
}, [items, language, cacheTreeNode, commitToWizard]);
|
|
407
335
|
const handleRemoveFromList = useCallback(() => {
|
|
408
|
-
const ids = new Set(selectedFromList.map((i) =>
|
|
409
|
-
const next = items.filter((i) => !ids.has(
|
|
336
|
+
const ids = new Set(selectedFromList.map((i) => i.descriptor.id));
|
|
337
|
+
const next = items.filter((i) => !ids.has(i.descriptor.id));
|
|
410
338
|
setItems(next);
|
|
411
339
|
commitToWizard(next);
|
|
412
340
|
setSelectedFromList([]);
|
|
@@ -422,18 +350,5 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
422
350
|
setItems(next);
|
|
423
351
|
commitToWizard(next);
|
|
424
352
|
}, [items, commitToWizard]);
|
|
425
|
-
|
|
426
|
-
// rest, so the tree and the list scroll inside it, never the whole step.
|
|
427
|
-
const storePicker = onlyStore ? undefined : (_jsxs("div", { className: "flex w-64 max-w-full flex-col gap-2", children: [_jsx("span", { className: "text-neutral-grey-50 text-xs font-medium tracking-wider", children: "Content store" }), _jsx(ContentStoreSelect, { "data-testid": "translation-content-store", value: store, placeholder: "Select a store", onValueChange: (value) => {
|
|
428
|
-
setStore(value);
|
|
429
|
-
setSelectedInTree([]);
|
|
430
|
-
}, stores: writableStores })] }));
|
|
431
|
-
return (_jsx("div", { className: "flex h-full min-h-0 flex-col", children: 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
|
|
432
|
-
.filter((root) => root.storeId === store &&
|
|
433
|
-
(root.kind === "content" || root.kind === "media"))
|
|
434
|
-
.map((root) => root.id), hideRootNodes: false, isItemSelectable: isWritable, unselectableItemTitle: NO_WRITE_ACCESS_TITLE, selectedItemsLabel: "Selected", 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", treeHeader: storePicker, frameless: true }) })) : (_jsxs("div", { className: "flex flex-col gap-4 p-6", children: [storePicker, _jsx("p", { className: "text-neutral-grey-50 text-sm", children: !store
|
|
435
|
-
? "Select a content store to choose translation items."
|
|
436
|
-
: storeLanguages === null
|
|
437
|
-
? "Loading languages..."
|
|
438
|
-
: "This store declares no languages." })] })) }));
|
|
353
|
+
return (_jsx(ItemCollectionEditor, { items: items, selectedInTree: selectedInTree, onSelectedInTreeChange: setSelectedInTree, selectedFromList: selectedFromList, onSelectedFromListChange: setSelectedFromList, onAddToList: handleAddToList, onRemoveFromList: handleRemoveFromList, onAddItem: handleAddItem, onRemoveItem: handleRemoveItem, onToggleSubitems: handleToggleSubitems, language: language, rootItemIds: TRANSLATION_ROOT_ITEM_IDS, 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, expandIdPath: expandIdPath, localStorageKey: "translation-wizard.itemCollectionSplitter", treeSearchContainerClassName: "border-b-0 p-0 pb-3", frameless: true }));
|
|
439
354
|
}
|
|
@@ -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,EAAE,MAAM,SAAS,CAAC;AAQ/C,wBAAgB,YAAY,CAAC,EAC3B,QAAe,EACf,IAAI,EACJ,OAAO,EACP,eAAe,EACf,WAAW,GACZ,EAAE,oBAAoB,qBAqYtB"}
|
|
@@ -4,7 +4,6 @@ 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";
|
|
8
7
|
const PROMPT_CUSTOMIZATION_TYPE = "replace";
|
|
9
8
|
const ResetIcon = (props) => React.createElement(RotateCcw, props);
|
|
10
9
|
export function ProviderStep({ isActive = true, data, setData, onStepCompleted, editContext, }) {
|
|
@@ -16,29 +15,17 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
16
15
|
// it with a fresh AI suggestion.
|
|
17
16
|
const userTouchedNameRef = useRef(!!data.batchName);
|
|
18
17
|
const dataRef = useRef(data);
|
|
19
|
-
|
|
20
|
-
if (lastDataPropRef.current !== data) {
|
|
21
|
-
lastDataPropRef.current = data;
|
|
18
|
+
useEffect(() => {
|
|
22
19
|
dataRef.current = data;
|
|
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]);
|
|
20
|
+
}, [data]);
|
|
36
21
|
// Push name changes back into wizard data (debounced via simple equality).
|
|
37
22
|
useEffect(() => {
|
|
38
|
-
|
|
23
|
+
if ((dataRef.current.batchName ?? "") === batchName)
|
|
24
|
+
return;
|
|
25
|
+
setData((current) => (current.batchName ?? "") === batchName
|
|
39
26
|
? current
|
|
40
27
|
: { ...current, batchName });
|
|
41
|
-
}, [batchName,
|
|
28
|
+
}, [batchName, setData]);
|
|
42
29
|
// Auto-suggest a name when the step becomes active and the user hasn't
|
|
43
30
|
// already provided/edited one. Fires once per item+language combination so
|
|
44
31
|
// navigating away and back doesn't re-fetch.
|
|
@@ -49,17 +36,13 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
49
36
|
return;
|
|
50
37
|
if (userTouchedNameRef.current)
|
|
51
38
|
return;
|
|
52
|
-
const
|
|
53
|
-
? data.selectionTreeItems.map((s) => s.descriptor)
|
|
54
|
-
: data.items.map((i) => i.descriptor)).filter(Boolean);
|
|
39
|
+
const itemIds = (data.selectionTreeItems && data.selectionTreeItems.length > 0
|
|
40
|
+
? data.selectionTreeItems.map((s) => s.descriptor.id)
|
|
41
|
+
: data.items.map((i) => i.descriptor.id)).filter(Boolean);
|
|
55
42
|
const langs = [...data.targetLanguages].sort();
|
|
56
|
-
if (
|
|
57
|
-
langs.length === 0 ||
|
|
58
|
-
descriptors.some((d) => !d.database || !d.language))
|
|
43
|
+
if (itemIds.length === 0 || langs.length === 0)
|
|
59
44
|
return;
|
|
60
|
-
const
|
|
61
|
-
const language = data.sourceLanguage || descriptors[0].language;
|
|
62
|
-
const key = JSON.stringify({ items, language, langs });
|
|
45
|
+
const key = JSON.stringify({ itemIds: [...itemIds].sort(), langs });
|
|
63
46
|
if (lastSuggestionKeyRef.current === key)
|
|
64
47
|
return;
|
|
65
48
|
lastSuggestionKeyRef.current = key;
|
|
@@ -68,7 +51,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
68
51
|
void (async () => {
|
|
69
52
|
try {
|
|
70
53
|
const includeSubitems = !!data.selectionTreeItems?.some((s) => s.includeSubitems);
|
|
71
|
-
const name = await suggestBatchName({
|
|
54
|
+
const name = await suggestBatchName({ itemIds, targetLanguages: langs, includeSubitems }, sessionId);
|
|
72
55
|
if (cancelled || userTouchedNameRef.current)
|
|
73
56
|
return;
|
|
74
57
|
if (name)
|
|
@@ -87,14 +70,15 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
87
70
|
sessionId,
|
|
88
71
|
data.selectionTreeItems,
|
|
89
72
|
data.items,
|
|
90
|
-
data.sourceLanguage,
|
|
91
73
|
data.targetLanguages,
|
|
92
74
|
]);
|
|
93
75
|
const customPromptRef = useRef(customPrompt);
|
|
94
76
|
const hasInitializedRef = useRef(false);
|
|
95
77
|
const lastProviderRef = useRef(data.translationProvider);
|
|
96
78
|
const updateTimerRef = useRef(null);
|
|
97
|
-
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
customPromptRef.current = customPrompt;
|
|
81
|
+
}, [customPrompt]);
|
|
98
82
|
const selectedProvider = useMemo(() => data.translationProviders.find((p) => p.name === data.translationProvider), [data.translationProviders, data.translationProvider]);
|
|
99
83
|
const serviceData = useMemo(() => {
|
|
100
84
|
if (!data.serviceCustomData || !data.translationProvider)
|
|
@@ -149,7 +133,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
149
133
|
}, [data.translationProvider, isActive, onStepCompleted]);
|
|
150
134
|
const handleProviderChange = (e) => {
|
|
151
135
|
const newProvider = e.target.value;
|
|
152
|
-
|
|
136
|
+
setData((current) => {
|
|
153
137
|
const newServiceCustomData = new Map();
|
|
154
138
|
current.serviceCustomData?.forEach((value, key) => {
|
|
155
139
|
if (key !== "AI" || newProvider === "AI") {
|
|
@@ -165,9 +149,10 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
165
149
|
};
|
|
166
150
|
const handleCustomPromptToggle = (enabled) => {
|
|
167
151
|
const prompt = defaultPrompt || "";
|
|
168
|
-
if (enabled)
|
|
152
|
+
if (enabled) {
|
|
169
153
|
setCustomPrompt(prompt);
|
|
170
|
-
|
|
154
|
+
}
|
|
155
|
+
setData((current) => {
|
|
171
156
|
const newServiceCustomData = new Map(current.serviceCustomData || new Map());
|
|
172
157
|
if (enabled) {
|
|
173
158
|
newServiceCustomData.set(current.translationProvider, {
|
|
@@ -190,34 +175,36 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
190
175
|
};
|
|
191
176
|
const updateParentData = useCallback(() => {
|
|
192
177
|
const trimmedCustomPrompt = customPromptRef.current.trim();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (!provider)
|
|
196
|
-
return current;
|
|
197
|
-
const currentServiceData = current.serviceCustomData?.get(provider);
|
|
198
|
-
// The toggle itself owns disabling/removal. A delayed prompt sync must
|
|
199
|
-
// never delete a choice made after its timer was scheduled.
|
|
200
|
-
if (currentServiceData?.enableCustomPrompt !== true)
|
|
201
|
-
return current;
|
|
202
|
-
const nextServiceData = {
|
|
203
|
-
enableCustomPrompt: true,
|
|
204
|
-
customPrompt: trimmedCustomPrompt,
|
|
205
|
-
promptCustomizationType: PROMPT_CUSTOMIZATION_TYPE,
|
|
206
|
-
};
|
|
207
|
-
const isSame = currentServiceData?.enableCustomPrompt === true &&
|
|
208
|
-
(currentServiceData.customPrompt || "") === trimmedCustomPrompt &&
|
|
209
|
-
currentServiceData.promptCustomizationType ===
|
|
210
|
-
PROMPT_CUSTOMIZATION_TYPE;
|
|
211
|
-
if (isSame)
|
|
178
|
+
setData((current) => {
|
|
179
|
+
if (!current.translationProvider)
|
|
212
180
|
return current;
|
|
213
181
|
const newServiceCustomData = new Map(current.serviceCustomData || new Map());
|
|
214
|
-
|
|
182
|
+
const currentServiceData = current.serviceCustomData?.get(current.translationProvider);
|
|
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
|
+
}
|
|
215
202
|
return {
|
|
216
203
|
...current,
|
|
217
204
|
serviceCustomData: newServiceCustomData,
|
|
218
205
|
};
|
|
219
206
|
});
|
|
220
|
-
}, [
|
|
207
|
+
}, [setData]);
|
|
221
208
|
useEffect(() => {
|
|
222
209
|
if (!isActive || !supportsPromptCustomization)
|
|
223
210
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TranslationStepProps } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Language-only step. Item selection lives in its own step
|
|
4
4
|
* (see ItemSelectionStep). The legacy name is kept so existing imports
|
|
5
5
|
* keep working.
|
|
6
6
|
*/
|
|
@@ -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,EAAE,MAAM,SAAS,CAAC;AAG/C;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAe,EACf,IAAI,EACJ,OAAO,EACP,eAAe,EACf,WAAW,GACZ,EAAE,oBAAoB,+BA4YtB"}
|