Skip to content

Detach components from group on deletion via model event#330

Merged
jbrooksuk merged 3 commits intomainfrom
copilot/fix-component-deletion-issue
Feb 24, 2026
Merged

Detach components from group on deletion via model event#330
jbrooksuk merged 3 commits intomainfrom
copilot/fix-component-deletion-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

Deleting a component group via the Filament admin (single or bulk) left orphaned components with a dangling component_group_id, making them invisible on the status page and rendering only the raw ID in the admin UI.

The DeleteComponentGroup action already nullified component_group_id correctly, but Filament's built-in DeleteAction/DeleteBulkAction call $model->delete() directly, bypassing that action entirely.

Changes

  • ComponentGroup model — add a deleting Eloquent event in booted() that nullifies component_group_id on all related components before the group is removed. This makes the detachment unconditional regardless of the deletion path (API action, Filament single/bulk delete, or direct model call).
protected static function booted(): void
{
    static::deleting(function (ComponentGroup $componentGroup): void {
        $componentGroup->components()->update(['component_group_id' => null]);
    });
}

The explicit update call in DeleteComponentGroup becomes redundant but harmless — it now runs twice in the API path, which is a no-op on the second pass.

  • tests/Unit/Models/ComponentGroupTest.php — added two tests that directly exercise the model event (bypassing the action class, matching the Filament delete path):
    • resets component_group_id on components when the group is deleted — asserts all related components have component_group_id = null after $group->delete().
    • does not delete components when the group is deleted — asserts the components themselves still exist in the database after the group is deleted.
Original prompt

This section details on the original issue you should resolve

<issue_title>Deattach component from component group when deleting the group</issue_title>
<issue_description>Hi,

I had a component group called "Managed Services". Inside I have the component "MailStore".
I deleted the component group, so I expected to either the components inside to get deleted too or they will convert to groupless components.

When viewing the status page, the component was not listed.
In the dashboard, it is still there, but only the component ID is shown:

Image

My idea is, to either deattach the component group so it will become a groupless component, or delete the component too.

Thanks!</issue_description>

<agent_instructions>Fix the bug, when deleting a component group they should be removed from the component group.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…letion

Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix deletion of components from component group Detach components from group on deletion via model event Feb 24, 2026
Copilot AI requested a review from jbrooksuk February 24, 2026 10:28
@jbrooksuk
Copy link
Member

@copilot add tests to verify this behavior.

Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot add tests to verify this behavior.

Added two tests to tests/Unit/Models/ComponentGroupTest.php in c431a70:

  • resets component_group_id on components when the group is deleted — verifies the model event nullifies component_group_id when $group->delete() is called directly.
  • does not delete components when the group is deleted — verifies components survive the group deletion.

@jbrooksuk jbrooksuk marked this pull request as ready for review February 24, 2026 12:47
@jbrooksuk jbrooksuk merged commit c57dd8e into main Feb 24, 2026
31 checks passed
@jbrooksuk jbrooksuk deleted the copilot/fix-component-deletion-issue branch February 24, 2026 20:02
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.

Deattach component from component group when deleting the group

2 participants