feat(controls): control sets, a control that adds a row of fields at once - #511
Merged
Merged
Conversation
A control with controlSet.fields describes one row of fields. Each member can name a registered control and override its data (arrays such as options are replaced), or give field data as it is. Every expansion is a fresh copy; unknown controls are skipped with a warning. Refs #227
…s clicked
Clicking a control set runs onBeforeAdd once with componentType 'controlSet'
and the expanded { layout, row, fields }, then adds one new row holding every
field (one column, or one column per field with layout 'columns').
controls.addElement adds a set too. A set's drag keeps its button instead of
a ghost preview.
Refs #227
A dropped control set becomes one new row: at the drop index on a stage, or right after the row it was dropped in. onBeforeAdd reports that stage and index. A held drop is added once allowed, unless its target was removed meanwhile; a set with no fields adds nothing. Also fixes Stage#onAdd swallowing the return value of super.onAdd, which the new "onAdd returns the new row" drop test exposed for a stage-level drop. Refs #227
How to define a set in controls.elements, how members start from a control and override it, where a clicked or dropped set goes, and what onBeforeAdd receives for one. Refs #227
…ed on it A control set dropped on a row never changes that row's columns (it lands in a new row right after it), so Row#onAdd should not call autoColumnWidths for that drop. It previously always did, silently resetting any custom widths (e.g. 25%/75%) to equal shares and firing columnResized. Same fix covers an empty-set drop on a row. Refs #227
expandControlSet destructured each controlSet.fields member directly, throwing a TypeError on a null (or otherwise non-object) member. Since describeControl runs before dom.remove(item) in Component#onAdd, a throw here left the dragged control's placeholder stuck on the canvas. Skip a non-object member with a warning, in the same format as an unknown control's. Refs #227
…eral member names its control The control sets doc left `controls.addElement(id)`'s `id` ambiguous with `meta.id`; only a top-level `id` on the definition works, and it must be distinct from `meta.id` or a generated uuid is used. Also document that a literal (control-less) member can still name its control via `meta.id`, which becomes its `config.controlId`. Rewrap the 134-column pointer line in docs/options/controls/README.md's "## elements" section to fit 120. Refs #227
…nning The drag e2e test only checked that the Address set was added, not that it landed where it was dropped; assert its row's position in the stage's own children order instead. The veto test waited a fixed 300ms without confirming the document listener actually ran; have it set a flag and poll for it before asserting no rows were added. Refs #227
Collaborator
Author
|
🎉 This PR is included in version 5.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Control sets: a control that adds several predefined fields at once, like formBuilder's
inputSets. Clicking or dropping one adds a single new row holding all of its fields, with new ids every time.A set is an ordinary
controls.elementsentry with acontrolSetkey:controlstart from that control's data (itsmeta.id) and override it; arrays such asoptionsreplace the control's instead of being appended. Members withoutcontrolare field data as is, and can name their control withmeta.id.onBeforeAdd/formeoBeforeAdd(Feature: event/action upgrades #281) run once for the whole set withcomponentType: 'controlSet', the set'scontrolId,data: { layout, row, fields }, and the page and index the row goes to. A held drop is added once allowed, unless its target was removed meanwhile. The usualonAddRow/onAddColumn/onAddFieldevents follow.controls.addElement(id)adds a set without the hook.formeo: control set "<id>" …console warning. A set left with no fields adds nothing and runs no hook.Existing controls and existing
onBeforeAddhandlers are unchanged; handlers that switch oncomponentTypemay now also see'controlSet'.Docs
docs/controls/custom-controls.md("Control sets"), a pointer indocs/options/controls/README.md, and'controlSet'in theonBeforeAddsection ofdocs/options/events/README.md.Testing
npm test: 701 pass (672 on main). New:src/lib/js/components/controls/control-set.test.js,src/lib/js/components/control-sets.test.jsnpm run lint: cleantest.skips). New spec:tests/control-sets.spec.jsFollow-ups
controls.addElementcould accept a control'smeta.id(today it needs the control's ownid, for every control)Fixes #227