Drop the shared delete, bulk and capture affordances under a switch

Three controls carry most of the app's mutation surface between them. The row
delete is spelled once for measurements, lab results, biomarkers, allergies,
family history, custom metrics and medication supply; the selection bar is
the only bulk delete; the capture picker is the fastest path to four entry
forms on a phone and bypasses every page header.

Deleting belongs to the owner at every grant level, so the first two are
absent inside somebody else's record rather than greyed out: a disabled bin
still claims the row is the delegate's to remove. The picker keeps the two
kinds a delegation admits and drops a mood entry and a glass of water, which
the server refuses under a switch; when nothing survives, the bar's plus
button goes with them instead of opening an empty sheet.
This commit is contained in:
Marc-André Bombeck committed 2026-08-03 12:11:29 +02:00
1 parent 3e7127dca5
commit bc43a9f062
7 files changed
+334 -34

No files matched your search

@@ -15,6 +15,7 @@ import {
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { useTranslations } from "@/lib/i18n/context";
import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
/**
* Shared single-row delete button + confirm dialog for the data-
@@ -25,6 +26,15 @@ import { useTranslations } from "@/lib/i18n/context";
* so the title/description are passed in rather than reaching for a fixed
* translation key. `cancelLabel` / `confirmLabel` default to the shared
* `common.*` strings.
*
* v1.36.x — this is the one place a row delete is spelled across the app
* (measurements, lab results, biomarkers, allergies, family history, custom
* metrics, medication inventory), so the delegation rule is enforced here
* rather than at twelve call sites: deleting is the owner's alone, at every
* grant level, so inside somebody else's record the trigger is absent. Not
* disabled — a greyed bin still claims the row is the delegate's to remove.
* A caller that ever needs a delete a delegate MAY perform would have to say
* so explicitly, and today there is none.
*/
export function DeleteButton({
onConfirm,
@@ -47,6 +57,8 @@ export function DeleteButton({
iconClassName?: string;
}) {
const { t } = useTranslations();
const { canManage } = useRecordCapabilities();
if (!canManage) return null;
return (
<AlertDialog>
<AlertDialogTrigger asChild>
@@ -15,6 +15,7 @@ import {
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { useTranslations } from "@/lib/i18n/context";
import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
/**
* Selection action bar for the data-management lists (measurements +
@@ -29,6 +30,11 @@ import { useTranslations } from "@/lib/i18n/context";
*
* The confirm copy is passed in because the title/body differ per surface
* (measurements vs mood) and the count is interpolated by the caller.
*
* v1.36.x — bulk delete is the owner's alone at every grant level, so the bar
* is absent inside somebody else's record. The row checkboxes that feed it are
* dropped at their lists for the same reason; this guard is the backstop, so a
* list that forgets cannot leave a delete button floating over the page.
*/
export function SelectionActionBar({
count,
@@ -46,8 +52,9 @@ export function SelectionActionBar({
confirmBody: string;
}) {
const { t } = useTranslations();
const { canManage } = useRecordCapabilities();
if (count <= 0) return null;
if (count <= 0 || !canManage) return null;
return (
<div