@asteby/metacore-runtime-react 53.5.0 → 53.6.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 +6 -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 +10 -1
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +196 -87
- 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 +71 -0
- package/package.json +5 -5
- package/src/__tests__/addon-config-surface.test.tsx +18 -6
- package/src/__tests__/connector-blocks.test.tsx +302 -0
- package/src/index.ts +4 -0
- package/src/setup/addon-config-surface.tsx +356 -192
- 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 +71 -0
|
@@ -16,7 +16,7 @@ import { createContext, useContext, useEffect, useId, useRef, useState } from 'r
|
|
|
16
16
|
import { useMutation } from '@tanstack/react-query'
|
|
17
17
|
import { useTranslation } from 'react-i18next'
|
|
18
18
|
import { toast } from 'sonner'
|
|
19
|
-
import { Cable, Check,
|
|
19
|
+
import { AlertCircle, Cable, Check, Link2, Loader2, RefreshCw, Settings } from 'lucide-react'
|
|
20
20
|
import {
|
|
21
21
|
Badge,
|
|
22
22
|
Button,
|
|
@@ -40,6 +40,17 @@ import { useApi, type ApiClient } from '../api-context'
|
|
|
40
40
|
import { evaluateVisibleWhen, getVisibleWhen } from '../dynamic-form-schema'
|
|
41
41
|
import type { VisibleWhen } from '../types'
|
|
42
42
|
import { useSetupT } from './messages'
|
|
43
|
+
import { StepStatusBadge } from './step-status-badge'
|
|
44
|
+
import { ConnectorBlocks, HelpText } from './connector-blocks'
|
|
45
|
+
import {
|
|
46
|
+
buildWizardSteps,
|
|
47
|
+
errorMessage,
|
|
48
|
+
hasExplicitTest,
|
|
49
|
+
normalizeBlockResult,
|
|
50
|
+
stepStatus,
|
|
51
|
+
type BlockResult,
|
|
52
|
+
type ConnectorFormBlock,
|
|
53
|
+
} from './connector-blocks-model'
|
|
43
54
|
import {
|
|
44
55
|
isSecretCredential,
|
|
45
56
|
missingRequired,
|
|
@@ -91,6 +102,8 @@ export interface ConnectorFormLayoutSection {
|
|
|
91
102
|
key: string
|
|
92
103
|
title?: string // i18n key
|
|
93
104
|
description?: string // i18n key
|
|
105
|
+
/** Setup blocks (webhook_url / instructions / action), host-filled. */
|
|
106
|
+
blocks?: ConnectorFormBlock[]
|
|
94
107
|
}
|
|
95
108
|
export interface ConnectorFormLayout {
|
|
96
109
|
mode?: 'sections' | 'steps'
|
|
@@ -154,8 +167,18 @@ export interface AddonConfigSurfaceProps {
|
|
|
154
167
|
expectedOptionKinds?: Record<string, string>
|
|
155
168
|
/** Title name; default `manifest.display_name ?? manifest.name`. */
|
|
156
169
|
displayName?: string
|
|
170
|
+
/**
|
|
171
|
+
* OAuth connectors (auth != "token") have no credential form: the surface
|
|
172
|
+
* shows the connection state and a "Conectar cuenta" button that calls this
|
|
173
|
+
* (the host starts its OAuth flow). Absent → no button.
|
|
174
|
+
*/
|
|
175
|
+
onConnectOAuth?: (connector: ConnectorEntry) => void
|
|
157
176
|
}
|
|
158
177
|
|
|
178
|
+
/** Key of the implicit "Probar conexión" block (connector.test_export). */
|
|
179
|
+
const TEST_BLOCK_KEY = '__test_connection'
|
|
180
|
+
const SYNC_BLOCK_KEY = '__sync'
|
|
181
|
+
|
|
159
182
|
// ─── Connector credential field (reusable render) ───────────────────────────
|
|
160
183
|
// One connector credential field: label (i18n) + control (select|password|text)
|
|
161
184
|
// + optional help. Shared by the unified config dialog for both the essential
|
|
@@ -287,7 +310,7 @@ function ConnectorCredentialFieldControl({
|
|
|
287
310
|
{warning}
|
|
288
311
|
</p>
|
|
289
312
|
) : null}
|
|
290
|
-
{help ? <
|
|
313
|
+
{help ? <HelpText text={help} /> : null}
|
|
291
314
|
</div>
|
|
292
315
|
)
|
|
293
316
|
}
|
|
@@ -465,6 +488,7 @@ export function AddonConfigSurface({
|
|
|
465
488
|
client,
|
|
466
489
|
expectedOptionKinds = NO_OPTION_KINDS,
|
|
467
490
|
displayName,
|
|
491
|
+
onConnectOAuth,
|
|
468
492
|
}: AddonConfigSurfaceProps) {
|
|
469
493
|
const idPrefix = useId()
|
|
470
494
|
const { t, i18n } = useTranslation()
|
|
@@ -498,8 +522,15 @@ export function AddonConfigSurface({
|
|
|
498
522
|
const [formError, setFormError] = useState<string | null>(null)
|
|
499
523
|
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({})
|
|
500
524
|
const errorRef = useRef<HTMLDivElement>(null)
|
|
525
|
+
// Results of the step actions (by block key) and whether the operator typed
|
|
526
|
+
// credentials not saved yet (an action tests what is STORED: it saves first).
|
|
527
|
+
const [blockResults, setBlockResults] = useState<Record<string, BlockResult | undefined>>({})
|
|
528
|
+
const [credDirty, setCredDirty] = useState(false)
|
|
529
|
+
const stepHeadingRef = useRef<HTMLHeadingElement>(null)
|
|
530
|
+
const stepMoved = useRef(false)
|
|
501
531
|
const setCred = (key: string, val: string) => {
|
|
502
532
|
setCredValues((v) => ({ ...v, [key]: val }))
|
|
533
|
+
setCredDirty(true)
|
|
503
534
|
if (fieldErrors[key]) {
|
|
504
535
|
setFieldErrors((e) => {
|
|
505
536
|
const { [key]: _drop, ...rest } = e
|
|
@@ -550,8 +581,11 @@ export function AddonConfigSurface({
|
|
|
550
581
|
}
|
|
551
582
|
setCredValues(seed)
|
|
552
583
|
setCurrentStep(0)
|
|
584
|
+
stepMoved.current = false
|
|
553
585
|
setFormError(null)
|
|
554
586
|
setFieldErrors({})
|
|
587
|
+
setBlockResults({})
|
|
588
|
+
setCredDirty(false)
|
|
555
589
|
if (!canManageIssuer || !connector?.provider || credFields.length === 0) return
|
|
556
590
|
let cancelled = false
|
|
557
591
|
api
|
|
@@ -617,12 +651,20 @@ export function AddonConfigSurface({
|
|
|
617
651
|
const keys = [
|
|
618
652
|
...credFields.flatMap((f) => [f.label, f.description]),
|
|
619
653
|
...layoutSections.flatMap((sec) => [sec.title, sec.description]),
|
|
654
|
+
...layoutSections.flatMap((sec) => (sec.blocks ?? []).flatMap((b) => [b.title, b.description, b.label])),
|
|
620
655
|
].filter((k): k is string => !!k)
|
|
621
656
|
if (keys.length === 0 || keys.every((k) => i18n.exists(k))) return
|
|
622
657
|
void ensureAddonBundle?.(connector.addon_key, i18n)
|
|
623
658
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
624
659
|
}, [open, connector?.addon_key, credFields.length])
|
|
625
660
|
|
|
661
|
+
// Section/step help: an i18n key or a literal sentence (never a raw key).
|
|
662
|
+
const addonText = (key?: string) => {
|
|
663
|
+
if (!key) return ''
|
|
664
|
+
const out = textOrFallback(t(key, { defaultValue: '' }), key, '')
|
|
665
|
+
return out || (/\s/.test(key) ? key : '')
|
|
666
|
+
}
|
|
667
|
+
|
|
626
668
|
const credLabel = (f: ConnectorCredentialField) => {
|
|
627
669
|
const fallback = humanizeKey(f.key)
|
|
628
670
|
return f.label ? textOrFallback(t(f.label, { defaultValue: fallback }), f.label, fallback) : fallback
|
|
@@ -666,6 +708,7 @@ export function AddonConfigSurface({
|
|
|
666
708
|
onSuccess: () => {
|
|
667
709
|
setFormError(null)
|
|
668
710
|
setFieldErrors({})
|
|
711
|
+
setCredDirty(false)
|
|
669
712
|
notify.success(st('installed_addons.config_saved'))
|
|
670
713
|
onOpenChange(false)
|
|
671
714
|
onSaved?.()
|
|
@@ -698,8 +741,9 @@ export function AddonConfigSurface({
|
|
|
698
741
|
}
|
|
699
742
|
const sectionKey = credFields.find((f) => f.key === first)?.section
|
|
700
743
|
if (sectionKey) {
|
|
701
|
-
|
|
702
|
-
|
|
744
|
+
// Index among the WIZARD steps (sections without fields/blocks are not steps).
|
|
745
|
+
const idx = wizardSteps.findIndex((sec) => sec.key === sectionKey)
|
|
746
|
+
if (idx >= 0) goToStep(idx)
|
|
703
747
|
}
|
|
704
748
|
window.setTimeout(() => {
|
|
705
749
|
const el = document.getElementById(`${idPrefix}-cred-${first}`)
|
|
@@ -735,68 +779,78 @@ export function AddonConfigSurface({
|
|
|
735
779
|
saveMutation.mutate()
|
|
736
780
|
}
|
|
737
781
|
|
|
738
|
-
//
|
|
739
|
-
//
|
|
740
|
-
//
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
782
|
+
// Saves typed-but-unsaved credentials before an action runs: actions (and
|
|
783
|
+
// the connector test) read the STORED credentials, so testing what is on
|
|
784
|
+
// screen requires persisting it first. Returns an error message, or null.
|
|
785
|
+
const persistCredsIfDirty = async (): Promise<string | null> => {
|
|
786
|
+
if (!credDirty || !connector || !canManageIssuer) return null
|
|
787
|
+
const miss = missingRequired(credFields, credValues, !!connector.connected)
|
|
788
|
+
if (miss.length > 0) {
|
|
789
|
+
const errs: Record<string, string> = {}
|
|
790
|
+
for (const k of miss) errs[k] = st('installed_addons.field_required')
|
|
791
|
+
setFieldErrors(errs)
|
|
792
|
+
return st('installed_addons.missing_fields', {
|
|
793
|
+
fields: miss.map((k) => credLabel(credFields.find((f) => f.key === k)!)).join(', '),
|
|
794
|
+
})
|
|
795
|
+
}
|
|
796
|
+
const payload: Record<string, string> = {}
|
|
797
|
+
for (const [k, v] of Object.entries(credValues)) {
|
|
798
|
+
if (v != null && v !== '') payload[k] = v
|
|
799
|
+
}
|
|
800
|
+
await api.post(`/integrations/${connector.provider}`, payload)
|
|
801
|
+
setCredDirty(false)
|
|
802
|
+
onSaved?.()
|
|
803
|
+
return null
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Runs a step action: the implicit connection test (connector.test_export)
|
|
807
|
+
// or a declared action block (host route /blocks/:key/run). The result is
|
|
808
|
+
// shown inline (aria-live) with retry, never as a toast that disappears.
|
|
809
|
+
const runAction = async (block: ConnectorFormBlock): Promise<BlockResult> => {
|
|
810
|
+
const fail = st('blocks.failed')
|
|
811
|
+
try {
|
|
812
|
+
const pre = await persistCredsIfDirty()
|
|
813
|
+
if (pre) return { status: 'error', message: pre, details: [] }
|
|
814
|
+
if (block.key === SYNC_BLOCK_KEY) return await runSync()
|
|
815
|
+
const url =
|
|
816
|
+
block.key === TEST_BLOCK_KEY
|
|
817
|
+
? `/integrations/${connector?.provider}/test`
|
|
818
|
+
: `/integrations/${connector?.provider}/blocks/${encodeURIComponent(block.key)}/run`
|
|
819
|
+
const res = await api.post(url, {})
|
|
820
|
+
return normalizeBlockResult(res.data, fail)
|
|
821
|
+
} catch (err) {
|
|
822
|
+
return { status: 'error', message: errorMessage(err, fail), details: [] }
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
const setResult = (key: string, r: BlockResult) => setBlockResults((prev) => ({ ...prev, [key]: r }))
|
|
762
826
|
|
|
763
827
|
// "Sincronizar ahora": ops-native connectors with a sync worker (hub →
|
|
764
828
|
// partner read-models) run one sync now and report the run summary.
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
notify.warning(`${summary} · ${(data.errors ?? []).join('; ')}`)
|
|
791
|
-
} else {
|
|
792
|
-
notify.success(summary)
|
|
793
|
-
}
|
|
794
|
-
},
|
|
795
|
-
onError: (err: unknown) => {
|
|
796
|
-
const msg = (err as { response?: { data?: { message?: string } } })?.response?.data?.message
|
|
797
|
-
notify.error(msg || st('installed_addons.sync_failed'))
|
|
798
|
-
},
|
|
799
|
-
})
|
|
829
|
+
const runSync = async (): Promise<BlockResult> => {
|
|
830
|
+
const res = await api.post(connector?.sync_endpoint ?? '', {})
|
|
831
|
+
const data = res.data?.data as
|
|
832
|
+
| {
|
|
833
|
+
status?: string
|
|
834
|
+
message?: string
|
|
835
|
+
licenses?: { fetched?: number }
|
|
836
|
+
instances?: { fetched?: number }
|
|
837
|
+
accounts?: { fetched?: number }
|
|
838
|
+
errors?: string[]
|
|
839
|
+
}
|
|
840
|
+
| undefined
|
|
841
|
+
if (data?.status === 'skipped') {
|
|
842
|
+
return { status: 'warn', message: data.message || st('installed_addons.sync_skipped'), details: [] }
|
|
843
|
+
}
|
|
844
|
+
const summary = st('installed_addons.sync_done', {
|
|
845
|
+
licenses: data?.licenses?.fetched ?? 0,
|
|
846
|
+
instances: data?.instances?.fetched ?? 0,
|
|
847
|
+
accounts: data?.accounts?.fetched ?? 0,
|
|
848
|
+
})
|
|
849
|
+
if (data?.status === 'partial') {
|
|
850
|
+
return { status: 'warn', message: `${summary} · ${(data.errors ?? []).join('; ')}`, details: [] }
|
|
851
|
+
}
|
|
852
|
+
return { status: 'ok', message: summary, details: [] }
|
|
853
|
+
}
|
|
800
854
|
|
|
801
855
|
const hasCredentials = credFields.length > 0
|
|
802
856
|
const hasSettings = definitions.length > 0
|
|
@@ -949,36 +1003,148 @@ export function AddonConfigSurface({
|
|
|
949
1003
|
</div>
|
|
950
1004
|
)
|
|
951
1005
|
|
|
952
|
-
//
|
|
1006
|
+
// OAuth connectors have no credential form: the surface shows their state and
|
|
1007
|
+
// hands "Conectar cuenta" to the host (its OAuth redirect flow).
|
|
1008
|
+
const isOAuth = !!connector && !!connector.auth && connector.auth !== 'token'
|
|
1009
|
+
const oauthPanel = isOAuth ? (
|
|
1010
|
+
<section className='flex flex-col gap-3 rounded-lg border border-border/70 p-3'>
|
|
1011
|
+
<div className='flex flex-wrap items-center justify-between gap-2'>
|
|
1012
|
+
<h4 className='flex items-center gap-2 text-sm font-medium'>
|
|
1013
|
+
<Link2 aria-hidden='true' className='h-4 w-4 text-muted-foreground' />
|
|
1014
|
+
{st('oauth.title')}
|
|
1015
|
+
</h4>
|
|
1016
|
+
<StepStatusBadge
|
|
1017
|
+
status={connector!.connected ? 'ok' : 'pending'}
|
|
1018
|
+
label={connector!.connected ? st('oauth.connected') : st('oauth.not_connected')}
|
|
1019
|
+
/>
|
|
1020
|
+
</div>
|
|
1021
|
+
<HelpText text={st('oauth.help')} />
|
|
1022
|
+
{onConnectOAuth ? (
|
|
1023
|
+
<Button
|
|
1024
|
+
type='button'
|
|
1025
|
+
variant={connector!.connected ? 'outline' : 'default'}
|
|
1026
|
+
className='h-auto min-h-11 w-full sm:w-fit'
|
|
1027
|
+
onClick={() => onConnectOAuth(connector!)}
|
|
1028
|
+
>
|
|
1029
|
+
{connector!.connected ? st('oauth.reconnect') : st('oauth.connect')}
|
|
1030
|
+
</Button>
|
|
1031
|
+
) : null}
|
|
1032
|
+
</section>
|
|
1033
|
+
) : null
|
|
1034
|
+
|
|
1035
|
+
// Wizard steps: form_layout sections with fields OR blocks, + a final
|
|
953
1036
|
// "Ajustes" step when the addon also ships settings.
|
|
954
|
-
const
|
|
955
|
-
?
|
|
1037
|
+
const wizardSteps = stepMode
|
|
1038
|
+
? buildWizardSteps(
|
|
1039
|
+
layoutSections,
|
|
1040
|
+
credFields.map((f) => f.section),
|
|
1041
|
+
hasSettings,
|
|
1042
|
+
)
|
|
956
1043
|
: []
|
|
957
|
-
const wizardSteps = [
|
|
958
|
-
...credSteps.map((sec) => ({
|
|
959
|
-
key: sec.key,
|
|
960
|
-
title: sec.title,
|
|
961
|
-
description: sec.description,
|
|
962
|
-
kind: 'creds' as const,
|
|
963
|
-
})),
|
|
964
|
-
...(stepMode && hasSettings
|
|
965
|
-
? [{ key: '__settings', title: 'installed_addons.section_settings', description: undefined, kind: 'settings' as const }]
|
|
966
|
-
: []),
|
|
967
|
-
]
|
|
968
1044
|
const totalSteps = wizardSteps.length
|
|
969
1045
|
const useStepper = stepMode && totalSteps > 1
|
|
970
1046
|
const stepIdx = Math.min(currentStep, Math.max(0, totalSteps - 1))
|
|
971
1047
|
const activeStep = wizardSteps[stepIdx]
|
|
972
1048
|
const isLastStep = stepIdx >= totalSteps - 1
|
|
973
1049
|
|
|
1050
|
+
// "Probar conexión" (connector.test_export) is a verification INSIDE the
|
|
1051
|
+
// flow (last credentials step / end of the credentials), not a footer
|
|
1052
|
+
// button — unless the addon already declares an action block for it.
|
|
1053
|
+
const implicitTest: ConnectorFormBlock | null =
|
|
1054
|
+
canTest && !hasExplicitTest(layoutSections, connector?.test_export)
|
|
1055
|
+
? {
|
|
1056
|
+
key: TEST_BLOCK_KEY,
|
|
1057
|
+
kind: 'action',
|
|
1058
|
+
title: st('blocks.test_title'),
|
|
1059
|
+
description: st('blocks.test_help'),
|
|
1060
|
+
label: st('installed_addons.test_connection'),
|
|
1061
|
+
}
|
|
1062
|
+
: null
|
|
1063
|
+
const syncBlock: ConnectorFormBlock | null = canSync
|
|
1064
|
+
? { key: SYNC_BLOCK_KEY, kind: 'action', title: st('blocks.sync_title'), label: st('installed_addons.sync_now') }
|
|
1065
|
+
: null
|
|
1066
|
+
const lastCredStep = (() => {
|
|
1067
|
+
for (let i = wizardSteps.length - 1; i >= 0; i--) if (wizardSteps[i].kind === 'creds') return wizardSteps[i].key
|
|
1068
|
+
return undefined
|
|
1069
|
+
})()
|
|
1070
|
+
const extraBlocks = [implicitTest, syncBlock].filter((b): b is ConnectorFormBlock => !!b)
|
|
1071
|
+
const blocksFor = (sectionKey: string, declared: ConnectorFormBlock[] = []) =>
|
|
1072
|
+
sectionKey === lastCredStep ? [...declared, ...extraBlocks] : declared
|
|
1073
|
+
|
|
1074
|
+
// Reading order inside a step: what the operator needs BEFORE typing
|
|
1075
|
+
// (instructions, the URL to paste in the provider's panel) goes above the
|
|
1076
|
+
// fields; verifications (actions) go below them.
|
|
1077
|
+
const leadBlocks = (blocks: ConnectorFormBlock[] = []) => blocks.filter((b) => b.kind !== 'action')
|
|
1078
|
+
const trailBlocks = (blocks: ConnectorFormBlock[] = []) => blocks.filter((b) => b.kind === 'action')
|
|
1079
|
+
|
|
1080
|
+
const renderBlocks = (blocks: ConnectorFormBlock[]) => (
|
|
1081
|
+
<ConnectorBlocks
|
|
1082
|
+
blocks={blocks}
|
|
1083
|
+
runAction={runAction}
|
|
1084
|
+
results={blockResults}
|
|
1085
|
+
onResult={setResult}
|
|
1086
|
+
actionsDisabled={!canManageIssuer}
|
|
1087
|
+
actionNote={credDirty ? st('blocks.save_first') : undefined}
|
|
1088
|
+
/>
|
|
1089
|
+
)
|
|
1090
|
+
|
|
1091
|
+
const stepState = (i: number) => {
|
|
1092
|
+
const s = wizardSteps[i]
|
|
1093
|
+
return stepStatus({
|
|
1094
|
+
index: i,
|
|
1095
|
+
current: stepIdx,
|
|
1096
|
+
fieldKeys: s.kind === 'creds' ? credFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
|
|
1097
|
+
fieldErrors,
|
|
1098
|
+
blockKeys: blocksFor(s.key, s.blocks).map((b) => b.key),
|
|
1099
|
+
results: blockResults,
|
|
1100
|
+
})
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// Moving between steps puts focus on the new step's heading (keyboard and
|
|
1104
|
+
// screen-reader users land on the content, not on the footer).
|
|
1105
|
+
const goToStep = (i: number) => {
|
|
1106
|
+
stepMoved.current = true
|
|
1107
|
+
setCurrentStep(i)
|
|
1108
|
+
}
|
|
1109
|
+
useEffect(() => {
|
|
1110
|
+
if (stepMoved.current) stepHeadingRef.current?.focus()
|
|
1111
|
+
}, [stepIdx])
|
|
1112
|
+
|
|
1113
|
+
// "Siguiente" checks the current step's required credentials first, so the
|
|
1114
|
+
// operator learns what is missing where it is, not at the end.
|
|
1115
|
+
const handleNext = () => {
|
|
1116
|
+
if (activeStep?.kind === 'creds' && connector && canManageIssuer) {
|
|
1117
|
+
const stepFields = credFields.filter((f) => f.section === activeStep.key)
|
|
1118
|
+
const miss = missingRequired(stepFields, credValues, !!connector.connected)
|
|
1119
|
+
if (miss.length > 0) {
|
|
1120
|
+
const errs: Record<string, string> = {}
|
|
1121
|
+
for (const k of miss) errs[k] = st('installed_addons.field_required')
|
|
1122
|
+
setFieldErrors(errs)
|
|
1123
|
+
setFormError(
|
|
1124
|
+
st('installed_addons.missing_fields', {
|
|
1125
|
+
fields: miss.map((k) => credLabel(credFields.find((f) => f.key === k)!)).join(', '),
|
|
1126
|
+
}),
|
|
1127
|
+
)
|
|
1128
|
+
focusFirstInvalid(miss)
|
|
1129
|
+
return
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
setFormError(null)
|
|
1133
|
+
goToStep(stepIdx + 1)
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
const hasAnyBlocks = layoutSections.some((s) => (s.blocks?.length ?? 0) > 0) || extraBlocks.length > 0
|
|
1137
|
+
const nothingToConfigure = !hasCredentials && !hasSettings && !isOAuth && !hasAnyBlocks
|
|
1138
|
+
const nothingToSave = !hasCredentials && !hasSettings
|
|
1139
|
+
|
|
974
1140
|
return (
|
|
975
1141
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
976
|
-
<DialogContent className='flex max-h-[85vh] flex-col'>
|
|
1142
|
+
<DialogContent className='flex max-h-[85vh] flex-col max-sm:max-h-[calc(100dvh-1rem)] max-sm:gap-3 max-sm:p-4'>
|
|
977
1143
|
<ConnectorFormStateContext.Provider
|
|
978
1144
|
value={{ fields: credFields, errors: fieldErrors, idPrefix, client: api, expectedOptionKinds }}
|
|
979
1145
|
>
|
|
980
|
-
<DialogHeader className='shrink-0'>
|
|
981
|
-
<DialogTitle>
|
|
1146
|
+
<DialogHeader className='shrink-0 pe-8 text-start'>
|
|
1147
|
+
<DialogTitle className='leading-snug'>
|
|
982
1148
|
{st('installed_addons.configure_title', { name: displayName ?? addon.manifest.display_name ?? addon.manifest.name })}
|
|
983
1149
|
</DialogTitle>
|
|
984
1150
|
<DialogDescription>
|
|
@@ -986,7 +1152,7 @@ export function AddonConfigSurface({
|
|
|
986
1152
|
</DialogDescription>
|
|
987
1153
|
</DialogHeader>
|
|
988
1154
|
|
|
989
|
-
<div className='-mr-2 flex flex-col gap-6 overflow-y-auto py-2 pr-2'>
|
|
1155
|
+
<div className='-mr-2 flex min-h-0 flex-col gap-6 overflow-y-auto py-2 pr-2'>
|
|
990
1156
|
{loading ? (
|
|
991
1157
|
<div className='flex justify-center py-8'>
|
|
992
1158
|
<Loader2 className='h-5 w-5 animate-spin text-muted-foreground' />
|
|
@@ -994,42 +1160,60 @@ export function AddonConfigSurface({
|
|
|
994
1160
|
) : useStepper ? (
|
|
995
1161
|
/* WIZARD por pasos: indicador + un paso a la vez (sin card-in-card). */
|
|
996
1162
|
<div className='flex flex-col gap-5'>
|
|
997
|
-
{/*
|
|
998
|
-
|
|
999
|
-
<
|
|
1163
|
+
{/* Stepper: 44px targets, a check on done steps, an alert on a
|
|
1164
|
+
step with errors; the step title wraps (never truncated). */}
|
|
1165
|
+
<nav aria-label={st('wizard.steps')} className='flex flex-col gap-2'>
|
|
1000
1166
|
<ol className='flex items-center'>
|
|
1001
1167
|
{wizardSteps.map((s, i) => {
|
|
1002
|
-
const
|
|
1168
|
+
const status = stepState(i)
|
|
1003
1169
|
const active = i === stepIdx
|
|
1170
|
+
const title = t(s.title ?? '', { defaultValue: humanizeKey(s.title) })
|
|
1004
1171
|
return (
|
|
1005
1172
|
<li
|
|
1006
1173
|
key={s.key}
|
|
1007
|
-
className={cn(
|
|
1008
|
-
'flex items-center',
|
|
1009
|
-
i < wizardSteps.length - 1 && 'flex-1',
|
|
1010
|
-
)}
|
|
1174
|
+
className={cn('flex items-center', i < wizardSteps.length - 1 && 'flex-1')}
|
|
1011
1175
|
>
|
|
1012
1176
|
<button
|
|
1013
1177
|
type='button'
|
|
1014
|
-
onClick={() =>
|
|
1015
|
-
title={t(s.title ?? '', { defaultValue: humanizeKey(s.title) })}
|
|
1178
|
+
onClick={() => goToStep(i)}
|
|
1016
1179
|
aria-current={active ? 'step' : undefined}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1180
|
+
aria-label={st('wizard.step_label', {
|
|
1181
|
+
n: i + 1,
|
|
1182
|
+
total: totalSteps,
|
|
1183
|
+
title,
|
|
1184
|
+
status: st(`status.${status}`),
|
|
1185
|
+
})}
|
|
1186
|
+
data-step-status={status}
|
|
1187
|
+
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'
|
|
1025
1188
|
>
|
|
1026
|
-
|
|
1189
|
+
<span
|
|
1190
|
+
aria-hidden='true'
|
|
1191
|
+
className={cn(
|
|
1192
|
+
'flex h-8 w-8 items-center justify-center rounded-full border text-xs font-semibold transition-all',
|
|
1193
|
+
active
|
|
1194
|
+
? 'border-primary bg-primary text-primary-foreground ring-4 ring-primary/15'
|
|
1195
|
+
: status === 'error'
|
|
1196
|
+
? 'border-destructive bg-destructive/10 text-destructive'
|
|
1197
|
+
: status === 'ok'
|
|
1198
|
+
? 'border-primary bg-primary/10 text-primary'
|
|
1199
|
+
: 'border-border text-muted-foreground',
|
|
1200
|
+
)}
|
|
1201
|
+
>
|
|
1202
|
+
{!active && status === 'error' ? (
|
|
1203
|
+
<AlertCircle className='h-4 w-4' />
|
|
1204
|
+
) : !active && status === 'ok' ? (
|
|
1205
|
+
<Check className='h-4 w-4' />
|
|
1206
|
+
) : (
|
|
1207
|
+
i + 1
|
|
1208
|
+
)}
|
|
1209
|
+
</span>
|
|
1027
1210
|
</button>
|
|
1028
1211
|
{i < wizardSteps.length - 1 && (
|
|
1029
1212
|
<span
|
|
1213
|
+
aria-hidden='true'
|
|
1030
1214
|
className={cn(
|
|
1031
|
-
'mx-1
|
|
1032
|
-
|
|
1215
|
+
'mx-1 h-0.5 flex-1 rounded-full transition-colors',
|
|
1216
|
+
i < stepIdx ? 'bg-primary' : 'bg-border',
|
|
1033
1217
|
)}
|
|
1034
1218
|
/>
|
|
1035
1219
|
)}
|
|
@@ -1037,35 +1221,45 @@ export function AddonConfigSurface({
|
|
|
1037
1221
|
)
|
|
1038
1222
|
})}
|
|
1039
1223
|
</ol>
|
|
1040
|
-
<div className='flex items-
|
|
1041
|
-
<
|
|
1224
|
+
<div className='flex items-start justify-between gap-3'>
|
|
1225
|
+
<h3
|
|
1226
|
+
ref={stepHeadingRef}
|
|
1227
|
+
tabIndex={-1}
|
|
1228
|
+
className='min-w-0 text-base leading-snug font-semibold break-words outline-none'
|
|
1229
|
+
>
|
|
1042
1230
|
{t(activeStep?.title ?? '', {
|
|
1043
1231
|
defaultValue: humanizeKey(activeStep?.title),
|
|
1044
1232
|
})}
|
|
1045
|
-
</
|
|
1046
|
-
<span className='shrink-0 text-
|
|
1047
|
-
{stepIdx + 1
|
|
1233
|
+
</h3>
|
|
1234
|
+
<span className='mt-0.5 shrink-0 text-xs font-medium tabular-nums text-muted-foreground'>
|
|
1235
|
+
{st('flow.step_of', { n: stepIdx + 1, total: totalSteps })}
|
|
1048
1236
|
</span>
|
|
1049
1237
|
</div>
|
|
1050
|
-
</
|
|
1238
|
+
</nav>
|
|
1051
1239
|
|
|
1052
|
-
<div className='flex flex-col gap-
|
|
1240
|
+
<div className='flex flex-col gap-4'>
|
|
1053
1241
|
{activeStep?.description && (
|
|
1054
|
-
<
|
|
1055
|
-
|
|
1056
|
-
|
|
1242
|
+
<HelpText text={addonText(activeStep.description)} />
|
|
1243
|
+
)}
|
|
1244
|
+
{activeStep?.kind === 'settings' ? (
|
|
1245
|
+
settingsBody
|
|
1246
|
+
) : !canManageIssuer ? (
|
|
1247
|
+
<>
|
|
1248
|
+
{issuerAdminNote}
|
|
1249
|
+
{renderBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))}
|
|
1250
|
+
</>
|
|
1251
|
+
) : (
|
|
1252
|
+
<>
|
|
1253
|
+
{renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))}
|
|
1254
|
+
{credFields.filter((f) => f.section === activeStep?.key).map(renderCred)}
|
|
1255
|
+
{renderBlocks(trailBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))}
|
|
1256
|
+
</>
|
|
1057
1257
|
)}
|
|
1058
|
-
{activeStep?.kind === 'settings'
|
|
1059
|
-
? settingsBody
|
|
1060
|
-
: !canManageIssuer
|
|
1061
|
-
? issuerAdminNote
|
|
1062
|
-
: credFields
|
|
1063
|
-
.filter((f) => f.section === activeStep?.key)
|
|
1064
|
-
.map(renderCred)}
|
|
1065
1258
|
</div>
|
|
1066
1259
|
</div>
|
|
1067
1260
|
) : (
|
|
1068
1261
|
<>
|
|
1262
|
+
{oauthPanel}
|
|
1069
1263
|
{/* Credenciales */}
|
|
1070
1264
|
{hasCredentials && (
|
|
1071
1265
|
<section className='flex flex-col gap-3'>
|
|
@@ -1081,24 +1275,23 @@ export function AddonConfigSurface({
|
|
|
1081
1275
|
// form_layout: one titled group per section, in declared order.
|
|
1082
1276
|
layoutSections.map((sec) => {
|
|
1083
1277
|
const fields = credFields.filter((f) => f.section === sec.key)
|
|
1084
|
-
if (fields.length === 0) return null
|
|
1278
|
+
if (fields.length === 0 && (sec.blocks?.length ?? 0) === 0) return null
|
|
1085
1279
|
return (
|
|
1086
1280
|
<div
|
|
1087
1281
|
key={sec.key}
|
|
1088
1282
|
className='flex flex-col gap-3 rounded-md border border-border/60 px-3 py-3'
|
|
1089
1283
|
>
|
|
1090
1284
|
{sec.title && (
|
|
1091
|
-
<div>
|
|
1285
|
+
<div className='flex flex-col gap-1'>
|
|
1092
1286
|
<h4 className='text-sm font-medium'>
|
|
1093
1287
|
{t(sec.title, { defaultValue: sec.title })}
|
|
1094
1288
|
</h4>
|
|
1095
1289
|
{sec.description && (
|
|
1096
|
-
<
|
|
1097
|
-
{t(sec.description, { defaultValue: '' })}
|
|
1098
|
-
</p>
|
|
1290
|
+
<HelpText text={addonText(sec.description)} />
|
|
1099
1291
|
)}
|
|
1100
1292
|
</div>
|
|
1101
1293
|
)}
|
|
1294
|
+
{renderBlocks(leadBlocks(sec.blocks))}
|
|
1102
1295
|
{fields.map((f) => (
|
|
1103
1296
|
<ConnectorCredentialFieldControl
|
|
1104
1297
|
key={f.key}
|
|
@@ -1109,6 +1302,7 @@ export function AddonConfigSurface({
|
|
|
1109
1302
|
onChange={(val) => setCred(f.key, val)}
|
|
1110
1303
|
/>
|
|
1111
1304
|
))}
|
|
1305
|
+
{renderBlocks(trailBlocks(sec.blocks))}
|
|
1112
1306
|
</div>
|
|
1113
1307
|
)
|
|
1114
1308
|
})
|
|
@@ -1129,7 +1323,7 @@ export function AddonConfigSurface({
|
|
|
1129
1323
|
className='rounded-md border border-border/60 px-3 py-2'
|
|
1130
1324
|
open={advancedFields.some((f) => !!fieldErrors[f.key]) || undefined}
|
|
1131
1325
|
>
|
|
1132
|
-
<summary className='cursor-pointer
|
|
1326
|
+
<summary className='flex min-h-11 cursor-pointer items-center text-sm font-medium text-muted-foreground select-none sm:min-h-8'>
|
|
1133
1327
|
{st('installed_addons.advanced')}
|
|
1134
1328
|
</summary>
|
|
1135
1329
|
<div className='flex flex-col gap-3 pt-3'>
|
|
@@ -1151,6 +1345,9 @@ export function AddonConfigSurface({
|
|
|
1151
1345
|
</section>
|
|
1152
1346
|
)}
|
|
1153
1347
|
|
|
1348
|
+
{/* Verificación (probar conexión / sincronizar) al final de las credenciales. */}
|
|
1349
|
+
{extraBlocks.length > 0 && renderBlocks(extraBlocks)}
|
|
1350
|
+
|
|
1154
1351
|
{/* Ajustes */}
|
|
1155
1352
|
{hasSettings && (
|
|
1156
1353
|
<section className='flex flex-col gap-3'>
|
|
@@ -1165,10 +1362,11 @@ export function AddonConfigSurface({
|
|
|
1165
1362
|
</section>
|
|
1166
1363
|
)}
|
|
1167
1364
|
|
|
1168
|
-
{
|
|
1169
|
-
<
|
|
1170
|
-
{st('
|
|
1171
|
-
|
|
1365
|
+
{nothingToConfigure && (
|
|
1366
|
+
<div className='flex flex-col items-start gap-1 rounded-lg border border-dashed p-4'>
|
|
1367
|
+
<p className='text-sm font-medium'>{st('empty.title')}</p>
|
|
1368
|
+
<HelpText text={st('empty.help')} />
|
|
1369
|
+
</div>
|
|
1172
1370
|
)}
|
|
1173
1371
|
</>
|
|
1174
1372
|
)}
|
|
@@ -1184,79 +1382,45 @@ export function AddonConfigSurface({
|
|
|
1184
1382
|
</div>
|
|
1185
1383
|
) : null}
|
|
1186
1384
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
)
|
|
1198
|
-
<CheckCircle2 className='h-4 w-4 text-emerald-500' />
|
|
1199
|
-
) : testMutation.isError ||
|
|
1200
|
-
(testMutation.data && !testMutation.data.ok) ? (
|
|
1201
|
-
<XCircle className='h-4 w-4 text-destructive' />
|
|
1202
|
-
) : (
|
|
1203
|
-
<Plug className='h-4 w-4' />
|
|
1204
|
-
)}
|
|
1205
|
-
{st('installed_addons.test_connection', {
|
|
1206
|
-
defaultValue: 'Probar conexión',
|
|
1207
|
-
})}
|
|
1385
|
+
{/* Footer: always visible (outside the scroll). ONE primary action
|
|
1386
|
+
(Siguiente / Guardar) full width on phones, Atrás + Cancelar
|
|
1387
|
+
sharing the row below; a single right-aligned row from sm up.
|
|
1388
|
+
Verifications live inside the steps, not here. */}
|
|
1389
|
+
<DialogFooter
|
|
1390
|
+
data-wizard-footer=''
|
|
1391
|
+
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'
|
|
1392
|
+
>
|
|
1393
|
+
{nothingToSave ? (
|
|
1394
|
+
<Button className='col-span-2 h-11 sm:h-9' onClick={() => onOpenChange(false)}>
|
|
1395
|
+
{st('common.close')}
|
|
1208
1396
|
</Button>
|
|
1209
1397
|
) : (
|
|
1210
|
-
|
|
1211
|
-
)}
|
|
1212
|
-
{canSync ? (
|
|
1213
|
-
<Button
|
|
1214
|
-
variant='outline'
|
|
1215
|
-
onClick={() => syncMutation.mutate()}
|
|
1216
|
-
disabled={syncMutation.isPending}
|
|
1217
|
-
className='gap-2'
|
|
1218
|
-
>
|
|
1219
|
-
{syncMutation.isPending ? (
|
|
1220
|
-
<Loader2 className='h-4 w-4 animate-spin' />
|
|
1221
|
-
) : (
|
|
1222
|
-
<RefreshCw className='h-4 w-4' />
|
|
1223
|
-
)}
|
|
1224
|
-
{st('installed_addons.sync_now', { defaultValue: 'Sincronizar ahora' })}
|
|
1225
|
-
</Button>
|
|
1226
|
-
) : null}
|
|
1227
|
-
<div className='flex gap-2'>
|
|
1228
|
-
{useStepper && stepIdx > 0 && (
|
|
1398
|
+
<>
|
|
1229
1399
|
<Button
|
|
1230
|
-
|
|
1231
|
-
onClick={
|
|
1400
|
+
className='order-first col-span-2 h-11 sm:order-last sm:h-9'
|
|
1401
|
+
onClick={useStepper && !isLastStep ? handleNext : handleSave}
|
|
1402
|
+
disabled={!(useStepper && !isLastStep) && (saveMutation.isPending || loading)}
|
|
1232
1403
|
>
|
|
1233
|
-
{
|
|
1234
|
-
|
|
1235
|
-
)}
|
|
1236
|
-
<Button variant='outline' onClick={() => onOpenChange(false)}>
|
|
1237
|
-
{st('common.cancel')}
|
|
1238
|
-
</Button>
|
|
1239
|
-
{useStepper && !isLastStep ? (
|
|
1240
|
-
<Button onClick={() => setCurrentStep((s) => s + 1)}>
|
|
1241
|
-
{st('common.next', { defaultValue: 'Siguiente' })}
|
|
1404
|
+
{saveMutation.isPending && <Loader2 className='mr-2 h-4 w-4 animate-spin' />}
|
|
1405
|
+
{useStepper && !isLastStep ? st('common.next') : st('common.save')}
|
|
1242
1406
|
</Button>
|
|
1243
|
-
|
|
1407
|
+
{useStepper && stepIdx > 0 && (
|
|
1408
|
+
<Button variant='outline' className='h-11 sm:h-9' onClick={() => goToStep(Math.max(0, stepIdx - 1))}>
|
|
1409
|
+
{st('common.back')}
|
|
1410
|
+
</Button>
|
|
1411
|
+
)}
|
|
1244
1412
|
<Button
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
}
|
|
1413
|
+
variant='ghost'
|
|
1414
|
+
className={cn('h-11 sm:order-first sm:h-9', !(useStepper && stepIdx > 0) && 'col-span-2')}
|
|
1415
|
+
onClick={() => onOpenChange(false)}
|
|
1249
1416
|
>
|
|
1250
|
-
{
|
|
1251
|
-
<Loader2 className='mr-2 h-4 w-4 animate-spin' />
|
|
1252
|
-
)}
|
|
1253
|
-
{st('common.save')}
|
|
1417
|
+
{st('common.cancel')}
|
|
1254
1418
|
</Button>
|
|
1255
|
-
|
|
1256
|
-
|
|
1419
|
+
</>
|
|
1420
|
+
)}
|
|
1257
1421
|
</DialogFooter>
|
|
1258
1422
|
</ConnectorFormStateContext.Provider>
|
|
1259
1423
|
</DialogContent>
|
|
1260
1424
|
</Dialog>
|
|
1261
1425
|
)
|
|
1262
|
-
}
|
|
1426
|
+
}
|