@qoretechnologies/reqraft 0.10.45 → 0.10.46-pr.105.g27ead6a
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/dist/components/form/engine/CompactRow.d.ts.map +1 -1
- package/dist/components/form/engine/CompactRow.js +31 -5
- package/dist/components/form/engine/CompactRow.js.map +1 -1
- package/dist/components/form/engine/FormEngine.d.ts +17 -0
- package/dist/components/form/engine/FormEngine.d.ts.map +1 -1
- package/dist/components/form/engine/FormEngine.js +135 -28
- package/dist/components/form/engine/FormEngine.js.map +1 -1
- package/dist/components/form/engine/compactRowStyles.d.ts.map +1 -1
- package/dist/components/form/engine/compactRowStyles.js +10 -1
- package/dist/components/form/engine/compactRowStyles.js.map +1 -1
- package/dist/components/form/fields/template/TemplateField.d.ts.map +1 -1
- package/dist/components/form/fields/template/TemplateField.js +46 -21
- package/dist/components/form/fields/template/TemplateField.js.map +1 -1
- package/dist/helpers/expressions.d.ts.map +1 -1
- package/dist/helpers/expressions.js +15 -2
- package/dist/helpers/expressions.js.map +1 -1
- package/package.json +1 -1
- package/src/components/form/engine/CompactRow.tsx +51 -2
- package/src/components/form/engine/FormEngine.stories.tsx +300 -0
- package/src/components/form/engine/FormEngine.tsx +195 -32
- package/src/components/form/engine/compactRowStyles.ts +41 -0
- package/src/components/form/fields/template/TemplateField.stories.tsx +75 -0
- package/src/components/form/fields/template/TemplateField.tsx +53 -27
- package/src/helpers/expressions.ts +16 -2
|
@@ -835,6 +835,24 @@ export interface IFormEngineProps extends Omit<IReqoreCollectionProps, 'onChange
|
|
|
835
835
|
* (non-compact) mode.
|
|
836
836
|
*/
|
|
837
837
|
initialExpandedOptions?: string[];
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Cap how many rows a status box shows before the rest fold behind a
|
|
841
|
+
* "N more fields" control. Applies to every box — Needs attention, Set and
|
|
842
|
+
* Optional alike — so a long form stays scannable instead of making the
|
|
843
|
+
* reader page past one box to reach the next.
|
|
844
|
+
*
|
|
845
|
+
* Optional keeps its own rule on top of this: a box that would have
|
|
846
|
+
* collapsed but holds preselected rows shows those rows rather than an
|
|
847
|
+
* arbitrary first-N. The cap then applies to that set, so
|
|
848
|
+
* `maxFieldsShown: 5` over 10 preselected fields shows 5 — and opening the
|
|
849
|
+
* control reveals EVERY row in the box, not just the other 5 preselected
|
|
850
|
+
* ones, because once the reader has asked to see more, hiding the rest is
|
|
851
|
+
* the same defect one level down.
|
|
852
|
+
*
|
|
853
|
+
* Unset (the default) leaves every box uncapped.
|
|
854
|
+
*/
|
|
855
|
+
maxFieldsShown?: number;
|
|
838
856
|
}
|
|
839
857
|
|
|
840
858
|
// Option types rendered full-width (IDE Options parity, commit 8e6b7781).
|
|
@@ -887,6 +905,7 @@ const FormEngineImpl = ({
|
|
|
887
905
|
autoFocusFirstRequired,
|
|
888
906
|
expandFirstRequired,
|
|
889
907
|
initialExpandedOptions,
|
|
908
|
+
maxFieldsShown,
|
|
890
909
|
...rest
|
|
891
910
|
}: IFormEngineProps) => {
|
|
892
911
|
// Built-ins + whatever the consumer declared for its own injected editors.
|
|
@@ -934,6 +953,9 @@ const FormEngineImpl = ({
|
|
|
934
953
|
const [showInvalidOptionsOnly, setShowInvalidOptionsOnly] = useState<boolean>(false);
|
|
935
954
|
// Which options are expanded into their editor (several can be open at once).
|
|
936
955
|
const [expandedOptions, setExpandedOptions] = useState<string[]>([]);
|
|
956
|
+
/** Status boxes whose "N more fields" control the reader has opened. Keyed by
|
|
957
|
+
box so opening Optional does not also unfold Set. */
|
|
958
|
+
const [expandedMoreBoxes, setExpandedMoreBoxes] = useState<TFormEngineBoxKey[]>([]);
|
|
937
959
|
|
|
938
960
|
// --- Reveal a status box's content when it is opened ----------------------
|
|
939
961
|
//
|
|
@@ -2490,6 +2512,9 @@ const FormEngineImpl = ({
|
|
|
2490
2512
|
const cBg = (theme as { main?: string } | undefined)?.main || '#181818';
|
|
2491
2513
|
const cRowBg = changeDarkness(getMainBackgroundColor(theme), 0.01);
|
|
2492
2514
|
const cGroupLine = `${cText}1f`;
|
|
2515
|
+
// The "N more fields" row's dashed edge. Well above the divider tint: this
|
|
2516
|
+
// one is an affordance the reader has to notice, not a hairline between rows.
|
|
2517
|
+
const cMoreBorder = `${cText}4d`;
|
|
2493
2518
|
|
|
2494
2519
|
// The closure surface the extracted CompactRow reads through context. Refs and
|
|
2495
2520
|
// setters are stable; the state/memo/handler fields change identity as they do
|
|
@@ -2859,6 +2884,30 @@ const FormEngineImpl = ({
|
|
|
2859
2884
|
// other and DOES get its sub-label.
|
|
2860
2885
|
const showGroupSubLabel = (groupName: string) =>
|
|
2861
2886
|
(groupName !== 'general' && groupName !== 'optional') || !!groups?.[groupName];
|
|
2887
|
+
|
|
2888
|
+
// `preselected` means "show this option by default when a new form is
|
|
2889
|
+
// loaded, so it's visible to the user". An empty non-required preselected
|
|
2890
|
+
// field buckets to 'optional' (nothing is wrong with it, and it has no
|
|
2891
|
+
// value), and the Optional box is collapsed by default — so the very
|
|
2892
|
+
// fields the schema asked to put in front of the author were the ones
|
|
2893
|
+
// nobody could see. A preselected row therefore forces its box open.
|
|
2894
|
+
//
|
|
2895
|
+
// A hidden row is an addable the author has not put in the form yet, so it
|
|
2896
|
+
// is never what `preselected` is talking about, however its schema is
|
|
2897
|
+
// flagged.
|
|
2898
|
+
const isPreselectedRow = (entry: TRowEntry) =>
|
|
2899
|
+
!entry.hidden &&
|
|
2900
|
+
!!(options?.[entry.name] as { preselected?: boolean } | undefined)?.preselected;
|
|
2901
|
+
// ONLY the Optional box. A preselected field that HAS a value buckets to
|
|
2902
|
+
// 'set' and one that fails validation to 'attention'; in both boxes the
|
|
2903
|
+
// field is already accounted for, and whether those boxes start collapsed
|
|
2904
|
+
// is the consumer's deliberate `compactCollapsedGroups` choice. Overriding
|
|
2905
|
+
// them here forced the Set box open against an explicit request.
|
|
2906
|
+
const groupHasPreselectedRow = (boxKey: TFormEngineBoxKey, groupName: string) =>
|
|
2907
|
+
boxKey === 'optional' && (buckets[boxKey][groupName] || []).some(isPreselectedRow);
|
|
2908
|
+
const boxHasPreselectedRows = (boxKey: TFormEngineBoxKey) =>
|
|
2909
|
+
boxKey === 'optional' &&
|
|
2910
|
+
bucketGroups[boxKey].some((groupName) => groupHasPreselectedRow(boxKey, groupName));
|
|
2862
2911
|
const STATUS_BOXES: Array<{
|
|
2863
2912
|
key: TFormEngineBoxKey;
|
|
2864
2913
|
label: string;
|
|
@@ -2947,6 +2996,52 @@ const FormEngineImpl = ({
|
|
|
2947
2996
|
});
|
|
2948
2997
|
};
|
|
2949
2998
|
|
|
2999
|
+
// One schema group inside a status box: its thin sub-label, the group's
|
|
3000
|
+
// subtitle, then its rows. Factored out of the box body so the SAME markup
|
|
3001
|
+
// renders both the groups a box shows directly and the ones it defers
|
|
3002
|
+
// behind the inner collapse.
|
|
3003
|
+
/** @param only when given, render just these rows of the group — the group
|
|
3004
|
+
can be split across the shown and folded halves of a capped box, and its
|
|
3005
|
+
label must appear above whichever half holds its first row. */
|
|
3006
|
+
const renderBoxGroup = (
|
|
3007
|
+
boxKey: TFormEngineBoxKey,
|
|
3008
|
+
groupName: string,
|
|
3009
|
+
only?: Set<string>
|
|
3010
|
+
) => {
|
|
3011
|
+
const groupConfig = groups?.[groupName];
|
|
3012
|
+
const rows =
|
|
3013
|
+
only ?
|
|
3014
|
+
(buckets[boxKey][groupName] || []).filter((entry) => only.has(entry.name))
|
|
3015
|
+
: buckets[boxKey][groupName];
|
|
3016
|
+
if (only && !rows.length) {
|
|
3017
|
+
return null;
|
|
3018
|
+
}
|
|
3019
|
+
return (
|
|
3020
|
+
<React.Fragment key={groupName}>
|
|
3021
|
+
{showGroupSubLabel(groupName) ?
|
|
3022
|
+
<StyledStatusBoxGroupLabel>
|
|
3023
|
+
{getOptionGroupLabel(groupName, groups)}
|
|
3024
|
+
</StyledStatusBoxGroupLabel>
|
|
3025
|
+
: null}
|
|
3026
|
+
{showGroupSubLabel(groupName) && groupConfig?.subtitle ?
|
|
3027
|
+
<ReqoreP
|
|
3028
|
+
size='small'
|
|
3029
|
+
effect={{ opacity: 0.6 }}
|
|
3030
|
+
style={{
|
|
3031
|
+
marginTop: 2,
|
|
3032
|
+
marginBottom: 8,
|
|
3033
|
+
marginLeft: GROUP_INDENT,
|
|
3034
|
+
paddingRight: 10,
|
|
3035
|
+
}}
|
|
3036
|
+
>
|
|
3037
|
+
{groupConfig.subtitle}
|
|
3038
|
+
</ReqoreP>
|
|
3039
|
+
: null}
|
|
3040
|
+
{renderGroupRows(rows)}
|
|
3041
|
+
</React.Fragment>
|
|
3042
|
+
);
|
|
3043
|
+
};
|
|
3044
|
+
|
|
2950
3045
|
return (
|
|
2951
3046
|
<OptionsContext.Provider value={{ schema: options, value: availableOptions }}>
|
|
2952
3047
|
<CompactRowContext.Provider value={compactRowContextValue}>
|
|
@@ -3008,6 +3103,54 @@ const FormEngineImpl = ({
|
|
|
3008
3103
|
const groupsInBox = bucketGroups[box.key];
|
|
3009
3104
|
const count = bucketCount(box.key);
|
|
3010
3105
|
if (!count) return null;
|
|
3106
|
+
const hasPreselectedRows = boxHasPreselectedRows(box.key);
|
|
3107
|
+
const wouldCollapse =
|
|
3108
|
+
compactCollapsedGroups.includes(box.key) &&
|
|
3109
|
+
!query &&
|
|
3110
|
+
!(box.key === 'optional' && onlyOptionalRows);
|
|
3111
|
+
// Only a box that was opened SOLELY to reveal a preselected
|
|
3112
|
+
// row splits its body; a box that renders open anyway shows
|
|
3113
|
+
// all of its groups as before.
|
|
3114
|
+
const splitForPreselected = wouldCollapse && hasPreselectedRows;
|
|
3115
|
+
|
|
3116
|
+
// Which rows this box shows, and which fold away, decided at
|
|
3117
|
+
// ROW level because `maxFieldsShown` counts fields — a
|
|
3118
|
+
// group-level split can only ever cut at a group boundary.
|
|
3119
|
+
// Group order is preserved so the visible rows read in the
|
|
3120
|
+
// same order they would if nothing were folded.
|
|
3121
|
+
const orderedRows: TRowEntry[] = groupsInBox.flatMap(
|
|
3122
|
+
(groupName) => buckets[box.key][groupName] || []
|
|
3123
|
+
);
|
|
3124
|
+
// Optional's own rule first: a box opened solely to reveal
|
|
3125
|
+
// preselected rows offers those, not an arbitrary first-N.
|
|
3126
|
+
const candidateRows =
|
|
3127
|
+
splitForPreselected ? orderedRows.filter(isPreselectedRow) : orderedRows;
|
|
3128
|
+
// …then the cap applies to whatever that left.
|
|
3129
|
+
const capped =
|
|
3130
|
+
maxFieldsShown !== undefined && candidateRows.length > maxFieldsShown;
|
|
3131
|
+
const shownRows = capped ? candidateRows.slice(0, maxFieldsShown) : candidateRows;
|
|
3132
|
+
const shownRowSet = new Set(shownRows.map((entry) => entry.name));
|
|
3133
|
+
// Everything the box holds that is not on show. Once the
|
|
3134
|
+
// reader asks for more they get the whole box — withholding
|
|
3135
|
+
// the non-preselected remainder behind a second control is
|
|
3136
|
+
// the same defect one level down.
|
|
3137
|
+
const deferredRowSet = new Set(
|
|
3138
|
+
orderedRows
|
|
3139
|
+
.filter((entry) => !shownRowSet.has(entry.name))
|
|
3140
|
+
.map((entry) => entry.name)
|
|
3141
|
+
);
|
|
3142
|
+
const deferredCount = deferredRowSet.size;
|
|
3143
|
+
const shownGroups = groupsInBox.filter((groupName) =>
|
|
3144
|
+
(buckets[box.key][groupName] || []).some((entry) =>
|
|
3145
|
+
shownRowSet.has(entry.name)
|
|
3146
|
+
)
|
|
3147
|
+
);
|
|
3148
|
+
const deferredGroups = groupsInBox.filter((groupName) =>
|
|
3149
|
+
(buckets[box.key][groupName] || []).some(
|
|
3150
|
+
(entry) => !shownRowSet.has(entry.name)
|
|
3151
|
+
)
|
|
3152
|
+
);
|
|
3153
|
+
const moreOpen = Boolean(query) || expandedMoreBoxes.includes(box.key);
|
|
3011
3154
|
const accent =
|
|
3012
3155
|
box.key === 'attention' ? cWarning
|
|
3013
3156
|
: box.key === 'set' ? cSuccess
|
|
@@ -3054,11 +3197,15 @@ const FormEngineImpl = ({
|
|
|
3054
3197
|
// nothing else. This does not generalise to the other two —
|
|
3055
3198
|
// a lone Set box collapsed is a deliberate ask, and its
|
|
3056
3199
|
// header still reports what is in there.
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3200
|
+
//
|
|
3201
|
+
// A PRESELECTED row overrides it too: the schema asked
|
|
3202
|
+
// for that field to be visible on a new form, so the
|
|
3203
|
+
// box it lands in opens. The groups it does NOT appear
|
|
3204
|
+
// in stay behind an inner collapse below, so opening
|
|
3205
|
+
// the box reveals the preselected fields without also
|
|
3206
|
+
// dumping every not-yet-added optional field on the
|
|
3207
|
+
// author.
|
|
3208
|
+
isCollapsed={wouldCollapse && !hasPreselectedRows}
|
|
3062
3209
|
label={
|
|
3063
3210
|
<StyledGroupHeader>
|
|
3064
3211
|
<ReqoreP effect={{ weight: 'bold' }} size='normal'>
|
|
@@ -3089,35 +3236,51 @@ const FormEngineImpl = ({
|
|
|
3089
3236
|
$success={cSuccess}
|
|
3090
3237
|
$rowBg={cRowBg}
|
|
3091
3238
|
$lineColor={cGroupLine}
|
|
3239
|
+
$moreBorder={cMoreBorder}
|
|
3092
3240
|
className={compactNarrow ? 'readfirst-narrow' : undefined}
|
|
3093
3241
|
>
|
|
3094
|
-
{
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3242
|
+
{shownGroups.map((groupName) =>
|
|
3243
|
+
renderBoxGroup(box.key, groupName, shownRowSet)
|
|
3244
|
+
)}
|
|
3245
|
+
{/* The control lives INSIDE the group body, as the last
|
|
3246
|
+
row, so it inherits the rows' grid, padding and
|
|
3247
|
+
hover and lines up with them. Outside it was a bare
|
|
3248
|
+
line of text in the box's corner, which is what the
|
|
3249
|
+
build #154 review rejected. */}
|
|
3250
|
+
{deferredCount ?
|
|
3251
|
+
<button
|
|
3252
|
+
type='button'
|
|
3253
|
+
className='readfirst-row readfirst-more-row options-readfirst-more'
|
|
3254
|
+
aria-expanded={moreOpen}
|
|
3255
|
+
onClick={() =>
|
|
3256
|
+
setExpandedMoreBoxes((prev) =>
|
|
3257
|
+
prev.includes(box.key) ?
|
|
3258
|
+
prev.filter((k) => k !== box.key)
|
|
3259
|
+
: [...prev, box.key]
|
|
3260
|
+
)
|
|
3261
|
+
}
|
|
3262
|
+
>
|
|
3263
|
+
<ReqoreP size='small' effect={{ opacity: 0.8 }}>
|
|
3264
|
+
{moreOpen ?
|
|
3265
|
+
'Show fewer'
|
|
3266
|
+
: `${deferredCount} more ${box.key === 'optional' ? 'optional ' : ''}field${deferredCount === 1 ? '' : 's'}`
|
|
3267
|
+
}
|
|
3268
|
+
</ReqoreP>
|
|
3269
|
+
<ReqoreIcon
|
|
3270
|
+
icon='ArrowDownSLine'
|
|
3271
|
+
size='small'
|
|
3272
|
+
className='readfirst-more-chevron'
|
|
3273
|
+
effect={{ opacity: 0.8 }}
|
|
3274
|
+
/>
|
|
3275
|
+
</button>
|
|
3276
|
+
: null}
|
|
3277
|
+
{/* A search forces the fold open for the same reason
|
|
3278
|
+
the boxes open: an unmounted row cannot be found. */}
|
|
3279
|
+
{deferredCount && moreOpen ?
|
|
3280
|
+
deferredGroups.map((groupName) =>
|
|
3281
|
+
renderBoxGroup(box.key, groupName, deferredRowSet)
|
|
3282
|
+
)
|
|
3283
|
+
: null}
|
|
3121
3284
|
</StyledGroupBody>
|
|
3122
3285
|
</StyledStatusBox>
|
|
3123
3286
|
);
|
|
@@ -450,6 +450,10 @@ export const StyledGroupBody = styled.div<{
|
|
|
450
450
|
$success: string;
|
|
451
451
|
$rowBg: string;
|
|
452
452
|
$lineColor: string;
|
|
453
|
+
/** Edge colour for the "N more fields" row. Its own value because the row
|
|
454
|
+
HAS to be seen — the divider tint that separates two fields is ~8% of the
|
|
455
|
+
text colour, which disappears entirely as a 1px dashed border. */
|
|
456
|
+
$moreBorder: string;
|
|
453
457
|
}>`
|
|
454
458
|
display: flex;
|
|
455
459
|
flex-flow: column;
|
|
@@ -529,6 +533,43 @@ export const StyledGroupBody = styled.div<{
|
|
|
529
533
|
.readfirst-row-hidden {
|
|
530
534
|
opacity: 0.65;
|
|
531
535
|
}
|
|
536
|
+
/* The "N more fields" control IS a field row — same grid, same padding, same
|
|
537
|
+
hover — so it lines up with the rows above instead of floating as a scrap
|
|
538
|
+
of text in the box's corner. A dashed edge and a lower-contrast label are
|
|
539
|
+
what say it is not itself a field: nothing here can be set.
|
|
540
|
+
|
|
541
|
+
It spans both content columns because it has no label/value split, and it
|
|
542
|
+
drops the inter-row hairline (the ::after rule) since it always sits last. */
|
|
543
|
+
.readfirst-more-row {
|
|
544
|
+
grid-template-columns: 1fr auto;
|
|
545
|
+
border: 1px dashed ${({ $moreBorder }) => $moreBorder};
|
|
546
|
+
background: transparent;
|
|
547
|
+
width: 100%;
|
|
548
|
+
text-align: left;
|
|
549
|
+
font: inherit;
|
|
550
|
+
color: inherit;
|
|
551
|
+
/* The dashed edge replaces the hairline; two lines would read as a divider
|
|
552
|
+
AND a border stacked. */
|
|
553
|
+
margin-top: 2px;
|
|
554
|
+
}
|
|
555
|
+
.readfirst-more-row::after {
|
|
556
|
+
display: none;
|
|
557
|
+
}
|
|
558
|
+
.readfirst-more-row:hover {
|
|
559
|
+
background: ${({ $hover }) => $hover};
|
|
560
|
+
border-style: solid;
|
|
561
|
+
}
|
|
562
|
+
.readfirst-more-row:focus-visible {
|
|
563
|
+
outline: 2px solid ${({ $focus }) => $focus};
|
|
564
|
+
outline-offset: -2px;
|
|
565
|
+
}
|
|
566
|
+
/* The chevron points the way the click goes: down to reveal, up to fold. */
|
|
567
|
+
.readfirst-more-row .readfirst-more-chevron {
|
|
568
|
+
transition: transform 0.15s ease;
|
|
569
|
+
}
|
|
570
|
+
.readfirst-more-row[aria-expanded='true'] .readfirst-more-chevron {
|
|
571
|
+
transform: rotate(180deg);
|
|
572
|
+
}
|
|
532
573
|
/* A disabled field (schema disabled flag or unmet dependencies) is not a
|
|
533
574
|
click target — no hover invite, not-allowed cursor; a lock replaces the
|
|
534
575
|
pencil. */
|
|
@@ -965,3 +965,78 @@ export const LongExampleValueTruncatedWithModal: StoryObj<typeof meta> = {
|
|
|
965
965
|
await _testsWaitForText('Attachment Body');
|
|
966
966
|
},
|
|
967
967
|
};
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* An EMPTY `any` field opens on the template selector, not the type picker.
|
|
971
|
+
*
|
|
972
|
+
* An `any` field has no editor of its own until a concrete type is chosen, so it
|
|
973
|
+
* used to open on the type picker — making the author answer a question about
|
|
974
|
+
* storage ("Text or Number?") before they could say what they meant, and often a
|
|
975
|
+
* question they cannot answer, because the value they want is a reference to
|
|
976
|
+
* something else whose type is not theirs to pick.
|
|
977
|
+
*
|
|
978
|
+
* The literal is still one menu item away: "Set Custom Value" in the ⋮ menu.
|
|
979
|
+
* That is the right way round — picking a template is choosing from a list,
|
|
980
|
+
* picking a literal is a decision.
|
|
981
|
+
*/
|
|
982
|
+
export const EmptyAnyOpensOnTemplates: StoryObj<typeof meta> = {
|
|
983
|
+
args: {
|
|
984
|
+
component: auto,
|
|
985
|
+
type: 'any',
|
|
986
|
+
allowTemplates: true,
|
|
987
|
+
allowCustomValues: true,
|
|
988
|
+
value: undefined,
|
|
989
|
+
},
|
|
990
|
+
parameters: {
|
|
991
|
+
docs: {
|
|
992
|
+
description: {
|
|
993
|
+
story:
|
|
994
|
+
'An untyped, empty field that accepts templates opens showing the template selector rather than a data-type picker.',
|
|
995
|
+
},
|
|
996
|
+
},
|
|
997
|
+
},
|
|
998
|
+
play: async ({ canvasElement }) => {
|
|
999
|
+
await waitFor(() =>
|
|
1000
|
+
expect(canvasElement.querySelector('.template-selector')).toBeTruthy()
|
|
1001
|
+
);
|
|
1002
|
+
},
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* An `any` field that ALREADY HOLDS A LITERAL opens on that literal.
|
|
1007
|
+
*
|
|
1008
|
+
* The other half of the same choice, and the one that keeps it safe: defaulting
|
|
1009
|
+
* to the template view unconditionally would hide a value the author had already
|
|
1010
|
+
* typed, which reads as the value having been lost.
|
|
1011
|
+
*/
|
|
1012
|
+
export const AnyWithLiteralOpensOnTheValue: StoryObj<typeof meta> = {
|
|
1013
|
+
args: {
|
|
1014
|
+
component: auto,
|
|
1015
|
+
type: 'any',
|
|
1016
|
+
allowTemplates: true,
|
|
1017
|
+
allowCustomValues: true,
|
|
1018
|
+
value: 'already-typed',
|
|
1019
|
+
},
|
|
1020
|
+
parameters: {
|
|
1021
|
+
docs: {
|
|
1022
|
+
description: {
|
|
1023
|
+
story:
|
|
1024
|
+
'An untyped field holding a literal keeps showing that literal — only an empty one defaults to the template selector.',
|
|
1025
|
+
},
|
|
1026
|
+
},
|
|
1027
|
+
},
|
|
1028
|
+
play: async ({ canvasElement }) => {
|
|
1029
|
+
// The property that matters is that the VALUE is still on screen. Asserting
|
|
1030
|
+
// the absence of `.template-selector` would be wrong: that class is also on
|
|
1031
|
+
// a control that renders either way, so it says nothing about which view is
|
|
1032
|
+
// active.
|
|
1033
|
+
await waitFor(() => {
|
|
1034
|
+
const held = [
|
|
1035
|
+
...canvasElement.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>(
|
|
1036
|
+
'input, textarea'
|
|
1037
|
+
),
|
|
1038
|
+
].some((el) => el.value === 'already-typed');
|
|
1039
|
+
expect(held).toBe(true);
|
|
1040
|
+
});
|
|
1041
|
+
},
|
|
1042
|
+
};
|
|
@@ -320,8 +320,60 @@ export const TemplateField = memo(
|
|
|
320
320
|
});
|
|
321
321
|
const type = rest.ui_type || rest.type || rest.defaultType;
|
|
322
322
|
|
|
323
|
+
const filteredTemplates = useMemo<IReqoreFormTemplates>(():
|
|
324
|
+
| IReqoreFormTemplates
|
|
325
|
+
| undefined => {
|
|
326
|
+
if (!allowTemplates) {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
let result: IReqoreFormTemplates = templates;
|
|
331
|
+
|
|
332
|
+
if (filterTemplatesByType) {
|
|
333
|
+
result = templatesFilterFunc(templates, type, !!rest.arg_schema);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (filterTemplatesFunc) {
|
|
337
|
+
result = filterTemplatesFunc(result);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return result;
|
|
341
|
+
}, [
|
|
342
|
+
JSON.stringify(templates),
|
|
343
|
+
type,
|
|
344
|
+
allowTemplates,
|
|
345
|
+
filterTemplatesByType,
|
|
346
|
+
JSON.stringify(rest.arg_schema),
|
|
347
|
+
filterTemplatesFunc,
|
|
348
|
+
]);
|
|
349
|
+
|
|
350
|
+
// An `any`-typed field has no editor of its own until a concrete type is
|
|
351
|
+
// chosen, so it opened on the TYPE PICKER: before an author could say what
|
|
352
|
+
// they meant, they had to answer a question about storage — "is this a Text
|
|
353
|
+
// or a Number?" — that they often cannot answer, because the value they
|
|
354
|
+
// want is a reference to something else whose type is not theirs to pick.
|
|
355
|
+
//
|
|
356
|
+
// So an untyped field that accepts templates now opens on the template
|
|
357
|
+
// selector, which is the answer most of them want, and "Set Custom Value"
|
|
358
|
+
// in the ⋮ menu is the way to a literal of a chosen type. That is the
|
|
359
|
+
// reverse of the old default, and it is the right way round: choosing a
|
|
360
|
+
// template is picking from a list, choosing a literal is a decision.
|
|
361
|
+
//
|
|
362
|
+
// Only while the field is EMPTY. A field already holding a literal must
|
|
363
|
+
// open showing that literal — flipping to the template view would hide a
|
|
364
|
+
// value the author put there and make it look lost.
|
|
365
|
+
// ...and only when there is actually something to pick. A field with no
|
|
366
|
+
// templates on offer would otherwise open on an EMPTY picker, which is a
|
|
367
|
+
// worse place to start than the type picker it replaced.
|
|
368
|
+
const typeIsAnyLike = type === 'any' || type === 'auto';
|
|
369
|
+
const isEmptyValue = value === undefined || value === null || value === '';
|
|
370
|
+
const hasTemplatesOnOffer = !!size(filteredTemplates?.items);
|
|
323
371
|
const [isTemplate, setIsTemplate] = useState<boolean>(
|
|
324
|
-
(isDefaultTemplate ||
|
|
372
|
+
(isDefaultTemplate ||
|
|
373
|
+
isValueTemplate(value) ||
|
|
374
|
+
!allowCustomValues ||
|
|
375
|
+
(typeIsAnyLike && isEmptyValue && hasTemplatesOnOffer)) &&
|
|
376
|
+
allowTemplates
|
|
325
377
|
);
|
|
326
378
|
const [internalIsFunction, setInternalIsFunction] = useState<boolean>(
|
|
327
379
|
!!isDefaultFunction && !!allowFunctions
|
|
@@ -413,32 +465,6 @@ export const TemplateField = memo(
|
|
|
413
465
|
const componentTypeProp = componentFromType ? { type } : {};
|
|
414
466
|
const fieldAriaLabel = rest['aria-label'] ?? label ?? rest.display_name ?? name;
|
|
415
467
|
|
|
416
|
-
const filteredTemplates = useMemo<IReqoreFormTemplates>(():
|
|
417
|
-
| IReqoreFormTemplates
|
|
418
|
-
| undefined => {
|
|
419
|
-
if (!allowTemplates) {
|
|
420
|
-
return undefined;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
let result: IReqoreFormTemplates = templates;
|
|
424
|
-
|
|
425
|
-
if (filterTemplatesByType) {
|
|
426
|
-
result = templatesFilterFunc(templates, type, !!rest.arg_schema);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
if (filterTemplatesFunc) {
|
|
430
|
-
result = filterTemplatesFunc(result);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return result;
|
|
434
|
-
}, [
|
|
435
|
-
JSON.stringify(templates),
|
|
436
|
-
type,
|
|
437
|
-
allowTemplates,
|
|
438
|
-
filterTemplatesByType,
|
|
439
|
-
JSON.stringify(rest.arg_schema),
|
|
440
|
-
filterTemplatesFunc,
|
|
441
|
-
]);
|
|
442
468
|
|
|
443
469
|
const handleTemplateFieldChange = useCallback(
|
|
444
470
|
(_name: string, val: string) => {
|
|
@@ -46,14 +46,28 @@ export const argumentMatchesType = (
|
|
|
46
46
|
);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* `auto` is the codebase's other spelling of `any` — `Field.tsx` maps both to
|
|
51
|
+
* one renderer, and FormEngine tests `type === 'any' || type === 'auto'` in
|
|
52
|
+
* several places — but the TYPES LIST only carries `any`.
|
|
53
|
+
*
|
|
54
|
+
* That mattered here because an unknown main type falls into the "not found"
|
|
55
|
+
* branch below and answers FALSE for every check. So an `auto`-typed field was
|
|
56
|
+
* judged incompatible with everything: `filterTemplatesByType()` removed every
|
|
57
|
+
* template from it, and the picker offered a group header with nothing under
|
|
58
|
+
* it. The field was not "a field with no templates" — it was a field whose
|
|
59
|
+
* templates had all been filtered away by a name mismatch.
|
|
60
|
+
*/
|
|
61
|
+
const normalizeAnyLikeTypeName = (name: string): string => (name === 'auto' ? 'any' : name);
|
|
62
|
+
|
|
49
63
|
export const areQorusTypesCompatible = (
|
|
50
64
|
mainType: string | string[],
|
|
51
65
|
checkType: string | string[],
|
|
52
66
|
fallbackTypes?: IQorusTypeObject[]
|
|
53
67
|
): boolean => {
|
|
54
68
|
const types = getQorusTypes() || fallbackTypes || defaultQorusTypes;
|
|
55
|
-
const mainTypes = isArray(mainType) ? mainType : [mainType];
|
|
56
|
-
const checkTypes = isArray(checkType) ? checkType : [checkType];
|
|
69
|
+
const mainTypes = (isArray(mainType) ? mainType : [mainType]).map(normalizeAnyLikeTypeName);
|
|
70
|
+
const checkTypes = (isArray(checkType) ? checkType : [checkType]).map(normalizeAnyLikeTypeName);
|
|
57
71
|
// Get each of the main types from the types list
|
|
58
72
|
for (const main of mainTypes) {
|
|
59
73
|
// Get the type object from the types
|