feat(meadows): add danger-zone delete action to the meadow detail page
GitHub issue · Closed
Summary
- Meadow detail page lacked any way to remove a meadow; the only path was direct DB access. This PR closes that gap with a destructive, confirmation-gated action restricted to organization members.
- Added
Hive.Meadows.delete_meadow/1, a thin wrapper around Repo.delete/1. Existing migrations already declare on_delete: :delete_all on the join tables for meadows_github_repositories, meadows_specs, meadow_webhooks, and grafana_alerts, so the cascade happens at the DB layer; the meadow context does not need its own multi.
- Added a “Danger zone” card to the meadow detail layout in
MeadowComponents. It uses a Noora modal with header_type="warning" for confirmation. Considered the data-confirm native-prompt approach used by webhook deletion, but the meadow blast radius (webhooks, repository links, spec links all dropped) warranted a richer modal that names the meadow explicitly. The card is only rendered when editable? is true, matching the existing pattern used for webhook management.
MeadowLive.Show gains delete_meadow and close_delete_meadow event handlers. Delete is guarded behind socket.assigns.editable? (same guard already used by save, create_webhook, delete_webhook) and on success flashes “Meadow deleted.” and push_navigates back to /meadows. The trash icon and destructive button variant are both already provided by Noora.
Testing
mix test (310 tests, 0 failures)
mix format
mix compile --warnings-as-errors
mix credo --strict lib/hive/meadows.ex lib/hive_web/live/meadow_live/show.ex lib/hive_web/components/meadow_components.ex (only a pre-existing nested-alias suggestion in unrelated code)
New test coverage:
Hive.MeadowsTest — “deletes the meadow and cascades its repository links” verifies the join row is dropped while the shared GitHubRepository row is preserved.
HiveWeb.MeadowLive.ShowTest — “deletes a meadow and redirects to the meadows index” asserts the Danger zone is rendered, that the event triggers a live redirect to /meadows, and that the meadow no longer appears in list_meadows/0.