Files
twenty/packages
Sonarly Claude Code b41ce33e21 fix: guard DestroySingleRecordCommand against missing record selection
https://sonarly.com/issue/15498?type=bug

`DestroySingleRecordCommand` throws an unhandled "Selected record ID is required" error when rendered via the server-driven command menu path (`IS_COMMAND_MENU_ITEM_ENABLED` flag) because the server path lacks the client-side `shouldBeRegistered` guard that prevents rendering single-record commands in exclusion mode or empty selection.

Fix: Created `useSelectedRecordIdOrNull` hook (non-throwing variant of `useSelectedRecordIdOrThrow`) and updated `DestroySingleRecordCommand` to use it, returning `null` when no single record is selected.

This follows the exact pattern established in the prior fix for `NavigateToNextRecordSingleRecordCommand` and `NavigateToPreviousRecordSingleRecordCommand` (commit 89516f06bb on another branch).

**Changes:**

1. **`useSelectedRecordIdOrNull.tsx` (new)** — Same logic as `useSelectedRecordIdOrThrow` but returns `null` instead of throwing when in exclusion mode or when no records are selected.

2. **`DestroySingleRecordCommand.tsx`** — Switched from `useSelectedRecordIdOrThrow` to `useSelectedRecordIdOrNull`. Added early return of `null` when `recordId` is null, preventing the component from rendering the `CommandModal`. Also added a guard in `handleDeleteClick` for safety.

The root issue is that the server-driven command menu path (`IS_COMMAND_MENU_ITEM_ENABLED` feature flag) doesn't replicate the legacy path's `shouldBeRegistered` guard that checked `isDefined(selectedRecord?.deletedAt)`. Rather than restructuring the server-driven path's filtering architecture, this makes the component resilient to being rendered without a selected record.
2026-03-17 08:16:21 +00:00
..