forge
Explore
Log in

Don't you dare go Hollow

♻️ one row-actions menu on every table

Browse files at this commit

365bc383c3d75386b345f7731ab957ed11c3f2c2Burak BoduroğluParent: 691fcf8
  • refactor
    • ♻️ one row-actions menu on every table
Show full message
refactor: ♻️ one row-actions menu on every table
- TableRowActions is always the ⋮ menu, even for a single action, so
  eye, pencil and trash icons no longer vary from table to table
- items are ordered view, edit and others, then a separator and the
  destructive ones; destructive items go through a confirm dialog
- homework submissions rows all use the same menu
- class, event, meal, question and builder school detail pages move
  delete into the header actions menu instead of a red top-level button
- whiteboard participant removal asks for confirmation
src/components/courses/course-teachers-panel.tsxmodified+10 -9
@@ -10,6 +10,7 @@ import { DataTable } from "@/components/ui/data-table";
1010 import { EmptyState } from "@/components/ui/empty-state";
1111 import { IconTrash } from "@/components/ui/icons";
1212 import { SidePanel } from "@/components/ui/side-panel";
13+import { TableRowActions } from "@/components/ui/table-row-actions";
1314 import { UserSearchSelect } from "@/components/users/user-search-select";
1415 import { createFlash } from "@/lib/flash";
1516 import { useT } from "@/stores/preferences-context";
@@ -48,15 +49,15 @@ export function CourseTeachersPanel(props: {
4849 header: t("common.actions"),
4950 meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" },
5051 cell: (cell: { row: { original: PersonRef } }) => (
51- <Button
52- variant="ghost"
53- size="sm"
54- class="h-8 w-8 rounded-lg p-0 text-destructive-text hover:bg-destructive/10"
55- onClick={() => setRemoveTarget(cell.row.original)}
56- >
57- <IconTrash class="h-4 w-4" />
58- <span class="sr-only">{t("courses.unassignTeacher")}</span>
59- </Button>
52+ <TableRowActions
53+ label={t("common.actions")}
54+ actions={[{
55+ label: t("courses.unassignTeacher"),
56+ icon: <IconTrash class="h-4 w-4" />,
57+ destructive: true,
58+ onSelect: () => setRemoveTarget(cell.row.original),
59+ }]}
60+ />
6061 ),
6162 },
6263 ]
src/components/homework/course-homework-panel.tsxmodified+2 -1
@@ -15,7 +15,7 @@ import { ConfirmDialog } from "@/components/ui/confirm-dialog";
1515 import { DataTable, DataTableSkeleton } from "@/components/ui/data-table";
1616 import { DatePicker } from "@/components/ui/date-picker";
1717 import { EmptyState } from "@/components/ui/empty-state";
18-import { IconEdit, IconTrash } from "@/components/ui/icons";
18+import { IconEdit, IconEye, IconTrash } from "@/components/ui/icons";
1919 import { Input } from "@/components/ui/input";
2020 import { Label } from "@/components/ui/label";
2121 import { Select } from "@/components/ui/select";
@@ -193,6 +193,7 @@ export function CourseHomeworkPanel(props: {
193193 <TableRowActions
194194 label={t("common.actions")}
195195 actions={[
196+ { label: t("common.view"), icon: <IconEye class="h-4 w-4" />, onSelect: () => void navigate({ to: "/homework/$id", params: { id: cell.row.original.id } }) },
196197 { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => openEdit(cell.row.original) },
197198 { label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteTarget(cell.row.original) },
198199 ]}
src/components/notes/note-files-panel.tsxmodified+5 -5
@@ -210,6 +210,11 @@ export function NoteFilesPanel(props: {
210210 <TableRowActions
211211 label={t("common.actions")}
212212 actions={[
213+ {
214+ label: t("common.view"),
215+ icon: <IconEye class="h-4 w-4" />,
216+ onSelect: () => setPreviewFile(file),
217+ },
213218 ...(canManage() && isDrawing(file)
214219 ? [
215220 {
@@ -219,11 +224,6 @@ export function NoteFilesPanel(props: {
219224 },
220225 ]
221226 : []),
222- {
223- label: t("common.view"),
224- icon: <IconEye class="h-4 w-4" />,
225- onSelect: () => setPreviewFile(file),
226- },
227227 {
228228 label: t("notes.downloadFile"),
229229 icon: <IconDownload class="h-4 w-4" />,
src/components/notes/rag-output-drawer.test.tsxmodified+3 -2
@@ -179,8 +179,9 @@ describe("RagOutputDrawer", () => {
179179 expect(screen.getByText("Preview")).toBeTruthy();
180180 expect(screen.getByText("hücre zarı")).toBeTruthy();
181181 expect(screen.getByText("organel")).toBeTruthy();
182- expect(screen.queryByRole("button", { name: "Actions" })).toBeNull();
183- expect(screen.getByRole("button", { name: "Delete" })).toBeTruthy();
182+ // Delete sits inside the shared actions menu, never as a bare icon button.
183+ expect(screen.getByRole("button", { name: "Actions" })).toBeTruthy();
184+ expect(screen.queryByRole("button", { name: "Delete" })).toBeNull();
184185 expect(screen.getByRole("button", { name: "Export" })).toBeTruthy();
185186 expect(screen.queryByRole("button", { name: "View" })).toBeNull();
186187 });
src/components/ui/table-row-actions.tsxmodified+33 -44
@@ -4,6 +4,7 @@ import {
44 DropdownMenu,
55 DropdownMenuContent,
66 DropdownMenuItem,
7+ DropdownMenuSeparator,
78 DropdownMenuTrigger,
89 } from "@/components/ui/dropdown-menu";
910 import { IconDotsVertical } from "@/components/ui/icons";
@@ -17,19 +18,37 @@ type TableRowAction = {
1718 disabled?: boolean;
1819 };
1920
21+/**
22+ * The one row/header actions control: always a dropdown behind the same
23+ * action-menu trigger, even for a single action, so every table reads the same.
24+ * Order is normalised here — view/edit/other items first in the order given,
25+ * then a separator and the destructive items last. Callers put "view" first
26+ * and route destructive items through a ConfirmDialog.
27+ */
2028 export function TableRowActions(props: { label: string; actions: TableRowAction[]; compact?: boolean; triggerLabel?: string }) {
2129 const t = useT();
22- const singleAction = () => props.actions.length === 1 ? props.actions[0] : undefined;
23- const run = (action: TableRowAction) => {
24- if (action.disabled) return;
25- setTimeout(action.onSelect, 0);
26- };
30+ const safeActions = () => props.actions.filter((action) => !action.destructive);
31+ const destructiveActions = () => props.actions.filter((action) => action.destructive);
32+
33+ const item = (action: TableRowAction) => (
34+ <DropdownMenuItem
35+ class="flex items-center gap-2.5 text-xs"
36+ destructive={action.destructive}
37+ disabled={action.disabled}
38+ // Defer to the next macrotask so the menu fully closes (and
39+ // restores focus to its trigger) before the action opens a
40+ // panel/dialog — otherwise the non-modal SidePanel reads that
41+ // focus-restore as an outside interaction and instantly closes.
42+ onSelect={() => setTimeout(action.onSelect, 0)}
43+ >
44+ {action.icon}
45+ <span>{action.label}</span>
46+ </DropdownMenuItem>
47+ );
2748
2849 return (
2950 <div class="flex justify-center">
30- <Show
31- when={singleAction()}
32- fallback={<DropdownMenu placement="bottom-end" gutter={6}>
51+ <DropdownMenu placement="bottom-end" gutter={6}>
3352 <DropdownMenuTrigger
3453 class={props.compact
3554 ? "inline-flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-expanded:bg-muted data-expanded:text-foreground"
@@ -42,43 +61,13 @@ export function TableRowActions(props: { label: string; actions: TableRowAction[
4261 <IconDotsVertical class="h-3.5 w-3.5" />
4362 </DropdownMenuTrigger>
4463 <DropdownMenuContent class="w-48">
45- <For each={props.actions}>
46- {(action) => (
47- <DropdownMenuItem
48- class="flex items-center gap-2.5 text-xs"
49- destructive={action.destructive}
50- disabled={action.disabled}
51- // Defer to the next macrotask so the menu fully closes (and
52- // restores focus to its trigger) before the action opens a
53- // panel/dialog — otherwise the non-modal SidePanel reads that
54- // focus-restore as an outside interaction and instantly closes.
55- onSelect={() => setTimeout(action.onSelect, 0)}
56- >
57- {action.icon}
58- <span>{action.label}</span>
59- </DropdownMenuItem>
60- )}
61- </For>
64+ <For each={safeActions()}>{item}</For>
65+ <Show when={safeActions().length > 0 && destructiveActions().length > 0}>
66+ <DropdownMenuSeparator />
67+ </Show>
68+ <For each={destructiveActions()}>{item}</For>
6269 </DropdownMenuContent>
63- </DropdownMenu>}
64- >
65- {(action) => (
66- <button
67- type="button"
68- data-row-actions-trigger
69- class="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-transparent text-muted-foreground outline-hidden transition-colors hover:border-primary/20 hover:bg-primary/8 hover:text-primary-text focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
70- aria-label={action().label}
71- title={action().label}
72- disabled={action().disabled}
73- onClick={(event) => {
74- event.stopPropagation();
75- run(action());
76- }}
77- >
78- {action().icon}
79- </button>
80- )}
81- </Show>
70+ </DropdownMenu>
8271 </div>
8372 );
8473 }
src/components/whiteboard/board-settings-panel.tsxmodified+17 -2
@@ -4,6 +4,7 @@ import type { Board } from "@/api/boards";
44 import { BoardBulkInvite } from "@/components/whiteboard/board-bulk-invite";
55 import { ErrorAlert } from "@/components/ui/error-alert";
66 import { Button } from "@/components/ui/button";
7+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
78 import { DataTable } from "@/components/ui/data-table";
89 import { Input } from "@/components/ui/input";
910 import { Label } from "@/components/ui/label";
@@ -37,6 +38,7 @@ export function BoardSettingsPanel(props: {
3738 const t = useT();
3839 const [title, setTitle] = createSignal("");
3940 const [personId, setPersonId] = createSignal("");
41+ const [removeTarget, setRemoveTarget] = createSignal<ParticipantRow | null>(null);
4042 const [error, setError] = createSignal("");
4143 const [pending, setPending] = createSignal(false);
4244
@@ -105,14 +107,13 @@ export function BoardSettingsPanel(props: {
105107 fallback={<span class="text-xs text-muted-foreground">{cell.row.original.creator ? t("whiteboard.creator") : "—"}</span>}
106108 >
107109 <TableRowActions
108- compact
109110 label={t("common.actions")}
110111 actions={[{
111112 label: t("whiteboard.removeParticipant"),
112113 icon: <span class="text-base leading-none">×</span>,
113114 destructive: true,
114115 disabled: pending(),
115- onSelect: () => void saveParticipants(props.participants().filter((id) => id !== cell.row.original.id)),
116+ onSelect: () => setRemoveTarget(cell.row.original),
116117 }]}
117118 />
118119 </Show>
@@ -173,6 +174,20 @@ export function BoardSettingsPanel(props: {
173174 />
174175 </section>
175176
177+ <ConfirmDialog
178+ open={removeTarget() != null}
179+ onOpenChange={(open) => !open && setRemoveTarget(null)}
180+ title={t("whiteboard.removeParticipant")}
181+ variant="destructive"
182+ summary={removeTarget()?.name ?? ""}
183+ onConfirm={async () => {
184+ const target = removeTarget();
185+ if (!target) return;
186+ await saveParticipants(props.participants().filter((id) => id !== target.id));
187+ setRemoveTarget(null);
188+ }}
189+ />
190+
176191 {/* Inviting a whole group is the creator's alone, exactly like the
177192 roster edits above. */}
178193 <Show when={props.canManageParticipants()}>
src/pages/bank-question-detail-page.tsxmodified+10 -4
@@ -25,6 +25,7 @@ import { formatDate } from "@/lib/format";
2525 import { hasMinRole } from "@/lib/roles";
2626 import { useAuth } from "@/stores/auth-context";
2727 import { usePreferences, useT } from "@/stores/preferences-context";
28+import { TableRowActions } from "@/components/ui/table-row-actions";
2829
2930 export default function BankQuestionDetailPage() {
3031 return (
@@ -105,10 +106,15 @@ function BankQuestionDetailContent() {
105106 <IconEdit class="h-4 w-4" />
106107 {t("common.edit")}
107108 </Button>
108- <Button variant="destructive" size="sm" class="rounded-lg" onClick={() => setDeleteOpen(true)}>
109- <IconTrash class="h-4 w-4" />
110- {t("common.delete")}
111- </Button>
109+ <TableRowActions
110+ label={t("common.actions")}
111+ actions={[{
112+ label: t("common.delete"),
113+ icon: <IconTrash class="h-4 w-4" />,
114+ destructive: true,
115+ onSelect: () => setDeleteOpen(true),
116+ }]}
117+ />
112118 </Show>
113119 </>
114120 }
src/pages/builder-school-detail-page.tsxmodified+10 -4
@@ -34,6 +34,7 @@ import { formatDateTime } from "@/lib/format";
3434 import { useAuth } from "@/stores/auth-context";
3535 import { BuilderProvider } from "@/stores/builder-context";
3636 import { usePreferences, useT } from "@/stores/preferences-context";
37+import { TableRowActions } from "@/components/ui/table-row-actions";
3738
3839 export default function BuilderSchoolDetailPage() {
3940 return (
@@ -142,10 +143,15 @@ function BuilderSchoolDetailContent() {
142143 <IconExternalLink class="h-4 w-4" />
143144 {t("builder.enterSchool")}
144145 </Button>
145- <Button type="button" variant="destructive" size="sm" class="rounded-lg" onClick={() => setDeleteOpen(true)}>
146- <IconTrash class="h-4 w-4" />
147- {t("common.delete")}
148- </Button>
146+ <TableRowActions
147+ label={t("common.actions")}
148+ actions={[{
149+ label: t("common.delete"),
150+ icon: <IconTrash class="h-4 w-4" />,
151+ destructive: true,
152+ onSelect: () => setDeleteOpen(true),
153+ }]}
154+ />
149155 </div>
150156 }
151157 />
src/pages/class-detail-page.tsxmodified+10 -1
@@ -265,7 +265,16 @@ function ClassDetailContent() {
265265 {t("classBlueprints.apply")}
266266 </Button>
267267 <Button size="sm" variant="outline" class="rounded-lg" onClick={() => { setName(c().name); setGrade(c().grade ?? ""); setYearId(c().year ?? ""); setTeacherId(c().teacher?.id ?? ""); setEditing(true); }}>{t("common.edit")}</Button>
268- <Button size="sm" variant="outline" class="rounded-lg text-destructive-text" onClick={() => setDeleteOpen(true)}>{t("classGroups.deleteClass")}</Button>
268+ <TableRowActions
269+ label={t("common.actions")}
270+ actions={[{
271+ label: t("classGroups.deleteClass"),
272+ icon: <IconTrash class="h-4 w-4" />,
273+ destructive: true,
274+ disabled: pending(),
275+ onSelect: () => setDeleteOpen(true),
276+ }]}
277+ />
269278 </div>
270279 </Show>
271280 </header>
src/pages/event-detail-page.tsxmodified+10 -4
@@ -193,10 +193,16 @@ function EventDetailContent() {
193193 <IconEdit class="h-4 w-4" />
194194 {t("common.edit")}
195195 </Button>
196- <Button type="button" variant="destructive" size="sm" class="flex-1 rounded-xl sm:flex-none" disabled={pending()} onClick={() => setDeleteOpen(true)}>
197- <IconTrash class="h-4 w-4" />
198- {t("common.delete")}
199- </Button>
196+ <TableRowActions
197+ label={t("common.actions")}
198+ actions={[{
199+ label: t("common.delete"),
200+ icon: <IconTrash class="h-4 w-4" />,
201+ destructive: true,
202+ disabled: pending(),
203+ onSelect: () => setDeleteOpen(true),
204+ }]}
205+ />
200206 </div>
201207 ) : undefined
202208 }
src/pages/meal-detail-page.tsxmodified+2 -1
@@ -52,6 +52,7 @@ import { personLabel } from "@/lib/person";
5252 import { hasMinRole } from "@/lib/roles";
5353 import { useAuth } from "@/stores/auth-context";
5454 import { usePreferences, useT } from "@/stores/preferences-context";
55+import { TableRowActions } from "@/components/ui/table-row-actions";
5556
5657 export default function MealDetailPage() {
5758 return <RouteGuard><MealDetailContent /></RouteGuard>;
@@ -190,7 +191,7 @@ function MealDetailContent() {
190191 <PageHeader
191192 title={t("meals.menu")}
192193 description={t("meals.detailHelp")}
193- actions={canManage() ? <div class="detail-action-group"><Button variant="outline" size="sm" onClick={() => { setCapacity(current().capacity == null ? "" : String(current().capacity)); setShowMenuEdit(true); }}><IconEdit class="h-4 w-4" />{t("common.edit")}</Button><Button variant="destructive" size="sm" onClick={() => setDeleteMenuOpen(true)}><IconTrash class="h-4 w-4" />{t("common.delete")}</Button></div> : undefined}
194+ actions={canManage() ? <div class="detail-action-group"><Button variant="outline" size="sm" onClick={() => { setCapacity(current().capacity == null ? "" : String(current().capacity)); setShowMenuEdit(true); }}><IconEdit class="h-4 w-4" />{t("common.edit")}</Button><TableRowActions label={t("common.actions")} actions={[{ label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteMenuOpen(true) }]} /></div> : undefined}
194195 />
195196 </div>
196197 <Show when={limits.error}><ErrorAlert message={formatApiError(limits.error)} onRetry={() => void refetchLimits()} /></Show>
src/pages/payments-page.tsxmodified+9 -15
@@ -477,21 +477,15 @@ function PaymentsContent() {
477477 cellClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap",
478478 },
479479 cell: (cell) => (
480- <div class="flex items-center justify-center gap-1">
481- <Button size="sm" variant="outline" class="h-8 gap-1 rounded-lg px-2 text-xs" onClick={() => openAssign(cell.row.original)}>
482- <IconPlus class="h-4 w-4" />
483- {t("payments.assign")}
484- </Button>
485- <TableRowActions
486- label={t("common.actions")}
487- compact
488- actions={[
489- { label: t("common.view"), icon: <IconEye class="h-4 w-4" />, onSelect: () => setViewPlan(cell.row.original) },
490- { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => startEdit(cell.row.original) },
491- { label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteTarget(cell.row.original) },
492- ]}
493- />
494- </div>
480+ <TableRowActions
481+ label={t("common.actions")}
482+ actions={[
483+ { label: t("common.view"), icon: <IconEye class="h-4 w-4" />, onSelect: () => setViewPlan(cell.row.original) },
484+ { label: t("payments.assign"), icon: <IconPlus class="h-4 w-4" />, onSelect: () => openAssign(cell.row.original) },
485+ { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => startEdit(cell.row.original) },
486+ { label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteTarget(cell.row.original) },
487+ ]}
488+ />
495489 ),
496490 },
497491 ]);
src/pages/question-detail-page.tsxmodified+10 -4
@@ -15,6 +15,7 @@ import { ConfirmDialog } from "@/components/ui/confirm-dialog";
1515 import { Label } from "@/components/ui/label";
1616 import { Textarea } from "@/components/ui/textarea";
1717 import { IconTrash, IconCheck, IconX, IconEdit, IconMessage, IconPhoto } from "@/components/ui/icons";
18+import { TableRowActions } from "@/components/ui/table-row-actions";
1819 import { ReplayableImage } from "@/components/ui/replayable-image";
1920 import { personLabel } from "@/lib/person";
2021
@@ -138,10 +139,15 @@ function QuestionDetailContent() {
138139 </Button>
139140 </Show>
140141 <Show when={q().asker.id === auth.user()?.id || isModerator()}>
141- <Button variant="destructive" onClick={() => setDeleteConfirmQ(true)}>
142- <IconTrash class="mr-2 h-4 w-4" />
143- {q().status === "pending" && isModerator() ? t("common.reject") : t("common.delete")}
144- </Button>
142+ <TableRowActions
143+ label={t("common.actions")}
144+ actions={[{
145+ label: q().status === "pending" && isModerator() ? t("common.reject") : t("common.delete"),
146+ icon: <IconTrash class="h-4 w-4" />,
147+ destructive: true,
148+ onSelect: () => setDeleteConfirmQ(true),
149+ }]}
150+ />
145151 </Show>
146152 </div>
147153 </div>