@asteby/metacore-runtime-react 53.6.0 → 53.8.1
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 +38 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +3 -1
- package/dist/api-context.d.ts.map +1 -1
- package/dist/api-context.js +15 -0
- package/dist/cache-scope.d.ts +52 -0
- package/dist/cache-scope.d.ts.map +1 -0
- package/dist/cache-scope.js +200 -0
- package/dist/capability-providers/index.d.ts +4 -0
- package/dist/capability-providers/index.d.ts.map +1 -0
- package/dist/capability-providers/index.js +3 -0
- package/dist/capability-providers/model.d.ts +201 -0
- package/dist/capability-providers/model.d.ts.map +1 -0
- package/dist/capability-providers/model.js +293 -0
- package/dist/capability-providers/provider-sortable-list.d.ts +86 -0
- package/dist/capability-providers/provider-sortable-list.d.ts.map +1 -0
- package/dist/capability-providers/provider-sortable-list.js +263 -0
- package/dist/capability-providers/reorder.d.ts +10 -0
- package/dist/capability-providers/reorder.d.ts.map +1 -0
- package/dist/capability-providers/reorder.js +31 -0
- package/dist/dashboard-types.d.ts +2 -4
- package/dist/dashboard-types.d.ts.map +1 -1
- package/dist/dynamic-kanban.d.ts.map +1 -1
- package/dist/dynamic-kanban.js +9 -4
- package/dist/dynamic-relation.d.ts.map +1 -1
- package/dist/dynamic-relation.js +5 -2
- package/dist/dynamic-table.d.ts +2 -0
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +40 -6
- package/dist/dynamic-view.d.ts.map +1 -1
- package/dist/dynamic-view.js +3 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/metadata-cache.d.ts +22 -2
- package/dist/metadata-cache.d.ts.map +1 -1
- package/dist/metadata-cache.js +73 -13
- package/dist/query-batch.d.ts +12 -0
- package/dist/query-batch.d.ts.map +1 -1
- package/dist/query-batch.js +70 -29
- package/dist/setup/addon-config-surface.d.ts +7 -1
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +128 -10
- package/dist/setup/messages.d.ts.map +1 -1
- package/dist/setup/messages.js +10 -0
- package/dist/use-option-ids.d.ts.map +1 -1
- package/dist/use-option-ids.js +3 -1
- package/dist/use-options-resolver.d.ts +4 -1
- package/dist/use-options-resolver.d.ts.map +1 -1
- package/dist/use-options-resolver.js +27 -16
- package/dist/widgets/charts.d.ts.map +1 -1
- package/dist/widgets/charts.js +11 -43
- package/dist/widgets/widget-format.d.ts +1 -41
- package/dist/widgets/widget-format.d.ts.map +1 -1
- package/dist/widgets/widget-format.js +3 -138
- package/package.json +4 -4
- package/src/__tests__/addon-config-surface.test.tsx +55 -0
- package/src/__tests__/charts-reexport.test.ts +30 -0
- package/src/action-modal-dispatcher.tsx +3 -1
- package/src/api-context.tsx +14 -0
- package/src/cache-scope-inflight.test.ts +369 -0
- package/src/cache-scope.test.ts +234 -0
- package/src/cache-scope.ts +202 -0
- package/src/capability-providers/index.ts +46 -0
- package/src/capability-providers/model.test.ts +186 -0
- package/src/capability-providers/model.ts +464 -0
- package/src/capability-providers/provider-sortable-list.test.tsx +284 -0
- package/src/capability-providers/provider-sortable-list.tsx +452 -0
- package/src/capability-providers/reorder.ts +29 -0
- package/src/dashboard-types.ts +2 -11
- package/src/dynamic-kanban.tsx +9 -4
- package/src/dynamic-relation.tsx +5 -2
- package/src/dynamic-table.tsx +41 -10
- package/src/dynamic-view.tsx +3 -1
- package/src/index.ts +13 -0
- package/src/metadata-cache.ts +85 -15
- package/src/query-batch.ts +71 -30
- package/src/setup/addon-config-surface.tsx +202 -18
- package/src/setup/messages.ts +10 -0
- package/src/use-option-ids.ts +3 -1
- package/src/use-options-resolver.ts +28 -15
- package/src/widgets/charts.tsx +26 -189
- package/src/widgets/widget-format.ts +14 -181
- package/vitest.setup.ts +16 -0
|
@@ -17,7 +17,7 @@ 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 { AlertCircle, Cable, Check, Link2, Loader2, RefreshCw, Settings } from 'lucide-react';
|
|
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';
|
|
@@ -50,7 +50,7 @@ const ConnectorFormStateContext = createContext({
|
|
|
50
50
|
idPrefix: 'addon-config',
|
|
51
51
|
expectedOptionKinds: {},
|
|
52
52
|
});
|
|
53
|
-
function ConnectorCredentialFieldControl({ field, value, connected, provider, onChange, }) {
|
|
53
|
+
function ConnectorCredentialFieldControl({ field, value, connected, provider, onChange, stored = false, onReveal, resetKey, }) {
|
|
54
54
|
const { t } = useTranslation();
|
|
55
55
|
const st = useSetupT();
|
|
56
56
|
const form = useContext(ConnectorFormStateContext);
|
|
@@ -64,6 +64,58 @@ function ConnectorCredentialFieldControl({ field, value, connected, provider, on
|
|
|
64
64
|
: '';
|
|
65
65
|
const isSecret = isSecretCredential(field);
|
|
66
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
|
+
};
|
|
67
119
|
const error = form.errors[field.key];
|
|
68
120
|
const mismatch = shapeMismatch(field, value, form.fields);
|
|
69
121
|
const target = mismatch?.suggestedKey
|
|
@@ -74,10 +126,11 @@ function ConnectorCredentialFieldControl({ field, value, connected, provider, on
|
|
|
74
126
|
? 'installed_addons.shape_public_key'
|
|
75
127
|
: 'installed_addons.shape_secret_key', { target: target ? labelOf(target) : '' })
|
|
76
128
|
: '';
|
|
77
|
-
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',
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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] }));
|
|
81
134
|
}
|
|
82
135
|
// useApi() hands every component its own wrapper object, so the cache cannot be
|
|
83
136
|
// keyed by client: it is module-level, keyed by provider + export, and dropped
|
|
@@ -163,7 +216,7 @@ function DynamicConnectorSelect({ field, value, provider, connected, onChange, }
|
|
|
163
216
|
// Fixed header + footer, scrollable body — a connector can declare many fields
|
|
164
217
|
// (env, keys, RFC, régimen, CP, base_url, stamp/cancel path) that would
|
|
165
218
|
// otherwise overflow the viewport.
|
|
166
|
-
export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSaved, canManageIssuer = true, activeBranch = null, ensureAddonBundle, notify = toast, client, expectedOptionKinds = NO_OPTION_KINDS, displayName, onConnectOAuth, }) {
|
|
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, }) {
|
|
167
220
|
const idPrefix = useId();
|
|
168
221
|
const { t, i18n } = useTranslation();
|
|
169
222
|
const st = useSetupT();
|
|
@@ -198,6 +251,14 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
198
251
|
// credentials not saved yet (an action tests what is STORED: it saves first).
|
|
199
252
|
const [blockResults, setBlockResults] = useState({});
|
|
200
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] ?? '') : '';
|
|
201
262
|
const stepHeadingRef = useRef(null);
|
|
202
263
|
const stepMoved = useRef(false);
|
|
203
264
|
const setCred = (key, val) => {
|
|
@@ -258,6 +319,9 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
258
319
|
setFieldErrors({});
|
|
259
320
|
setBlockResults({});
|
|
260
321
|
setCredDirty(false);
|
|
322
|
+
setStoredKeys(new Set());
|
|
323
|
+
envScoped.current = new Set();
|
|
324
|
+
loadedEnv.current = null;
|
|
261
325
|
if (!canManageIssuer || !connector?.provider || credFields.length === 0)
|
|
262
326
|
return;
|
|
263
327
|
let cancelled = false;
|
|
@@ -267,6 +331,11 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
267
331
|
const stored = (res.data?.data?.values ?? {});
|
|
268
332
|
if (cancelled)
|
|
269
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]));
|
|
270
339
|
// Only fields the user has not touched yet.
|
|
271
340
|
setCredValues((prev) => {
|
|
272
341
|
const next = { ...prev };
|
|
@@ -289,6 +358,40 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
289
358
|
};
|
|
290
359
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
291
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]);
|
|
292
395
|
// Load stored settings values + definitions. The backend returns the
|
|
293
396
|
// manifest's setting definitions alongside the stored values; fall back to
|
|
294
397
|
// the manifest we already have so custom (declarative) addons whose lifecycle
|
|
@@ -523,7 +626,22 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
523
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.',
|
|
524
627
|
}) }));
|
|
525
628
|
const canSync = !!connector?.sync_endpoint && !!connector?.connected;
|
|
526
|
-
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));
|
|
527
645
|
// One setting control, shared by the flat layout and the wizard's last step.
|
|
528
646
|
const renderSetting = (def) => {
|
|
529
647
|
const id = `${idPrefix}-setting-${def.key}`;
|
|
@@ -657,6 +775,6 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
657
775
|
const fields = credFields.filter((f) => f.section === sec.key);
|
|
658
776
|
if (fields.length === 0 && (sec.blocks?.length ?? 0) === 0)
|
|
659
777
|
return null;
|
|
660
|
-
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 ?? '', value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), renderBlocks(trailBlocks(sec.blocks))] }, sec.key));
|
|
661
|
-
})) : (_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: '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 ?? '', 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') })] })) })] }) }) }));
|
|
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') })] })) })] }) }) }));
|
|
662
780
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/setup/messages.ts"],"names":[],"mappings":"AAMA,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAElC,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/setup/messages.ts"],"names":[],"mappings":"AAMA,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAElC,eAAO,MAAM,iBAAiB,EAAE,IAuJ/B,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,IAoJ/B,CAAA;AAED,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAA;AAOzE,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAGjE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAa/B"}
|
package/dist/setup/messages.js
CHANGED
|
@@ -142,6 +142,11 @@ export const SETUP_MESSAGES_ES = {
|
|
|
142
142
|
'installed_addons.whole_org': 'Toda la organización',
|
|
143
143
|
'installed_addons.only_branch': 'Solo {{name}}',
|
|
144
144
|
'installed_addons.secret_stored': 'Hay un valor guardado. Déjalo vacío para conservarlo.',
|
|
145
|
+
'installed_addons.field_view': 'Ver',
|
|
146
|
+
'installed_addons.field_hide': 'Ocultar',
|
|
147
|
+
'installed_addons.field_edit': 'Editar',
|
|
148
|
+
'installed_addons.field_cancel_edit': 'Cancelar edición',
|
|
149
|
+
'installed_addons.field_reveal_error': 'No se pudo mostrar el valor.',
|
|
145
150
|
'common.back': 'Atrás',
|
|
146
151
|
'common.next': 'Siguiente',
|
|
147
152
|
'common.cancel': 'Cancelar',
|
|
@@ -285,6 +290,11 @@ export const SETUP_MESSAGES_EN = {
|
|
|
285
290
|
'installed_addons.whole_org': 'Whole organization',
|
|
286
291
|
'installed_addons.only_branch': 'Only {{name}}',
|
|
287
292
|
'installed_addons.secret_stored': 'A value is stored. Leave it empty to keep it.',
|
|
293
|
+
'installed_addons.field_view': 'View',
|
|
294
|
+
'installed_addons.field_hide': 'Hide',
|
|
295
|
+
'installed_addons.field_edit': 'Edit',
|
|
296
|
+
'installed_addons.field_cancel_edit': 'Cancel editing',
|
|
297
|
+
'installed_addons.field_reveal_error': 'Could not show the value.',
|
|
288
298
|
'common.back': 'Back',
|
|
289
299
|
'common.next': 'Next',
|
|
290
300
|
'common.cancel': 'Cancel',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-option-ids.d.ts","sourceRoot":"","sources":["../src/use-option-ids.ts"],"names":[],"mappings":"AAuBA,OAAO,EAA0D,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEpH,MAAM,MAAM,kBAAkB,GACxB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE;AAC7C,qFAAqF;GACnF;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE;AACvB,4DAA4D;GAC1D;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAA;AAE3B,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,MAAM,CAAA;AA8EnC,MAAM,WAAW,uBAAuB;IACpC,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,GAAG,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,yBAAyB;IACtC,yDAAyD;IACzD,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IACjD,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,yBAAyB,
|
|
1
|
+
{"version":3,"file":"use-option-ids.d.ts","sourceRoot":"","sources":["../src/use-option-ids.ts"],"names":[],"mappings":"AAuBA,OAAO,EAA0D,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEpH,MAAM,MAAM,kBAAkB,GACxB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE;AAC7C,qFAAqF;GACnF;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE;AACvB,4DAA4D;GAC1D;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAA;AAE3B,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,MAAM,CAAA;AA8EnC,MAAM,WAAW,uBAAuB;IACpC,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,GAAG,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,yBAAyB;IACtC,yDAAyD;IACzD,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IACjD,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,yBAAyB,CAuC5F"}
|
package/dist/use-option-ids.js
CHANGED
|
@@ -116,7 +116,9 @@ export function useResolveOptionIds(args) {
|
|
|
116
116
|
queries: (active ? list : []).map((id) => ({
|
|
117
117
|
queryKey: [QUERY_ROOT, scope, url, effectiveField, id],
|
|
118
118
|
queryFn: () => enqueue(api, scope, url, effectiveField, id),
|
|
119
|
-
|
|
119
|
+
// Unknown identity: nothing may be reused from a previous account.
|
|
120
|
+
staleTime: scope ? OPTION_IDS_TTL_MS : 0,
|
|
121
|
+
...(scope ? {} : { gcTime: 0 }),
|
|
120
122
|
retry: false,
|
|
121
123
|
refetchOnWindowFocus: false,
|
|
122
124
|
})),
|
|
@@ -113,7 +113,10 @@ export declare function onOptionsCacheInvalidated(fn: () => void): () => void;
|
|
|
113
113
|
export declare function optionsRequestKey(scope: string, url: string, field: string, query: string, limit: number | undefined, filter: string | undefined, context?: Record<string, string>): string;
|
|
114
114
|
/** Normalized picker context: string values only, empty dropped (null when none). */
|
|
115
115
|
export declare function normalizeOptionsContext(context: Record<string, string | null | undefined> | undefined): Record<string, string> | undefined;
|
|
116
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* `org:user:lang` scope + branch of the host session: part of every options
|
|
118
|
+
* cache key. Empty when the identity is unknown (callers then skip the cache).
|
|
119
|
+
*/
|
|
117
120
|
export declare function optionsScope(): string;
|
|
118
121
|
export declare function useOptionsResolver(args: UseOptionsResolverArgs): UseOptionsResolverResult;
|
|
119
122
|
export declare function projectOption(raw: any): ResolvedOption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-options-resolver.d.ts","sourceRoot":"","sources":["../src/use-options-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-options-resolver.d.ts","sourceRoot":"","sources":["../src/use-options-resolver.ts"],"names":[],"mappings":"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"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// free; legacy callers that still ship `searchEndpoint` keep working.
|
|
13
13
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
14
14
|
import { useApi } from './api-context';
|
|
15
|
+
import { cacheScope, onCacheScopeChange } from './cache-scope';
|
|
15
16
|
import { applyOptionFilter } from './option-filter';
|
|
16
17
|
import { loadQueryPart, optionsBatchToken, optionsModelFromUrl } from './query-batch';
|
|
17
18
|
/**
|
|
@@ -44,6 +45,8 @@ export function invalidateOptionsCache() {
|
|
|
44
45
|
fn();
|
|
45
46
|
}
|
|
46
47
|
const invalidationListeners = new Set();
|
|
48
|
+
// Options are shaped by who asks (permissions, org): drop them with the scope.
|
|
49
|
+
onCacheScopeChange(() => invalidateOptionsCache());
|
|
47
50
|
/** Runs `fn` on every invalidateOptionsCache (id-label lookups drop with it). */
|
|
48
51
|
export function onOptionsCacheInvalidated(fn) {
|
|
49
52
|
invalidationListeners.add(fn);
|
|
@@ -78,21 +81,22 @@ function contextKey(context) {
|
|
|
78
81
|
.map((k) => `${k}=${context[k]}`)
|
|
79
82
|
.join('&');
|
|
80
83
|
}
|
|
81
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* `org:user:lang` scope + branch of the host session: part of every options
|
|
86
|
+
* cache key. Empty when the identity is unknown (callers then skip the cache).
|
|
87
|
+
*/
|
|
82
88
|
export function optionsScope() {
|
|
83
|
-
|
|
89
|
+
const scope = cacheScope();
|
|
90
|
+
if (!scope)
|
|
84
91
|
return '';
|
|
85
|
-
let
|
|
92
|
+
let branch = '';
|
|
86
93
|
try {
|
|
87
|
-
|
|
88
|
-
if (raw)
|
|
89
|
-
org = String(JSON.parse(raw).organization_id ?? '');
|
|
94
|
+
branch = typeof localStorage === 'undefined' ? '' : (localStorage.getItem('active_branch_id') ?? '');
|
|
90
95
|
}
|
|
91
96
|
catch {
|
|
92
|
-
|
|
97
|
+
branch = '';
|
|
93
98
|
}
|
|
94
|
-
|
|
95
|
-
return `${org}|${branch}`;
|
|
99
|
+
return `${scope}|${branch}`;
|
|
96
100
|
}
|
|
97
101
|
function readOptionsEnvelope(body) {
|
|
98
102
|
const rawOptions = Array.isArray(body?.data) ? body.data : [];
|
|
@@ -151,7 +155,10 @@ export function useOptionsResolver(args) {
|
|
|
151
155
|
setError(null);
|
|
152
156
|
return;
|
|
153
157
|
}
|
|
154
|
-
const
|
|
158
|
+
const askedScope = optionsScope();
|
|
159
|
+
// Unknown identity: no cache, no shared in-flight request.
|
|
160
|
+
const scoped = askedScope !== '';
|
|
161
|
+
const key = optionsRequestKey(askedScope, url, effectiveField, query ?? '', limit, filterValue, context);
|
|
155
162
|
if (refreshKey !== seenRefresh.current) {
|
|
156
163
|
seenRefresh.current = refreshKey;
|
|
157
164
|
optionsEpoch.set(key, (optionsEpoch.get(key) ?? 0) + 1);
|
|
@@ -160,7 +167,7 @@ export function useOptionsResolver(args) {
|
|
|
160
167
|
}
|
|
161
168
|
const epoch = optionsEpoch.get(key) ?? 0;
|
|
162
169
|
const generation = optionsGeneration;
|
|
163
|
-
const cached = optionsCache.get(key);
|
|
170
|
+
const cached = scoped ? optionsCache.get(key) : undefined;
|
|
164
171
|
if (cached && Date.now() - cached.at < OPTIONS_TTL_MS) {
|
|
165
172
|
setOptions(cached.payload.options);
|
|
166
173
|
setMeta(cached.payload.meta);
|
|
@@ -170,7 +177,7 @@ export function useOptionsResolver(args) {
|
|
|
170
177
|
}
|
|
171
178
|
setLoading(true);
|
|
172
179
|
setError(null);
|
|
173
|
-
let pending = optionsInflight.get(key);
|
|
180
|
+
let pending = scoped ? optionsInflight.get(key) : undefined;
|
|
174
181
|
if (!pending) {
|
|
175
182
|
const params = { field: effectiveField };
|
|
176
183
|
if (query)
|
|
@@ -194,14 +201,17 @@ export function useOptionsResolver(args) {
|
|
|
194
201
|
data: part.data,
|
|
195
202
|
meta: part.meta,
|
|
196
203
|
});
|
|
197
|
-
if ((optionsEpoch.get(key) ?? 0) === epoch && optionsGeneration === generation) {
|
|
204
|
+
if (scoped && optionsScope() === askedScope && (optionsEpoch.get(key) ?? 0) === epoch && optionsGeneration === generation) {
|
|
198
205
|
optionsCache.set(key, { payload, at: Date.now() });
|
|
199
206
|
}
|
|
200
207
|
return payload;
|
|
201
208
|
}
|
|
202
209
|
catch (err) {
|
|
203
210
|
const msg = err instanceof Error ? err.message : '';
|
|
204
|
-
const batchMiss = msg === 'batch unavailable' ||
|
|
211
|
+
const batchMiss = msg === 'batch unavailable' ||
|
|
212
|
+
msg === 'batch part missing' ||
|
|
213
|
+
msg === 'batch scope changed' ||
|
|
214
|
+
msg === 'batch cache cleared';
|
|
205
215
|
if (!batchMiss)
|
|
206
216
|
throw err;
|
|
207
217
|
}
|
|
@@ -212,7 +222,7 @@ export function useOptionsResolver(args) {
|
|
|
212
222
|
throw new Error(body?.message || 'options resolver: unsuccessful response');
|
|
213
223
|
}
|
|
214
224
|
const payload = readOptionsEnvelope(body);
|
|
215
|
-
if ((optionsEpoch.get(key) ?? 0) === epoch && optionsGeneration === generation) {
|
|
225
|
+
if (scoped && optionsScope() === askedScope && (optionsEpoch.get(key) ?? 0) === epoch && optionsGeneration === generation) {
|
|
216
226
|
optionsCache.set(key, { payload, at: Date.now() });
|
|
217
227
|
}
|
|
218
228
|
return payload;
|
|
@@ -220,7 +230,8 @@ export function useOptionsResolver(args) {
|
|
|
220
230
|
if (optionsInflight.get(key) === pending)
|
|
221
231
|
optionsInflight.delete(key);
|
|
222
232
|
});
|
|
223
|
-
|
|
233
|
+
if (scoped)
|
|
234
|
+
optionsInflight.set(key, pending);
|
|
224
235
|
}
|
|
225
236
|
let cancelled = false;
|
|
226
237
|
pending
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charts.d.ts","sourceRoot":"","sources":["../../src/widgets/charts.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"charts.d.ts","sourceRoot":"","sources":["../../src/widgets/charts.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAU9B,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/D,YAAY,EAAE,iBAAiB,EAAE,CAAA;AA4BjC,wBAAgB,SAAS,CAAC,CAAC,EAAE,iBAAiB,qBAE7C;AACD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAE9C;AACD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAE9C;AACD,wBAAgB,SAAS,CAAC,CAAC,EAAE,iBAAiB,qBAE7C;AACD,wBAAgB,WAAW,CAAC,CAAC,EAAE,iBAAiB,qBAE/C"}
|
package/dist/widgets/charts.js
CHANGED
|
@@ -1,55 +1,23 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import {
|
|
3
|
-
import { cn } from '@asteby/metacore-ui/lib';
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AreaChartBody, BarChartBody, DonutChartBody, LineChartBody, PieChartBody, } from '@asteby/metacore-charts/recharts';
|
|
4
3
|
import { WidgetCard, WidgetEmpty } from './widget-card';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// resolve. This height + the card chrome gives every chart card a consistent,
|
|
10
|
-
// taller footprint that balances cleanly against compact stat cards.
|
|
11
|
-
const CHART_H = 'h-[190px]';
|
|
12
|
-
function ChartArea({ children }) {
|
|
13
|
-
return (_jsx("div", { className: cn(CHART_H, 'w-full'), children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: children }) }));
|
|
4
|
+
import { hasSeries } from './renderers';
|
|
5
|
+
function ChartWidget(p) {
|
|
6
|
+
const { Body } = p;
|
|
7
|
+
return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(Body, { series: p.data.series, accent: p.spec.accent, format: p.spec.format, locale: p.locale, currency: p.currency, id: p.spec.key })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
|
|
14
8
|
}
|
|
15
|
-
// Compact recharts tooltip styled with theme tokens.
|
|
16
|
-
function ChartTooltip({ ctx }) {
|
|
17
|
-
return (_jsx(Tooltip, { cursor: { fill: 'var(--muted, rgba(148,163,184,0.12))', opacity: 0.4 }, contentStyle: {
|
|
18
|
-
background: 'var(--popover, #fff)',
|
|
19
|
-
border: '1px solid var(--border, #e2e8f0)',
|
|
20
|
-
borderRadius: 8,
|
|
21
|
-
fontSize: 12,
|
|
22
|
-
color: 'var(--popover-foreground, #0f172a)',
|
|
23
|
-
boxShadow: '0 4px 16px rgba(0,0,0,0.08)',
|
|
24
|
-
}, labelStyle: { color: 'var(--muted-foreground, #64748b)', marginBottom: 2 }, formatter: (v) => formatWidgetValue(Number(v), ctx) }));
|
|
25
|
-
}
|
|
26
|
-
// --- bar ------------------------------------------------------------------
|
|
27
9
|
export function BarWidget(p) {
|
|
28
|
-
|
|
29
|
-
const a = accentClasses(p.spec.accent);
|
|
30
|
-
return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(ChartArea, { children: _jsxs(BarChart, { data: p.data.series, margin: { top: 4, right: 4, left: -16, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Bar, { dataKey: "value", fill: a.chartVar, radius: [4, 4, 0, 0], maxBarSize: 48 })] }) })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
|
|
31
|
-
}
|
|
32
|
-
// --- line / area (shared) -------------------------------------------------
|
|
33
|
-
function TimeSeriesWidget(p) {
|
|
34
|
-
const ctx = fmtCtx(p.spec, p.locale, p.currency);
|
|
35
|
-
const a = accentClasses(p.spec.accent);
|
|
36
|
-
const gradId = `wg-grad-${p.spec.key}`;
|
|
37
|
-
return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(ChartArea, { children: p.variant === 'area' ? (_jsxs(AreaChart, { data: p.data.series, margin: { top: 4, right: 6, left: -16, bottom: 0 }, children: [_jsx("defs", { children: _jsxs("linearGradient", { id: gradId, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: a.chartVar, stopOpacity: 0.35 }), _jsx("stop", { offset: "100%", stopColor: a.chartVar, stopOpacity: 0.02 })] }) }), _jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Area, { type: "monotone", dataKey: "value", stroke: a.chartVar, strokeWidth: 2, fill: `url(#${gradId})` })] })) : (_jsxs(LineChart, { data: p.data.series, margin: { top: 4, right: 6, left: -16, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Line, { type: "monotone", dataKey: "value", stroke: a.chartVar, strokeWidth: 2, dot: false, activeDot: { r: 4 } })] })) })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
|
|
10
|
+
return _jsx(ChartWidget, { ...p, Body: BarChartBody });
|
|
38
11
|
}
|
|
39
12
|
export function LineWidget(p) {
|
|
40
|
-
return _jsx(
|
|
13
|
+
return _jsx(ChartWidget, { ...p, Body: LineChartBody });
|
|
41
14
|
}
|
|
42
15
|
export function AreaWidget(p) {
|
|
43
|
-
return _jsx(
|
|
44
|
-
}
|
|
45
|
-
// --- pie / donut (shared) -------------------------------------------------
|
|
46
|
-
function CircularWidget(p) {
|
|
47
|
-
const ctx = fmtCtx(p.spec, p.locale, p.currency);
|
|
48
|
-
return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsxs("div", { className: cn(CHART_H, 'flex items-center gap-3'), children: [_jsx("div", { className: "h-full min-h-0 w-[46%] shrink-0", children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(PieChart, { children: [_jsx(ChartTooltip, { ctx: ctx }), _jsx(Pie, { data: p.data.series, dataKey: "value", nameKey: "label", innerRadius: p.variant === 'donut' ? '55%' : 0, outerRadius: "92%", paddingAngle: p.variant === 'donut' ? 2 : 0, stroke: "var(--background, #fff)", strokeWidth: 2, children: p.data.series.map((_, i) => (_jsx(Cell, { fill: paletteColor(i) }, i))) })] }) }) }), _jsx("ul", { className: "flex min-w-0 flex-1 flex-col gap-1.5", children: p.data.series.slice(0, 6).map((pt, i) => (_jsxs("li", { className: "flex items-center gap-2 text-xs", children: [_jsx("span", { className: "size-2.5 shrink-0 rounded-sm", style: { background: paletteColor(i) } }), _jsx("span", { className: "truncate text-muted-foreground", children: pt.label }), _jsx("span", { className: "ml-auto shrink-0 font-medium tabular-nums text-foreground", children: formatWidgetValue(pt.value, ctx) })] }, pt.key))) })] })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
|
|
16
|
+
return _jsx(ChartWidget, { ...p, Body: AreaChartBody });
|
|
49
17
|
}
|
|
50
18
|
export function PieWidget(p) {
|
|
51
|
-
return _jsx(
|
|
19
|
+
return _jsx(ChartWidget, { ...p, Body: PieChartBody });
|
|
52
20
|
}
|
|
53
21
|
export function DonutWidget(p) {
|
|
54
|
-
return _jsx(
|
|
22
|
+
return _jsx(ChartWidget, { ...p, Body: DonutChartBody });
|
|
55
23
|
}
|
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export interface WidgetFormatCtx {
|
|
3
|
-
format?: WidgetFormat;
|
|
4
|
-
locale?: string;
|
|
5
|
-
currency?: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Formats a scalar/series value with the widget's declared format. `currency`
|
|
9
|
-
* uses the org currency + locale (same fallback chain as table cells); `percent`
|
|
10
|
-
* treats the value as a fraction (0.142 → "14.2%"); `compact` uses Intl compact
|
|
11
|
-
* notation (1_200 → "1.2K").
|
|
12
|
-
*/
|
|
13
|
-
export declare function formatWidgetValue(value: number, { format, locale, currency }: WidgetFormatCtx): string;
|
|
14
|
-
/** Axis-tick formatter — always compact so charts stay legible. */
|
|
15
|
-
export declare function formatAxisTick(value: number, { format, locale, currency }: WidgetFormatCtx): string;
|
|
16
|
-
/** Formats the compare delta fraction (0.142 → "+14.2%"). */
|
|
17
|
-
export declare function formatDelta(delta: number, locale?: string): string;
|
|
18
|
-
export interface AccentClasses {
|
|
19
|
-
/** Icon chip background + foreground. */
|
|
20
|
-
chip: string;
|
|
21
|
-
/** Text color for accented labels. */
|
|
22
|
-
text: string;
|
|
23
|
-
/** Solid bar/fill background (progress, list proportion). */
|
|
24
|
-
bar: string;
|
|
25
|
-
/** Soft track background behind a bar. */
|
|
26
|
-
track: string;
|
|
27
|
-
/** Hex-ish CSS color used for recharts stroke/fill (var-based). */
|
|
28
|
-
chartVar: string;
|
|
29
|
-
}
|
|
30
|
-
/** Resolves the accent class bundle, defaulting to `sky`. */
|
|
31
|
-
export declare function accentClasses(accent?: WidgetAccent): AccentClasses;
|
|
32
|
-
/**
|
|
33
|
-
* A categorical palette for multi-series charts (pie/donut/bar by bucket).
|
|
34
|
-
* Cycles the accent chart vars so slices stay theme-aware + dark-mode safe.
|
|
35
|
-
*/
|
|
36
|
-
export declare const CHART_PALETTE: string[];
|
|
37
|
-
/** Picks a palette color by index, wrapping around. */
|
|
38
|
-
export declare function paletteColor(index: number): string;
|
|
39
|
-
/** Grid/axis muted color from the theme (works in light + dark). */
|
|
40
|
-
export declare const CHART_MUTED = "var(--muted-foreground, #94a3b8)";
|
|
41
|
-
export declare const CHART_GRID = "var(--border, #e2e8f0)";
|
|
1
|
+
export { formatWidgetValue, formatAxisTick, formatDelta, accentClasses, paletteColor, CHART_PALETTE, CHART_GRID, CHART_MUTED, type AccentClasses, type WidgetFormatCtx, } from '@asteby/metacore-charts';
|
|
42
2
|
//# sourceMappingURL=widget-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-format.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-format.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"widget-format.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-format.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,eAAe,GACvB,MAAM,yBAAyB,CAAA"}
|