Skip to content

Conversation

@edanzer
Copy link
Contributor

@edanzer edanzer commented Jan 16, 2026

Proposed changes:

We recently added a new forms tab and forms list to the dashboard behind our central form management flag.

This PR adds a Trash action that allows us to move Forms to trash. Specifically:

  • adds a Trash action to the actions dropdown
  • adds a custom hook to hold the delete form logic, and which calls deleteEntityRecord
  • adds a modal to confirm the action
  • adds a success notification in the lower corner

Screenshot: Trash Action

forms-trash-action

Screenshot: Confirmation Popup

forms-trash-popup

Screenshot: Confirmation
forms-trash-confirmation

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

See Central Forms Management project on Linear.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Add this feature flag to your test site.

add_filter( 'jetpack_block_editor_feature_flags', 'eb_register_feature' );
function eb_register_feature( $flags ) {
    $flags['central-form-management'] = true;
    return $flags;
}
  • Create a new form. You can go to Jetpack > Form and click the Create Button which will create a new form post. Add your form, save, return to Jetpack > Forms and confirm your form shows in the list
  • Test deletion. Click the three dots in the Actions column and then Trash. Confirm you get a confirmation popup, and confirm. Confirm your form post is deleted, removed from the forms list, and that a notification message appears in the lower right.

Test for no regressions:

  • Remove feature flag and confirm everything works as before

@edanzer edanzer requested a review from a team January 16, 2026 20:08
@edanzer edanzer self-assigned this Jan 16, 2026
Copilot AI review requested due to automatic review settings January 16, 2026 20:08
@edanzer edanzer added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. [Pri] Normal [Package] Forms labels Jan 16, 2026

return queryParams;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted this to re-usable method since we now import and use it beyond this hook.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/delete-form-post branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/delete-form-post

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link
Contributor

Copilot AI left a comment

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 adds a delete/trash action to the Forms management dashboard, allowing users to move forms to trash with a confirmation dialog and success notifications.

Changes:

  • Add a new useDeleteForm hook to manage the delete flow including state, API calls, and cache invalidation
  • Extract query building logic into getFormsListQuery function for reuse
  • Integrate trash action into the Forms list UI with confirmation dialog and notifications

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
projects/packages/forms/src/dashboard/hooks/use-forms-data.ts Refactored query building logic into a reusable exported function
projects/packages/forms/src/dashboard/hooks/use-delete-form.ts New hook implementing the complete delete/trash workflow with confirmation, API calls, error handling, and cache invalidation
projects/packages/forms/src/dashboard/forms/index.tsx Integrated trash action into the Forms list with ConfirmDialog UI component
projects/packages/forms/changelog/add-delete-form-post Added changelog entry for the new feature

Significance: minor
Type: added

Forms: add form delete action.
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

The changelog entry should not use a "Forms:" prefix since this entry is already within the forms package. According to the project guidelines, the package name should not be used as a prefix for entries in that same package. Consider changing "Forms: add form delete action." to "Add form delete action."

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +47 to +143
export default function useDeleteForm( {
view,
setView,
recordsLength,
}: UseDeleteFormArgs ): UseDeleteFormReturn {
const [ formPendingDelete, setFormPendingDelete ] = useState< FormListItem | null >( null );
const [ isDeleteConfirmDialogOpen, setIsDeleteConfirmDialogOpen ] = useState( false );
const [ isDeleting, setIsDeleting ] = useState( false );

const { deleteEntityRecord, invalidateResolution } = useDispatch( 'core' ) as CoreDispatch;
const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore );

const page = view.page ?? 1;
const perPage = view.perPage ?? 20;
const search = view.search ?? '';

const currentQuery = useMemo(
() => getFormsListQuery( page, perPage, search ),
[ page, perPage, search ]
);

const openDeleteConfirmDialog = useCallback( ( item: FormListItem ) => {
setFormPendingDelete( item );
setIsDeleteConfirmDialogOpen( true );
}, [] );

const closeDeleteConfirmDialog = useCallback( () => {
setIsDeleteConfirmDialogOpen( false );
setFormPendingDelete( null );
}, [] );

const onConfirmDelete = useCallback( async () => {
if ( ! formPendingDelete || isDeleting ) {
return;
}

setIsDeleteConfirmDialogOpen( false );
setIsDeleting( true );

const shouldNavigateToPreviousPage = page > 1 && recordsLength === 1;

try {
await deleteEntityRecord(
'postType',
'jetpack_form',
formPendingDelete.id,
{ force: false },
{ throwOnError: true }
);

createSuccessNotice( __( 'Form moved to trash.', 'jetpack-forms' ), {
type: 'snackbar',
id: 'delete-form',
} );

if ( shouldNavigateToPreviousPage ) {
setView( { ...view, page: page - 1 } );
}
} catch {
createErrorNotice( __( 'Could not move form to trash.', 'jetpack-forms' ), {
type: 'snackbar',
id: 'delete-form-error',
} );
} finally {
setIsDeleting( false );
setFormPendingDelete( null );

// Invalidate the list query so the trashed form disappears from the table and totals refresh.
invalidateResolution( 'getEntityRecords', [ 'postType', 'jetpack_form', currentQuery ] );
invalidateResolution( 'getEntityRecords', [
'postType',
'jetpack_form',
{ ...currentQuery, per_page: 1, _fields: 'id' },
] );
}
}, [
createErrorNotice,
createSuccessNotice,
currentQuery,
deleteEntityRecord,
formPendingDelete,
invalidateResolution,
isDeleting,
page,
recordsLength,
setView,
view,
] );

return {
isDeleteConfirmDialogOpen,
isDeleting,
openDeleteConfirmDialog,
closeDeleteConfirmDialog,
onConfirmDelete,
};
}
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

The new useDeleteForm hook lacks test coverage. Similar hooks in this directory, such as use-response-navigation, have comprehensive test coverage. Consider adding tests to verify the delete flow, including confirmation dialog state management, success/error handling, cache invalidation, and pagination edge cases.

Copilot uses AI. Check for mistakes.
@jp-launch-control
Copy link

jp-launch-control bot commented Jan 16, 2026

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/dashboard/forms/index.tsx 0/50 (0.00%) 0.00% 7 💔
projects/packages/forms/src/dashboard/hooks/use-forms-data.ts 0/11 (0.00%) 0.00% 1 ❤️‍🩹

1 file is newly checked for coverage.

File Coverage
projects/packages/forms/src/dashboard/hooks/use-delete-form.ts 0/33 (0.00%) 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@edanzer edanzer force-pushed the add/delete-form-post branch from 02e251e to c80d29a Compare January 20, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Contact Form [Package] Forms [Pri] Normal [Status] Needs Review This PR is ready for review. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants