File size: 7,370 Bytes
e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e 39a9177 e9a4c3e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | // ---------------------------------------------------------------------------
// connectors/ViewDeleteDisclosure.tsx β W49-T16 (ruling R32, contract C3),
// re-cut by W51-T03 (ruling R6, contract C8).
//
// ββ R32, second half, verbatim: *"deleting a view must first disclose who it
// is shared to and which Sheet cells depend on it."* So this is not a generic
// "Are you sure?" β the whole point is the two FACTS above the button:
//
// Shared with Anna and 2 others Β· used by 3 Sheet cells
//
// ββ IT IS A DIALOG **BODY** NOW, NOT A DIALOG. R6: *"ONE ConfirmDialog for
// every destructive action β¦ the view-delete panel"*. So the scrim, the panel,
// the trash mark, the title, the two buttons and the focus/Escape contract all
// moved to `ui/ConfirmDialog.tsx`, and what is left here is the only thing that
// was ever unique to a view delete: the DISCLOSURE. `CustomerGrid.tsx` renders
// `<ConfirmDialog β¦ body={<ViewDeleteDisclosure β¦ />} />`.
//
// β AND THAT IS WHY THE PORTAL LEFT WITH THEM. This used to call `BodyPortal`
// and `useOverlayLayer` itself; nested inside a dialog that does both, two
// surfaces would claim Escape and focus for one visible panel β the exact
// "topmost wins" race the wave-51 kit exists to end, and the thing
// `verify_overlay.py` pins. One overlay, one claim.
//
// β STYLES ARE INLINE `var(--lp-*)` RATHER THAN A STYLESHEET, and that is a
// FENCE fact rather than a preference: neither W49-T16 nor W51-T03 owns a CSS
// file this component could import. The discipline DESIGN.md Β§5 asks for is
// unchanged β every colour and size below is a token, there is not one literal
// hex and not one literal font-size.
//
// β STANDING RULE 2 β NO EM DASH AND NO EN DASH IN ANY STRING THAT REACHES A
// SCREEN. The separator between the two facts is a MIDDOT (Β·), which the ruling
// quotes itself. Sentence case throughout, no ALL-CAPS chrome, no emojis.
//
// β NO CLIENT UNION OVER A SERVER VOCABULARY (the wave-9 law). A dependent's
// `kind` and `label` arrive as STRINGS from `/api/v1/dependents`, so a kind the
// server adds later β `sheet_cell` the moment W49-T11 registers it β renders
// with no change here.
// ---------------------------------------------------------------------------
import type { CSSProperties } from "react";
/** One row of C3's `Dependent`. `kind` and `label` are read as strings, never a union. */
export interface ViewDependent {
kind: string;
label: string;
count: number;
ids: string[];
}
/** The share half of `GET /api/v1/dependents?kind=view`. `names` are usernames. */
export interface ViewShareAudience {
owner?: string | null;
names: string[];
count: number;
/** The server's own sentence, when it sent one. Preferred over recomposing it here. */
sentence?: string;
}
/**
* β NO `viewName`, NO `busy`, NO `onConfirm`/`onCancel` ANY MORE (W51-T03). Those four belonged
* to a panel that owned its own title and buttons; `ConfirmDialog` owns them now, and leaving
* duplicates here would let the dialog's title and this body's title drift apart by one edit.
*/
export interface ViewDeleteDisclosureProps {
/** Everything that depends on the view. Zero-count kinds are ABSENT, never zero. */
dependents: ViewDependent[];
/** Who the view is shared with, or undefined while it is still loading. */
share?: ViewShareAudience;
/** True while the disclosure is still being fetched. */
loading?: boolean;
/** A kind the server could not answer, so the dialog does not imply it is empty. */
unanswered?: string[];
error?: string;
}
/**
* "Shared with anna and 2 others", or "" when nobody holds a grant.
*
* β THE EMPTY STRING IS THE ANSWER FOR "shared with nobody", not "Shared with 0
* people". Same rule as the dependents list: a zero is a claim, and an absent
* clause is the honest rendering.
*/
export function audienceSentence(share?: ViewShareAudience): string {
const names = (share?.names ?? []).map((name) => String(name || "").trim()).filter(Boolean);
if (!names.length) return "";
if (names.some((name) => name === "*")) return "Shared with everyone in this workspace";
if (names.length === 1) return `Shared with ${names[0]}`;
if (names.length === 2) return `Shared with ${names[0]} and 1 other`;
return `Shared with ${names[0]} and ${names.length - 1} others`;
}
/**
* "used by 3 Sheet cells", or "" when nothing depends.
*
* The counts and their nouns both come from the server, so a kind registered
* after this file shipped still reads correctly.
*/
export function usageSentence(dependents: ViewDependent[]): string {
const parts = (dependents ?? [])
.filter((item) => Number(item?.count) > 0)
.map((item) => `${item.count} ${item.label}`);
if (!parts.length) return "";
const listed =
parts.length === 1 ? parts[0] : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`;
return `used by ${listed}`;
}
/** The two facts, joined by a MIDDOT. Never a dash (standing rule 2). */
export function disclosureLine(share: ViewShareAudience | undefined,
dependents: ViewDependent[]): string {
return [audienceSentence(share), usageSentence(dependents)].filter(Boolean).join(" Β· ");
}
/**
* Token-only rules. No literal hex, no literal font-size, no literal z-index.
*
* β THREE ENTRIES, DOWN FROM ELEVEN (W51-T03). `backdrop`, `panel`, `head`, `mark`, `title`,
* `actions`, `button` and the two button variants described a SURFACE, and this component is no
* longer a surface β `.lp-dialog` in `styles/wave51/kit.css` is. Keeping them would have left a
* second, unreachable statement of the dialog's width, radius, shadow and red, which is exactly
* the "second shape for the same act" DESIGN.md Β§4 refuses.
*/
const S: Record<string, CSSProperties> = {
facts: { margin: 0, color: "var(--lp-muted)" },
note: { margin: 0, color: "var(--lp-muted)", fontSize: "var(--lp-fs-2xs)" },
alert: { margin: 0, color: "var(--lp-red-deep)", fontSize: "var(--lp-fs-2xs)" },
};
/**
* R32's pre-delete disclosure: the facts a reader needs before the button they already see.
*
* β NEVER OVER-EXPLAIN (DESIGN.md Β§4). One line of facts, and a second line only when the
* server could not answer or the delete already failed. There is no paragraph explaining what
* deleting means, and there is no confirmation control here at all: this renders INSIDE
* `ConfirmDialog`, which owns the title, Cancel, the red "Delete view", the focus trap and
* Escape.
*/
export function ViewDeleteDisclosure({
dependents,
share,
loading = false,
unanswered = [],
error = "",
}: ViewDeleteDisclosureProps) {
const facts = disclosureLine(share, dependents);
return (
<>
{loading ? (
<p style={S.facts} role="status" aria-live="polite">
Checking what depends on this view
</p>
) : facts ? (
<p style={S.facts}>{facts}</p>
) : (
<p style={S.facts}>Nothing else depends on this view.</p>
)}
{unanswered.length > 0 ? (
<p style={S.note}>
{unanswered.join(", ")} could not be checked, so this list may be incomplete.
</p>
) : null}
{error ? (
<p style={S.alert} role="alert">
{error}
</p>
) : null}
</>
);
}
export default ViewDeleteDisclosure;
|