Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

feat: add template field management functions in SuperDocTemplateBuilder#5

Merged
caio-pizzol merged 1 commit intomainfrom
caio/sd-533-fix-field-deletion-to-remove-from-both-document-and-list
Oct 9, 2025
Merged

feat: add template field management functions in SuperDocTemplateBuilder#5
caio-pizzol merged 1 commit intomainfrom
caio/sd-533-fix-field-deletion-to-remove-from-both-document-and-list

Conversation

@caio-pizzol
Copy link
Contributor

@caio-pizzol caio-pizzol commented Oct 9, 2025

Note

Improves TemplateBuilder field deletion and discovery using shared helpers, editor-state syncing, error handling, and redundant-update guards.

  • Template field syncing:
    • Add getTemplateFieldsFromEditor to extract fields from editor and areTemplateFieldsEqual to prevent redundant state updates.
  • Deletion flow (deleteField):
    • Handle missing active editor by updating local state, firing callbacks, and clearing selection.
    • Wrap editor delete command in try/catch; if command fails or field persists, fall back to manual removal based on discovered fields.
    • Sync templateFields with document via getTemplateFieldsFromEditor and avoid unnecessary updates; return accurate success status.
  • Discovery (discoverFields):
    • Use getTemplateFieldsFromEditor and only update when fields actually change.

Written by Cursor Bugbot for commit 1ca104d. This will update automatically on new commits. Configure here.

@linear
Copy link

linear bot commented Oct 9, 2025

SD-533 Fix Field Deletion to Remove from Both Document and List

Summary

Ensure field deletion properly removes the field from both the document and the FieldsList component.

Tasks

  • Debug the deleteField callback in src/index.tsx to identify why state updates may not be occurring
  • Verify that editor.commands.deleteStructuredContentById is returning true on successful deletion
  • Ensure setTemplateFields state update is being triggered when deletion succeeds
  • Add error handling for cases where the editor command fails but the field should still be removed from state
  • Consider decoupling document deletion from list state updates to prevent sync issues
  • Add logging to track deletion flow and identify where the disconnect occurs
  • Test deletion from FieldList component to confirm both document and list are updated

Notes

Currently in src/index.tsx, the deleteField function only updates the templateFields state if the editor command returns success. This creates a potential sync issue where the field might be removed from the document but not from the list (or vice versa) if the command fails or returns false unexpectedly. The FieldList component at src/defaults/FieldList.tsx calls onDelete(field.id) which triggers this deleteField callback. We need to ensure the state management is robust and the list always reflects the actual document state.

@caio-pizzol caio-pizzol enabled auto-merge (squash) October 9, 2025 17:30
@caio-pizzol caio-pizzol merged commit 66d06b9 into main Oct 9, 2025
2 checks passed
@caio-pizzol caio-pizzol deleted the caio/sd-533-fix-field-deletion-to-remove-from-both-document-and-list branch October 9, 2025 17:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant