Skip to content

Introduce useDeleteController#10876

Merged
Madeorsk merged 6 commits intonextfrom
use-delete-controller
Sep 1, 2025
Merged

Introduce useDeleteController#10876
Madeorsk merged 6 commits intonextfrom
use-delete-controller

Conversation

@djhi
Copy link
Contributor

@djhi djhi commented Aug 1, 2025

Problem

We currently have a lot of duplicated logic in useDeleteWithConfirmController and useDeleteWithUndoController. Besides they handle things that should only belong in the UI hooks/components (onClick, dialog handlers and state).

Solution

  • Introduce useDeleteController that can be used for all mutation modes
  • Use it in useDeleteWithConfirmController and useDeleteWithUndoController as we want to keep them for backward compatibility
  • Use it in the DeleteWithUndoButton and DeleteWithConfirmButton
  • Modify the DeleteWithConfirmButton so that it always closes the confirmation dialog before running user provided side effects

How To Test

  • Buttons should work as before
  • Tests should succeed as before

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)

Copy link
Contributor

@Madeorsk Madeorsk left a comment

Choose a reason for hiding this comment

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

Are useDeleteWithConfirmController and useDeleteWithUndoController deprecated? I'm not sure that it is a good choice as we can see that it forces UI implementation to duplicate parts of the logic (that will most likely be duplicated again in other UI kits). A good compromise could be to provide a few helpers / primitive functions with consistent side effects (like the propagation stop on click).

);
record && unselect([record.id]);
redirect(redirectTo, resource);
},
Copy link
Contributor

Choose a reason for hiding this comment

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

It's sad to have this duplicated again. Maybe introduce a defaultOnSuccess / defaultOnError in useDeleteController so you can use them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed:

  1. both useDeleteWithConfirmController and useDeleteWithUndoController are deprecated
  2. we don't want to export default side effects to reuse them

if (typeof onClick === 'function') {
onClick(event);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This handleDelete override is exactly the same in useDeleteWithUndoController. What about doing it in useDeleteController directly? Or you want to keep useDeleteController as generic as possible so it can be used for something else than a clickable component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to keep useDeleteController as generic as possible so it can be used for something else than a clickable component

);
}
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Using something like defaultOnSuccess / defaultOnError like my other suggestion could help to deduplicate this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, we'll keep the duplication

@Madeorsk Madeorsk added this to the 5.11.0 milestone Sep 1, 2025
@Madeorsk Madeorsk merged commit daca68b into next Sep 1, 2025
15 checks passed
@Madeorsk Madeorsk deleted the use-delete-controller branch September 1, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

4 participants