Split canvas dragdrop extraction - #16
Merged
matteius merged 7 commits intoAug 5, 2026
Merged
Conversation
…directly 8 tests files exercise canvas/drag-drop methods indirectly through object.create(formBuilder.prototype). Moving to canvasMethods.tests.js to mirror the new module's location, and added new test coverage for the previously untested methods in that module.
…single-step canvas setupCanvas's Sortable onAdd (existing-field-moved branch) and onUpdate handlers mutated this.fields directly without calling pushUndo() first, so Ctrl+Z couldn't undo a single-step canvas drag-reorder. PR opensensor#12 fixed the equivalent gap for cross-step move/reorder (handleFieldMovedToStep/updateFieldOrderInStep) but never touched setupCanvas - this was flagged as still-open in the module-split plan. (addFieldAtPosition already pushed its own undo snapshot, so the palette-drop branch of onAdd was unaffected.)
…alue
id used store.nextFieldId('new'), which reads-then-increments the counter, while field_name (via getDefaultName) read the counter afterward - already incremented - so a new field's id and its default field_name carried different numbers (e.g. id "new_5" alongside field_name "text_6"). handleFieldDroppedToStep already computed field_name before touching the counter, so its id/field_name pair always matched; addFieldAtPosition now does the same, reading field_name first.
Fix pre-existing unescaped innerHTML issue as it will pop on copilot checks
ViolanteCodes
added a commit
to vanburencountymi-digital-information/form-manager
that referenced
this pull request
Aug 4, 2026
…, commit static_overrides requirements.txt now pins to ViolanteCodes/django-forms-workflows@150caaa (opensensor/django-forms-workflows#16), which extracts the canvas/drag-drop controller out of form-builder.js the same way #11/#12 already did for the API client and property editor. form-builder.js and form-builder-property-editor.js overrides rebuilt against the new pin; form-builder-api.js and form_builder.html need no changes since their upstream source is byte-identical between the old and new pin - verified, not assumed. Also committing form-builder-api.js and form_builder.html for the first time
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the FormBuilder module-splitting work by extracting the canvas / drag-drop / field palette / multi-step canvas / context-menu responsibilities out of form-builder.js into a dedicated form-builder-canvas.js module, and restructures tests to exercise the extracted canvasMethods directly. It also includes small behavioral fixes around undo history for single-step drag operations and HTML escaping in canvas rendering.
Changes:
- Extracts canvas + drag/drop + field CRUD + multi-step canvas + context menu logic into
form-builder-canvas.jsand mixes it intoFormBuilder.prototype. - Replaces multiple per-method tests with a consolidated
canvasMethods.test.jsthat directly tests the extracted module (including new coverage for previously untested methods). - Fixes undo snapshot behavior for single-step canvas reorder/move operations and escapes additional field attributes during canvas rendering.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| django_forms_workflows/static/django_forms_workflows/js/form-builder.js | Imports and mixes in canvasMethods, removing canvas-related method bodies from the core class file. |
| django_forms_workflows/static/django_forms_workflows/js/form-builder-canvas.js | New extracted module containing palette/canvas/drag-drop/step rendering/context menu/field CRUD logic plus bugfixes. |
| tests_js/form-builder/updateFieldOrderInStep.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/toggleMultiStepMode.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/setupCanvas.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/multiStepFieldIndexSync.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/moveAllFieldsToMainCanvas.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/handleFieldMovedToStep.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/handleFieldDroppedToStep.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder/addFieldAtPosition.test.js | Removed; coverage moved into tests_js/form-builder-canvas/canvasMethods.test.js. |
| tests_js/form-builder-canvas/canvasMethods.test.js | New consolidated test suite targeting canvasMethods directly with expanded coverage. |
Suppressed comments (1)
django_forms_workflows/static/django_forms_workflows/js/form-builder-canvas.js:970
allFieldsis built but never used. This extra allocation/loop can be removed; the method currently only re-renders the main canvas/preview.
// Collect all fields from all steps
const allFields = [];
this.formSteps.forEach(step => {
if (step.fields) {
allFields.push(...step.fields);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Extracts the field palette, canvas/drag-drop, field CRUD, multi-step canvas, and context-menu code out of form-builder.js into its own module, continuing the module-split saga from #11/#12, and fixes a couple of small bugs found along the way:
new_${fieldIdCounter++}call sites to store.nextFieldId(), consistent with how the rest of the store is used elsewhere