@asteby/metacore-runtime-react 53.5.0 → 53.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/setup/addon-config-surface.d.ts +16 -1
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +319 -92
- package/dist/setup/connector-blocks-model.d.ts +79 -0
- package/dist/setup/connector-blocks-model.d.ts.map +1 -0
- package/dist/setup/connector-blocks-model.js +96 -0
- package/dist/setup/connector-blocks.d.ts +48 -0
- package/dist/setup/connector-blocks.d.ts.map +1 -0
- package/dist/setup/connector-blocks.js +132 -0
- package/dist/setup/index.d.ts +2 -0
- package/dist/setup/index.d.ts.map +1 -1
- package/dist/setup/index.js +2 -0
- package/dist/setup/messages.d.ts.map +1 -1
- package/dist/setup/messages.js +81 -0
- package/package.json +5 -5
- package/src/__tests__/addon-config-surface.test.tsx +73 -6
- package/src/__tests__/connector-blocks.test.tsx +302 -0
- package/src/index.ts +4 -0
- package/src/setup/addon-config-surface.tsx +557 -209
- package/src/setup/connector-blocks-model.ts +163 -0
- package/src/setup/connector-blocks.tsx +341 -0
- package/src/setup/index.ts +12 -0
- package/src/setup/messages.ts +81 -0
|
@@ -17,16 +17,22 @@ import { createContext, useContext, useEffect, useId, useRef, useState } from 'r
|
|
|
17
17
|
import { useMutation } from '@tanstack/react-query';
|
|
18
18
|
import { useTranslation } from 'react-i18next';
|
|
19
19
|
import { toast } from 'sonner';
|
|
20
|
-
import { Cable, Check,
|
|
20
|
+
import { AlertCircle, Cable, Check, Eye, EyeOff, Link2, Loader2, Pencil, RefreshCw, Settings, X } from 'lucide-react';
|
|
21
21
|
import { Badge, Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, } from '@asteby/metacore-ui/primitives';
|
|
22
22
|
import { cn } from '@asteby/metacore-ui/lib';
|
|
23
23
|
import { useApi } from '../api-context';
|
|
24
24
|
import { evaluateVisibleWhen, getVisibleWhen } from '../dynamic-form-schema';
|
|
25
25
|
import { useSetupT } from './messages';
|
|
26
|
+
import { StepStatusBadge } from './step-status-badge';
|
|
27
|
+
import { ConnectorBlocks, HelpText } from './connector-blocks';
|
|
28
|
+
import { buildWizardSteps, errorMessage, hasExplicitTest, normalizeBlockResult, stepStatus, } from './connector-blocks-model';
|
|
26
29
|
import { isSecretCredential, missingRequired, parseSaveError, shapeMismatch, textOrFallback, } from './connector-form-model';
|
|
27
30
|
// Empty write_only value (typed then erased) must not overwrite the stored secret.
|
|
28
31
|
const isBlank = (v) => v == null || (typeof v === 'string' && v.trim() === '');
|
|
29
32
|
const NO_OPTION_KINDS = {};
|
|
33
|
+
/** Key of the implicit "Probar conexión" block (connector.test_export). */
|
|
34
|
+
const TEST_BLOCK_KEY = '__test_connection';
|
|
35
|
+
const SYNC_BLOCK_KEY = '__sync';
|
|
30
36
|
// ─── Connector credential field (reusable render) ───────────────────────────
|
|
31
37
|
// One connector credential field: label (i18n) + control (select|password|text)
|
|
32
38
|
// + optional help. Shared by the unified config dialog for both the essential
|
|
@@ -44,7 +50,7 @@ const ConnectorFormStateContext = createContext({
|
|
|
44
50
|
idPrefix: 'addon-config',
|
|
45
51
|
expectedOptionKinds: {},
|
|
46
52
|
});
|
|
47
|
-
function ConnectorCredentialFieldControl({ field, value, connected, provider, onChange, }) {
|
|
53
|
+
function ConnectorCredentialFieldControl({ field, value, connected, provider, onChange, stored = false, onReveal, resetKey, }) {
|
|
48
54
|
const { t } = useTranslation();
|
|
49
55
|
const st = useSetupT();
|
|
50
56
|
const form = useContext(ConnectorFormStateContext);
|
|
@@ -58,6 +64,58 @@ function ConnectorCredentialFieldControl({ field, value, connected, provider, on
|
|
|
58
64
|
: '';
|
|
59
65
|
const isSecret = isSecretCredential(field);
|
|
60
66
|
const isDynamic = field.type === 'dynamic_select' || !!field.options_source;
|
|
67
|
+
// A stored field opens LOCKED (pencil to edit, eye to view) so a value is
|
|
68
|
+
// never changed by accident; a fresh field is editable straight away.
|
|
69
|
+
const [editing, setEditing] = useState(false);
|
|
70
|
+
const [visible, setVisible] = useState(false);
|
|
71
|
+
const [revealed, setRevealed] = useState(null);
|
|
72
|
+
const [revealing, setRevealing] = useState(false);
|
|
73
|
+
const [armed, setArmed] = useState(false);
|
|
74
|
+
const initial = useRef('');
|
|
75
|
+
const locked = stored && !editing;
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
setEditing(false);
|
|
78
|
+
setVisible(false);
|
|
79
|
+
setRevealed(null);
|
|
80
|
+
}, [resetKey]);
|
|
81
|
+
const canEye = isSecret ? (locked ? !!onReveal : true) : false;
|
|
82
|
+
const toggleEye = async () => {
|
|
83
|
+
if (visible) {
|
|
84
|
+
setVisible(false);
|
|
85
|
+
setRevealed(null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (locked && onReveal) {
|
|
89
|
+
setRevealing(true);
|
|
90
|
+
try {
|
|
91
|
+
setRevealed(await onReveal(field.key));
|
|
92
|
+
setVisible(true);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
setRevealed(null);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
setRevealing(false);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
setVisible(true);
|
|
103
|
+
};
|
|
104
|
+
const startEdit = () => {
|
|
105
|
+
initial.current = value;
|
|
106
|
+
if (isSecret)
|
|
107
|
+
onChange('');
|
|
108
|
+
setVisible(false);
|
|
109
|
+
setRevealed(null);
|
|
110
|
+
setArmed(true);
|
|
111
|
+
setEditing(true);
|
|
112
|
+
requestAnimationFrame(() => document.getElementById(`${form.idPrefix}-cred-${field.key}`)?.focus());
|
|
113
|
+
};
|
|
114
|
+
const cancelEdit = () => {
|
|
115
|
+
onChange(initial.current);
|
|
116
|
+
setVisible(false);
|
|
117
|
+
setEditing(false);
|
|
118
|
+
};
|
|
61
119
|
const error = form.errors[field.key];
|
|
62
120
|
const mismatch = shapeMismatch(field, value, form.fields);
|
|
63
121
|
const target = mismatch?.suggestedKey
|
|
@@ -68,10 +126,11 @@ function ConnectorCredentialFieldControl({ field, value, connected, provider, on
|
|
|
68
126
|
? 'installed_addons.shape_public_key'
|
|
69
127
|
: 'installed_addons.shape_secret_key', { target: target ? labelOf(target) : '' })
|
|
70
128
|
: '';
|
|
71
|
-
return (_jsxs("div", { className: 'flex flex-col gap-1', "data-field": field.key, children: [_jsxs(Label, { htmlFor: `${form.idPrefix}-cred-${field.key}`, children: [label, field.required ? _jsx("span", { className: 'text-destructive', children: " *" }) : null] }), isDynamic ? (_jsx(DynamicConnectorSelect, { field: field, value: value, provider: provider, connected: connected, onChange: onChange })) : field.type === 'select' && field.options?.length ? (_jsxs(Select, { value: value, onValueChange: onChange, children: [_jsx(SelectTrigger, { id: `${form.idPrefix}-cred-${field.key}`, "aria-invalid": !!error || undefined, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: field.options.map((o) => (_jsx(SelectItem, { value: o.value, children: t(o.label, { defaultValue: o.value }) }, o.value))) })] })) : (_jsx(Input, { id: `${form.idPrefix}-cred-${field.key}`, type: isSecret ? 'password' : 'text',
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
129
|
+
return (_jsxs("div", { className: 'flex flex-col gap-1', "data-field": field.key, children: [_jsxs(Label, { htmlFor: `${form.idPrefix}-cred-${field.key}`, children: [label, field.required ? _jsx("span", { className: 'text-destructive', children: " *" }) : null] }), isDynamic ? (_jsx(DynamicConnectorSelect, { field: field, value: value, provider: provider, connected: connected, onChange: onChange })) : field.type === 'select' && field.options?.length ? (_jsxs(Select, { value: value, onValueChange: onChange, children: [_jsx(SelectTrigger, { id: `${form.idPrefix}-cred-${field.key}`, "aria-invalid": !!error || undefined, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: field.options.map((o) => (_jsx(SelectItem, { value: o.value, children: t(o.label, { defaultValue: o.value }) }, o.value))) })] })) : (_jsxs("div", { className: 'flex items-center gap-1.5', children: [_jsx(Input, { id: `${form.idPrefix}-cred-${field.key}`, name: `cfg_${field.key}`, type: isSecret && !visible ? 'password' : 'text',
|
|
130
|
+
// Browsers ignore autocomplete=off and fill the text field that
|
|
131
|
+
// precedes a password input; a field stays read-only until the user
|
|
132
|
+
// focuses it (and while locked) so nothing is filled behind their back.
|
|
133
|
+
autoComplete: isSecret ? 'new-password' : 'off', "data-1p-ignore": true, "data-lpignore": 'true', "data-form-type": 'other', readOnly: locked || !armed, onFocus: () => setArmed(true), spellCheck: false, autoCapitalize: 'off', "aria-invalid": !!error || undefined, "aria-describedby": error ? `${form.idPrefix}-cred-${field.key}-error` : undefined, className: cn(error && 'border-destructive focus-visible:ring-destructive/40', locked && 'bg-muted/40 text-muted-foreground'), placeholder: (connected || stored) && isSecret ? '••••••••' : '', value: locked && isSecret ? (revealed ?? '') : value, onChange: (e) => onChange(e.target.value) }), canEye && (_jsx(Button, { type: 'button', variant: 'ghost', size: 'icon', className: 'size-9 shrink-0', disabled: revealing, "aria-label": visible ? st('installed_addons.field_hide', { defaultValue: 'Ocultar' }) : st('installed_addons.field_view', { defaultValue: 'Ver' }), onClick: () => void toggleEye(), children: revealing ? _jsx(Loader2, { className: 'size-4 animate-spin' }) : visible ? _jsx(EyeOff, { className: 'size-4' }) : _jsx(Eye, { className: 'size-4' }) })), locked ? (_jsx(Button, { type: 'button', variant: 'ghost', size: 'icon', className: 'size-9 shrink-0', "aria-label": st('installed_addons.field_edit', { defaultValue: 'Editar' }), onClick: startEdit, children: _jsx(Pencil, { className: 'size-4' }) })) : stored ? (_jsx(Button, { type: 'button', variant: 'ghost', size: 'icon', className: 'size-9 shrink-0', "aria-label": st('installed_addons.field_cancel_edit', { defaultValue: 'Cancelar edición' }), onClick: cancelEdit, children: _jsx(X, { className: 'size-4' }) })) : null] })), error ? (_jsx("p", { id: `${form.idPrefix}-cred-${field.key}-error`, role: 'alert', className: 'text-xs text-destructive', children: error })) : null, warning ? (_jsx("p", { className: 'text-xs text-amber-600 dark:text-amber-400', role: 'status', children: warning })) : null, help ? _jsx(HelpText, { text: help }) : null] }));
|
|
75
134
|
}
|
|
76
135
|
// useApi() hands every component its own wrapper object, so the cache cannot be
|
|
77
136
|
// keyed by client: it is module-level, keyed by provider + export, and dropped
|
|
@@ -157,7 +216,7 @@ function DynamicConnectorSelect({ field, value, provider, connected, onChange, }
|
|
|
157
216
|
// Fixed header + footer, scrollable body — a connector can declare many fields
|
|
158
217
|
// (env, keys, RFC, régimen, CP, base_url, stamp/cancel path) that would
|
|
159
218
|
// otherwise overflow the viewport.
|
|
160
|
-
export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSaved, canManageIssuer = true, activeBranch = null, ensureAddonBundle, notify = toast, client, expectedOptionKinds = NO_OPTION_KINDS, displayName, }) {
|
|
219
|
+
export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSaved, canManageIssuer = true, canRevealSecrets = false, activeBranch = null, ensureAddonBundle, notify = toast, client, expectedOptionKinds = NO_OPTION_KINDS, displayName, onConnectOAuth, }) {
|
|
161
220
|
const idPrefix = useId();
|
|
162
221
|
const { t, i18n } = useTranslation();
|
|
163
222
|
const st = useSetupT();
|
|
@@ -188,8 +247,23 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
188
247
|
const [formError, setFormError] = useState(null);
|
|
189
248
|
const [fieldErrors, setFieldErrors] = useState({});
|
|
190
249
|
const errorRef = useRef(null);
|
|
250
|
+
// Results of the step actions (by block key) and whether the operator typed
|
|
251
|
+
// credentials not saved yet (an action tests what is STORED: it saves first).
|
|
252
|
+
const [blockResults, setBlockResults] = useState({});
|
|
253
|
+
const [credDirty, setCredDirty] = useState(false);
|
|
254
|
+
// Credential keys the backend already holds (non-secret values + secrets_set).
|
|
255
|
+
const [storedKeys, setStoredKeys] = useState(new Set());
|
|
256
|
+
// Credentials that differ between sandbox and production (served by /values) and
|
|
257
|
+
// the environment the stored values were loaded for: flipping the selector swaps them.
|
|
258
|
+
const envScoped = useRef(new Set());
|
|
259
|
+
const loadedEnv = useRef(null);
|
|
260
|
+
const envField = credFields.find((f) => f.type === 'select' && ['environment', 'mode', 'env'].includes(f.key));
|
|
261
|
+
const envValue = envField ? (credValues[envField.key] ?? '') : '';
|
|
262
|
+
const stepHeadingRef = useRef(null);
|
|
263
|
+
const stepMoved = useRef(false);
|
|
191
264
|
const setCred = (key, val) => {
|
|
192
265
|
setCredValues((v) => ({ ...v, [key]: val }));
|
|
266
|
+
setCredDirty(true);
|
|
193
267
|
if (fieldErrors[key]) {
|
|
194
268
|
setFieldErrors((e) => {
|
|
195
269
|
const { [key]: _drop, ...rest } = e;
|
|
@@ -240,8 +314,14 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
240
314
|
}
|
|
241
315
|
setCredValues(seed);
|
|
242
316
|
setCurrentStep(0);
|
|
317
|
+
stepMoved.current = false;
|
|
243
318
|
setFormError(null);
|
|
244
319
|
setFieldErrors({});
|
|
320
|
+
setBlockResults({});
|
|
321
|
+
setCredDirty(false);
|
|
322
|
+
setStoredKeys(new Set());
|
|
323
|
+
envScoped.current = new Set();
|
|
324
|
+
loadedEnv.current = null;
|
|
245
325
|
if (!canManageIssuer || !connector?.provider || credFields.length === 0)
|
|
246
326
|
return;
|
|
247
327
|
let cancelled = false;
|
|
@@ -251,6 +331,11 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
251
331
|
const stored = (res.data?.data?.values ?? {});
|
|
252
332
|
if (cancelled)
|
|
253
333
|
return;
|
|
334
|
+
const secretsSet = (res.data?.data?.secrets_set ?? []);
|
|
335
|
+
envScoped.current = new Set((res.data?.data?.env_scoped ?? []));
|
|
336
|
+
if (envField)
|
|
337
|
+
loadedEnv.current = stored[envField.key] ?? '';
|
|
338
|
+
setStoredKeys(new Set([...Object.keys(stored).filter((k) => stored[k] !== ''), ...secretsSet]));
|
|
254
339
|
// Only fields the user has not touched yet.
|
|
255
340
|
setCredValues((prev) => {
|
|
256
341
|
const next = { ...prev };
|
|
@@ -273,6 +358,40 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
273
358
|
};
|
|
274
359
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
275
360
|
}, [open, connector?.provider, canManageIssuer]);
|
|
361
|
+
// Sandbox and production keep their own credentials: flipping the selector
|
|
362
|
+
// swaps the environment-scoped fields for the ones stored for that environment
|
|
363
|
+
// (locked when it has them, empty when it does not) instead of making the
|
|
364
|
+
// operator paste every key again. Nothing is saved until «Guardar».
|
|
365
|
+
useEffect(() => {
|
|
366
|
+
if (!open || !envField || !envValue || !canManageIssuer || !connector?.provider)
|
|
367
|
+
return;
|
|
368
|
+
if (loadedEnv.current === null || loadedEnv.current === envValue)
|
|
369
|
+
return;
|
|
370
|
+
let cancelled = false;
|
|
371
|
+
api
|
|
372
|
+
.get(`/integrations/${connector.provider}/values?environment=${encodeURIComponent(envValue)}`)
|
|
373
|
+
.then((res) => {
|
|
374
|
+
if (cancelled)
|
|
375
|
+
return;
|
|
376
|
+
const stored = (res.data?.data?.values ?? {});
|
|
377
|
+
const secretsSet = (res.data?.data?.secrets_set ?? []);
|
|
378
|
+
loadedEnv.current = envValue;
|
|
379
|
+
setStoredKeys(new Set([...Object.keys(stored).filter((k) => stored[k] !== ''), ...secretsSet]));
|
|
380
|
+
setCredValues((prev) => {
|
|
381
|
+
const next = { ...prev };
|
|
382
|
+
for (const k of envScoped.current)
|
|
383
|
+
next[k] = stored[k] ?? '';
|
|
384
|
+
return next;
|
|
385
|
+
});
|
|
386
|
+
})
|
|
387
|
+
.catch(() => {
|
|
388
|
+
/* keep what is on screen */
|
|
389
|
+
});
|
|
390
|
+
return () => {
|
|
391
|
+
cancelled = true;
|
|
392
|
+
};
|
|
393
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
394
|
+
}, [open, envValue]);
|
|
276
395
|
// Load stored settings values + definitions. The backend returns the
|
|
277
396
|
// manifest's setting definitions alongside the stored values; fall back to
|
|
278
397
|
// the manifest we already have so custom (declarative) addons whose lifecycle
|
|
@@ -309,12 +428,20 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
309
428
|
const keys = [
|
|
310
429
|
...credFields.flatMap((f) => [f.label, f.description]),
|
|
311
430
|
...layoutSections.flatMap((sec) => [sec.title, sec.description]),
|
|
431
|
+
...layoutSections.flatMap((sec) => (sec.blocks ?? []).flatMap((b) => [b.title, b.description, b.label])),
|
|
312
432
|
].filter((k) => !!k);
|
|
313
433
|
if (keys.length === 0 || keys.every((k) => i18n.exists(k)))
|
|
314
434
|
return;
|
|
315
435
|
void ensureAddonBundle?.(connector.addon_key, i18n);
|
|
316
436
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
317
437
|
}, [open, connector?.addon_key, credFields.length]);
|
|
438
|
+
// Section/step help: an i18n key or a literal sentence (never a raw key).
|
|
439
|
+
const addonText = (key) => {
|
|
440
|
+
if (!key)
|
|
441
|
+
return '';
|
|
442
|
+
const out = textOrFallback(t(key, { defaultValue: '' }), key, '');
|
|
443
|
+
return out || (/\s/.test(key) ? key : '');
|
|
444
|
+
};
|
|
318
445
|
const credLabel = (f) => {
|
|
319
446
|
const fallback = humanizeKey(f.key);
|
|
320
447
|
return f.label ? textOrFallback(t(f.label, { defaultValue: fallback }), f.label, fallback) : fallback;
|
|
@@ -359,6 +486,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
359
486
|
onSuccess: () => {
|
|
360
487
|
setFormError(null);
|
|
361
488
|
setFieldErrors({});
|
|
489
|
+
setCredDirty(false);
|
|
362
490
|
notify.success(st('installed_addons.config_saved'));
|
|
363
491
|
onOpenChange(false);
|
|
364
492
|
onSaved?.();
|
|
@@ -390,9 +518,10 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
390
518
|
}
|
|
391
519
|
const sectionKey = credFields.find((f) => f.key === first)?.section;
|
|
392
520
|
if (sectionKey) {
|
|
393
|
-
|
|
521
|
+
// Index among the WIZARD steps (sections without fields/blocks are not steps).
|
|
522
|
+
const idx = wizardSteps.findIndex((sec) => sec.key === sectionKey);
|
|
394
523
|
if (idx >= 0)
|
|
395
|
-
|
|
524
|
+
goToStep(idx);
|
|
396
525
|
}
|
|
397
526
|
window.setTimeout(() => {
|
|
398
527
|
const el = document.getElementById(`${idPrefix}-cred-${first}`);
|
|
@@ -424,55 +553,72 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
424
553
|
setFieldErrors({});
|
|
425
554
|
saveMutation.mutate();
|
|
426
555
|
};
|
|
427
|
-
//
|
|
428
|
-
//
|
|
429
|
-
//
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
556
|
+
// Saves typed-but-unsaved credentials before an action runs: actions (and
|
|
557
|
+
// the connector test) read the STORED credentials, so testing what is on
|
|
558
|
+
// screen requires persisting it first. Returns an error message, or null.
|
|
559
|
+
const persistCredsIfDirty = async () => {
|
|
560
|
+
if (!credDirty || !connector || !canManageIssuer)
|
|
561
|
+
return null;
|
|
562
|
+
const miss = missingRequired(credFields, credValues, !!connector.connected);
|
|
563
|
+
if (miss.length > 0) {
|
|
564
|
+
const errs = {};
|
|
565
|
+
for (const k of miss)
|
|
566
|
+
errs[k] = st('installed_addons.field_required');
|
|
567
|
+
setFieldErrors(errs);
|
|
568
|
+
return st('installed_addons.missing_fields', {
|
|
569
|
+
fields: miss.map((k) => credLabel(credFields.find((f) => f.key === k))).join(', '),
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
const payload = {};
|
|
573
|
+
for (const [k, v] of Object.entries(credValues)) {
|
|
574
|
+
if (v != null && v !== '')
|
|
575
|
+
payload[k] = v;
|
|
576
|
+
}
|
|
577
|
+
await api.post(`/integrations/${connector.provider}`, payload);
|
|
578
|
+
setCredDirty(false);
|
|
579
|
+
onSaved?.();
|
|
580
|
+
return null;
|
|
581
|
+
};
|
|
582
|
+
// Runs a step action: the implicit connection test (connector.test_export)
|
|
583
|
+
// or a declared action block (host route /blocks/:key/run). The result is
|
|
584
|
+
// shown inline (aria-live) with retry, never as a toast that disappears.
|
|
585
|
+
const runAction = async (block) => {
|
|
586
|
+
const fail = st('blocks.failed');
|
|
587
|
+
try {
|
|
588
|
+
const pre = await persistCredsIfDirty();
|
|
589
|
+
if (pre)
|
|
590
|
+
return { status: 'error', message: pre, details: [] };
|
|
591
|
+
if (block.key === SYNC_BLOCK_KEY)
|
|
592
|
+
return await runSync();
|
|
593
|
+
const url = block.key === TEST_BLOCK_KEY
|
|
594
|
+
? `/integrations/${connector?.provider}/test`
|
|
595
|
+
: `/integrations/${connector?.provider}/blocks/${encodeURIComponent(block.key)}/run`;
|
|
596
|
+
const res = await api.post(url, {});
|
|
597
|
+
return normalizeBlockResult(res.data, fail);
|
|
598
|
+
}
|
|
599
|
+
catch (err) {
|
|
600
|
+
return { status: 'error', message: errorMessage(err, fail), details: [] };
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
const setResult = (key, r) => setBlockResults((prev) => ({ ...prev, [key]: r }));
|
|
447
604
|
// "Sincronizar ahora": ops-native connectors with a sync worker (hub →
|
|
448
605
|
// partner read-models) run one sync now and report the run summary.
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
notify.warning(`${summary} · ${(data.errors ?? []).join('; ')}`);
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
notify.success(summary);
|
|
469
|
-
}
|
|
470
|
-
},
|
|
471
|
-
onError: (err) => {
|
|
472
|
-
const msg = err?.response?.data?.message;
|
|
473
|
-
notify.error(msg || st('installed_addons.sync_failed'));
|
|
474
|
-
},
|
|
475
|
-
});
|
|
606
|
+
const runSync = async () => {
|
|
607
|
+
const res = await api.post(connector?.sync_endpoint ?? '', {});
|
|
608
|
+
const data = res.data?.data;
|
|
609
|
+
if (data?.status === 'skipped') {
|
|
610
|
+
return { status: 'warn', message: data.message || st('installed_addons.sync_skipped'), details: [] };
|
|
611
|
+
}
|
|
612
|
+
const summary = st('installed_addons.sync_done', {
|
|
613
|
+
licenses: data?.licenses?.fetched ?? 0,
|
|
614
|
+
instances: data?.instances?.fetched ?? 0,
|
|
615
|
+
accounts: data?.accounts?.fetched ?? 0,
|
|
616
|
+
});
|
|
617
|
+
if (data?.status === 'partial') {
|
|
618
|
+
return { status: 'warn', message: `${summary} · ${(data.errors ?? []).join('; ')}`, details: [] };
|
|
619
|
+
}
|
|
620
|
+
return { status: 'ok', message: summary, details: [] };
|
|
621
|
+
};
|
|
476
622
|
const hasCredentials = credFields.length > 0;
|
|
477
623
|
const hasSettings = definitions.length > 0;
|
|
478
624
|
const canTest = !!connector?.test_export && canManageIssuer;
|
|
@@ -480,7 +626,22 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
480
626
|
defaultValue: 'Solo un administrador de la organización puede ver y guardar los datos del emisor y el certificado. Pide a un administrador que los configure.',
|
|
481
627
|
}) }));
|
|
482
628
|
const canSync = !!connector?.sync_endpoint && !!connector?.connected;
|
|
483
|
-
const
|
|
629
|
+
const revealSecret = async (key) => {
|
|
630
|
+
try {
|
|
631
|
+
const res = await api.get(`/integrations/${connector?.provider}/values/${encodeURIComponent(key)}/reveal${envValue ? `?environment=${encodeURIComponent(envValue)}` : ''}`);
|
|
632
|
+
return String(res.data?.data?.value ?? '');
|
|
633
|
+
}
|
|
634
|
+
catch (err) {
|
|
635
|
+
notify.error(st('installed_addons.field_reveal_error', { defaultValue: 'No se pudo mostrar el valor.' }));
|
|
636
|
+
throw err;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
const storedProps = (key) => ({
|
|
640
|
+
stored: storedKeys.has(key),
|
|
641
|
+
resetKey: envValue,
|
|
642
|
+
onReveal: canRevealSecrets ? revealSecret : undefined,
|
|
643
|
+
});
|
|
644
|
+
const renderCred = (f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key));
|
|
484
645
|
// One setting control, shared by the flat layout and the wizard's last step.
|
|
485
646
|
const renderSetting = (def) => {
|
|
486
647
|
const id = `${idPrefix}-setting-${def.key}`;
|
|
@@ -502,52 +663,118 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
502
663
|
const targetPicker = canTargetBranch ? (_jsxs("div", { className: 'flex flex-wrap items-center gap-2 rounded-md border p-2 text-sm', children: [_jsx("span", { className: 'text-muted-foreground', children: st('installed_addons.applies_to') }), _jsx(Button, { type: 'button', size: 'sm', variant: branchMode ? 'outline' : 'default', onClick: () => setTarget('org'), children: st('installed_addons.whole_org') }), _jsx(Button, { type: 'button', size: 'sm', variant: branchMode ? 'default' : 'outline', onClick: () => setTarget('branch'), children: st('installed_addons.only_branch', { name: activeBranch?.name, defaultValue: 'Solo {{name}}' }) })] })) : null;
|
|
503
664
|
// Settings (Ajustes) body, reused by the flat layout and the wizard's last step.
|
|
504
665
|
const settingsBody = (_jsxs("div", { className: 'flex flex-col gap-3', children: [targetPicker, shownDefs.map(renderSetting)] }));
|
|
505
|
-
//
|
|
666
|
+
// OAuth connectors have no credential form: the surface shows their state and
|
|
667
|
+
// hands "Conectar cuenta" to the host (its OAuth redirect flow).
|
|
668
|
+
const isOAuth = !!connector && !!connector.auth && connector.auth !== 'token';
|
|
669
|
+
const oauthPanel = isOAuth ? (_jsxs("section", { className: 'flex flex-col gap-3 rounded-lg border border-border/70 p-3', children: [_jsxs("div", { className: 'flex flex-wrap items-center justify-between gap-2', children: [_jsxs("h4", { className: 'flex items-center gap-2 text-sm font-medium', children: [_jsx(Link2, { "aria-hidden": 'true', className: 'h-4 w-4 text-muted-foreground' }), st('oauth.title')] }), _jsx(StepStatusBadge, { status: connector.connected ? 'ok' : 'pending', label: connector.connected ? st('oauth.connected') : st('oauth.not_connected') })] }), _jsx(HelpText, { text: st('oauth.help') }), onConnectOAuth ? (_jsx(Button, { type: 'button', variant: connector.connected ? 'outline' : 'default', className: 'h-auto min-h-11 w-full sm:w-fit', onClick: () => onConnectOAuth(connector), children: connector.connected ? st('oauth.reconnect') : st('oauth.connect') })) : null] })) : null;
|
|
670
|
+
// Wizard steps: form_layout sections with fields OR blocks, + a final
|
|
506
671
|
// "Ajustes" step when the addon also ships settings.
|
|
507
|
-
const
|
|
508
|
-
? layoutSections
|
|
672
|
+
const wizardSteps = stepMode
|
|
673
|
+
? buildWizardSteps(layoutSections, credFields.map((f) => f.section), hasSettings)
|
|
509
674
|
: [];
|
|
510
|
-
const wizardSteps = [
|
|
511
|
-
...credSteps.map((sec) => ({
|
|
512
|
-
key: sec.key,
|
|
513
|
-
title: sec.title,
|
|
514
|
-
description: sec.description,
|
|
515
|
-
kind: 'creds',
|
|
516
|
-
})),
|
|
517
|
-
...(stepMode && hasSettings
|
|
518
|
-
? [{ key: '__settings', title: 'installed_addons.section_settings', description: undefined, kind: 'settings' }]
|
|
519
|
-
: []),
|
|
520
|
-
];
|
|
521
675
|
const totalSteps = wizardSteps.length;
|
|
522
676
|
const useStepper = stepMode && totalSteps > 1;
|
|
523
677
|
const stepIdx = Math.min(currentStep, Math.max(0, totalSteps - 1));
|
|
524
678
|
const activeStep = wizardSteps[stepIdx];
|
|
525
679
|
const isLastStep = stepIdx >= totalSteps - 1;
|
|
526
|
-
|
|
527
|
-
|
|
680
|
+
// "Probar conexión" (connector.test_export) is a verification INSIDE the
|
|
681
|
+
// flow (last credentials step / end of the credentials), not a footer
|
|
682
|
+
// button — unless the addon already declares an action block for it.
|
|
683
|
+
const implicitTest = canTest && !hasExplicitTest(layoutSections, connector?.test_export)
|
|
684
|
+
? {
|
|
685
|
+
key: TEST_BLOCK_KEY,
|
|
686
|
+
kind: 'action',
|
|
687
|
+
title: st('blocks.test_title'),
|
|
688
|
+
description: st('blocks.test_help'),
|
|
689
|
+
label: st('installed_addons.test_connection'),
|
|
690
|
+
}
|
|
691
|
+
: null;
|
|
692
|
+
const syncBlock = canSync
|
|
693
|
+
? { key: SYNC_BLOCK_KEY, kind: 'action', title: st('blocks.sync_title'), label: st('installed_addons.sync_now') }
|
|
694
|
+
: null;
|
|
695
|
+
const lastCredStep = (() => {
|
|
696
|
+
for (let i = wizardSteps.length - 1; i >= 0; i--)
|
|
697
|
+
if (wizardSteps[i].kind === 'creds')
|
|
698
|
+
return wizardSteps[i].key;
|
|
699
|
+
return undefined;
|
|
700
|
+
})();
|
|
701
|
+
const extraBlocks = [implicitTest, syncBlock].filter((b) => !!b);
|
|
702
|
+
const blocksFor = (sectionKey, declared = []) => sectionKey === lastCredStep ? [...declared, ...extraBlocks] : declared;
|
|
703
|
+
// Reading order inside a step: what the operator needs BEFORE typing
|
|
704
|
+
// (instructions, the URL to paste in the provider's panel) goes above the
|
|
705
|
+
// fields; verifications (actions) go below them.
|
|
706
|
+
const leadBlocks = (blocks = []) => blocks.filter((b) => b.kind !== 'action');
|
|
707
|
+
const trailBlocks = (blocks = []) => blocks.filter((b) => b.kind === 'action');
|
|
708
|
+
const renderBlocks = (blocks) => (_jsx(ConnectorBlocks, { blocks: blocks, runAction: runAction, results: blockResults, onResult: setResult, actionsDisabled: !canManageIssuer, actionNote: credDirty ? st('blocks.save_first') : undefined }));
|
|
709
|
+
const stepState = (i) => {
|
|
710
|
+
const s = wizardSteps[i];
|
|
711
|
+
return stepStatus({
|
|
712
|
+
index: i,
|
|
713
|
+
current: stepIdx,
|
|
714
|
+
fieldKeys: s.kind === 'creds' ? credFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
|
|
715
|
+
fieldErrors,
|
|
716
|
+
blockKeys: blocksFor(s.key, s.blocks).map((b) => b.key),
|
|
717
|
+
results: blockResults,
|
|
718
|
+
});
|
|
719
|
+
};
|
|
720
|
+
// Moving between steps puts focus on the new step's heading (keyboard and
|
|
721
|
+
// screen-reader users land on the content, not on the footer).
|
|
722
|
+
const goToStep = (i) => {
|
|
723
|
+
stepMoved.current = true;
|
|
724
|
+
setCurrentStep(i);
|
|
725
|
+
};
|
|
726
|
+
useEffect(() => {
|
|
727
|
+
if (stepMoved.current)
|
|
728
|
+
stepHeadingRef.current?.focus();
|
|
729
|
+
}, [stepIdx]);
|
|
730
|
+
// "Siguiente" checks the current step's required credentials first, so the
|
|
731
|
+
// operator learns what is missing where it is, not at the end.
|
|
732
|
+
const handleNext = () => {
|
|
733
|
+
if (activeStep?.kind === 'creds' && connector && canManageIssuer) {
|
|
734
|
+
const stepFields = credFields.filter((f) => f.section === activeStep.key);
|
|
735
|
+
const miss = missingRequired(stepFields, credValues, !!connector.connected);
|
|
736
|
+
if (miss.length > 0) {
|
|
737
|
+
const errs = {};
|
|
738
|
+
for (const k of miss)
|
|
739
|
+
errs[k] = st('installed_addons.field_required');
|
|
740
|
+
setFieldErrors(errs);
|
|
741
|
+
setFormError(st('installed_addons.missing_fields', {
|
|
742
|
+
fields: miss.map((k) => credLabel(credFields.find((f) => f.key === k))).join(', '),
|
|
743
|
+
}));
|
|
744
|
+
focusFirstInvalid(miss);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
setFormError(null);
|
|
749
|
+
goToStep(stepIdx + 1);
|
|
750
|
+
};
|
|
751
|
+
const hasAnyBlocks = layoutSections.some((s) => (s.blocks?.length ?? 0) > 0) || extraBlocks.length > 0;
|
|
752
|
+
const nothingToConfigure = !hasCredentials && !hasSettings && !isOAuth && !hasAnyBlocks;
|
|
753
|
+
const nothingToSave = !hasCredentials && !hasSettings;
|
|
754
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsx(DialogContent, { className: 'flex max-h-[85vh] flex-col max-sm:max-h-[calc(100dvh-1rem)] max-sm:gap-3 max-sm:p-4', children: _jsxs(ConnectorFormStateContext.Provider, { value: { fields: credFields, errors: fieldErrors, idPrefix, client: api, expectedOptionKinds }, children: [_jsxs(DialogHeader, { className: 'shrink-0 pe-8 text-start', children: [_jsx(DialogTitle, { className: 'leading-snug', children: st('installed_addons.configure_title', { name: displayName ?? addon.manifest.display_name ?? addon.manifest.name }) }), _jsx(DialogDescription, { children: st('installed_addons.configure_description') })] }), _jsx("div", { className: '-mr-2 flex min-h-0 flex-col gap-6 overflow-y-auto py-2 pr-2', children: loading ? (_jsx("div", { className: 'flex justify-center py-8', children: _jsx(Loader2, { className: 'h-5 w-5 animate-spin text-muted-foreground' }) })) : useStepper ? (_jsxs("div", { className: 'flex flex-col gap-5', children: [_jsxs("nav", { "aria-label": st('wizard.steps'), className: 'flex flex-col gap-2', children: [_jsx("ol", { className: 'flex items-center', children: wizardSteps.map((s, i) => {
|
|
755
|
+
const status = stepState(i);
|
|
528
756
|
const active = i === stepIdx;
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
757
|
+
const title = t(s.title ?? '', { defaultValue: humanizeKey(s.title) });
|
|
758
|
+
return (_jsxs("li", { className: cn('flex items-center', i < wizardSteps.length - 1 && 'flex-1'), children: [_jsx("button", { type: 'button', onClick: () => goToStep(i), "aria-current": active ? 'step' : undefined, "aria-label": st('wizard.step_label', {
|
|
759
|
+
n: i + 1,
|
|
760
|
+
total: totalSteps,
|
|
761
|
+
title,
|
|
762
|
+
status: st(`status.${status}`),
|
|
763
|
+
}), "data-step-status": status, className: 'flex h-11 w-11 shrink-0 items-center justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring', children: _jsx("span", { "aria-hidden": 'true', className: cn('flex h-8 w-8 items-center justify-center rounded-full border text-xs font-semibold transition-all', active
|
|
764
|
+
? 'border-primary bg-primary text-primary-foreground ring-4 ring-primary/15'
|
|
765
|
+
: status === 'error'
|
|
766
|
+
? 'border-destructive bg-destructive/10 text-destructive'
|
|
767
|
+
: status === 'ok'
|
|
768
|
+
? 'border-primary bg-primary/10 text-primary'
|
|
769
|
+
: 'border-border text-muted-foreground'), children: !active && status === 'error' ? (_jsx(AlertCircle, { className: 'h-4 w-4' })) : !active && status === 'ok' ? (_jsx(Check, { className: 'h-4 w-4' })) : (i + 1) }) }), i < wizardSteps.length - 1 && (_jsx("span", { "aria-hidden": 'true', className: cn('mx-1 h-0.5 flex-1 rounded-full transition-colors', i < stepIdx ? 'bg-primary' : 'bg-border') }))] }, s.key));
|
|
770
|
+
}) }), _jsxs("div", { className: 'flex items-start justify-between gap-3', children: [_jsx("h3", { ref: stepHeadingRef, tabIndex: -1, className: 'min-w-0 text-base leading-snug font-semibold break-words outline-none', children: t(activeStep?.title ?? '', {
|
|
535
771
|
defaultValue: humanizeKey(activeStep?.title),
|
|
536
|
-
}) }),
|
|
537
|
-
? settingsBody
|
|
538
|
-
: !canManageIssuer
|
|
539
|
-
? issuerAdminNote
|
|
540
|
-
: credFields
|
|
541
|
-
.filter((f) => f.section === activeStep?.key)
|
|
542
|
-
.map(renderCred)] })] })) : (_jsxs(_Fragment, { children: [hasCredentials && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Cable, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_credentials') })] }), !canManageIssuer ? (issuerAdminNote) : useLayout ? (
|
|
772
|
+
}) }), _jsx("span", { className: 'mt-0.5 shrink-0 text-xs font-medium tabular-nums text-muted-foreground', children: st('flow.step_of', { n: stepIdx + 1, total: totalSteps }) })] })] }), _jsxs("div", { className: 'flex flex-col gap-4', children: [activeStep?.description && (_jsx(HelpText, { text: addonText(activeStep.description) })), activeStep?.kind === 'settings' ? (settingsBody) : !canManageIssuer ? (_jsxs(_Fragment, { children: [issuerAdminNote, renderBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))] })) : (_jsxs(_Fragment, { children: [renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))), credFields.filter((f) => f.section === activeStep?.key).map(renderCred), renderBlocks(trailBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))] }))] })] })) : (_jsxs(_Fragment, { children: [oauthPanel, hasCredentials && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Cable, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_credentials') })] }), !canManageIssuer ? (issuerAdminNote) : useLayout ? (
|
|
543
773
|
// form_layout: one titled group per section, in declared order.
|
|
544
774
|
layoutSections.map((sec) => {
|
|
545
775
|
const fields = credFields.filter((f) => f.section === sec.key);
|
|
546
|
-
if (fields.length === 0)
|
|
776
|
+
if (fields.length === 0 && (sec.blocks?.length ?? 0) === 0)
|
|
547
777
|
return null;
|
|
548
|
-
return (_jsxs("div", { className: 'flex flex-col gap-3 rounded-md border border-border/60 px-3 py-3', children: [sec.title && (_jsxs("div", { children: [_jsx("h4", { className: 'text-sm font-medium', children: t(sec.title, { defaultValue: sec.title }) }), sec.description && (_jsx(
|
|
549
|
-
})) : (_jsxs(_Fragment, { children: [requiredFields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), advancedFields.length > 0 && (_jsxs("details", { className: 'rounded-md border border-border/60 px-3 py-2', open: advancedFields.some((f) => !!fieldErrors[f.key]) || undefined, children: [_jsx("summary", { className: 'cursor-pointer
|
|
550
|
-
(testMutation.data && !testMutation.data.ok) ? (_jsx(XCircle, { className: 'h-4 w-4 text-destructive' })) : (_jsx(Plug, { className: 'h-4 w-4' })), st('installed_addons.test_connection', {
|
|
551
|
-
defaultValue: 'Probar conexión',
|
|
552
|
-
})] })) : (_jsx("span", {})), canSync ? (_jsxs(Button, { variant: 'outline', onClick: () => syncMutation.mutate(), disabled: syncMutation.isPending, className: 'gap-2', children: [syncMutation.isPending ? (_jsx(Loader2, { className: 'h-4 w-4 animate-spin' })) : (_jsx(RefreshCw, { className: 'h-4 w-4' })), st('installed_addons.sync_now', { defaultValue: 'Sincronizar ahora' })] })) : null, _jsxs("div", { className: 'flex gap-2', children: [useStepper && stepIdx > 0 && (_jsx(Button, { variant: 'outline', onClick: () => setCurrentStep((s) => Math.max(0, s - 1)), children: st('common.back', { defaultValue: 'Atrás' }) })), _jsx(Button, { variant: 'outline', onClick: () => onOpenChange(false), children: st('common.cancel') }), useStepper && !isLastStep ? (_jsx(Button, { onClick: () => setCurrentStep((s) => s + 1), children: st('common.next', { defaultValue: 'Siguiente' }) })) : (_jsxs(Button, { onClick: handleSave, disabled: saveMutation.isPending || loading || (!hasCredentials && !hasSettings), children: [saveMutation.isPending && (_jsx(Loader2, { className: 'mr-2 h-4 w-4 animate-spin' })), st('common.save')] }))] })] })] }) }) }));
|
|
778
|
+
return (_jsxs("div", { className: 'flex flex-col gap-3 rounded-md border border-border/60 px-3 py-3', children: [sec.title && (_jsxs("div", { className: 'flex flex-col gap-1', children: [_jsx("h4", { className: 'text-sm font-medium', children: t(sec.title, { defaultValue: sec.title }) }), sec.description && (_jsx(HelpText, { text: addonText(sec.description) }))] })), renderBlocks(leadBlocks(sec.blocks)), fields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), renderBlocks(trailBlocks(sec.blocks))] }, sec.key));
|
|
779
|
+
})) : (_jsxs(_Fragment, { children: [requiredFields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), advancedFields.length > 0 && (_jsxs("details", { className: 'rounded-md border border-border/60 px-3 py-2', open: advancedFields.some((f) => !!fieldErrors[f.key]) || undefined, children: [_jsx("summary", { className: 'flex min-h-11 cursor-pointer items-center text-sm font-medium text-muted-foreground select-none sm:min-h-8', children: st('installed_addons.advanced') }), _jsx("div", { className: 'flex flex-col gap-3 pt-3', children: advancedFields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))) })] }))] }))] })), extraBlocks.length > 0 && renderBlocks(extraBlocks), hasSettings && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Settings, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_settings') })] }), targetPicker, shownDefs.map(renderSetting)] })), nothingToConfigure && (_jsxs("div", { className: 'flex flex-col items-start gap-1 rounded-lg border border-dashed p-4', children: [_jsx("p", { className: 'text-sm font-medium', children: st('empty.title') }), _jsx(HelpText, { text: st('empty.help') })] }))] })) }), formError ? (_jsx("div", { ref: errorRef, role: 'alert', className: 'max-h-40 shrink-0 overflow-y-auto whitespace-pre-wrap break-words rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive', children: formError })) : null, _jsx(DialogFooter, { "data-wizard-footer": '', className: 'grid shrink-0 grid-cols-2 gap-2 border-t pt-3 sm:flex sm:flex-row sm:justify-end sm:border-t-0 sm:pt-0', children: nothingToSave ? (_jsx(Button, { className: 'col-span-2 h-11 sm:h-9', onClick: () => onOpenChange(false), children: st('common.close') })) : (_jsxs(_Fragment, { children: [_jsxs(Button, { className: 'order-first col-span-2 h-11 sm:order-last sm:h-9', onClick: useStepper && !isLastStep ? handleNext : handleSave, disabled: !(useStepper && !isLastStep) && (saveMutation.isPending || loading), children: [saveMutation.isPending && _jsx(Loader2, { className: 'mr-2 h-4 w-4 animate-spin' }), useStepper && !isLastStep ? st('common.next') : st('common.save')] }), useStepper && stepIdx > 0 && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: () => goToStep(Math.max(0, stepIdx - 1)), children: st('common.back') })), _jsx(Button, { variant: 'ghost', className: cn('h-11 sm:order-first sm:h-9', !(useStepper && stepIdx > 0) && 'col-span-2'), onClick: () => onOpenChange(false), children: st('common.cancel') })] })) })] }) }) }));
|
|
553
780
|
}
|