@eifi1/ui-kit 0.37.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +11 -4
  2. package/dist/eslint/index.js +1 -1
  3. package/dist/feedback/feedback-comment-thread.d.ts +87 -0
  4. package/dist/feedback/feedback-comment-thread.js +170 -0
  5. package/dist/feedback/feedback-comment-thread.js.map +1 -0
  6. package/dist/feedback/feedback-dialog-labels.js +2 -1
  7. package/dist/feedback/feedback-dialog-labels.js.map +1 -1
  8. package/dist/feedback/feedback-dialog.d.ts +13 -0
  9. package/dist/feedback/feedback-dialog.js +12 -4
  10. package/dist/feedback/feedback-dialog.js.map +1 -1
  11. package/dist/feedback/feedback-labels.d.ts +11 -0
  12. package/dist/feedback/feedback-labels.js +4 -1
  13. package/dist/feedback/feedback-labels.js.map +1 -1
  14. package/dist/feedback/feedback-menu-labels.js +2 -1
  15. package/dist/feedback/feedback-menu-labels.js.map +1 -1
  16. package/dist/feedback/feedback-menu.d.ts +17 -3
  17. package/dist/feedback/feedback-menu.js +11 -1
  18. package/dist/feedback/feedback-menu.js.map +1 -1
  19. package/dist/feedback/feedback-public-labels.d.ts +53 -0
  20. package/dist/feedback/feedback-public-labels.js +27 -0
  21. package/dist/feedback/feedback-public-labels.js.map +1 -0
  22. package/dist/feedback/feedback-public-list.d.ts +139 -0
  23. package/dist/feedback/feedback-public-list.js +299 -0
  24. package/dist/feedback/feedback-public-list.js.map +1 -0
  25. package/dist/feedback/feedback-public-switch.d.ts +51 -0
  26. package/dist/feedback/feedback-public-switch.js +50 -0
  27. package/dist/feedback/feedback-public-switch.js.map +1 -0
  28. package/dist/feedback/feedback-public-types.d.ts +75 -0
  29. package/dist/feedback/feedback-public-types.js +2 -0
  30. package/dist/feedback/feedback-public-types.js.map +1 -0
  31. package/dist/feedback/feedback-record.d.ts +32 -1
  32. package/dist/feedback/feedback-record.js +10 -0
  33. package/dist/feedback/feedback-record.js.map +1 -1
  34. package/dist/feedback/feedback-replies-context.d.ts +7 -0
  35. package/dist/feedback/feedback-replies-context.js +7 -0
  36. package/dist/feedback/feedback-replies-context.js.map +1 -0
  37. package/dist/feedback/feedback-replies.d.ts +97 -0
  38. package/dist/feedback/feedback-replies.js +114 -0
  39. package/dist/feedback/feedback-replies.js.map +1 -0
  40. package/dist/feedback/feedback-row-detail-labels.js +1 -0
  41. package/dist/feedback/feedback-row-detail-labels.js.map +1 -1
  42. package/dist/feedback/feedback-row-detail.d.ts +47 -10
  43. package/dist/feedback/feedback-row-detail.js +51 -50
  44. package/dist/feedback/feedback-row-detail.js.map +1 -1
  45. package/dist/feedback/feedback-submit-dialog.d.ts +3 -1
  46. package/dist/feedback/feedback-submit-dialog.js +6 -1
  47. package/dist/feedback/feedback-submit-dialog.js.map +1 -1
  48. package/dist/feedback/feedback-submit.d.ts +8 -0
  49. package/dist/feedback/feedback-submit.js +3 -2
  50. package/dist/feedback/feedback-submit.js.map +1 -1
  51. package/dist/feedback/feedback-table.d.ts +15 -5
  52. package/dist/feedback/feedback-table.js +46 -5
  53. package/dist/feedback/feedback-table.js.map +1 -1
  54. package/dist/feedback/feedback-thread-parts-labels.d.ts +6 -0
  55. package/dist/feedback/feedback-thread-parts-labels.js +36 -0
  56. package/dist/feedback/feedback-thread-parts-labels.js.map +1 -0
  57. package/dist/feedback/feedback-thread.d.ts +8 -0
  58. package/dist/feedback/feedback-thread.js +7 -2
  59. package/dist/feedback/feedback-thread.js.map +1 -1
  60. package/dist/feedback/feedback-vote-button.d.ts +49 -0
  61. package/dist/feedback/feedback-vote-button.js +72 -0
  62. package/dist/feedback/feedback-vote-button.js.map +1 -0
  63. package/dist/feedback.d.ts +6 -0
  64. package/dist/feedback.js +6 -0
  65. package/dist/feedback.js.map +1 -1
  66. package/dist/i18n/defaults.js +12 -0
  67. package/dist/i18n/defaults.js.map +1 -1
  68. package/dist/i18n/german.js +69 -3
  69. package/dist/i18n/german.js.map +1 -1
  70. package/dist/i18n/kit-labels.d.ts +16 -0
  71. package/dist/i18n/kit-labels.js.map +1 -1
  72. package/dist/i18n/locales/en.js +85 -3
  73. package/dist/i18n/locales/en.js.map +3 -3
  74. package/dist/i18n/locales/es.js +69 -3
  75. package/dist/i18n/locales/es.js.map +1 -1
  76. package/dist/i18n/locales/fr.js +69 -3
  77. package/dist/i18n/locales/fr.js.map +1 -1
  78. package/dist/i18n/locales/hu.js +69 -3
  79. package/dist/i18n/locales/hu.js.map +1 -1
  80. package/dist/i18n/locales/it.js +69 -3
  81. package/dist/i18n/locales/it.js.map +1 -1
  82. package/dist/i18n/locales/zh.js +69 -3
  83. package/dist/i18n/locales/zh.js.map +1 -1
  84. package/dist/i18n/review.js +5 -0
  85. package/dist/i18n/review.js.map +1 -1
  86. package/dist/index.d.ts +2 -0
  87. package/dist/index.js +6 -0
  88. package/dist/index.js.map +1 -1
  89. package/dist/notifications/feedback-notification-types-labels.d.ts +15 -0
  90. package/dist/notifications/feedback-notification-types-labels.js +11 -0
  91. package/dist/notifications/feedback-notification-types-labels.js.map +1 -0
  92. package/dist/notifications/feedback-notification-types.d.ts +28 -0
  93. package/dist/notifications/feedback-notification-types.js +21 -0
  94. package/dist/notifications/feedback-notification-types.js.map +1 -0
  95. package/package.json +1 -1
  96. package/src/feedback/feedback-comment-thread.tsx +277 -0
  97. package/src/feedback/feedback-dialog-labels.ts +1 -0
  98. package/src/feedback/feedback-dialog.tsx +30 -2
  99. package/src/feedback/feedback-labels.ts +14 -0
  100. package/src/feedback/feedback-menu-labels.ts +1 -0
  101. package/src/feedback/feedback-menu.tsx +29 -3
  102. package/src/feedback/feedback-public-labels.ts +80 -0
  103. package/src/feedback/feedback-public-list.tsx +478 -0
  104. package/src/feedback/feedback-public-switch.tsx +102 -0
  105. package/src/feedback/feedback-public-types.ts +82 -0
  106. package/src/feedback/feedback-record.ts +39 -1
  107. package/src/feedback/feedback-replies-context.ts +9 -0
  108. package/src/feedback/feedback-replies.tsx +235 -0
  109. package/src/feedback/feedback-row-detail-labels.ts +1 -0
  110. package/src/feedback/feedback-row-detail.tsx +115 -74
  111. package/src/feedback/feedback-submit-dialog.tsx +9 -0
  112. package/src/feedback/feedback-submit.tsx +10 -1
  113. package/src/feedback/feedback-table.tsx +73 -6
  114. package/src/feedback/feedback-thread-parts-labels.ts +41 -0
  115. package/src/feedback/feedback-thread.tsx +18 -1
  116. package/src/feedback/feedback-vote-button.tsx +123 -0
  117. package/src/feedback.ts +10 -0
  118. package/src/i18n/defaults.ts +12 -0
  119. package/src/i18n/german.ts +66 -0
  120. package/src/i18n/kit-labels.tsx +16 -0
  121. package/src/i18n/locales/en.ts +8 -0
  122. package/src/i18n/locales/es.ts +66 -0
  123. package/src/i18n/locales/fr.ts +66 -0
  124. package/src/i18n/locales/hu.ts +66 -0
  125. package/src/i18n/locales/it.ts +66 -0
  126. package/src/i18n/locales/zh.ts +66 -0
  127. package/src/i18n/review.ts +5 -0
  128. package/src/index.ts +9 -0
  129. package/src/notifications/feedback-notification-types-labels.ts +24 -0
  130. package/src/notifications/feedback-notification-types.ts +46 -0
