@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,214 +1,291 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const sameKeys = (a, b) => keysOf(a).join("\n") === keysOf(b).join("\n");
|
|
20
|
-
/** What a save sends: only the settings the person changed. */
|
|
21
|
-
export function settingsChanges(draft, saved) {
|
|
22
|
-
const set = {};
|
|
23
|
-
const jobs = Number(draft.maxConcurrentTranslationJobs);
|
|
24
|
-
if (draft.maxConcurrentTranslationJobs.trim() !== "" &&
|
|
25
|
-
jobs !== saved.maxConcurrentTranslationJobs)
|
|
26
|
-
set.maxConcurrentTranslationJobs = jobs;
|
|
27
|
-
const perBatch = Number(draft.maxConcurrentJobsPerBatch);
|
|
28
|
-
if (draft.maxConcurrentJobsPerBatch.trim() !== "" &&
|
|
29
|
-
perBatch !== saved.maxConcurrentJobsPerBatch)
|
|
30
|
-
set.maxConcurrentJobsPerBatch = perBatch;
|
|
31
|
-
if (draft.skipSharedFields !== saved.skipSharedFields)
|
|
32
|
-
set.skipSharedFields = draft.skipSharedFields;
|
|
33
|
-
if (draft.displayCosts !== saved.displayCosts)
|
|
34
|
-
set.displayCosts = draft.displayCosts;
|
|
35
|
-
if (!sameKeys(draft.excludedContentTypes, saved.excludedContentTypes))
|
|
36
|
-
set.excludedContentTypes = keysOf(draft.excludedContentTypes);
|
|
37
|
-
return set;
|
|
38
|
-
}
|
|
2
|
+
import { useCallback, useState, useEffect, } from "react";
|
|
3
|
+
import { Button, Card, useEditContext, Splitter, ItemConfigPanel, DeleteIcon, } from "@parhelia/core";
|
|
4
|
+
import { CheckCircle as LucideCheckCircle, AlertCircle as LucideAlertCircle, RefreshCw as LucideRefreshCw, Plus as LucidePlus, Settings as LucideSettings, Languages as LucideLanguages, ListChecks as LucideListChecks, } from "lucide-react";
|
|
5
|
+
import { getAvailableTranslationServices, createProviderSettings, getTranslationStructure, ensureTranslationStructure, } from "../services/translationService";
|
|
6
|
+
const CheckCircleIcon = LucideCheckCircle;
|
|
7
|
+
const AlertCircleIcon = LucideAlertCircle;
|
|
8
|
+
const RefreshCwIcon = LucideRefreshCw;
|
|
9
|
+
const PlusIcon = LucidePlus;
|
|
10
|
+
const SettingsIcon = LucideSettings;
|
|
11
|
+
const LanguagesIcon = LucideLanguages;
|
|
12
|
+
const ListChecksIcon = LucideListChecks;
|
|
13
|
+
const DEFAULT_STRUCTURE_SETTINGS = {
|
|
14
|
+
translationFolderPath: "/sitecore/system/Parhelia/Settings/Translation",
|
|
15
|
+
translationFolderTemplateId: "b1e40cfe-6e36-4a0e-a49e-19c10b2127b7",
|
|
16
|
+
translationProvidersPath: "/sitecore/system/Parhelia/Settings/Translation/Translation Providers",
|
|
17
|
+
translationProvidersTemplateId: "1e7ee67d-fab9-47c8-b159-d4002f1a84f9",
|
|
18
|
+
};
|
|
39
19
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* the setting follows the shipped default again (the way System Settings shows its root settings).
|
|
43
|
-
*/
|
|
44
|
-
function TranslationSettingRow({ name, page, busy, onReset, label, htmlFor, hint, toggle, control, children, }) {
|
|
45
|
-
const customized = page.customized.includes(name);
|
|
46
|
-
return (_jsx(SettingsRow, { "data-testid": `translation-setting-state-${name}`, "data-customized": customized ? "true" : "false", htmlFor: htmlFor, label: _jsxs("span", { className: "flex items-center gap-2", children: [label, customized && _jsx("span", { className: settingsText.meta, children: "Customized" })] }), description: hint || customized ? (_jsxs(_Fragment, { children: [hint, customized && (_jsx("div", { children: _jsx(Button, { variant: "link", size: "xxs", className: "h-auto px-0 text-xs", onClick: () => onReset(name), disabled: busy, "data-testid": `translation-setting-reset-${name}`, children: "Reset to default" }) }))] })) : undefined, toggle: toggle, control: control, children: children }));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Settings → Localization → Translation Services, on every host and every CMS: which translation services are set up
|
|
50
|
-
* (each with the fields its service declares), and how translation runs.
|
|
20
|
+
* Settings panel for Translation Services configuration.
|
|
21
|
+
* Configure translation services (OpenAI, Azure, DeepL, etc.) registered in DI.
|
|
51
22
|
*/
|
|
52
23
|
export function TranslationServicesPanel() {
|
|
53
24
|
const editContext = useEditContext();
|
|
54
|
-
const [
|
|
55
|
-
const [
|
|
56
|
-
const [
|
|
57
|
-
const [
|
|
58
|
-
const [
|
|
59
|
-
const [
|
|
60
|
-
const [
|
|
61
|
-
const [
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
25
|
+
const [state, setState] = useState("loading");
|
|
26
|
+
const [services, setServices] = useState([]);
|
|
27
|
+
const [error, setError] = useState(null);
|
|
28
|
+
const [selectedConfigTarget, setSelectedConfigTarget] = useState(null);
|
|
29
|
+
const [structureSettings, setStructureSettings] = useState(DEFAULT_STRUCTURE_SETTINGS);
|
|
30
|
+
const [structureState, setStructureState] = useState(null);
|
|
31
|
+
const [structureLoading, setStructureLoading] = useState(false);
|
|
32
|
+
const [ensuringStructure, setEnsuringStructure] = useState(false);
|
|
33
|
+
const handleOpenConfig = useCallback((service) => {
|
|
34
|
+
if (service.isConfigured && service.settingsItemId) {
|
|
35
|
+
setSelectedConfigTarget({
|
|
36
|
+
key: `service:${service.serviceName}`,
|
|
37
|
+
itemId: service.settingsItemId,
|
|
38
|
+
title: `Configure: ${service.displayName || service.serviceName}`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
69
41
|
}, []);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const changes = useMemo(() => (page && draft ? settingsChanges(draft, page.settings) : {}), [page, draft]);
|
|
82
|
-
const dirty = Object.keys(changes).length > 0;
|
|
83
|
-
if (loadError)
|
|
84
|
-
return (_jsx(SettingsPanelLayout, { testId: "translation-services-panel", children: _jsxs(Alert, { variant: "destructive", children: [_jsx(AlertCircle, { className: "h-4 w-4", strokeWidth: 1 }), _jsx(AlertDescription, { children: loadError })] }) }));
|
|
85
|
-
if (!page || !draft)
|
|
86
|
-
return (_jsx(SettingsPanelLayout, { testId: "translation-services-panel", children: _jsx(SettingsCard, { icon: _jsx(Languages, { strokeWidth: 1 }), title: "Translation providers", description: "The translation services of this installation. People can pick a service for translation once it is set up.", children: _jsx(LoadingState, { variant: "inline", message: "Loading translation settings" }) }) }));
|
|
87
|
-
const createProvider = async (provider) => {
|
|
88
|
-
setBusyProvider(provider.serviceName);
|
|
89
|
-
setProviderError(null);
|
|
42
|
+
const handleOpenStructureConfig = useCallback((itemId, title) => {
|
|
43
|
+
setSelectedConfigTarget({
|
|
44
|
+
key: `structure:${itemId}`,
|
|
45
|
+
itemId,
|
|
46
|
+
title,
|
|
47
|
+
});
|
|
48
|
+
}, []);
|
|
49
|
+
const handleCloseConfig = useCallback(() => {
|
|
50
|
+
setSelectedConfigTarget(null);
|
|
51
|
+
}, []);
|
|
52
|
+
const loadStructure = useCallback(async () => {
|
|
90
53
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
54
|
+
setStructureLoading(true);
|
|
55
|
+
const result = await getTranslationStructure(structureSettings);
|
|
56
|
+
if (result.type === "success" && result.data) {
|
|
57
|
+
if (result.data.success && result.data.data) {
|
|
58
|
+
setStructureState(result.data.data);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new Error(result.data.error ||
|
|
62
|
+
result.details ||
|
|
63
|
+
"Failed to read translation structure");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(result.details || "Failed to read translation structure");
|
|
68
|
+
}
|
|
95
69
|
}
|
|
96
|
-
catch (
|
|
97
|
-
|
|
70
|
+
catch (e) {
|
|
71
|
+
setError(e?.message || "Failed to read translation structure");
|
|
98
72
|
}
|
|
99
73
|
finally {
|
|
100
|
-
|
|
74
|
+
setStructureLoading(false);
|
|
101
75
|
}
|
|
102
|
-
};
|
|
103
|
-
const
|
|
104
|
-
if (!editing)
|
|
105
|
-
return;
|
|
106
|
-
setBusyProvider(editing.serviceName);
|
|
107
|
-
setDialogError(null);
|
|
76
|
+
}, [structureSettings]);
|
|
77
|
+
const ensureStructure = useCallback(async () => {
|
|
108
78
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
79
|
+
setEnsuringStructure(true);
|
|
80
|
+
setError(null);
|
|
81
|
+
const result = await ensureTranslationStructure(structureSettings);
|
|
82
|
+
if (result.type === "success" && result.data) {
|
|
83
|
+
if (result.data.success && result.data.data) {
|
|
84
|
+
setStructureState(result.data.data);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
throw new Error(result.data.error ||
|
|
88
|
+
result.details ||
|
|
89
|
+
"Failed to create translation structure");
|
|
90
|
+
}
|
|
91
|
+
throw new Error(result.details || "Failed to create translation structure");
|
|
111
92
|
}
|
|
112
|
-
catch (
|
|
113
|
-
|
|
93
|
+
catch (e) {
|
|
94
|
+
setError(e?.message || "Failed to create translation structure");
|
|
95
|
+
return false;
|
|
114
96
|
}
|
|
115
97
|
finally {
|
|
116
|
-
|
|
98
|
+
setEnsuringStructure(false);
|
|
117
99
|
}
|
|
118
|
-
};
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
100
|
+
}, [structureSettings]);
|
|
101
|
+
const loadData = useCallback(async () => {
|
|
102
|
+
try {
|
|
103
|
+
setState("loading");
|
|
104
|
+
setError(null);
|
|
105
|
+
await loadStructure();
|
|
106
|
+
const result = await getAvailableTranslationServices();
|
|
107
|
+
if (result.type === "success" && result.data) {
|
|
108
|
+
if (!result.data.success || !result.data.data) {
|
|
109
|
+
throw new Error(result.data.error ||
|
|
110
|
+
result.details ||
|
|
111
|
+
"Failed to load translation services. The translation API may not be available.");
|
|
112
|
+
}
|
|
113
|
+
const availableServices = result.data.data;
|
|
114
|
+
const serviceStates = availableServices.map((svc) => ({
|
|
115
|
+
...svc,
|
|
116
|
+
creating: false,
|
|
117
|
+
deleting: false,
|
|
118
|
+
}));
|
|
119
|
+
setServices(serviceStates);
|
|
120
|
+
setState(availableServices.length === 0 ? "error" : "success");
|
|
128
121
|
}
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
else {
|
|
123
|
+
setState("error");
|
|
124
|
+
setError(result.details ||
|
|
125
|
+
"Failed to load translation services. The translation API may not be available.");
|
|
131
126
|
}
|
|
132
|
-
};
|
|
133
|
-
const message = `Delete the settings of "${provider.displayName}"? People can no longer pick it for translation until it is set up again.`;
|
|
134
|
-
if (!editContext?.confirm) {
|
|
135
|
-
if (window.confirm(message))
|
|
136
|
-
void remove();
|
|
137
|
-
return;
|
|
138
127
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
message
|
|
142
|
-
acceptLabel: "Delete",
|
|
143
|
-
showCancel: true,
|
|
144
|
-
accept: remove,
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
const saveSettings = async (set, reset = []) => {
|
|
148
|
-
setSavingSettings(true);
|
|
149
|
-
setSettingsError(null);
|
|
150
|
-
try {
|
|
151
|
-
apply(await translationSettingsService.saveSettings(set, reset));
|
|
128
|
+
catch (e) {
|
|
129
|
+
setState("error");
|
|
130
|
+
setError(e?.message || "Failed to load translation services");
|
|
152
131
|
}
|
|
153
|
-
|
|
154
|
-
|
|
132
|
+
}, [loadStructure]);
|
|
133
|
+
const handleStructureInputChange = useCallback((field) => (e) => {
|
|
134
|
+
setStructureSettings((prev) => ({
|
|
135
|
+
...prev,
|
|
136
|
+
[field]: e.target.value,
|
|
137
|
+
}));
|
|
138
|
+
}, []);
|
|
139
|
+
const createSettings = useCallback(async (serviceName, templateId) => {
|
|
140
|
+
try {
|
|
141
|
+
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: true } : s));
|
|
142
|
+
setError(null);
|
|
143
|
+
const language = editContext?.item?.language ??
|
|
144
|
+
editContext?.currentItemDescriptor?.language ??
|
|
145
|
+
"en";
|
|
146
|
+
const result = await createProviderSettings(serviceName, templateId, language, structureSettings);
|
|
147
|
+
if (result.type === "success" && result.data) {
|
|
148
|
+
const payload = result.data.data;
|
|
149
|
+
if (result.data.success && payload) {
|
|
150
|
+
const settingsItemId = payload.itemId;
|
|
151
|
+
setServices((prev) => prev.map((s) => s.serviceName === serviceName
|
|
152
|
+
? {
|
|
153
|
+
...s,
|
|
154
|
+
isConfigured: true,
|
|
155
|
+
creating: false,
|
|
156
|
+
settingsItemId,
|
|
157
|
+
}
|
|
158
|
+
: s));
|
|
159
|
+
// Reload data to ensure consistency
|
|
160
|
+
setTimeout(() => loadData(), 500);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
throw new Error(result.data.error ||
|
|
164
|
+
result.details ||
|
|
165
|
+
"Failed to create settings");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error(result.details || "Failed to create settings");
|
|
170
|
+
}
|
|
155
171
|
}
|
|
156
|
-
|
|
157
|
-
|
|
172
|
+
catch (e) {
|
|
173
|
+
const errorMessage = e?.message || "Unknown error";
|
|
174
|
+
// Provide more helpful error messages for common issues
|
|
175
|
+
let displayMessage = errorMessage;
|
|
176
|
+
if (errorMessage.includes("Translation Providers folder not found") ||
|
|
177
|
+
errorMessage.includes("Translation folder not found")) {
|
|
178
|
+
displayMessage =
|
|
179
|
+
"The required folder structure is missing. Configure and create the parent items in the Settings section above.";
|
|
180
|
+
}
|
|
181
|
+
else if (errorMessage.includes("already exists")) {
|
|
182
|
+
displayMessage = `Settings for ${serviceName} already exist. Please refresh the list.`;
|
|
183
|
+
// Reload data to show updated status
|
|
184
|
+
setTimeout(() => loadData(), 500);
|
|
185
|
+
}
|
|
186
|
+
setError(`Failed to create settings for ${serviceName}: ${displayMessage}`);
|
|
187
|
+
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: false } : s));
|
|
158
188
|
}
|
|
159
|
-
};
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
189
|
+
}, [editContext, loadData, structureSettings]);
|
|
190
|
+
const deleteSettings = useCallback(async (service) => {
|
|
191
|
+
if (!editContext || !service.settingsItemId)
|
|
192
|
+
return;
|
|
163
193
|
try {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
194
|
+
setServices((prev) => prev.map((s) => s.serviceName === service.serviceName
|
|
195
|
+
? { ...s, deleting: true }
|
|
196
|
+
: s));
|
|
197
|
+
setError(null);
|
|
198
|
+
const language = editContext.item?.language ??
|
|
199
|
+
editContext.currentItemDescriptor?.language ??
|
|
200
|
+
"en";
|
|
201
|
+
const deleted = await editContext.operations.deleteItems([
|
|
202
|
+
{
|
|
203
|
+
id: service.settingsItemId,
|
|
204
|
+
language,
|
|
205
|
+
version: 0,
|
|
206
|
+
},
|
|
207
|
+
]);
|
|
208
|
+
if (deleted) {
|
|
209
|
+
if (selectedConfigTarget?.key === `service:${service.serviceName}` ||
|
|
210
|
+
selectedConfigTarget?.itemId === service.settingsItemId) {
|
|
211
|
+
setSelectedConfigTarget(null);
|
|
170
212
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
213
|
+
setServices((prev) => prev.map((s) => s.serviceName === service.serviceName
|
|
214
|
+
? {
|
|
215
|
+
...s,
|
|
216
|
+
isConfigured: false,
|
|
217
|
+
settingsItemId: undefined,
|
|
218
|
+
deleting: false,
|
|
219
|
+
}
|
|
220
|
+
: s));
|
|
221
|
+
await loadData();
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
setServices((prev) => prev.map((s) => s.serviceName === service.serviceName
|
|
225
|
+
? { ...s, deleting: false }
|
|
226
|
+
: s));
|
|
227
|
+
}
|
|
176
228
|
}
|
|
177
|
-
|
|
178
|
-
|
|
229
|
+
catch (e) {
|
|
230
|
+
setError(e?.message ||
|
|
231
|
+
`Failed to delete settings for ${service.displayName || service.serviceName}`);
|
|
232
|
+
setServices((prev) => prev.map((s) => s.serviceName === service.serviceName
|
|
233
|
+
? { ...s, deleting: false }
|
|
234
|
+
: s));
|
|
179
235
|
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
236
|
+
}, [editContext, loadData, selectedConfigTarget]);
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
loadData();
|
|
239
|
+
}, [loadData]);
|
|
240
|
+
const configuredCount = services.filter((s) => s.isConfigured).length;
|
|
241
|
+
const totalCount = services.length;
|
|
242
|
+
const translationFolderExists = !!structureState?.translationFolder?.exists;
|
|
243
|
+
const providersFolderExists = !!structureState?.translationProvidersFolder?.exists;
|
|
244
|
+
// Build the services list content
|
|
245
|
+
const servicesListContent = (_jsxs("div", { className: "flex h-full flex-col gap-4 p-4", "data-testid": "translation-services-panel", children: [_jsx(Card, { icon: _jsx(ListChecksIcon, { strokeWidth: 1, className: "h-5 w-5" }), title: "Prerequisites", description: "Required Sitecore folders for translation settings.", noPadding: true, className: "shrink-0", headerActions: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex items-center gap-1.5 text-xs text-neutral-grey-50", children: translationFolderExists && providersFolderExists ? (_jsxs(_Fragment, { children: [_jsx(CheckCircleIcon, { className: "h-3.5 w-3.5 text-feedback-green", strokeWidth: 1 }), "All parent items found"] })) : (_jsxs(_Fragment, { children: [_jsx(AlertCircleIcon, { className: "h-3.5 w-3.5 text-feedback-orange", strokeWidth: 1 }), "Parent items missing"] })) }), !providersFolderExists && (_jsxs(Button, { size: "sm", variant: "default", onClick: ensureStructure, disabled: ensuringStructure || structureLoading, children: [ensuringStructure ? (_jsx(RefreshCwIcon, { strokeWidth: 1, className: "mr-1 h-4 w-4 animate-spin" })) : (_jsx(PlusIcon, { strokeWidth: 1, className: "mr-1 h-4 w-4" })), "Ensure items"] }))] }), children: _jsxs("div", { className: "divide-y divide-border-default border-t border-border-default", children: [_jsxs("div", { "data-testid": "translation-structure-folder", className: `flex items-center gap-3 px-3 py-3 text-sm transition-colors ${selectedConfigTarget?.key ===
|
|
246
|
+
`structure:${structureState?.translationFolder?.itemId}`
|
|
247
|
+
? "bg-feedback-blue-light"
|
|
248
|
+
: "bg-white"}`, children: [translationFolderExists ? (_jsx(CheckCircleIcon, { className: "h-4 w-4 shrink-0 text-feedback-green", strokeWidth: 1 })) : (_jsx(AlertCircleIcon, { className: "h-4 w-4 shrink-0 text-feedback-orange", strokeWidth: 1 })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "font-medium text-neutral-grey-100", children: "Translation folder" }), _jsx("div", { className: "mt-0.5 truncate font-mono text-xs text-neutral-grey-50", children: structureSettings.translationFolderPath })] }), translationFolderExists &&
|
|
249
|
+
structureState?.translationFolder?.itemId && (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => handleOpenStructureConfig(structureState.translationFolder.itemId, "Configure: Translation folder"), title: "Configure", children: _jsx(SettingsIcon, { className: "h-3.5 w-3.5", strokeWidth: 1 }) }))] }), _jsxs("div", { "data-testid": "translation-structure-providers-folder", className: `flex items-center gap-3 px-3 py-3 text-sm transition-colors ${selectedConfigTarget?.key ===
|
|
250
|
+
`structure:${structureState?.translationProvidersFolder?.itemId}`
|
|
251
|
+
? "bg-feedback-blue-light"
|
|
252
|
+
: "bg-white"}`, children: [providersFolderExists ? (_jsx(CheckCircleIcon, { className: "h-4 w-4 shrink-0 text-feedback-green", strokeWidth: 1 })) : (_jsx(AlertCircleIcon, { className: "h-4 w-4 shrink-0 text-feedback-orange", strokeWidth: 1 })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: "font-medium text-neutral-grey-100", children: "Translation providers folder" }), _jsx("div", { className: "mt-0.5 truncate font-mono text-xs text-neutral-grey-50", children: structureSettings.translationProvidersPath })] }), providersFolderExists &&
|
|
253
|
+
structureState?.translationProvidersFolder?.itemId && (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => handleOpenStructureConfig(structureState.translationProvidersFolder.itemId, "Configure: Translation Providers folder"), title: "Configure", children: _jsx(SettingsIcon, { className: "h-3.5 w-3.5", strokeWidth: 1 }) }))] })] }) }), _jsxs(Card, { icon: _jsx(LanguagesIcon, { strokeWidth: 1, className: "h-5 w-5" }), title: _jsxs(_Fragment, { children: ["Translation providers", " ", _jsxs("span", { className: "font-normal text-neutral-grey-50", children: ["(", configuredCount, " of ", totalCount, " configured)"] })] }), description: "Translation services registered in Parhelia and their settings.", noPadding: true, className: "flex min-h-0 flex-1 flex-col overflow-hidden", children: [((totalCount === 0 && state === "success") || error) && (_jsxs("div", { className: "border-border-default space-y-2 border-t px-4 py-3", children: [totalCount === 0 && state === "success" && (_jsx("div", { className: "rounded border border-feedback-orange/30 bg-feedback-orange-light p-2 text-xs text-feedback-orange", children: "No translation services are registered in dependency injection. Please check the server configuration." })), error && (_jsx("div", { className: "rounded border border-feedback-red bg-feedback-red-light p-2 text-xs whitespace-pre-wrap text-feedback-red", children: error }))] })), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto border-t border-border-default", "data-testid": "translation-services-providers", children: services.length > 0 && (_jsx("div", { className: "divide-y divide-border-default", children: services.map((service) => {
|
|
254
|
+
const isSelected = selectedConfigTarget?.key ===
|
|
255
|
+
`service:${service.serviceName}`;
|
|
256
|
+
const isConfigured = service.isConfigured;
|
|
257
|
+
return (_jsxs("div", { className: `group flex items-center gap-3 px-3 py-3 text-sm transition-colors ${isSelected
|
|
258
|
+
? "bg-feedback-blue-light"
|
|
259
|
+
: "bg-white hover:bg-neutral-grey-5"}`, children: [isConfigured ? (_jsx(CheckCircleIcon, { className: "h-4 w-4 shrink-0 text-feedback-green", strokeWidth: 1 })) : (_jsx(AlertCircleIcon, { className: "h-4 w-4 shrink-0 text-feedback-orange", strokeWidth: 1 })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [_jsx("span", { className: "truncate font-medium text-neutral-grey-100", children: service.displayName || service.serviceName }), service.displayName &&
|
|
260
|
+
service.displayName !== service.serviceName && (_jsx("span", { className: "shrink-0 rounded bg-neutral-grey-5 badge-pad-sm text-[10px] font-medium text-neutral-grey-50", children: service.serviceName })), !isConfigured && (_jsx("span", { className: "shrink-0 rounded bg-feedback-orange-light badge-pad-sm text-[10px] font-medium text-feedback-orange", children: "Not configured" }))] }), isConfigured &&
|
|
261
|
+
service.supportedLanguages &&
|
|
262
|
+
service.supportedLanguages.length > 0 && (_jsxs("div", { className: "mt-0.5 truncate text-xs text-neutral-grey-50", children: ["Languages: ", service.supportedLanguages.join(", ")] }))] }), _jsx("div", { className: "flex shrink-0 items-center gap-0.5", children: isConfigured && service.settingsItemId ? (_jsxs("div", { className: "flex items-center gap-0.5 opacity-60 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100", children: [_jsx(Button, { size: "sm", variant: "ghost", onClick: () => handleOpenConfig(service), disabled: service.deleting, title: "Configure", children: _jsx(SettingsIcon, { className: "h-3.5 w-3.5", strokeWidth: 1 }) }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => deleteSettings(service), className: "text-neutral-grey-50 hover:bg-neutral-grey-5 hover:text-neutral-grey-50", disabled: service.deleting, title: `Delete settings for ${service.displayName || service.serviceName}`, children: service.deleting ? (_jsx(RefreshCwIcon, { strokeWidth: 1, className: "h-3.5 w-3.5 animate-spin" })) : (_jsx(DeleteIcon, { size: "md" })) })] })) : (_jsxs(Button, { size: "sm", variant: "default", onClick: () => createSettings(service.serviceName, service.templateId), disabled: service.creating, title: `Create settings using template: ${service.templateName}`, children: [service.creating ? (_jsx(RefreshCwIcon, { strokeWidth: 1, className: "mr-1 h-3.5 w-3.5 animate-spin" })) : (_jsx(PlusIcon, { strokeWidth: 1, className: "mr-1 h-3.5 w-3.5" })), "Create"] })) })] }, service.serviceName));
|
|
263
|
+
}) })) })] })] }));
|
|
264
|
+
// Build splitter panels - only show config panel when a service is selected
|
|
265
|
+
const panels = selectedConfigTarget?.itemId
|
|
266
|
+
? [
|
|
267
|
+
{
|
|
268
|
+
name: "services-list",
|
|
269
|
+
defaultSize: "auto",
|
|
270
|
+
content: servicesListContent,
|
|
271
|
+
className: "overflow-hidden",
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "service-config",
|
|
275
|
+
defaultSize: 400,
|
|
276
|
+
content: (_jsx(ItemConfigPanel, { itemId: selectedConfigTarget.itemId, title: selectedConfigTarget.title, onClose: handleCloseConfig }, selectedConfigTarget.itemId)),
|
|
277
|
+
className: "overflow-hidden",
|
|
278
|
+
},
|
|
279
|
+
]
|
|
280
|
+
: [
|
|
281
|
+
{
|
|
282
|
+
name: "services-list",
|
|
283
|
+
defaultSize: "auto",
|
|
284
|
+
content: servicesListContent,
|
|
285
|
+
className: "overflow-hidden",
|
|
286
|
+
},
|
|
287
|
+
];
|
|
288
|
+
const SplitterComponent = Splitter;
|
|
289
|
+
return (_jsx(SplitterComponent, { panels: panels, localStorageKey: "translation-services-panel-splitter", direction: editContext?.isMobile ? "vertical" : "horizontal", className: "h-full w-full" }));
|
|
213
290
|
}
|
|
214
291
|
export default TranslationServicesPanel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationSetupStep.d.ts","sourceRoot":"","sources":["../../src/setup/LocalizationSetupStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAgCzE,wBAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"LocalizationSetupStep.d.ts","sourceRoot":"","sources":["../../src/setup/LocalizationSetupStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAgCzE,wBAAgB,qBAAqB,sBA6QpC;eAEc,qBAAqB"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { useCallback, useState } from "react";
|
|
3
|
-
import { Card, Button } from "@parhelia/core";
|
|
3
|
+
import { Card, Button, useEditContext } from "@parhelia/core";
|
|
4
4
|
import { CheckCircle as LucideCheckCircle, AlertCircle as LucideAlertCircle, Languages as LucideLanguages, RefreshCw as LucideRefreshCw, Plus as LucidePlus, } from "lucide-react";
|
|
5
|
-
import { getAvailableTranslationServices, } from "../services/translationService";
|
|
6
|
-
import { translationSettingsService } from "../services/translationSettingsService";
|
|
5
|
+
import { getAvailableTranslationServices, createProviderSettings, } from "../services/translationService";
|
|
7
6
|
const CheckCircleIcon = LucideCheckCircle;
|
|
8
7
|
const AlertCircleIcon = LucideAlertCircle;
|
|
9
8
|
const LanguagesIcon = LucideLanguages;
|
|
10
9
|
const RefreshCwIcon = LucideRefreshCw;
|
|
11
10
|
const PlusIcon = LucidePlus;
|
|
12
11
|
export function LocalizationSetupStep() {
|
|
12
|
+
const editContext = useEditContext();
|
|
13
13
|
const [state, setState] = useState("checking");
|
|
14
14
|
const [error, setError] = useState(null);
|
|
15
15
|
const [services, setServices] = useState([]);
|
|
@@ -49,7 +49,7 @@ export function LocalizationSetupStep() {
|
|
|
49
49
|
const totalCount = serviceStates.length;
|
|
50
50
|
if (configuredCount === 0) {
|
|
51
51
|
setState("error");
|
|
52
|
-
setError(`Found ${totalCount} translation service${totalCount !== 1 ? "s" : ""} in DI, but none have
|
|
52
|
+
setError(`Found ${totalCount} translation service${totalCount !== 1 ? "s" : ""} in DI, but none have Sitecore Settings items configured.`);
|
|
53
53
|
}
|
|
54
54
|
else if (configuredCount < totalCount) {
|
|
55
55
|
setState("partial");
|
|
@@ -71,28 +71,47 @@ export function LocalizationSetupStep() {
|
|
|
71
71
|
setError(e?.message || "Failed to check localization setup");
|
|
72
72
|
}
|
|
73
73
|
}, []);
|
|
74
|
-
const createSettings = useCallback(async (serviceName) => {
|
|
74
|
+
const createSettings = useCallback(async (serviceName, templateId) => {
|
|
75
75
|
try {
|
|
76
76
|
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: true } : s));
|
|
77
77
|
setError(null);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
const language = editContext?.item?.language ??
|
|
79
|
+
editContext?.currentItemDescriptor?.language ??
|
|
80
|
+
"en";
|
|
81
|
+
const result = await createProviderSettings(serviceName, templateId, language);
|
|
82
|
+
if (result.type === "success" && result.data) {
|
|
83
|
+
if (result.data.success && result.data.data) {
|
|
84
|
+
setServices((prev) => prev.map((s) => s.serviceName === serviceName
|
|
85
|
+
? {
|
|
86
|
+
...s,
|
|
87
|
+
isConfigured: true,
|
|
88
|
+
creating: false,
|
|
89
|
+
settingsItemId: result.data?.data?.itemId,
|
|
90
|
+
}
|
|
91
|
+
: s));
|
|
92
|
+
setTimeout(() => checkLocalization(), 500);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error(result.data.error ||
|
|
96
|
+
result.details ||
|
|
97
|
+
"Failed to create settings");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw new Error(result.details || "Failed to create settings");
|
|
102
|
+
}
|
|
84
103
|
}
|
|
85
104
|
catch (e) {
|
|
86
105
|
setError(`Failed to create settings for ${serviceName}: ${e?.message || "Unknown error"}`);
|
|
87
106
|
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: false } : s));
|
|
88
107
|
}
|
|
89
|
-
}, [checkLocalization]);
|
|
108
|
+
}, [editContext, checkLocalization]);
|
|
90
109
|
React.useEffect(() => {
|
|
91
110
|
checkLocalization();
|
|
92
111
|
}, [checkLocalization]);
|
|
93
112
|
const configuredCount = services.filter((s) => s.isConfigured).length;
|
|
94
113
|
const totalCount = services.length;
|
|
95
|
-
return (_jsx(Card, { icon: _jsx(LanguagesIcon, { strokeWidth: 1, className: "h-5 w-5" }), title: "Localization setup", description: "Verifies that translation services registered in DI have corresponding
|
|
114
|
+
return (_jsx(Card, { icon: _jsx(LanguagesIcon, { strokeWidth: 1, className: "h-5 w-5" }), title: "Localization setup", description: "Verifies that translation services registered in DI have corresponding Sitecore Settings items.", children: _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [statusIcon(state), _jsx("span", { className: "text-sm text-neutral-grey-100", children: state === "success"
|
|
96
115
|
? `All ${totalCount} translation service${totalCount !== 1 ? "s" : ""} configured`
|
|
97
116
|
: state === "partial"
|
|
98
117
|
? `${configuredCount} of ${totalCount} services configured`
|
|
@@ -103,6 +122,6 @@ export function LocalizationSetupStep() {
|
|
|
103
122
|
: "Checking..." })] }), _jsxs(Button, { size: "sm", variant: "outline", onClick: checkLocalization, children: [_jsx(RefreshCwIcon, { strokeWidth: 1, className: "h-4 w-4" }), "Recheck"] })] }), services.length > 0 && (_jsxs("div", { className: "space-y-2 rounded-lg border border-border-default bg-neutral-grey-5 p-3", children: [_jsx("div", { className: "text-xs font-medium text-neutral-grey-50 tracking-wide", children: "Translation Services" }), services.map((service) => (_jsxs("div", { className: "flex items-center justify-between rounded-md bg-background p-3 shadow-sm border border-border-default", children: [_jsxs("div", { className: "flex items-center gap-2", children: [service.isConfigured ? (_jsx(CheckCircleIcon, { className: "h-3.5 w-3.5 text-[var(--color-feedback-green)]", strokeWidth: 1 })) : (_jsx(AlertCircleIcon, { className: "h-3.5 w-3.5 text-[var(--color-feedback-orange)]", strokeWidth: 1 })), _jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium text-neutral-grey-100", children: service.displayName || service.serviceName }), service.displayName &&
|
|
104
123
|
service.displayName !== service.serviceName && (_jsxs("div", { className: "text-xs text-neutral-grey-50", children: ["Service: ", service.serviceName] })), service.isConfigured &&
|
|
105
124
|
service.supportedLanguages &&
|
|
106
|
-
service.supportedLanguages.length > 0 && (_jsxs("div", { className: "text-xs text-neutral-grey-50", children: ["Languages: ", service.supportedLanguages.join(", ")] }))] })] }), !service.isConfigured && (_jsxs(Button, { size: "xs", onClick: () => createSettings(service.serviceName), disabled: service.creating, title: `Create
|
|
125
|
+
service.supportedLanguages.length > 0 && (_jsxs("div", { className: "text-xs text-neutral-grey-50", children: ["Languages: ", service.supportedLanguages.join(", ")] }))] })] }), !service.isConfigured && (_jsxs(Button, { size: "xs", onClick: () => createSettings(service.serviceName, service.templateId), disabled: service.creating, title: `Create using template: ${service.templateName}`, children: [service.creating ? (_jsx(RefreshCwIcon, { strokeWidth: 1, className: "h-3 w-3 animate-spin" })) : (_jsx(PlusIcon, { strokeWidth: 1, className: "h-3 w-3" })), "Create Settings"] }))] }, service.serviceName)))] })), error && (_jsx("div", { className: "rounded-md border border-feedback-orange/30 bg-feedback-orange-light p-3 text-xs whitespace-pre-wrap text-feedback-orange", children: error }))] }) }));
|
|
107
126
|
}
|
|
108
127
|
export default LocalizationSetupStep;
|