Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion web/src/pages/admin-backups/RestoreRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { SettingFieldStatus } from "@/pages/admin-settings/SettingField";
import { RowDisclosure } from "./Disclosure";
import { itemState, type ItemState } from "./restoreGroups";
import { REASON_SENTENCES, displayLabel, toggleKeys } from "./restoreModel";
import { useOverflowsInline } from "./useOverflowsInline";

/** Toggles item keys; stable for the page's life so memoized rows don't re-render. */
export type ToggleKeys = (keys: string[], checked: boolean) => void;
Expand Down Expand Up @@ -352,6 +353,7 @@ export const ItemRow = memo(function ItemRow({
const details = open ? itemDetails(t, item) : null;
const hasDetails = hasItemDetails(item);
const label = displayLabel(item);
const [nameRef, nameOverflows] = useOverflowsInline<HTMLLabelElement>(label);
const paths = item.kind === "library" ? item.library?.paths : undefined;
// The row is its own container, since its width depends on the admin sidebar and
// restore summary as much as on the viewport. A narrow row wraps the whole name
Expand All @@ -371,13 +373,17 @@ export const ItemRow = memo(function ItemRow({
{/* block: Label is a flex box, which would clip the name without an ellipsis.
Beside a detail, a one-line row stops the name at 60% and ends it in "…";
Chromium breaks at <wbr> even under nowrap, so that row hides them. A name
with nothing beside it wraps instead, so it is never cut short. */}
with nothing beside it wraps instead, so it is never cut short. A name
clips sideways only while part of it can't wrap to fit, such as one long
run of joined emoji; a one-line row with a detail truncates instead. */}
<Label
ref={nameRef}
htmlFor={controlId}
title={label}
className={cn(
"block max-w-full shrink-0 text-sm font-medium wrap-anywhere",
secondary && "@2xl:max-w-[60%] @2xl:truncate @2xl:[&_wbr]:hidden",
nameOverflows && (secondary ? "@max-2xl:overflow-x-clip" : "overflow-x-clip"),
!item.selectable && "text-muted-foreground",
)}
>
Expand Down
20 changes: 18 additions & 2 deletions web/src/pages/admin-backups/RestoreUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
requiredPrimary,
toggleKeys,
} from "./restoreModel";
import { useOverflowsInline } from "./useOverflowsInline";

function droppedLibraries(t: Translate, count: number): string {
return t("web.admin.backups.restore.users.droppedLibraries", {
Expand Down Expand Up @@ -179,6 +180,9 @@ export const AccountRow = memo(function AccountRow({
const controlId = useId();
const detailsId = useId();
const [open, setOpen] = useState(false);
const [nameRef, nameOverflows] = useOverflowsInline<HTMLLabelElement>(item.label);
// The merge line exists only while the details are open, so opening them measures it.
const [mergeRef, mergeOverflows] = useOverflowsInline<HTMLParagraphElement>(open && item);
const account = item.account;
if (!account) return null;
const chosen = new Set(chosenProfiles ? chosenProfiles.split("\u0000") : []);
Expand Down Expand Up @@ -218,7 +222,9 @@ export const AccountRow = memo(function AccountRow({
// row's name and contact about 220 px, so below 52rem the row shows only the badge's
// icon, and the merge status only when it names another account; the details show
// the admin role and the status. The badge can cut a long merge destination short,
// so the details show a merge in full at every width.
// so the details show a merge in full at every width. As in ItemRow, a name clips
// sideways only while part of it can't wrap to fit: in the label, and in the merge
// status, which names the account it merges into.
return (
<li className="border-border/60 @container border-b last:border-b-0">
<div className="flex min-h-10 items-center gap-3 py-1.5">
Expand All @@ -232,11 +238,13 @@ export const AccountRow = memo(function AccountRow({
/>
<div className="flex min-w-0 flex-1 flex-col gap-x-2 gap-y-0.5 @2xl:flex-row @2xl:items-baseline">
<Label
ref={nameRef}
htmlFor={controlId}
title={item.label}
className={cn(
"block max-w-full shrink-0 text-sm font-medium wrap-anywhere",
contact && "@2xl:max-w-[45%] @2xl:truncate @2xl:[&_wbr]:hidden",
nameOverflows && (contact ? "@max-2xl:overflow-x-clip" : "overflow-x-clip"),
!item.selectable && "text-muted-foreground",
)}
>
Expand Down Expand Up @@ -301,7 +309,15 @@ export const AccountRow = memo(function AccountRow({
{open ? (
<div id={detailsId} className="space-y-1 ps-7 pb-3">
{status ? (
<p className={cn("text-[13px] wrap-anywhere", !merges && "@[52rem]:hidden")}>
<p
ref={mergeRef}
title={status}
className={cn(
"text-[13px] wrap-anywhere",
!merges && "@[52rem]:hidden",
mergeOverflows && "overflow-x-clip",
)}
>
{status}
</p>
) : null}
Expand Down
26 changes: 26 additions & 0 deletions web/src/pages/admin-backups/useOverflowsInline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useLayoutEffect, useRef, useState } from "react";

/**
* Whether an element's text is wider than its box, such as a name holding one
* long run of joined emoji that no line break can split. A row clips such text
* sideways only while this is true: clipping text that fits would trim letters
* whose ink reaches past their edge, and in Firefox also tall marks above and
* below the line. Measured after layout, again whenever the box resizes, and
* whenever `content` changes. A name that fits can measure a fraction of a pixel
* wider than its box, so that counts as fitting.
*/
export function useOverflowsInline<T extends HTMLElement>(content: unknown) {
const ref = useRef<T>(null);
const [overflows, setOverflows] = useState(false);
useLayoutEffect(() => {
const element = ref.current;
if (!element) return;
const measure = () => setOverflows(element.scrollWidth > element.clientWidth + 1);
measure();
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(measure);
observer.observe(element);
return () => observer.disconnect();
}, [content]);
return [ref, overflows] as const;
}
Loading