@@ -0,0 +1,478 @@
1
+ import { useMemo, useState } from "react";
2
+ import type { ReactNode } from "react";
3
+ import { ChevronLeft, ChevronRight, MessageSquare, ThumbsUp } from "lucide-react";
4
+ import { DataTable, type DataTableColumn } from "../components/data-table";
5
+ import { DEFAULT_DATA_TABLE_LABELS } from "../components/data-table-labels";
6
+ import { IconButton } from "../components/icon-button";
7
+ import { SearchField } from "../components/search-field";
8
+ import { ToggleGroup } from "../components/toggle-group";
9
+ import type { CommitScope } from "../components/write-lock";
10
+ import { useKitLabels, type LabelOverride } from "../i18n/kit-labels";
11
+ import { cn } from "../lib/cn";
12
+ import { EMPTY_FORMATTED_VALUE } from "../lib/format";
13
+ import { FeedbackCategoryBadge, FeedbackDetail, FeedbackDetailSection, FeedbackProse, FeedbackStatusBadge } from "./feedback-inbox";
14
+ import { useFeedbackCategoryLabels } from "./feedback-labels";
15
+ import { FeedbackCommentThread, type FeedbackCommentsLabels } from "./feedback-comment-thread";
16
+ import { DEFAULT_FEEDBACK_PUBLIC_LABELS, type FeedbackPublicLabels } from "./feedback-public-labels";
17
+ import type {
18
+ FeedbackComment,
19
+ FeedbackPublicListItem,
20
+ FeedbackPublicRecord,
21
+ FeedbackPublicSort,
22
+ FeedbackVoteState,
23
+ } from "./feedback-public-types";
24
+ import {
25
+ useFeedbackPageLabels,
26
+ useFeedbackRenderDate,
27
+ type FeedbackPageLabels,
28
+ type FeedbackRenderDate,
29
+ } from "./feedback-table";
30
+ import { FeedbackVoteButton } from "./feedback-vote-button";
31
+
32
+ export { DEFAULT_FEEDBACK_PUBLIC_LABELS };
33
+ export type { FeedbackPublicLabels };
34
+
35
+ /** `feedbackPublic` resolved: English, then `<UiKitProvider labels>`, then `labels`. */
36
+ export function useFeedbackPublicLabels(labels?: LabelOverride<FeedbackPublicLabels>): FeedbackPublicLabels {
37
+ return useKitLabels("feedbackPublic", DEFAULT_FEEDBACK_PUBLIC_LABELS, labels);
38
+ }
39
+
40
+ /** The sort toggle's order: the server's default first (§9.6). */
41
+ const SORTS: readonly FeedbackPublicSort[] = ["newest", "votes", "updated"];
42
+
43
+ /** A date in a cell, as the inbox writes it: `<time>`, nowrap, tabular figures. */
44
+ function PublicDate({ value, renderDate }: { value: string | null | undefined; renderDate: FeedbackRenderDate }) {
45
+ if (!value) return <span className="text-placeholder">{EMPTY_FORMATTED_VALUE}</span>;
46
+ return (
47
+ <time dateTime={value} className="whitespace-nowrap tabular-nums text-muted">
48
+ {renderDate(value)}
49
+ </time>
50
+ );
51
+ }
52
+
53
+ /** The visible comments as a small chip beside the title — the count in figures, the
54
+ * words for a screen reader. Nothing at 0. */
55
+ function CommentCount({ count, labels }: { count: number; labels: FeedbackPublicLabels }) {
56
+ if (!count) return null;
57
+ return (
58
+ <span className="inline-flex shrink-0 items-center gap-1 text-xs text-muted" data-feedback-comment-count={count}>
59
+ <MessageSquare className="size-3.5" aria-hidden />
60
+ <span aria-hidden className="tabular-nums">
61
+ {count}
62
+ </span>
63
+ <span className="sr-only">{labels.comments(count)}</span>
64
+ </span>
65
+ );
66
+ }
67
+
68
+ /** The votes on a phone card: the thumb and the count, in the brand colour when the
69
+ * viewer's own. */
70
+ function VoteCount({ count, voted, labels }: { count: number; voted: boolean; labels: FeedbackPublicLabels }) {
71
+ return (
72
+ <span
73
+ className={cn("ms-auto inline-flex shrink-0 items-center gap-1 text-xs", voted ? "text-brand" : "text-muted")}
74
+ data-feedback-vote-count={count}
75
+ >
76
+ <ThumbsUp className="size-3.5" aria-hidden />
77
+ <span aria-hidden className="tabular-nums">
78
+ {count}
79
+ </span>
80
+ <span className="sr-only">{labels.votes(count)}</span>
81
+ </span>
82
+ );
83
+ }
84
+
85
+ /** 0.38.1: previous / next over the server's pages when it answers no total
86
+ * (`GET /feedback/public` — Kurvenschmiede): "Page 3" between two arrows. The arrows'
87
+ * names are `dataTable`'s, the strip's; the page's is `feedbackPublic.page`. */
88
+ function PublicPager({
89
+ page,
90
+ hasMore,
91
+ onPageChange,
92
+ labels,
93
+ }: {
94
+ page: number;
95
+ hasMore: boolean;
96
+ onPageChange: (page: number) => void;
97
+ labels: FeedbackPublicLabels;
98
+ }) {
99
+ const tableLabels = useKitLabels("dataTable", DEFAULT_DATA_TABLE_LABELS);
100
+ const name = labels.page(page + 1);
101
+ return (
102
+ <div
103
+ role="group"
104
+ aria-label={name}
105
+ className="flex items-center justify-end gap-2 text-sm text-secondary"
106
+ data-feedback-public-pager={page}
107
+ >
108
+ <IconButton
109
+ size="sm"
110
+ variant="secondary"
111
+ label={tableLabels.prevPage}
112
+ disabled={page <= 0}
113
+ onClick={() => onPageChange(page - 1)}
114
+ >
115
+ {/* "Previous" points back along the line — left in LTR, right in RTL. */}
116
+ <ChevronLeft className="rtl:-scale-x-100" />
117
+ </IconButton>
118
+ <span className="tabular-nums" aria-hidden>
119
+ {name}
120
+ </span>
121
+ <IconButton
122
+ size="sm"
123
+ variant="secondary"
124
+ label={tableLabels.nextPage}
125
+ disabled={!hasMore}
126
+ onClick={() => onPageChange(page + 1)}
127
+ >
128
+ <ChevronRight className="rtl:-scale-x-100" />
129
+ </IconButton>
130
+ </div>
131
+ );
132
+ }
133
+
134
+ /* ── The list ─────────────────────────────────────────────────────────────── */
135
+
136
+ export interface FeedbackPublicListProps<T extends FeedbackPublicListItem = FeedbackPublicListItem> {
137
+ /** `GET /feedback/public?sort=&q=` — the server's page, in the server's order. */
138
+ rows: T[];
139
+ /** How many the query has in all — the line beside the sort. Left out, no line. */
140
+ total?: number;
141
+ /** The server sorts (§9.6): the toggle only says which way. */
142
+ sort: FeedbackPublicSort;
143
+ onSortChange: (sort: FeedbackPublicSort) => void;
144
+ /** The search box's text (`q`, titles only). */
145
+ search?: string;
146
+ /**
147
+ * The search box is drawn ONLY with this handler: where the app's titles are sealed
148
+ * (Kurvenschmiede, `FeedbackDeps.public_search=False`, §9.9) there is nothing to search
149
+ * on and the server answers `q` with a 422 — so it passes none.
150
+ */
151
+ onSearchChange?: (search: string) => void;
152
+ /** The opened row: the app's {@link FeedbackPublicDetail} with the row's
153
+ * `GET /feedback/public/{id}` and its comments. */
154
+ renderDetail: (row: T) => ReactNode;
155
+ /** `PUT` / `DELETE /feedback/{id}/vote` for a row's button (`next`: the new state);
156
+ * resolve with the answer, reject to roll back. */
157
+ onVote: (row: T, next: boolean) => Promise<FeedbackVoteState>;
158
+ /** The page is loading: the table says so where its rows would be. */
159
+ loading?: boolean;
160
+ /** The opened row's id, when the app keeps it (a `?row=` param). Left out, the list
161
+ * keeps it itself. */
162
+ openId?: number | null;
163
+ onOpenChange?: (id: number | null) => void;
164
+ /**
165
+ * 0.38.1: the opened report when it is NOT on this page — a `?row=` link to an older
166
+ * one (Kurvenschmiede). The app fetches it (`GET /feedback/public/{id}`, a list item's
167
+ * fields and more) and passes it with `openId`; while `openId` is its id it is drawn
168
+ * first, above the page's rows, and opened with `renderDetail` (on the phone, in the
169
+ * full-screen dialog). Closed, it is gone. A row the page has already is never drawn
170
+ * twice: the page's own is opened instead.
171
+ */
172
+ openRow?: T | null;
173
+ /**
174
+ * 0.38.1: the server's page, from 0 — for a pager where `/feedback/public` answers no
175
+ * total (Kurvenschmiede). With {@link onPageChange} a **Previous / Page n / Next**
176
+ * strip stands under the table; Next is off without {@link hasMore}. Left out, no
177
+ * pager: the server's `limit` is all there is.
178
+ */
179
+ page?: number;
180
+ /** 0.38.1: there is a page after this one (e.g. the page came back full). */
181
+ hasMore?: boolean;
182
+ /** 0.38.1: go to another page (`page ± 1`); the app fetches it. Draws the pager. */
183
+ onPageChange?: (page: number) => void;
184
+ /** A vote COMMITS — see Button's `commit`. */
185
+ commit?: CommitScope;
186
+ /** See {@link FeedbackRenderDate}. Default: the kit's, with the weekday. */
187
+ renderDate?: FeedbackRenderDate;
188
+ /** Over the `feedbackPublic` namespace. The shared column names (#, Date, Category,
189
+ * Subject, Status) are `feedbackPage`'s: pass `pageLabels` for those. */
190
+ labels?: LabelOverride<FeedbackPublicLabels>;
191
+ pageLabels?: LabelOverride<FeedbackPageLabels>;
192
+ className?: string;
193
+ }
194
+
195
+ /**
196
+ * **All feedback** — the reports every user the app lets in may read (round 0.38,
197
+ * docs/feedback-harmonization.md §9.3, §9.9; keksdose's `/all-feedback`).
198
+ *
199
+ * - **Titles only** (decision 23): #, Date, Category, Subject (with the visible
200
+ * comments), Votes, Status. No body, no submitter, no file — the list item carries
201
+ * none of them (§9.10).
202
+ * - **The server sorts**: the toggle **Newest / Most wanted / Recently updated** sets
203
+ * `sort`, and the columns themselves do not sort (a page of 50 sorted in the browser
204
+ * would not be the 50 the sort asks for).
205
+ * - **The search box only with `onSearchChange`**: an app whose titles are sealed
206
+ * passes none (§9.9).
207
+ * - **Votes** are `FeedbackVoteButton`s, optimistic, the viewer's own report pressed
208
+ * and locked ("Your report", §9.6).
209
+ * - A row opens in place with `renderDetail` — on the phone, in a full-screen dialog.
210
+ * The phone cards carry the title, the status, the category, the date and the two
211
+ * counts; the vote itself is in the opened report (a button inside the card, which is
212
+ * the row's own button, would be two controls in one).
213
+ *
214
+ * No client paging: the server's `limit` is the page, and `total` says how many there
215
+ * are. For more than one page, `page` / `hasMore` / `onPageChange` draw a previous /
216
+ * next strip that needs no total (0.38.1); `openRow` shows a `?row=` report from
217
+ * another page. Needs a router, as every `DataTable` does.
218
+ */
219
+ export function FeedbackPublicList<T extends FeedbackPublicListItem = FeedbackPublicListItem>({
220
+ rows,
221
+ total,
222
+ sort,
223
+ onSortChange,
224
+ search = "",
225
+ onSearchChange,
226
+ renderDetail,
227
+ onVote,
228
+ loading = false,
229
+ openId: openIdProp,
230
+ onOpenChange,
231
+ openRow,
232
+ page: pageIndex = 0,
233
+ hasMore = false,
234
+ onPageChange,
235
+ commit,
236
+ renderDate: renderDateProp,
237
+ labels: labelsProp,
238
+ pageLabels: pageLabelsProp,
239
+ className,
240
+ }: FeedbackPublicListProps<T>) {
241
+ const labels = useFeedbackPublicLabels(labelsProp);
242
+ const page = useFeedbackPageLabels(pageLabelsProp);
243
+ const categoryLabels = useFeedbackCategoryLabels();
244
+ const renderDate = useFeedbackRenderDate(renderDateProp);
245
+ const [ownOpenId, setOwnOpenId] = useState<number | null>(null);
246
+ const openId = openIdProp !== undefined ? openIdProp : ownOpenId;
247
+ const setOpen = (id: number | null) => {
248
+ if (openIdProp === undefined) setOwnOpenId(id);
249
+ onOpenChange?.(id);
250
+ };
251
+ // A `?row=` report from another page: first, while it is the open one, and only when
252
+ // the page does not have it itself.
253
+ const shownRows =
254
+ openRow && openId === openRow.id && !rows.some((row) => row.id === openRow.id) ? [openRow, ...rows] : rows;
255
+
256
+ const columns = useMemo<DataTableColumn<T>[]>(
257
+ () => [
258
+ {
259
+ key: "id",
260
+ header: page.columnId,
261
+ cell: (row) => <span className="font-mono text-xs text-muted">{row.id}</span>,
262
+ mobileHidden: true,
263
+ },
264
+ {
265
+ key: "date",
266
+ header: page.columnDate,
267
+ cell: (row) => <PublicDate value={row.created_at} renderDate={renderDate} />,
268
+ },
269
+ {
270
+ key: "category",
271
+ header: page.columnCategory,
272
+ cell: (row) => <FeedbackCategoryBadge category={row.category} label={categoryLabels[row.category]} />,
273
+ },
274
+ {
275
+ key: "title",
276
+ header: page.columnSubject,
277
+ cell: (row) => (
278
+ <span className="inline-flex min-w-0 max-w-full items-center gap-2 large:items-start">
279
+ <span className="min-w-0 truncate-until-large font-medium">{row.title}</span>
280
+ <CommentCount count={row.comment_count} labels={labels} />
281
+ </span>
282
+ ),
283
+ mobilePrimary: true,
284
+ },
285
+ {
286
+ key: "votes",
287
+ header: labels.columnVotes,
288
+ className: "whitespace-nowrap",
289
+ // The cell is a button: the row's own link must never wrap it.
290
+ noRowLink: true,
291
+ cell: (row) => (
292
+ <FeedbackVoteButton
293
+ votes={row.votes}
294
+ voted={row.voted}
295
+ own={row.mine}
296
+ onVote={(next) => onVote(row, next)}
297
+ commit={commit}
298
+ size="sm"
299
+ />
300
+ ),
301
+ },
302
+ {
303
+ key: "status",
304
+ header: page.columnStatus,
305
+ className: "whitespace-nowrap",
306
+ cell: (row) => <FeedbackStatusBadge status={row.status} />,
307
+ },
308
+ ],
309
+ [page, labels, categoryLabels, renderDate, onVote, commit],
310
+ );
311
+
312
+ return (
313
+ <div className={cn("flex flex-col gap-3", className)} data-feedback-public-list="" aria-busy={loading || undefined}>
314
+ <div className="flex flex-wrap items-center gap-2">
315
+ <ToggleGroup
316
+ aria-label={labels.sort}
317
+ value={sort}
318
+ onChange={(value) => onSortChange(value)}
319
+ options={SORTS.map((value) => ({
320
+ value,
321
+ label: value === "newest" ? labels.sortNewest : value === "votes" ? labels.sortVotes : labels.sortUpdated,
322
+ }))}
323
+ />
324
+ {onSearchChange && (
325
+ <SearchField
326
+ aria-label={labels.search}
327
+ placeholder={labels.search}
328
+ value={search}
329
+ onChange={onSearchChange}
330
+ className="min-w-[12rem] flex-1 md:max-w-xs"
331
+ />
332
+ )}
333
+ {total !== undefined && (
334
+ <span className="ms-auto text-sm text-muted" data-feedback-public-total={total}>
335
+ {labels.total(total)}
336
+ </span>
337
+ )}
338
+ </div>
339
+ <DataTable
340
+ rows={shownRows}
341
+ columns={columns}
342
+ rowKey={(row) => row.id}
343
+ rowName={(row) => row.title}
344
+ onRowClick={(row) => setOpen(openId === row.id ? null : row.id)}
345
+ isExpanded={(row) => row.id === openId}
346
+ expandedRow={(row) => renderDetail(row)}
347
+ mobileExpandAsDialog
348
+ paginated={false}
349
+ empty={loading ? labels.loading : labels.empty}
350
+ mobileCard={(row) => (
351
+ <div className="min-w-0 space-y-1">
352
+ <div className="flex items-start justify-between gap-2">
353
+ <span className="min-w-0 flex-1 font-medium [overflow-wrap:anywhere]">{row.title}</span>
354
+ <FeedbackStatusBadge status={row.status} className="shrink-0" />
355
+ </div>
356
+ <div className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted">
357
+ <FeedbackCategoryBadge category={row.category} compact label={categoryLabels[row.category]} />
358
+ <PublicDate value={row.created_at} renderDate={renderDate} />
359
+ <CommentCount count={row.comment_count} labels={labels} />
360
+ {/* A count, not the button: the whole card is the row's button, and a button
361
+ inside it is two controls in one. The vote is in the opened report. */}
362
+ <VoteCount count={row.votes} voted={row.voted || row.mine} labels={labels} />
363
+ </div>
364
+ </div>
365
+ )}
366
+ />
367
+ {onPageChange && (pageIndex > 0 || hasMore) && (
368
+ <PublicPager page={pageIndex} hasMore={hasMore} onPageChange={onPageChange} labels={labels} />
369
+ )}
370
+ </div>
371
+ );
372
+ }
373
+
374
+ /* ── The detail ───────────────────────────────────────────────────────────── */
375
+
376
+ export interface FeedbackPublicDetailProps {
377
+ /** `GET /feedback/public/{id}`: the public body (attachment URLs already stripped by
378
+ * the server, §9.4) and the replies. */
379
+ row: FeedbackPublicRecord;
380
+ /** `GET /feedback/{id}/comments`, oldest first; `undefined` while it loads. */
381
+ comments: readonly FeedbackComment[] | undefined;
382
+ /** `PUT` / `DELETE /feedback/{id}/vote`; resolve with the answer, reject to roll back. */
383
+ onVote: (next: boolean) => Promise<FeedbackVoteState>;
384
+ /** The viewer is the app's admin: Hide / Unhide on the comments. */
385
+ isAdmin?: boolean;
386
+ /** `POST /feedback/{id}/comments`. Left out — a demo, a reader who may not write — no
387
+ * composer. */
388
+ onComment?: (body: string) => void | Promise<unknown>;
389
+ /** The admin's hide (`PATCH …/comments/{id} {hidden}`). */
390
+ onHide?: (comment: FeedbackComment, hidden: boolean) => void | Promise<unknown>;
391
+ /** The writer's delete (`DELETE …/comments/{id}`), after a confirm. */
392
+ onDelete?: (comment: FeedbackComment) => void | Promise<unknown>;
393
+ /** A comment is being sent. */
394
+ pending?: boolean;
395
+ /** The vote and the thread's buttons COMMIT — see Button's `commit`. */
396
+ commit?: CommitScope;
397
+ /** Voting is off for this viewer (a demo): `true`, or the reason. */
398
+ voteDisabled?: boolean | string;
399
+ /** See {@link FeedbackRenderDate}. */
400
+ renderDate?: FeedbackRenderDate;
401
+ /** "Now" for the thread's relative times — pin it in tests and stories. */
402
+ now?: Date | number;
403
+ /** Over the `feedbackPublic` namespace. */
404
+ labels?: LabelOverride<FeedbackPublicLabels>;
405
+ /** Over the `feedbackComments` namespace, for the thread. */
406
+ commentLabels?: LabelOverride<FeedbackCommentsLabels>;
407
+ className?: string;
408
+ }
409
+
410
+ /**
411
+ * One public report opened (round 0.38, docs/feedback-harmonization.md §9.3, §9.10): who
412
+ * filed it — the first name the server sent, else **"A user"** (§9.5) — and when; the
413
+ * **vote**; the **public body**; and the **conversation**, the admin's replies and other
414
+ * people's comments merged oldest first (§9.8, `FeedbackCommentThread`), with the box to
415
+ * add one.
416
+ *
417
+ * What it never draws, because the public record never carries it (§9.10): an address,
418
+ * a last name, a screenshot, a file, the page the report was filed on. The body is the
419
+ * server's `public_body` — the client strips nothing and adds nothing.
420
+ */
421
+ export function FeedbackPublicDetail({
422
+ row,
423
+ comments,
424
+ onVote,
425
+ isAdmin = false,
426
+ onComment,
427
+ onHide,
428
+ onDelete,
429
+ pending,
430
+ commit,
431
+ voteDisabled,
432
+ renderDate: renderDateProp,
433
+ now,
434
+ labels: labelsProp,
435
+ commentLabels,
436
+ className,
437
+ }: FeedbackPublicDetailProps) {
438
+ const labels = useFeedbackPublicLabels(labelsProp);
439
+ const renderDate = useFeedbackRenderDate(renderDateProp);
440
+ return (
441
+ <FeedbackDetail className={className}>
442
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-2" data-feedback-public-detail={row.id}>
443
+ <span className="text-sm text-secondary" data-feedback-author="">
444
+ {labels.filedBy(row.author_name ?? labels.anonymous)}
445
+ </span>
446
+ <PublicDate value={row.created_at} renderDate={renderDate} />
447
+ <FeedbackVoteButton
448
+ votes={row.votes}
449
+ voted={row.voted}
450
+ own={row.mine}
451
+ onVote={onVote}
452
+ disabled={voteDisabled}
453
+ commit={commit}
454
+ className="ms-auto"
455
+ />
456
+ </div>
457
+ <FeedbackDetailSection title={labels.body}>
458
+ {/* Rework rounds stay in it — the author's own words (§9.4). */}
459
+ <FeedbackProse>{row.body}</FeedbackProse>
460
+ </FeedbackDetailSection>
461
+ <FeedbackDetailSection title={labels.conversation}>
462
+ <FeedbackCommentThread
463
+ replies={row.replies}
464
+ comments={comments ?? []}
465
+ loading={comments === undefined}
466
+ isAdmin={isAdmin}
467
+ onComment={onComment}
468
+ onHide={onHide}
469
+ onDelete={onDelete}
470
+ pending={pending}
471
+ commit={commit}
472
+ now={now}
473
+ labels={commentLabels}
474
+ />
475
+ </FeedbackDetailSection>
476
+ </FeedbackDetail>
477
+ );
478
+ }
@@ -0,0 +1,102 @@
1
+ import { Switch } from "../components/switch";
2
+ import type { CommitScope } from "../components/write-lock";
3
+ import { useKitLabels, type LabelOverride } from "../i18n/kit-labels";
4
+ import { FEEDBACK_AUTHOR_EDITABLE_STATUSES, type FeedbackRecord } from "./feedback-record";
5
+ import { DEFAULT_FEEDBACK_PUBLIC_LABELS, type FeedbackPublicLabels } from "./feedback-public-labels";
6
+
7
+ /** What the switch reads off a report: {@link FeedbackRecord}'s fields (§9.3). */
8
+ export type FeedbackPublicSwitchRow = Pick<
9
+ FeedbackRecord,
10
+ "user_id" | "category" | "status" | "public" | "filed_private" | "mine"
11
+ >;
12
+
13
+ /** Who is looking: the app's admin check, and the signed-in user's id. */
14
+ export interface FeedbackPublicSwitchViewer {
15
+ isAdmin: boolean;
16
+ viewerId?: number | null;
17
+ }
18
+
19
+ /** The viewer filed the row — `mine` when the server sent it, else the ids (never for an
20
+ * erased author, `user_id: null`). */
21
+ function isAuthorOf(row: FeedbackPublicSwitchRow, viewerId: number | null | undefined): boolean {
22
+ if (row.mine != null) return row.mine;
23
+ return row.user_id !== null && viewerId !== undefined && viewerId !== null && row.user_id === viewerId;
24
+ }
25
+
26
+ /**
27
+ * Whether the viewer may flip a report's `public` flag — the server's rule (§9.3), so the
28
+ * switch never offers what the `PATCH {public}` would refuse with a 403:
29
+ *
30
+ * - never on a CRASH (decision 9: a crash is private whatever its flag);
31
+ * - an admin, at any status;
32
+ * - the author while the status is OPEN, READY or IN_PROGRESS
33
+ * (`FEEDBACK_AUTHOR_EDITABLE_STATUSES`), and on a `filed_private` report — one the
34
+ * 0.38 migration made public — at any status: that is the opt-out the notice offers.
35
+ */
36
+ export function feedbackPublicSwitchAllowed(
37
+ row: FeedbackPublicSwitchRow,
38
+ { isAdmin, viewerId }: FeedbackPublicSwitchViewer,
39
+ ): boolean {
40
+ if (row.category === "CRASH") return false;
41
+ if (isAdmin) return true;
42
+ if (!isAuthorOf(row, viewerId)) return false;
43
+ return row.filed_private === true || FEEDBACK_AUTHOR_EDITABLE_STATUSES.includes(row.status);
44
+ }
45
+
46
+ export interface FeedbackPublicSwitchProps extends FeedbackPublicSwitchViewer {
47
+ row: FeedbackPublicSwitchRow;
48
+ /** `PATCH /feedback/{id} {"public": next}` — the app's mutation. */
49
+ onChange: (next: boolean) => void;
50
+ /** The PATCH is in flight: the switch holds still. */
51
+ pending?: boolean;
52
+ /** Flipping it SAVES: pass `true` to put it under the page's `WriteLockProvider`
53
+ * (Switch's `commit`). Off by default, as on the inbox's status buttons. */
54
+ commit?: CommitScope;
55
+ /** Over the `feedbackPublic` namespace (`visibleToOthers`, `visibleHint`,
56
+ * `visibleLocked`). */
57
+ labels?: LabelOverride<FeedbackPublicLabels>;
58
+ className?: string;
59
+ }
60
+
61
+ /**
62
+ * **Visible to others** — a report's `public` flag (round 0.38, docs/feedback-harmonization.md
63
+ * §9.3, decision 6), for the row detail (`FeedbackRowDetail`'s `onPublicChange`) or an
64
+ * app's own page.
65
+ *
66
+ * - Drawn for the admin and the author only: nobody else is sent `public` (§9.10). Not
67
+ * drawn on a CRASH, and not when the row carries no `public` at all (a server before
68
+ * 0.38, or an app without public parts — kastlan).
69
+ * - The author past the open window sees it **locked with the reason** ("Only while the
70
+ * report is open"), focusable, so the reason reaches a keyboard; a `filed_private`
71
+ * report is never locked for its author ({@link feedbackPublicSwitchAllowed}).
72
+ * - The line under it says what "visible" means: the title and the text, never the
73
+ * screenshots or files (decision 1).
74
+ */
75
+ export function FeedbackPublicSwitch({
76
+ row,
77
+ isAdmin,
78
+ viewerId,
79
+ onChange,
80
+ pending = false,
81
+ commit,
82
+ labels: labelsProp,
83
+ className,
84
+ }: FeedbackPublicSwitchProps) {
85
+ const labels = useKitLabels("feedbackPublic", DEFAULT_FEEDBACK_PUBLIC_LABELS, labelsProp);
86
+ if (row.category === "CRASH" || row.public == null) return null;
87
+ if (!isAdmin && !isAuthorOf(row, viewerId)) return null;
88
+ const allowed = feedbackPublicSwitchAllowed(row, { isAdmin, viewerId });
89
+ return (
90
+ <Switch
91
+ className={className}
92
+ label={labels.visibleToOthers}
93
+ description={labels.visibleHint}
94
+ checked={row.public === true}
95
+ disabled={pending}
96
+ disabledReason={allowed ? undefined : labels.visibleLocked}
97
+ commit={commit}
98
+ onCheckedChange={(next) => onChange(next)}
99
+ data-feedback-public={row.public ? "on" : "off"}
100
+ />
101
+ );
102
+ }
@@ -0,0 +1,82 @@
1
+ import type { FeedbackCategory, FeedbackStatus } from "./feedback-vocabulary";
2
+
3
+ /**
4
+ * The shapes of round 0.38's public feedback (docs/feedback-harmonization.md §9): the
5
+ * admin's replies as a list (§9.7), other people's comments as rows (§9.8), the upvote
6
+ * (§9.6) and the two public views of a report (§9.3). Types only: what the server
7
+ * answers, as the three apps' clients receive it.
8
+ *
9
+ * A name is always the server's (§9.5): `author_name` is a first name for others, the
10
+ * full name for an admin, and `null` when there is none to show (an erased or incomplete
11
+ * account, a loop's reply). The client never builds one from an id.
12
+ */
13
+
14
+ /** One answer of the admin's — `FeedbackReplyResponse`, §9.7. Oldest first. */
15
+ export interface FeedbackReply {
16
+ id: number;
17
+ /** `null`: a loop's reply, a migrated `outcome`, or an erased admin — drawn as the
18
+ * app's word for its admin ("Admin"). */
19
+ author_name: string | null;
20
+ body: string;
21
+ /** The status this reply moved the report to; `null` = no status change. */
22
+ status_to: FeedbackStatus | null;
23
+ /** Where it moved from — the admin view only. */
24
+ status_from?: FeedbackStatus | null;
25
+ /** ISO 8601. */
26
+ created_at: string;
27
+ }
28
+
29
+ /** One comment by someone who reads the report — `FeedbackCommentResponse`, §9.8. */
30
+ export interface FeedbackComment {
31
+ id: number;
32
+ /** First name for others, the full name for an admin; `null` → "A user". */
33
+ author_name: string | null;
34
+ /** The viewer wrote it (they may delete it). */
35
+ mine: boolean;
36
+ /** keksdose's migrated rows whose writer was an admin (K2): drawn as a staff post. */
37
+ staff: boolean;
38
+ /** `null` when hidden, but for its writer and an admin. */
39
+ body: string | null;
40
+ hidden: boolean;
41
+ /** ISO 8601. */
42
+ created_at: string;
43
+ }
44
+
45
+ /** What `PUT` / `DELETE /feedback/{id}/vote` answer — `FeedbackVoteResponse`, §9.6. */
46
+ export interface FeedbackVoteState {
47
+ votes: number;
48
+ voted: boolean;
49
+ }
50
+
51
+ /** The public list's server-side sort (§9.6): newest first (default), most votes (then
52
+ * newest), or most recently updated. */
53
+ export type FeedbackPublicSort = "newest" | "votes" | "updated";
54
+
55
+ /** One row of `GET /feedback/public` — `FeedbackPublicListItem`, §9.3, §9.9: titles
56
+ * only, no body, no files, no account. */
57
+ export interface FeedbackPublicListItem extends FeedbackVoteState {
58
+ id: number;
59
+ title: string;
60
+ category: FeedbackCategory;
61
+ status: FeedbackStatus;
62
+ /** First name, or `null` → "A user". */
63
+ author_name: string | null;
64
+ /** The viewer filed it. */
65
+ mine: boolean;
66
+ /** Visible comments. */
67
+ comment_count: number;
68
+ /** ISO 8601. */
69
+ created_at: string;
70
+ /** ISO 8601. */
71
+ updated_at: string;
72
+ /** ISO 8601, or `null`. */
73
+ resolved_at: string | null;
74
+ }
75
+
76
+ /** `GET /feedback/public/{id}` — `FeedbackPublicResponse`, §9.3: the list row plus the
77
+ * public body (every attachment URL stripped by the server, §9.4) and the replies. The
78
+ * comments are fetched beside it (`GET /feedback/{id}/comments`). */
79
+ export interface FeedbackPublicRecord extends FeedbackPublicListItem {
80
+ body: string;
81
+ replies: FeedbackReply[];
82
+ }