@asteby/metacore-runtime-react 53.10.1 → 53.11.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 +28 -0
- package/dist/dynamic-form.d.ts +10 -1
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +6 -6
- package/dist/dynamic-relation-helpers.d.ts +51 -0
- package/dist/dynamic-relation-helpers.d.ts.map +1 -1
- package/dist/dynamic-relation-helpers.js +139 -2
- package/dist/dynamic-relation.d.ts +16 -0
- package/dist/dynamic-relation.d.ts.map +1 -1
- package/dist/dynamic-relation.js +205 -12
- package/dist/dynamic-relations.d.ts.map +1 -1
- package/dist/dynamic-relations.js +1 -1
- package/dist/relation-gallery.d.ts +31 -0
- package/dist/relation-gallery.d.ts.map +1 -0
- package/dist/relation-gallery.js +154 -0
- package/dist/setup/addon-config-surface.d.ts +6 -0
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +24 -14
- package/dist/setup/connector-form-model.d.ts +28 -0
- package/dist/setup/connector-form-model.d.ts.map +1 -1
- package/dist/setup/connector-form-model.js +26 -0
- package/dist/upload-field.d.ts +19 -1
- package/dist/upload-field.d.ts.map +1 -1
- package/dist/upload-field.js +50 -3
- package/package.json +1 -1
- package/src/__tests__/relation-gallery-helpers.test.ts +125 -0
- package/src/__tests__/relation-gallery.test.tsx +170 -0
- package/src/dynamic-form.tsx +20 -2
- package/src/dynamic-relation-helpers.ts +171 -2
- package/src/dynamic-relation.tsx +257 -14
- package/src/dynamic-relations.tsx +1 -0
- package/src/relation-gallery.tsx +488 -0
- package/src/setup/addon-config-surface.tsx +33 -17
- package/src/setup/connector-conditional-fields.test.ts +58 -0
- package/src/setup/connector-form-model.ts +69 -0
- package/src/upload-field.tsx +60 -2
|
@@ -26,7 +26,7 @@ import { useSetupT } from './messages';
|
|
|
26
26
|
import { StepStatusBadge } from './step-status-badge';
|
|
27
27
|
import { ConnectorBlocks, HelpText } from './connector-blocks';
|
|
28
28
|
import { buildWizardSteps, errorMessage, hasExplicitTest, normalizeBlockResult, stepStatus, } from './connector-blocks-model';
|
|
29
|
-
import { isSecretCredential, missingRequired, parseSaveError, shapeMismatch, textOrFallback, } from './connector-form-model';
|
|
29
|
+
import { isSecretCredential, missingRequired, applicableFields, visibleSections, parseSaveError, shapeMismatch, textOrFallback, } from './connector-form-model';
|
|
30
30
|
// Empty write_only value (typed then erased) must not overwrite the stored secret.
|
|
31
31
|
const isBlank = (v) => v == null || (typeof v === 'string' && v.trim() === '');
|
|
32
32
|
const NO_OPTION_KINDS = {};
|
|
@@ -236,8 +236,6 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
236
236
|
clearConnectorLookupCache();
|
|
237
237
|
}, [open]);
|
|
238
238
|
const credFields = connector?.credentials ?? [];
|
|
239
|
-
const requiredFields = credFields.filter((f) => f.required);
|
|
240
|
-
const advancedFields = credFields.filter((f) => !f.required);
|
|
241
239
|
// A connector with a form_layout groups its credentials into titled sections
|
|
242
240
|
// (a light wizard). Fall back to the required/advanced split when absent.
|
|
243
241
|
const layoutSections = connector?.form_layout?.sections ?? [];
|
|
@@ -270,6 +268,18 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
270
268
|
const loadedEnv = useRef(null);
|
|
271
269
|
const envField = credFields.find((f) => f.type === 'select' && ['environment', 'mode', 'env'].includes(f.key));
|
|
272
270
|
const envValue = envField ? (credValues[envField.key] ?? '') : '';
|
|
271
|
+
// What the form SHOWS for the live values: a credential whose own visible_when
|
|
272
|
+
// (or whose section's) is false is not applicable — never required, never
|
|
273
|
+
// validated, never counted in a step's error, never sent (connector_email:
|
|
274
|
+
// choosing Resend must not demand the SendGrid key).
|
|
275
|
+
const credDefaults = {};
|
|
276
|
+
for (const f of credFields)
|
|
277
|
+
if (f.default != null && f.default !== '')
|
|
278
|
+
credDefaults[f.key] = String(f.default);
|
|
279
|
+
const activeSections = visibleSections(layoutSections, credValues, credDefaults);
|
|
280
|
+
const activeFields = applicableFields(credFields, layoutSections, credValues, credDefaults);
|
|
281
|
+
// Only what applies is sent: a hidden provider's field is left out.
|
|
282
|
+
const isSendable = (key) => !credFields.some((f) => f.key === key) || activeFields.some((f) => f.key === key);
|
|
273
283
|
const stepHeadingRef = useRef(null);
|
|
274
284
|
const stepMoved = useRef(false);
|
|
275
285
|
const setCred = (key, val) => {
|
|
@@ -507,7 +517,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
507
517
|
// secret leaves it untouched (server merges).
|
|
508
518
|
const payload = {};
|
|
509
519
|
for (const [k, v] of Object.entries(credValues)) {
|
|
510
|
-
if (v != null && v !== '')
|
|
520
|
+
if (v != null && v !== '' && isSendable(k))
|
|
511
521
|
payload[k] = v;
|
|
512
522
|
}
|
|
513
523
|
await api.post(`/integrations/${connector.provider}`, payload);
|
|
@@ -590,7 +600,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
590
600
|
const handleSave = () => {
|
|
591
601
|
setFormError(null);
|
|
592
602
|
if (connector && canManageIssuer) {
|
|
593
|
-
const miss = missingRequired(
|
|
603
|
+
const miss = missingRequired(activeFields, credValues, !!connector.connected);
|
|
594
604
|
if (miss.length > 0) {
|
|
595
605
|
const errs = {};
|
|
596
606
|
for (const k of miss) {
|
|
@@ -614,7 +624,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
614
624
|
const persistCredsIfDirty = async () => {
|
|
615
625
|
if (!credDirty || !connector || !canManageIssuer)
|
|
616
626
|
return null;
|
|
617
|
-
const miss = missingRequired(
|
|
627
|
+
const miss = missingRequired(activeFields, credValues, !!connector.connected);
|
|
618
628
|
if (miss.length > 0) {
|
|
619
629
|
const errs = {};
|
|
620
630
|
for (const k of miss)
|
|
@@ -626,7 +636,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
626
636
|
}
|
|
627
637
|
const payload = {};
|
|
628
638
|
for (const [k, v] of Object.entries(credValues)) {
|
|
629
|
-
if (v != null && v !== '')
|
|
639
|
+
if (v != null && v !== '' && isSendable(k))
|
|
630
640
|
payload[k] = v;
|
|
631
641
|
}
|
|
632
642
|
await api.post(`/integrations/${connector.provider}`, payload);
|
|
@@ -737,7 +747,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
737
747
|
// Wizard steps: form_layout sections with fields OR blocks, + a final
|
|
738
748
|
// "Ajustes" step when the addon also ships settings.
|
|
739
749
|
const wizardSteps = stepMode
|
|
740
|
-
? buildWizardSteps(
|
|
750
|
+
? buildWizardSteps(activeSections, activeFields.map((f) => f.section), hasSettings)
|
|
741
751
|
: [];
|
|
742
752
|
const totalSteps = wizardSteps.length;
|
|
743
753
|
const useStepper = stepMode && totalSteps > 1;
|
|
@@ -778,7 +788,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
778
788
|
return stepStatus({
|
|
779
789
|
index: i,
|
|
780
790
|
current: stepIdx,
|
|
781
|
-
fieldKeys: s.kind === 'creds' ?
|
|
791
|
+
fieldKeys: s.kind === 'creds' ? activeFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
|
|
782
792
|
fieldErrors,
|
|
783
793
|
blockKeys: blocksFor(s.key, s.blocks).map((b) => b.key),
|
|
784
794
|
results: blockResults,
|
|
@@ -798,7 +808,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
798
808
|
// operator learns what is missing where it is, not at the end.
|
|
799
809
|
const handleNext = () => {
|
|
800
810
|
if (activeStep?.kind === 'creds' && connector && canManageIssuer) {
|
|
801
|
-
const stepFields =
|
|
811
|
+
const stepFields = activeFields.filter((f) => f.section === activeStep.key);
|
|
802
812
|
const miss = missingRequired(stepFields, credValues, !!connector.connected);
|
|
803
813
|
if (miss.length > 0) {
|
|
804
814
|
const errs = {};
|
|
@@ -852,12 +862,12 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
|
|
|
852
862
|
: 'border-border text-muted-foreground'), children: !active && status === 'error' ? (_jsx(AlertCircle, { className: 'h-4 w-4' })) : !active && status === 'ok' ? (_jsx(Check, { className: 'h-4 w-4' })) : (i + 1) }) }), i < wizardSteps.length - 1 && (_jsx("span", { "aria-hidden": 'true', className: cn('mx-1 h-0.5 flex-1 rounded-full transition-colors', i < stepIdx ? 'bg-primary' : 'bg-border') }))] }, s.key));
|
|
853
863
|
}) }), _jsxs("div", { className: 'flex items-start justify-between gap-3', children: [_jsx("h3", { ref: stepHeadingRef, tabIndex: -1, className: 'min-w-0 text-base leading-snug font-semibold break-words outline-none', children: t(activeStep?.title ?? '', {
|
|
854
864
|
defaultValue: humanizeKey(activeStep?.title),
|
|
855
|
-
}) }), _jsx("span", { className: 'mt-0.5 shrink-0 text-xs font-medium tabular-nums text-muted-foreground', children: st('flow.step_of', { n: stepIdx + 1, total: totalSteps }) })] })] }), _jsxs("div", { className: 'flex flex-col gap-4', children: [activeStep?.description && (_jsx(HelpText, { text: addonText(activeStep.description) })), activeStep?.kind === 'settings' ? (settingsBody) : !canManageIssuer ? (_jsxs(_Fragment, { children: [issuerAdminNote, renderBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))] })) : (_jsxs(_Fragment, { children: [renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))),
|
|
865
|
+
}) }), _jsx("span", { className: 'mt-0.5 shrink-0 text-xs font-medium tabular-nums text-muted-foreground', children: st('flow.step_of', { n: stepIdx + 1, total: totalSteps }) })] })] }), _jsxs("div", { className: 'flex flex-col gap-4', children: [activeStep?.description && (_jsx(HelpText, { text: addonText(activeStep.description) })), activeStep?.kind === 'settings' ? (settingsBody) : !canManageIssuer ? (_jsxs(_Fragment, { children: [issuerAdminNote, renderBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))] })) : (_jsxs(_Fragment, { children: [renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))), activeFields.filter((f) => f.section === activeStep?.key).map(renderCred), renderBlocks(trailBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))] }))] })] })) : (_jsxs(_Fragment, { children: [oauthPanel, hasCredentials && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Cable, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_credentials') })] }), !canManageIssuer ? (issuerAdminNote) : useLayout ? (
|
|
856
866
|
// form_layout: one titled group per section, in declared order.
|
|
857
|
-
|
|
858
|
-
const fields =
|
|
867
|
+
activeSections.map((sec) => {
|
|
868
|
+
const fields = activeFields.filter((f) => f.section === sec.key);
|
|
859
869
|
if (fields.length === 0 && (sec.blocks?.length ?? 0) === 0)
|
|
860
870
|
return null;
|
|
861
871
|
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));
|
|
862
|
-
})) : (_jsxs(_Fragment, { children: [
|
|
872
|
+
})) : (_jsxs(_Fragment, { children: [activeFields.filter((f) => f.required).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))), activeFields.some((f) => !f.required) && (_jsxs("details", { className: 'rounded-md border border-border/60 px-3 py-2', open: activeFields.filter((f) => !f.required).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: activeFields.filter((f) => !f.required).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: 'flex shrink-0 flex-col gap-2 border-t pt-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between sm:space-x-0', children: nothingToSave ? (_jsx(Button, { className: 'h-11 w-full sm:ml-auto sm:h-9 sm:w-auto', onClick: () => onOpenChange(false), children: st('common.close') })) : (_jsxs(_Fragment, { children: [_jsxs("p", { role: 'status', "aria-live": 'polite', "data-save-status": saveStatus, className: cn('flex shrink-0 items-center gap-1.5 whitespace-nowrap text-xs', saveStatus === 'dirty' ? 'font-medium text-amber-600 dark:text-amber-400' : 'text-muted-foreground', saveStatus === 'saved' && 'text-emerald-600 dark:text-emerald-400'), children: [saveStatus === 'saving' ? (_jsx(Loader2, { className: 'h-3.5 w-3.5 animate-spin' })) : saveStatus === 'saved' ? (_jsx(Check, { className: 'h-3.5 w-3.5' })) : (_jsx("span", { "aria-hidden": true, className: cn('h-2 w-2 rounded-full', saveStatus === 'dirty' ? 'bg-amber-500' : 'bg-muted-foreground/40') })), st(`form.status_${saveStatus}`)] }), _jsxs("div", { className: 'flex flex-wrap items-center gap-2 sm:ml-auto sm:flex-nowrap sm:justify-end', children: [_jsx(Button, { variant: 'ghost', className: 'h-11 px-3 sm:h-9', onClick: () => onOpenChange(false), children: dirty ? st('common.cancel') : st('common.close') }), useStepper && stepIdx > 0 && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: () => goToStep(Math.max(0, stepIdx - 1)), children: st('common.back') })), useStepper && !isLastStep && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: handleNext, children: st('common.next') })), _jsxs(Button, { className: 'h-11 flex-1 sm:h-9 sm:flex-none', onClick: handleSave, disabled: saveMutation.isPending || loading, "data-testid": 'config-save', children: [saveMutation.isPending && _jsx(Loader2, { className: 'mr-2 h-4 w-4 animate-spin' }), st('common.save')] })] })] })) })] }) }) }));
|
|
863
873
|
}
|
|
@@ -37,4 +37,32 @@ export declare function parseSaveError(err: unknown, fallback: string): SaveErro
|
|
|
37
37
|
export declare function textOrFallback(text: string | undefined, key: string, fallback: string): string;
|
|
38
38
|
/** Cheap content hash so a re-published bundle with the same key count re-merges. */
|
|
39
39
|
export declare function bundleSignature(labels: Record<string, unknown>): string;
|
|
40
|
+
export interface VisibilityPredicate {
|
|
41
|
+
field?: string;
|
|
42
|
+
equals?: unknown;
|
|
43
|
+
in?: unknown[];
|
|
44
|
+
class?: string;
|
|
45
|
+
}
|
|
46
|
+
interface ConditionalField {
|
|
47
|
+
key: string;
|
|
48
|
+
section?: string;
|
|
49
|
+
visible_when?: VisibilityPredicate;
|
|
50
|
+
visibleWhen?: VisibilityPredicate;
|
|
51
|
+
}
|
|
52
|
+
interface ConditionalSection {
|
|
53
|
+
key: string;
|
|
54
|
+
visible_when?: VisibilityPredicate;
|
|
55
|
+
visibleWhen?: VisibilityPredicate;
|
|
56
|
+
}
|
|
57
|
+
/** Same semantics as `evaluateVisibleWhen` (no field / no comparison => visible). */
|
|
58
|
+
export declare function predicateHolds(cond: VisibilityPredicate | undefined, values: Record<string, string>, defaults?: Record<string, string>): boolean;
|
|
59
|
+
/** Sections the form shows for these values. */
|
|
60
|
+
export declare function visibleSections<S extends ConditionalSection>(sections: S[], values: Record<string, string>, defaults?: Record<string, string>): S[];
|
|
61
|
+
/**
|
|
62
|
+
* Fields the form shows for these values: the field's own `visible_when` holds
|
|
63
|
+
* AND its section's does. Hidden fields are not validated, not counted in a
|
|
64
|
+
* step's error state and not sent.
|
|
65
|
+
*/
|
|
66
|
+
export declare function applicableFields<F extends ConditionalField>(fields: F[], sections: ConditionalSection[], values: Record<string, string>, defaults?: Record<string, string>): F[];
|
|
67
|
+
export {};
|
|
40
68
|
//# sourceMappingURL=connector-form-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector-form-model.d.ts","sourceRoot":"","sources":["../../src/setup/connector-form-model.ts"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,YAAY,CAAA;AASzD,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAMnE;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,cAAc,YAAsC,CAAA;AAI1F,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,cAAc,EAAE,GACvB,aAAa,GAAG,IAAI,CAatB;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EAAE,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,SAAS,EAAE,OAAO,GACjB,MAAM,EAAE,CAOV;AAED,MAAM,WAAW,SAAS;IACxB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CASxE;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG9F;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAKvE"}
|
|
1
|
+
{"version":3,"file":"connector-form-model.d.ts","sourceRoot":"","sources":["../../src/setup/connector-form-model.ts"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,YAAY,CAAA;AASzD,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAMnE;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,cAAc,YAAsC,CAAA;AAI1F,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,cAAc,EAAE,GACvB,aAAa,GAAG,IAAI,CAatB;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EAAE,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,SAAS,EAAE,OAAO,GACjB,MAAM,EAAE,CAOV;AAED,MAAM,WAAW,SAAS;IACxB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CASxE;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG9F;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAKvE;AASD,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,UAAU,gBAAgB;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,mBAAmB,CAAA;IAClC,WAAW,CAAC,EAAE,mBAAmB,CAAA;CAClC;AACD,UAAU,kBAAkB;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,CAAC,EAAE,mBAAmB,CAAA;IAClC,WAAW,CAAC,EAAE,mBAAmB,CAAA;CAClC;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAC5B,IAAI,EAAE,mBAAmB,GAAG,SAAS,EACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,OAAO,CAQT;AAED,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,CAAC,SAAS,kBAAkB,EAC1D,QAAQ,EAAE,CAAC,EAAE,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,CAAC,EAAE,CAEL;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EACzD,MAAM,EAAE,CAAC,EAAE,EACX,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,CAAC,EAAE,CAOL"}
|
|
@@ -74,3 +74,29 @@ export function bundleSignature(labels) {
|
|
|
74
74
|
h = ((h << 5) + h + s.charCodeAt(i)) | 0;
|
|
75
75
|
return `${Object.keys(labels).length}:${(h >>> 0).toString(36)}`;
|
|
76
76
|
}
|
|
77
|
+
/** Same semantics as `evaluateVisibleWhen` (no field / no comparison => visible). */
|
|
78
|
+
export function predicateHolds(cond, values, defaults = {}) {
|
|
79
|
+
if (!cond || typeof cond.field !== 'string' || cond.field.trim() === '')
|
|
80
|
+
return true;
|
|
81
|
+
const key = cond.field.trim();
|
|
82
|
+
const raw = values[key];
|
|
83
|
+
const current = raw == null || raw === '' ? (defaults[key] ?? '') : String(raw);
|
|
84
|
+
if (Array.isArray(cond.in) && cond.in.length > 0)
|
|
85
|
+
return cond.in.some((v) => String(v) === current);
|
|
86
|
+
if (cond.equals != null)
|
|
87
|
+
return String(cond.equals) === current;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
/** Sections the form shows for these values. */
|
|
91
|
+
export function visibleSections(sections, values, defaults = {}) {
|
|
92
|
+
return sections.filter((s) => predicateHolds(s.visible_when ?? s.visibleWhen, values, defaults));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Fields the form shows for these values: the field's own `visible_when` holds
|
|
96
|
+
* AND its section's does. Hidden fields are not validated, not counted in a
|
|
97
|
+
* step's error state and not sent.
|
|
98
|
+
*/
|
|
99
|
+
export function applicableFields(fields, sections, values, defaults = {}) {
|
|
100
|
+
const hidden = new Set(sections.filter((s) => !predicateHolds(s.visible_when ?? s.visibleWhen, values, defaults)).map((s) => s.key));
|
|
101
|
+
return fields.filter((f) => predicateHolds(f.visible_when ?? f.visibleWhen, values, defaults) && !(f.section && hidden.has(f.section)));
|
|
102
|
+
}
|
package/dist/upload-field.d.ts
CHANGED
|
@@ -3,7 +3,25 @@ export interface UploadFieldProps {
|
|
|
3
3
|
field: ActionFieldDef;
|
|
4
4
|
value: any;
|
|
5
5
|
onChange: (v: any) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Called after a successful upload of an image with its natural size,
|
|
8
|
+
* measured in the browser (no server round-trip, `/upload` contract
|
|
9
|
+
* unchanged). Lets a form fill derived width/height columns.
|
|
10
|
+
*/
|
|
11
|
+
onFileMeta?: (meta: {
|
|
12
|
+
width?: number;
|
|
13
|
+
height?: number;
|
|
14
|
+
}) => void;
|
|
6
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Natural pixel size of an image file, measured client-side. Resolves `{}` for
|
|
18
|
+
* a non-image or when the browser cannot decode it — never throws, never
|
|
19
|
+
* guesses.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readImageSize(file: Blob): Promise<{
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
}>;
|
|
7
25
|
/**
|
|
8
26
|
* Pulls the stored file url/path out of an upload response envelope, tolerating
|
|
9
27
|
* the common key shapes a host might return. Pure — exported for tests.
|
|
@@ -32,5 +50,5 @@ export declare function validateUploadFile(file: {
|
|
|
32
50
|
accept?: string;
|
|
33
51
|
maxSize?: number;
|
|
34
52
|
}): 'type' | 'size' | null;
|
|
35
|
-
export declare function UploadField({ field, value, onChange }: UploadFieldProps): import("react").JSX.Element;
|
|
53
|
+
export declare function UploadField({ field, value, onChange, onFileMeta }: UploadFieldProps): import("react").JSX.Element;
|
|
36
54
|
//# sourceMappingURL=upload-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-field.d.ts","sourceRoot":"","sources":["../src/upload-field.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload-field.d.ts","sourceRoot":"","sources":["../src/upload-field.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,cAAc,CAAA;IACrB,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CACnE;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA0B5F;AASD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CAWzD;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAK1D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAahG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAClD,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,MAAM,GAAG,MAAM,GAAG,IAAI,CAIxB;AAED,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,gBAAgB,+BA8HnF"}
|
package/dist/upload-field.js
CHANGED
|
@@ -16,6 +16,46 @@ import { useTranslation } from 'react-i18next';
|
|
|
16
16
|
import { getUploadConfig } from './dynamic-form-schema';
|
|
17
17
|
import { FilePickButton } from './file-pick-button';
|
|
18
18
|
import { useApi } from './api-context';
|
|
19
|
+
import { useImageUrl } from './image-url-context';
|
|
20
|
+
/**
|
|
21
|
+
* Natural pixel size of an image file, measured client-side. Resolves `{}` for
|
|
22
|
+
* a non-image or when the browser cannot decode it — never throws, never
|
|
23
|
+
* guesses.
|
|
24
|
+
*/
|
|
25
|
+
export async function readImageSize(file) {
|
|
26
|
+
if (!file || !String(file.type || '').startsWith('image/'))
|
|
27
|
+
return {};
|
|
28
|
+
try {
|
|
29
|
+
if (typeof createImageBitmap === 'function') {
|
|
30
|
+
const bmp = await createImageBitmap(file);
|
|
31
|
+
const out = { width: bmp.width, height: bmp.height };
|
|
32
|
+
bmp.close?.();
|
|
33
|
+
if (out.width > 0 && out.height > 0)
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// fall through to <img>
|
|
39
|
+
}
|
|
40
|
+
if (typeof Image === 'undefined' || typeof URL === 'undefined' || !URL.createObjectURL)
|
|
41
|
+
return {};
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
const url = URL.createObjectURL(file);
|
|
44
|
+
const img = new Image();
|
|
45
|
+
img.onload = () => {
|
|
46
|
+
URL.revokeObjectURL(url);
|
|
47
|
+
resolve(img.naturalWidth > 0 ? { width: img.naturalWidth, height: img.naturalHeight } : {});
|
|
48
|
+
};
|
|
49
|
+
img.onerror = () => {
|
|
50
|
+
URL.revokeObjectURL(url);
|
|
51
|
+
resolve({});
|
|
52
|
+
};
|
|
53
|
+
img.src = url;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function isImageField(field, accept) {
|
|
57
|
+
return field.type === 'image' || (accept ?? '').toLowerCase().split(',').some((t) => t.trim().startsWith('image/'));
|
|
58
|
+
}
|
|
19
59
|
/** Default host upload endpoint. Overridable per-field via `searchEndpoint`. */
|
|
20
60
|
const DEFAULT_UPLOAD_ENDPOINT = '/upload';
|
|
21
61
|
/**
|
|
@@ -78,9 +118,10 @@ export function validateUploadFile(file, opts) {
|
|
|
78
118
|
return 'size';
|
|
79
119
|
return null;
|
|
80
120
|
}
|
|
81
|
-
export function UploadField({ field, value, onChange }) {
|
|
121
|
+
export function UploadField({ field, value, onChange, onFileMeta }) {
|
|
82
122
|
const { t } = useTranslation();
|
|
83
123
|
const api = useApi();
|
|
124
|
+
const getImageUrl = useImageUrl();
|
|
84
125
|
const [uploading, setUploading] = useState(false);
|
|
85
126
|
const [error, setError] = useState(null);
|
|
86
127
|
const { accept, maxSize, storagePath } = getUploadConfig(field);
|
|
@@ -137,6 +178,12 @@ export function UploadField({ field, value, onChange }) {
|
|
|
137
178
|
return;
|
|
138
179
|
}
|
|
139
180
|
onChange(stored);
|
|
181
|
+
if (onFileMeta && isImageField(field, accept)) {
|
|
182
|
+
void readImageSize(file).then((meta) => {
|
|
183
|
+
if (meta.width && meta.height)
|
|
184
|
+
onFileMeta(meta);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
140
187
|
}
|
|
141
188
|
catch (err) {
|
|
142
189
|
setError(err?.response?.data?.message ||
|
|
@@ -145,7 +192,7 @@ export function UploadField({ field, value, onChange }) {
|
|
|
145
192
|
finally {
|
|
146
193
|
setUploading(false);
|
|
147
194
|
}
|
|
148
|
-
}, [api, endpoint, accept, maxSize, storagePath, onChange, t]);
|
|
195
|
+
}, [api, endpoint, accept, maxSize, storagePath, onChange, onFileMeta, field, t]);
|
|
149
196
|
return (_jsxs("div", { className: "grid gap-1.5", "data-widget": "upload", onDragOver: (e) => {
|
|
150
197
|
e.preventDefault();
|
|
151
198
|
}, onDrop: (e) => {
|
|
@@ -154,5 +201,5 @@ export function UploadField({ field, value, onChange }) {
|
|
|
154
201
|
if (!dropped || uploading)
|
|
155
202
|
return;
|
|
156
203
|
void handleFile(dropped);
|
|
157
|
-
}, children: [_jsx(FilePickButton, { id: field.key, accept: accept, loading: uploading, hasFile: hasValue, fileName: hasValue ? uploadedDisplayName(value) : undefined, onFile: (f) => void handleFile(f), pickLabel: field.placeholder || undefined }), error && (_jsx("span", { className: "text-sm text-destructive", role: "alert", children: error }))] }));
|
|
204
|
+
}, children: [hasValue && isImageField(field, accept) && (_jsx("img", { src: getImageUrl(String(value)), alt: "", className: "h-24 w-24 rounded-md border bg-muted object-cover", "data-testid": "upload-preview" })), _jsx(FilePickButton, { id: field.key, accept: accept, loading: uploading, hasFile: hasValue, fileName: hasValue ? uploadedDisplayName(value) : undefined, onFile: (f) => void handleFile(f), pickLabel: field.placeholder || undefined }), error && (_jsx("span", { className: "text-sm text-destructive", role: "alert", children: error }))] }));
|
|
158
205
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
deriveRelationFormFields,
|
|
4
|
+
isManagedRelationColumn,
|
|
5
|
+
nextRelationPosition,
|
|
6
|
+
relationColumnUi,
|
|
7
|
+
relationDerivedValues,
|
|
8
|
+
relationGalleryColumn,
|
|
9
|
+
relationInitialValues,
|
|
10
|
+
relationMediaKind,
|
|
11
|
+
relationPositionKey,
|
|
12
|
+
relationPositionSortable,
|
|
13
|
+
sortRelationRows,
|
|
14
|
+
} from '../dynamic-relation-helpers'
|
|
15
|
+
import { resolveWidget } from '../dynamic-form-schema'
|
|
16
|
+
import type { ColumnDefinition, TableMetadata } from '../types'
|
|
17
|
+
|
|
18
|
+
const col = (c: Partial<ColumnDefinition> & { key: string }): ColumnDefinition =>
|
|
19
|
+
({ label: c.key, type: 'text', sortable: false, filterable: false, ...c }) as ColumnDefinition
|
|
20
|
+
|
|
21
|
+
// What /metadata/table serves for ProductImage (products 0.23.2) — the manifest
|
|
22
|
+
// `widget: image` does not travel to the table endpoint, `display: image_stack`
|
|
23
|
+
// does (as cellStyle), plus the creator avatar column every table gets.
|
|
24
|
+
const productImagesToday: Pick<TableMetadata, 'columns'> = {
|
|
25
|
+
columns: [
|
|
26
|
+
col({ key: 'product_id', ref: 'products' }),
|
|
27
|
+
col({ key: 'variant_id', ref: 'product_variants' }),
|
|
28
|
+
col({ key: 'url', cellStyle: 'image_stack' }),
|
|
29
|
+
col({ key: 'alt' }),
|
|
30
|
+
col({ key: 'width', type: 'number' }),
|
|
31
|
+
col({ key: 'height', type: 'number' }),
|
|
32
|
+
col({ key: 'position', type: 'number' }),
|
|
33
|
+
col({ key: 'created_by.avatar', type: 'avatar', cellStyle: 'creator' }),
|
|
34
|
+
],
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const productImagesDeclared: Pick<TableMetadata, 'columns'> = {
|
|
38
|
+
columns: [
|
|
39
|
+
col({ key: 'product_id', ref: 'products' }),
|
|
40
|
+
col({ key: 'variant_id', ref: 'product_variants', styleConfig: { empty_label: 'Para todas las variantes' } }),
|
|
41
|
+
col({ key: 'url', cellStyle: 'image_stack', styleConfig: { gallery: true, max_size: 5242880 } }),
|
|
42
|
+
col({ key: 'alt', styleConfig: { default_from_parent: 'name' } }),
|
|
43
|
+
col({ key: 'width', type: 'number', styleConfig: { derive: 'image_width' } }),
|
|
44
|
+
col({ key: 'height', type: 'number', styleConfig: { derive: 'image_height' } }),
|
|
45
|
+
col({ key: 'position', type: 'number', styleConfig: { derive: 'next_position' } }),
|
|
46
|
+
col({ key: 'created_by.avatar', type: 'avatar', cellStyle: 'creator' }),
|
|
47
|
+
],
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('deriveRelationFormFields: galería de producto', () => {
|
|
51
|
+
// Protek 01/11: «Imagen» salía como input de texto y «Creado por» editable.
|
|
52
|
+
it('la columna de imagen es el widget de subida y la auditoría no aparece', () => {
|
|
53
|
+
const fields = deriveRelationFormFields(productImagesToday, 'product_id')
|
|
54
|
+
const byKey = Object.fromEntries(fields.map((f) => [f.key, f]))
|
|
55
|
+
expect(byKey.url?.type).toBe('image')
|
|
56
|
+
expect(byKey.url?.accept).toBe('image/*')
|
|
57
|
+
expect(resolveWidget(byKey.url!)).toBe('upload')
|
|
58
|
+
expect(byKey['created_by.avatar']).toBeUndefined()
|
|
59
|
+
expect(byKey.variant_id && resolveWidget(byKey.variant_id)).toBe('dynamic_select')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('sin display_config los campos numéricos siguen visibles (retrocompat)', () => {
|
|
63
|
+
const keys = deriveRelationFormFields(productImagesToday, 'product_id').map((f) => f.key)
|
|
64
|
+
expect(keys).toEqual(['variant_id', 'url', 'alt', 'width', 'height', 'position'])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('derived/hidden fuera del formulario; empty_label como placeholder', () => {
|
|
68
|
+
const fields = deriveRelationFormFields(productImagesDeclared, 'product_id')
|
|
69
|
+
expect(fields.map((f) => f.key)).toEqual(['variant_id', 'url', 'alt'])
|
|
70
|
+
expect(fields[0].placeholder).toBe('Para todas las variantes')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('una FK con display image_stack (logo de marca) sigue siendo picker, no subida', () => {
|
|
74
|
+
expect(relationMediaKind(col({ key: 'brand_id', ref: 'brands', cellStyle: 'image_stack' }))).toBeUndefined()
|
|
75
|
+
expect(relationMediaKind(col({ key: 'doc', widget: 'file' } as any))).toBe('file')
|
|
76
|
+
expect(relationMediaKind(col({ key: 'photo', type: 'image' }))).toBe('image')
|
|
77
|
+
expect(relationMediaKind(col({ key: 'sku' }))).toBeUndefined()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('auditoría y proyecciones con punto nunca son editables', () => {
|
|
81
|
+
for (const k of ['created_by', 'created_by.avatar', 'updated_by_id', 'deleted_by', 'organization_id', 'product.name']) {
|
|
82
|
+
expect(isManagedRelationColumn(k)).toBe(true)
|
|
83
|
+
}
|
|
84
|
+
expect(isManagedRelationColumn('alt')).toBe(false)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('valores derivados de la fila', () => {
|
|
89
|
+
const rows = [{ position: 0 }, { position: 3 }, { position: null }]
|
|
90
|
+
|
|
91
|
+
it('posición siguiente solo al crear; tamaño solo si se midió', () => {
|
|
92
|
+
expect(relationDerivedValues(productImagesDeclared, { isCreate: true, rows, image: { width: 1200.4, height: 800 } }))
|
|
93
|
+
.toEqual({ width: 1200, height: 800, position: 4 })
|
|
94
|
+
expect(relationDerivedValues(productImagesDeclared, { isCreate: false, rows, image: null })).toEqual({})
|
|
95
|
+
expect(relationDerivedValues(productImagesToday, { isCreate: true, rows, image: { width: 1, height: 1 } })).toEqual({})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('nextRelationPosition: 0 sin filas', () => {
|
|
99
|
+
expect(nextRelationPosition([])).toBe(0)
|
|
100
|
+
expect(nextRelationPosition([{ position: '2' }, { position: 'x' }])).toBe(3)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('texto alternativo sugerido con el nombre del padre', () => {
|
|
104
|
+
expect(relationInitialValues(productImagesDeclared, { name: 'BALATA DISCO' })).toEqual({ alt: 'BALATA DISCO' })
|
|
105
|
+
expect(relationInitialValues(productImagesDeclared, null)).toEqual({})
|
|
106
|
+
expect(relationInitialValues(productImagesToday, { name: 'X' })).toEqual({})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('orden y modo galería', () => {
|
|
111
|
+
it('ordena por position, estable, sin posición al final', () => {
|
|
112
|
+
const rows = [{ id: 'a', position: 2 }, { id: 'b' }, { id: 'c', position: 0 }, { id: 'd', position: 2 }]
|
|
113
|
+
expect(sortRelationRows(rows, 'position').map((r) => r.id)).toEqual(['c', 'a', 'd', 'b'])
|
|
114
|
+
expect(sortRelationRows(rows, undefined)).toBe(rows)
|
|
115
|
+
expect(relationPositionKey(productImagesToday)).toBe('position')
|
|
116
|
+
expect(relationPositionSortable(productImagesToday)).toBe(false)
|
|
117
|
+
expect(relationPositionSortable({ columns: [col({ key: 'position', sortable: true })] })).toBe(true)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('la galería es opt-in por display_config.gallery', () => {
|
|
121
|
+
expect(relationGalleryColumn(productImagesToday)).toBeUndefined()
|
|
122
|
+
expect(relationGalleryColumn(productImagesDeclared)?.key).toBe('url')
|
|
123
|
+
expect(relationColumnUi(col({ key: 'x', styleConfig: { derive: 'otra' } }))).toEqual({})
|
|
124
|
+
})
|
|
125
|
+
})
|