@asteby/metacore-runtime-react 53.4.0 → 53.5.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/README.md +73 -0
- package/dist/display-value.d.ts +11 -0
- package/dist/display-value.d.ts.map +1 -1
- package/dist/display-value.js +26 -1
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +17 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/setup/addon-config-surface.d.ts +110 -0
- package/dist/setup/addon-config-surface.d.ts.map +1 -0
- package/dist/setup/addon-config-surface.js +553 -0
- package/dist/setup/connector-form-model.d.ts +40 -0
- package/dist/setup/connector-form-model.d.ts.map +1 -0
- package/dist/setup/connector-form-model.js +76 -0
- package/dist/setup/flow-model.d.ts +49 -0
- package/dist/setup/flow-model.d.ts.map +1 -0
- package/dist/setup/flow-model.js +124 -0
- package/dist/setup/health-card.d.ts +25 -0
- package/dist/setup/health-card.d.ts.map +1 -0
- package/dist/setup/health-card.js +21 -0
- package/dist/setup/index.d.ts +11 -0
- package/dist/setup/index.d.ts.map +1 -0
- package/dist/setup/index.js +13 -0
- package/dist/setup/messages.d.ts +15 -0
- package/dist/setup/messages.d.ts.map +1 -0
- package/dist/setup/messages.js +249 -0
- package/dist/setup/records-table.d.ts +24 -0
- package/dist/setup/records-table.d.ts.map +1 -0
- package/dist/setup/records-table.js +80 -0
- package/dist/setup/setup-flow.d.ts +30 -0
- package/dist/setup/setup-flow.d.ts.map +1 -0
- package/dist/setup/setup-flow.js +277 -0
- package/dist/setup/setup-form-step.d.ts +20 -0
- package/dist/setup/setup-form-step.d.ts.map +1 -0
- package/dist/setup/setup-form-step.js +173 -0
- package/dist/setup/step-status-badge.d.ts +12 -0
- package/dist/setup/step-status-badge.d.ts.map +1 -0
- package/dist/setup/step-status-badge.js +21 -0
- package/dist/setup/tone.d.ts +8 -0
- package/dist/setup/tone.d.ts.map +1 -0
- package/dist/setup/tone.js +33 -0
- package/dist/setup/types.d.ts +130 -0
- package/dist/setup/types.d.ts.map +1 -0
- package/dist/setup/types.js +1 -0
- package/package.json +5 -1
- package/src/__tests__/addon-config-surface.test.tsx +248 -0
- package/src/__tests__/image-stack.test.tsx +58 -1
- package/src/__tests__/setup-components.test.tsx +147 -0
- package/src/__tests__/setup-flow-model.test.ts +117 -0
- package/src/__tests__/setup-flow.test.tsx +424 -0
- package/src/display-value.tsx +30 -1
- package/src/dynamic-columns.tsx +21 -5
- package/src/index.ts +25 -0
- package/src/setup/addon-config-surface.tsx +1262 -0
- package/src/setup/connector-form-model.ts +115 -0
- package/src/setup/flow-model.ts +156 -0
- package/src/setup/health-card.tsx +131 -0
- package/src/setup/index.ts +23 -0
- package/src/setup/messages.ts +263 -0
- package/src/setup/records-table.tsx +186 -0
- package/src/setup/setup-flow.tsx +562 -0
- package/src/setup/setup-form-step.tsx +342 -0
- package/src/setup/step-status-badge.tsx +47 -0
- package/src/setup/tone.ts +44 -0
- package/src/setup/types.ts +147 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Pure helpers for the connector credentials form (no React, no i18n instance):
|
|
2
|
+
// shape detection of pasted values, save-error parsing and required-field
|
|
3
|
+
// checks. Kept free of any provider name on purpose: the rules look at the
|
|
4
|
+
// SHAPE of a value and at how the form's own fields are declared, so every
|
|
5
|
+
// connector (any addon) benefits and none is special-cased.
|
|
6
|
+
|
|
7
|
+
/** The minimum a credential definition needs for these helpers. */
|
|
8
|
+
export interface CredentialLike {
|
|
9
|
+
key: string
|
|
10
|
+
label?: string
|
|
11
|
+
required?: boolean
|
|
12
|
+
secret?: boolean
|
|
13
|
+
type?: string
|
|
14
|
+
default?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CredentialShape = 'public_key' | 'secret_key'
|
|
18
|
+
|
|
19
|
+
const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
|
|
20
|
+
// Public (publishable) keys are short identifiers: "<PREFIX>-<uuid>" or the
|
|
21
|
+
// pk_live_/pk_test_ family. Server-side tokens are longer, numeric/hex blobs
|
|
22
|
+
// or sk_/rk_ prefixed. These are generic conventions, not one provider's.
|
|
23
|
+
const PUBLIC_SHAPES = [new RegExp(`^(?:[A-Z_]+-)?${UUID}$`, 'i'), /^pk_(?:live|test)_[A-Za-z0-9]+$/]
|
|
24
|
+
const SECRET_SHAPES = [/^(?:sk|rk)_(?:live|test)_[A-Za-z0-9]+$/, /^[A-Z_]+-\d{6,}-\d{4,}-[0-9a-f]{16,}-\d+$/i]
|
|
25
|
+
|
|
26
|
+
/** What a pasted value looks like, or null when it is not recognisable. */
|
|
27
|
+
export function credentialShape(raw: string): CredentialShape | null {
|
|
28
|
+
const v = raw.trim()
|
|
29
|
+
if (!v) return null
|
|
30
|
+
if (PUBLIC_SHAPES.some((r) => r.test(v))) return 'public_key'
|
|
31
|
+
if (SECRET_SHAPES.some((r) => r.test(v))) return 'secret_key'
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const isSecretCredential = (f: CredentialLike) => !!f.secret || f.type === 'secret'
|
|
36
|
+
|
|
37
|
+
const looksPublic = (f: CredentialLike) => /public|publishable|client_id/i.test(f.key)
|
|
38
|
+
|
|
39
|
+
export interface ShapeMismatch {
|
|
40
|
+
/** What the value looks like. */
|
|
41
|
+
shape: CredentialShape
|
|
42
|
+
/** The sibling field the value probably belongs to, when the form has one. */
|
|
43
|
+
suggestedKey?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A value pasted in the wrong box: a public key in the secret token field, or
|
|
48
|
+
* a secret in the public-key field. Only a warning (never blocks), and only
|
|
49
|
+
* raised when the form really has a field for what the value looks like.
|
|
50
|
+
*/
|
|
51
|
+
export function shapeMismatch(
|
|
52
|
+
field: CredentialLike,
|
|
53
|
+
value: string,
|
|
54
|
+
fields: CredentialLike[],
|
|
55
|
+
): ShapeMismatch | null {
|
|
56
|
+
const shape = credentialShape(value)
|
|
57
|
+
if (!shape) return null
|
|
58
|
+
const siblings = fields.filter((f) => f.key !== field.key)
|
|
59
|
+
if (shape === 'public_key' && isSecretCredential(field) && !looksPublic(field)) {
|
|
60
|
+
const target = siblings.find(looksPublic)
|
|
61
|
+
return target ? { shape, suggestedKey: target.key } : null
|
|
62
|
+
}
|
|
63
|
+
if (shape === 'secret_key' && looksPublic(field)) {
|
|
64
|
+
const target = siblings.find((f) => isSecretCredential(f) && !looksPublic(f))
|
|
65
|
+
return target ? { shape, suggestedKey: target.key } : null
|
|
66
|
+
}
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Required fields still empty. A stored secret (connected) counts as filled. */
|
|
71
|
+
export function missingRequired(
|
|
72
|
+
fields: CredentialLike[],
|
|
73
|
+
values: Record<string, string>,
|
|
74
|
+
connected: boolean,
|
|
75
|
+
): string[] {
|
|
76
|
+
return fields
|
|
77
|
+
.filter((f) => f.required)
|
|
78
|
+
.filter((f) => !(values[f.key] ?? '').trim())
|
|
79
|
+
.filter((f) => !(connected && isSecretCredential(f)))
|
|
80
|
+
.filter((f) => !(f.default != null && f.default !== ''))
|
|
81
|
+
.map((f) => f.key)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface SaveError {
|
|
85
|
+
/** The complete server message, never shortened. */
|
|
86
|
+
message: string
|
|
87
|
+
/** Fields the server (or the client check) says need attention. */
|
|
88
|
+
fieldKeys: string[]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Reads the kernel/ops error envelope: {message, errors: {field: [{code}]}}. */
|
|
92
|
+
export function parseSaveError(err: unknown, fallback: string): SaveError {
|
|
93
|
+
const data = (err as { response?: { data?: { message?: unknown; errors?: unknown } } })?.response
|
|
94
|
+
?.data
|
|
95
|
+
const message =
|
|
96
|
+
typeof data?.message === 'string' && data.message.trim() ? data.message.trim() : fallback
|
|
97
|
+
const errors = data?.errors
|
|
98
|
+
const fieldKeys =
|
|
99
|
+
errors && typeof errors === 'object' && !Array.isArray(errors) ? Object.keys(errors) : []
|
|
100
|
+
return { message, fieldKeys }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Never show a raw dotted key: fall back to `fallback` when the text is the key. */
|
|
104
|
+
export function textOrFallback(text: string | undefined, key: string, fallback: string): string {
|
|
105
|
+
if (!text || text === key) return fallback
|
|
106
|
+
return text
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Cheap content hash so a re-published bundle with the same key count re-merges. */
|
|
110
|
+
export function bundleSignature(labels: Record<string, unknown>): string {
|
|
111
|
+
let h = 5381
|
|
112
|
+
const s = JSON.stringify(labels)
|
|
113
|
+
for (let i = 0; i < s.length; i++) h = ((h << 5) + h + s.charCodeAt(i)) | 0
|
|
114
|
+
return `${Object.keys(labels).length}:${(h >>> 0).toString(36)}`
|
|
115
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Pure logic of a setup flow (no React): effective status with `depends_on`,
|
|
2
|
+
// which step is active, progress, completion and the polling cadence. Kept
|
|
3
|
+
// apart so it is tested without rendering anything.
|
|
4
|
+
import type { SetupFlowState, SetupStepDef, SetupStepState, StepStatus } from './types'
|
|
5
|
+
|
|
6
|
+
export const STEP_STATUSES: StepStatus[] = ['pending', 'running', 'ok', 'warn', 'error', 'blocked']
|
|
7
|
+
|
|
8
|
+
/** Accepts the array or the by-key map the server may send. */
|
|
9
|
+
export function normalizeState(raw: SetupFlowState | null | undefined): Record<string, SetupStepState> {
|
|
10
|
+
const out: Record<string, SetupStepState> = {}
|
|
11
|
+
const steps = raw?.steps
|
|
12
|
+
if (!steps) return out
|
|
13
|
+
if (Array.isArray(steps)) {
|
|
14
|
+
for (const s of steps) if (s?.key) out[s.key] = s
|
|
15
|
+
} else {
|
|
16
|
+
for (const [k, s] of Object.entries(steps)) if (s) out[k] = { ...s, key: s.key ?? k }
|
|
17
|
+
}
|
|
18
|
+
return out
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A step counts as satisfied (unblocks dependants) when ok, warn or skipped. */
|
|
22
|
+
export function isSatisfied(st: SetupStepState | undefined): boolean {
|
|
23
|
+
if (!st) return false
|
|
24
|
+
return st.status === 'ok' || st.status === 'warn' || st.skipped === true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Steps this one waits on that are not satisfied yet. */
|
|
28
|
+
export function unmetDependencies(
|
|
29
|
+
def: SetupStepDef,
|
|
30
|
+
states: Record<string, SetupStepState>,
|
|
31
|
+
): string[] {
|
|
32
|
+
return (def.depends_on ?? []).filter((k) => !isSatisfied(states[k]))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Status shown for a step: the server's, except that a step whose
|
|
37
|
+
* dependencies are unmet is `blocked` (unless it is already running/ok, which
|
|
38
|
+
* the server decides). A skipped step reads as `ok`.
|
|
39
|
+
*/
|
|
40
|
+
export function effectiveStatus(
|
|
41
|
+
def: SetupStepDef,
|
|
42
|
+
states: Record<string, SetupStepState>,
|
|
43
|
+
): StepStatus {
|
|
44
|
+
const st = states[def.key]
|
|
45
|
+
if (st?.skipped) return 'ok'
|
|
46
|
+
const own = st?.status ?? 'pending'
|
|
47
|
+
if (own === 'ok' || own === 'running') return own
|
|
48
|
+
if (unmetDependencies(def, states).length > 0) return 'blocked'
|
|
49
|
+
return own === 'blocked' ? 'pending' : own
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** First step that needs the person: not satisfied and not blocked; else the last. */
|
|
53
|
+
export function pickActiveStep(
|
|
54
|
+
defs: SetupStepDef[],
|
|
55
|
+
states: Record<string, SetupStepState>,
|
|
56
|
+
): string | undefined {
|
|
57
|
+
if (defs.length === 0) return undefined
|
|
58
|
+
const open = defs.find((d) => {
|
|
59
|
+
const eff = effectiveStatus(d, states)
|
|
60
|
+
return eff !== 'blocked' && !isSatisfied(states[d.key])
|
|
61
|
+
})
|
|
62
|
+
return (open ?? defs[defs.length - 1]).key
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface FlowProgress {
|
|
66
|
+
done: number
|
|
67
|
+
total: number
|
|
68
|
+
percent: number
|
|
69
|
+
complete: boolean
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Progress over the REQUIRED steps (optional ones do not hold completion
|
|
74
|
+
* back, but count as done when they are). The flow is complete when every
|
|
75
|
+
* required step is satisfied; an error step is never satisfied.
|
|
76
|
+
*/
|
|
77
|
+
export function flowProgress(
|
|
78
|
+
defs: SetupStepDef[],
|
|
79
|
+
states: Record<string, SetupStepState>,
|
|
80
|
+
serverCompleted?: boolean,
|
|
81
|
+
): FlowProgress {
|
|
82
|
+
const required = defs.filter((d) => !d.optional)
|
|
83
|
+
const total = required.length
|
|
84
|
+
const done = required.filter((d) => isSatisfied(states[d.key])).length
|
|
85
|
+
const complete = serverCompleted === true || (total > 0 && done === total)
|
|
86
|
+
const shown = serverCompleted === true ? total : done
|
|
87
|
+
return {
|
|
88
|
+
done: shown,
|
|
89
|
+
total,
|
|
90
|
+
percent: total === 0 ? 100 : Math.round((shown / total) * 100),
|
|
91
|
+
complete,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface BackoffOptions {
|
|
96
|
+
baseMs?: number
|
|
97
|
+
factor?: number
|
|
98
|
+
maxMs?: number
|
|
99
|
+
/** Ceiling honoured for a server `retry_after_s`. */
|
|
100
|
+
maxRetryAfterMs?: number
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Delay before the next poll. Without a hint: exponential from `baseMs`
|
|
105
|
+
* (2s, 3.2s, 5.1s…) capped at `maxMs` (30s). A server `retry_after_s` wins,
|
|
106
|
+
* but never below 1s nor above `maxRetryAfterMs` (5 min).
|
|
107
|
+
*/
|
|
108
|
+
export function nextPollDelayMs(
|
|
109
|
+
attempt: number,
|
|
110
|
+
retryAfterS?: number,
|
|
111
|
+
opts: BackoffOptions = {},
|
|
112
|
+
): number {
|
|
113
|
+
const { baseMs = 2000, factor = 1.6, maxMs = 30000, maxRetryAfterMs = 300000 } = opts
|
|
114
|
+
if (typeof retryAfterS === 'number' && Number.isFinite(retryAfterS) && retryAfterS > 0) {
|
|
115
|
+
return Math.min(Math.max(retryAfterS * 1000, 1000), maxRetryAfterMs)
|
|
116
|
+
}
|
|
117
|
+
const n = Math.max(0, Math.floor(attempt))
|
|
118
|
+
return Math.min(Math.round(baseMs * Math.pow(factor, n)), maxMs)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Only http(s) and app-relative paths may be opened from a `fix.url`. */
|
|
122
|
+
export function safeUrl(url: string | undefined): string | null {
|
|
123
|
+
if (!url) return null
|
|
124
|
+
const u = url.trim()
|
|
125
|
+
// Browsers strip tabs/newlines and treat `\` as `/`, so `/\evil.com` or
|
|
126
|
+
// `/<TAB>/evil.com` resolve to another host: reject control chars and
|
|
127
|
+
// backslashes outright, then require the resolved origin to be ours.
|
|
128
|
+
// eslint-disable-next-line no-control-regex
|
|
129
|
+
if (/[\\\u0000-\u001f\u007f]/.test(u)) return null
|
|
130
|
+
if (u.startsWith('/')) {
|
|
131
|
+
if (u.startsWith('//')) return null
|
|
132
|
+
const origin = typeof location !== 'undefined' && location.origin ? location.origin : 'http://localhost'
|
|
133
|
+
try {
|
|
134
|
+
return new URL(u, origin).origin === origin ? u : null
|
|
135
|
+
} catch {
|
|
136
|
+
return null
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const p = new URL(u)
|
|
141
|
+
return p.protocol === 'https:' || p.protocol === 'http:' ? p.toString() : null
|
|
142
|
+
} catch {
|
|
143
|
+
return null
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Merges a runStep/skipStep answer (step or whole flow) into the local map. */
|
|
148
|
+
export function mergeAnswer(
|
|
149
|
+
current: Record<string, SetupStepState>,
|
|
150
|
+
key: string,
|
|
151
|
+
answer: SetupStepState | SetupFlowState | void | undefined,
|
|
152
|
+
): { next: Record<string, SetupStepState>; needsRefetch: boolean } {
|
|
153
|
+
if (!answer) return { next: current, needsRefetch: true }
|
|
154
|
+
if ('steps' in answer) return { next: normalizeState(answer), needsRefetch: false }
|
|
155
|
+
return { next: { ...current, [key]: { ...answer, key: answer.key ?? key } }, needsRefetch: false }
|
|
156
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { AlertTriangle, CheckCircle2, HelpCircle, Info, RefreshCw, XCircle } from 'lucide-react'
|
|
2
|
+
import { Button } from '@asteby/metacore-ui/primitives'
|
|
3
|
+
import { cn } from '@asteby/metacore-ui/lib'
|
|
4
|
+
import { useSetupT } from './messages'
|
|
5
|
+
import { TONE_BADGE, TONE_TEXT, metricTone, type Tone } from './tone'
|
|
6
|
+
import type { DiagnosticSeverity, HealthIssue, HealthMetric, HealthStatus, SetupFix } from './types'
|
|
7
|
+
|
|
8
|
+
const STATUS_TONE: Record<HealthStatus, Tone> = { ok: 'good', warn: 'warn', error: 'bad', unknown: 'neutral' }
|
|
9
|
+
const STATUS_ICON = { ok: CheckCircle2, warn: AlertTriangle, error: XCircle, unknown: HelpCircle } as const
|
|
10
|
+
const SEVERITY_ICON: Record<DiagnosticSeverity, typeof Info> = { info: Info, warn: AlertTriangle, error: XCircle }
|
|
11
|
+
const SEVERITY_TONE: Record<DiagnosticSeverity, Tone> = { info: 'info', warn: 'warn', error: 'bad' }
|
|
12
|
+
|
|
13
|
+
export interface HealthCardProps {
|
|
14
|
+
title?: string
|
|
15
|
+
status: HealthStatus
|
|
16
|
+
/** One line under the status. */
|
|
17
|
+
summary?: string
|
|
18
|
+
metrics?: HealthMetric[]
|
|
19
|
+
issues?: HealthIssue[]
|
|
20
|
+
/** ISO date or preformatted text shown as "Checked …". */
|
|
21
|
+
checkedAt?: string
|
|
22
|
+
/** Setup progress, for a card in the installed-addons list. */
|
|
23
|
+
progress?: { done: number; total: number }
|
|
24
|
+
onFix?: (fix: SetupFix, issue: HealthIssue) => void
|
|
25
|
+
onRefresh?: () => void
|
|
26
|
+
refreshing?: boolean
|
|
27
|
+
/** Shows "Continue setup" (resumes the setup page). */
|
|
28
|
+
onContinue?: () => void
|
|
29
|
+
className?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Status + metrics (with tone) + issues (with fix) of an addon's health probe. */
|
|
33
|
+
export function HealthCard({
|
|
34
|
+
title,
|
|
35
|
+
status,
|
|
36
|
+
summary,
|
|
37
|
+
metrics,
|
|
38
|
+
issues,
|
|
39
|
+
checkedAt,
|
|
40
|
+
progress,
|
|
41
|
+
onFix,
|
|
42
|
+
onRefresh,
|
|
43
|
+
refreshing,
|
|
44
|
+
onContinue,
|
|
45
|
+
className,
|
|
46
|
+
}: HealthCardProps) {
|
|
47
|
+
const t = useSetupT()
|
|
48
|
+
const known: HealthStatus = status in STATUS_TONE ? status : 'unknown'
|
|
49
|
+
const Icon = STATUS_ICON[known]
|
|
50
|
+
const pct = progress && progress.total > 0 ? Math.round((progress.done / progress.total) * 100) : null
|
|
51
|
+
return (
|
|
52
|
+
<section className={cn('flex flex-col gap-4 rounded-lg border bg-card p-4 text-card-foreground', className)} aria-label={title ?? t('health.metrics')}>
|
|
53
|
+
<header className='flex flex-wrap items-start justify-between gap-3'>
|
|
54
|
+
<div className='min-w-0'>
|
|
55
|
+
{title ? <h3 className='truncate text-sm font-semibold'>{title}</h3> : null}
|
|
56
|
+
<div className='flex items-center gap-2 pt-1'>
|
|
57
|
+
<span data-health-status={known} className={cn('inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium', TONE_BADGE[STATUS_TONE[known]])}>
|
|
58
|
+
<Icon className='h-3.5 w-3.5' aria-hidden='true' />
|
|
59
|
+
{t(`health.status.${known}`)}
|
|
60
|
+
</span>
|
|
61
|
+
{checkedAt ? <span className='text-xs text-muted-foreground'>{t('health.checked_at', { when: checkedAt })}</span> : null}
|
|
62
|
+
</div>
|
|
63
|
+
{summary ? <p className='pt-2 text-sm text-muted-foreground'>{summary}</p> : null}
|
|
64
|
+
</div>
|
|
65
|
+
<div className='flex items-center gap-2'>
|
|
66
|
+
{onRefresh ? (
|
|
67
|
+
<Button type='button' variant='outline' size='sm' onClick={onRefresh} disabled={refreshing} className='gap-2'>
|
|
68
|
+
<RefreshCw className={cn('h-3.5 w-3.5', refreshing && 'animate-spin motion-reduce:animate-none')} aria-hidden='true' />
|
|
69
|
+
{t('health.refresh')}
|
|
70
|
+
</Button>
|
|
71
|
+
) : null}
|
|
72
|
+
{onContinue ? (
|
|
73
|
+
<Button type='button' size='sm' onClick={onContinue}>
|
|
74
|
+
{t('health.continue')}
|
|
75
|
+
</Button>
|
|
76
|
+
) : null}
|
|
77
|
+
</div>
|
|
78
|
+
</header>
|
|
79
|
+
|
|
80
|
+
{pct !== null && progress ? (
|
|
81
|
+
<div className='flex flex-col gap-1'>
|
|
82
|
+
<div role='progressbar' aria-valuemin={0} aria-valuemax={100} aria-valuenow={pct} aria-label={t('flow.progress')} className='h-1.5 w-full overflow-hidden rounded-full bg-muted'>
|
|
83
|
+
<div className='h-full rounded-full bg-primary transition-all motion-reduce:transition-none' style={{ width: `${pct}%` }} />
|
|
84
|
+
</div>
|
|
85
|
+
<span className='text-xs text-muted-foreground'>{t('health.progress', { done: progress.done, total: progress.total })}</span>
|
|
86
|
+
</div>
|
|
87
|
+
) : null}
|
|
88
|
+
|
|
89
|
+
{metrics && metrics.length > 0 ? (
|
|
90
|
+
<dl className='grid grid-cols-2 gap-3 sm:grid-cols-3'>
|
|
91
|
+
{metrics.map((m) => (
|
|
92
|
+
<div key={m.key} className='min-w-0 rounded-md border px-3 py-2' data-metric-tone={metricTone(m.tone)}>
|
|
93
|
+
<dt className='truncate text-xs text-muted-foreground'>{m.label}</dt>
|
|
94
|
+
<dd className={cn('truncate text-lg font-semibold tabular-nums', TONE_TEXT[metricTone(m.tone)])}>
|
|
95
|
+
{m.value}
|
|
96
|
+
{m.unit ? <span className='pl-1 text-xs font-normal text-muted-foreground'>{m.unit}</span> : null}
|
|
97
|
+
</dd>
|
|
98
|
+
{m.hint ? <p className='truncate text-xs text-muted-foreground'>{m.hint}</p> : null}
|
|
99
|
+
</div>
|
|
100
|
+
))}
|
|
101
|
+
</dl>
|
|
102
|
+
) : null}
|
|
103
|
+
|
|
104
|
+
{issues && issues.length > 0 ? (
|
|
105
|
+
<ul className='flex flex-col gap-2' aria-label={t('health.issues')}>
|
|
106
|
+
{issues.map((is, i) => {
|
|
107
|
+
const SevIcon = SEVERITY_ICON[is.severity] ?? Info
|
|
108
|
+
return (
|
|
109
|
+
<li key={is.id ?? i} className='flex flex-wrap items-start justify-between gap-2 rounded-md border px-3 py-2' data-severity={is.severity}>
|
|
110
|
+
<div className='flex min-w-0 flex-1 items-start gap-2'>
|
|
111
|
+
<SevIcon className={cn('mt-0.5 h-4 w-4 shrink-0', TONE_TEXT[SEVERITY_TONE[is.severity] ?? 'info'])} aria-hidden='true' />
|
|
112
|
+
<p className='min-w-0 text-sm'>
|
|
113
|
+
{is.message}
|
|
114
|
+
{is.detail ? <span className='block break-words text-xs text-muted-foreground'>{is.detail}</span> : null}
|
|
115
|
+
</p>
|
|
116
|
+
</div>
|
|
117
|
+
{is.fix && onFix ? (
|
|
118
|
+
<Button type='button' size='sm' variant='outline' className='h-7' onClick={() => onFix(is.fix!, is)}>
|
|
119
|
+
{is.fix.label ?? t('flow.fix')}
|
|
120
|
+
</Button>
|
|
121
|
+
) : null}
|
|
122
|
+
</li>
|
|
123
|
+
)
|
|
124
|
+
})}
|
|
125
|
+
</ul>
|
|
126
|
+
) : issues ? (
|
|
127
|
+
<p className='text-sm text-muted-foreground'>{t('health.no_issues')}</p>
|
|
128
|
+
) : null}
|
|
129
|
+
</section>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Setup flow + health components (kernel `contributions.setup` / `.health`) and
|
|
2
|
+
// the unified addon configuration surface. Import from the package root or from
|
|
3
|
+
// `@asteby/metacore-runtime-react/setup` to pull only this slice.
|
|
4
|
+
export * from './types'
|
|
5
|
+
export * from './flow-model'
|
|
6
|
+
export { useSetupT, SETUP_MESSAGES_ES, SETUP_MESSAGES_EN } from './messages'
|
|
7
|
+
export { StepStatusBadge, type StepStatusBadgeProps } from './step-status-badge'
|
|
8
|
+
export { RecordsTable, copyText, type RecordsTableProps } from './records-table'
|
|
9
|
+
export { HealthCard, type HealthCardProps } from './health-card'
|
|
10
|
+
export { SetupFlow, type SetupFlowProps, type SetupCustomStepProps } from './setup-flow'
|
|
11
|
+
export { SetupFormStep, type SetupFormStepProps } from './setup-form-step'
|
|
12
|
+
export {
|
|
13
|
+
AddonConfigSurface,
|
|
14
|
+
clearConnectorLookupCache,
|
|
15
|
+
type AddonConfigSurfaceProps,
|
|
16
|
+
type AddonConfigAddon,
|
|
17
|
+
type AddonConfigNotifier,
|
|
18
|
+
type AddonSettingDef,
|
|
19
|
+
type ConnectorEntry,
|
|
20
|
+
type ConnectorCredentialField,
|
|
21
|
+
type ConnectorFormLayout,
|
|
22
|
+
} from './addon-config-surface'
|
|
23
|
+
export * from './connector-form-model'
|