Skip to content

Split canvas dragdrop extraction - #16

Merged
matteius merged 7 commits into
opensensor:mainfrom
ViolanteCodes:split_canvas_dragdrop_extraction
Aug 5, 2026
Merged

Split canvas dragdrop extraction#16
matteius merged 7 commits into
opensensor:mainfrom
ViolanteCodes:split_canvas_dragdrop_extraction

Conversation

@ViolanteCodes

Copy link
Copy Markdown
Contributor

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:

  • 06eb7e2 - moves the canvas/drag-drop cluster out of form-builder.js into form-builder-canvas.js (no logic changes)
  • dc20bb3 - moves the corresponding tests to their own module, testing canvasMethods directly instead of through FormBuilder.prototype, plus new coverage for the ~26 previously-untested methods in the module
  • a476243 - switches the three new_${fieldIdCounter++} call sites to store.nextFieldId(), consistent with how the rest of the store is used elsewhere
  • 8d3dcaa - bugfix: pushes an undo snapshot before reordering/moving fields on the single-step canvas (setupCanvas's onAdd/onUpdate) - the single-step equivalent of Extract Property Editor into separate module #12's 5c6deb5, which fixed the same gap for cross-step move/reorder but never touched setupCanvas
  • 90122a5 - bugfix: addFieldAtPosition's id and default field_name now derive from the same counter value (previously the id was always one number ahead of the name)
  • 150caaa - bugfix: escapes field_name, width, and field_type in createFieldElement, which rendered raw while field_label right next to them was already escaped

…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
@matteius
matteius requested a lite review from Copilot August 5, 2026 02:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js and mixes it into FormBuilder.prototype.
  • Replaces multiple per-method tests with a consolidated canvasMethods.test.js that 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

  • allFields is 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.

Comment thread django_forms_workflows/static/django_forms_workflows/js/form-builder-canvas.js Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@matteius
matteius merged commit 0b0ad7c into opensensor:main Aug 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants