@estiva-app/ui 0.97.0 → 0.98.0

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.
@@ -14,6 +14,12 @@ Where a conversation's cards sit: two columns, or one 384px column beside the pa
14
14
  - `threads="beside"`, two columns: the comments fill the page; an open thread stands beside them, 384px.
15
15
  - `threads="under"`, one column: the comments are the 384px column beside the page; a thread opens under its comment, and the two become one card.
16
16
  - With two columns, `header` puts the comments' own **PageHeader** over their column only, and the thread runs the page's full height beside it.
17
+ - With two columns, each comment's `day` names its stretch with a line that stays at the top while the stretch scrolls (Peek's day lines).
18
+
19
+ <Canvas of={Stories.TwoColumnsDays} />
20
+
21
+ <Canvas of={Stories.TwoColumnsArchived} />
22
+
17
23
  - With one column, an item that is `resolved` waits closed under "Resolved" at the end, and one whose part was deleted (`gone`) under "On deleted blocks" before it, each with how many. A group opens by itself for the thread open in it. With two columns they stay in their place.
18
24
 
19
25
  <Canvas of={Stories.OneColumn} />
@@ -40,6 +46,12 @@ import { ConversationLayout } from '@estiva-app/ui'
40
46
  - Write nothing on the cards for opening: no `onClick`, `selected`, `onReply`, or the replies row's `onOpen` and
41
47
  `open`. The layout gives each **ConversationCard** its place, and the card opens its thread from it. What a card is
42
48
  given still wins.
49
+ - Two columns, an app that keeps its own place in the comments (where they were left, a "New" line, following what
50
+ arrives) has their scrolling box with `bodyRef` and `onBodyScroll`. Each comment's `day` draws the app's day lines,
51
+ each staying at the top while its own day scrolls under it; `before` is a line just above one comment (a "New"
52
+ line); `below` is under the comments (a **ReactionHorizon**); `top` stands at the top however few the comments are
53
+ (an **ArchivedNotice**). Few comments sit on the box, as a chat does. `empty` may be the app's own **EmptyState**,
54
+ or `null` for nothing.
43
55
  - The box at the foot of a thread that opens takes the caret, at its end, without scrolling: the layout tells it with
44
56
  `caretOnOpen`, which **CommentBox** reads. Nothing to pass; a box outside a layout never takes it this way.
45
57
 
@@ -3,7 +3,9 @@ import { useState } from 'react'
3
3
  import { ConversationCard, ReplyCard } from './ConversationCard'
4
4
  import { ConversationLayout, type ConversationItem } from './ConversationLayout'
5
5
  import { ONE, SHORT, SOME, THREE, TWO, WORDS, WriteBox, YOU, useReactions } from './conversation.examples'
6
+ import { ArchivedNotice } from './ArchivedNotice'
6
7
  import { Panel } from './Panel'
8
+ import { ReactionHorizon } from './ReactionHorizon'
7
9
  import { QuotedLine } from './QuotedLine'
8
10
  import { SkeletonBar } from './Skeleton'
9
11
  import { Thread } from './Thread'
@@ -105,6 +107,51 @@ export const TwoColumns: Story = {
105
107
  },
106
108
  }
107
109
 
110
+ /**
111
+ * Two columns, as Peek's file page and DMs: each day's comments under a line naming it, which stays at the top while
112
+ * its stretch scrolls; the reactions note under the comments. Few comments sit on the box, as a chat does.
113
+ */
114
+ export const TwoColumnsDays: Story = {
115
+ name: 'Two columns, days',
116
+ render: () => {
117
+ const card = (who: typeof ONE, time: string, words: string) => (
118
+ <ConversationCard author={who} time={time}>
119
+ {words}
120
+ </ConversationCard>
121
+ )
122
+ const items: ConversationItem[] = [
123
+ { id: 'd1', day: 'Monday', card: card(ONE, '9:14 AM', WORDS) },
124
+ { id: 'd2', day: 'Monday', card: card(TWO, '9:40 AM', 'A second comment that Monday.') },
125
+ { id: 'd3', day: 'Today', card: card(ONE, '8:02 AM', 'The first comment today.') },
126
+ { id: 'd4', day: 'Today', card: card(TWO, '10:21 AM', 'A second comment today.') },
127
+ ]
128
+ return <ConversationLayout threads="beside" items={items} below={<ReactionHorizon limit={100} omitted={3} />} box={<WriteBox label="Comment" />} />
129
+ },
130
+ }
131
+
132
+ /** Two columns, an archived file: its card at the top however few the comments, the box's line saying why nothing can be written. */
133
+ export const TwoColumnsArchived: Story = {
134
+ name: 'Two columns, archived',
135
+ render: () => (
136
+ <ConversationLayout
137
+ threads="beside"
138
+ top={<ArchivedNotice by="Person one" when="Monday" resolution="Shipped. What was left moved to the next file." />}
139
+ items={[
140
+ {
141
+ id: 'a1',
142
+ day: 'Monday',
143
+ card: (
144
+ <ConversationCard author={ONE} time="9:14 AM" readOnly>
145
+ {WORDS}
146
+ </ConversationCard>
147
+ ),
148
+ },
149
+ ]}
150
+ box={<WriteBox closed="Archived. Unarchive it to comment." />}
151
+ />
152
+ ),
153
+ }
154
+
108
155
  /** One column beside the page: a thread opens under its comment. */
109
156
  export const OneColumn: Story = {
110
157
  name: 'One column',
@@ -238,3 +238,103 @@ describe('ConversationLayout, read-only (an archived file)', () => {
238
238
  expect(asked).toHaveBeenLastCalledWith('a')
239
239
  })
240
240
  })
241
+
242
+ describe('ConversationLayout, two columns, what an app with its own list keeps (Peek, 1 November)', () => {
243
+ const card = (words: string) => (
244
+ <ConversationCard author={ONE} time="11:08 AM">
245
+ {words}
246
+ </ConversationCard>
247
+ )
248
+ const dayItems: ConversationItem[] = [
249
+ { id: 'a', card: card('Monday one'), day: 'Monday' },
250
+ { id: 'b', card: card('Monday two'), day: 'Monday', before: <p>New</p> },
251
+ { id: 'c', card: card('Today one'), day: 'Today' },
252
+ ]
253
+
254
+ it('names each day once, over its own stretch of comments, the line staying at the top while its stretch scrolls', () => {
255
+ render(<ConversationLayout threads="beside" items={dayItems} />)
256
+ const monday = screen.getByRole('separator', { name: 'Monday' })
257
+ const today = screen.getByRole('separator', { name: 'Today' })
258
+ expect(screen.getAllByRole('separator', { name: 'Monday' }).length).toBe(1)
259
+ expect(monday.className).toContain('sticky')
260
+ // Each line is held by its own day's stretch, so the next day's line pushes it away.
261
+ expect(monday.parentElement?.textContent).toContain('Monday two')
262
+ expect(monday.parentElement?.textContent).not.toContain('Today one')
263
+ expect(today.parentElement?.textContent).toContain('Today one')
264
+ })
265
+
266
+ it('draws a comment’s `before` just above it, outside its card', () => {
267
+ render(<ConversationLayout threads="beside" items={dayItems} />)
268
+ const line = screen.getByText('New')
269
+ const item = document.querySelector('[data-conversation-item="b"]')!
270
+ expect(line.nextElementSibling).toBe(item)
271
+ })
272
+
273
+ it('gives the app its scrolling box and says when it scrolled', () => {
274
+ const ref = { current: null as HTMLDivElement | null }
275
+ const scrolled = vi.fn()
276
+ render(<ConversationLayout threads="beside" items={dayItems} bodyRef={ref} onBodyScroll={scrolled} />)
277
+ expect(ref.current?.contains(document.querySelector('[data-conversation-item="a"]'))).toBe(true)
278
+ fireEvent.scroll(ref.current!)
279
+ expect(scrolled).toHaveBeenCalled()
280
+ })
281
+
282
+ it('sits a short conversation on its box: the room it leaves is above it, under `top`', () => {
283
+ render(<ConversationLayout threads="beside" items={dayItems} top={<p>Archived</p>} below={<p>Reactions note</p>} box={<p>The box</p>} />)
284
+ const top = screen.getByText('Archived').parentElement!
285
+ const room = top.nextElementSibling as HTMLElement
286
+ expect(room.className).toContain('flex-1')
287
+ // The room grows only because the scroll content is at least as tall as the column.
288
+ expect(top.parentElement?.className).toContain('min-h-full')
289
+ expect(room.nextElementSibling?.textContent).toContain('Today one')
290
+ // The note is under the comments, in their list.
291
+ const words = ['Today one', 'Reactions note'].map((w) => screen.getByText(w))
292
+ expect(words[0].compareDocumentPosition(words[1]) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
293
+ })
294
+
295
+ it('redraws no comment when older ones arrive at the top, a day of their own above (PEE-7)', () => {
296
+ const later: ConversationItem[] = [
297
+ { id: 'b', card: card('Monday one'), day: 'Monday' },
298
+ { id: 'c', card: card('Today one'), day: 'Today' },
299
+ ]
300
+ const { rerender } = render(<ConversationLayout threads="beside" items={later} />)
301
+ const before = ['b', 'c'].map((id) => document.querySelector(`[data-conversation-item="${id}"]`))
302
+ rerender(<ConversationLayout threads="beside" items={[{ id: 'a', card: card('Sunday one'), day: 'Sunday' }, ...later]} />)
303
+ // The same elements, not equal ones: a redrawn card would lose an open menu or dialog.
304
+ ;['b', 'c'].forEach((id, i) => expect(document.querySelector(`[data-conversation-item="${id}"]`)).toBe(before[i]))
305
+ })
306
+
307
+ it('draws nothing for a `top` of false, and no `below` while reading', () => {
308
+ const { container } = render(<ConversationLayout threads="beside" items={dayItems} top={false} />)
309
+ expect(container.querySelector('.pt-4.px-4')).toBeNull()
310
+ cleanup()
311
+ render(<ConversationLayout threads="beside" items={[]} loading below={<p>Reactions note</p>} />)
312
+ expect(screen.queryByText('Reactions note')).toBeNull()
313
+ })
314
+
315
+ it('keeps its name with the message when the column throws, and the thread beside it stays', () => {
316
+ const quiet = vi.spyOn(console, 'error').mockImplementation(() => {})
317
+ function Throws(): never {
318
+ throw new Error('a card that throws')
319
+ }
320
+ render(
321
+ <ConversationLayout
322
+ threads="beside"
323
+ title="A DM with Person one"
324
+ items={[{ id: 'x', card: <Throws />, thread: <p>The thread</p> }]}
325
+ open="x"
326
+ />,
327
+ )
328
+ expect(screen.getByText('A DM with Person one')).toBeTruthy()
329
+ expect(screen.getByText('The thread')).toBeTruthy()
330
+ quiet.mockRestore()
331
+ })
332
+
333
+ it('says an empty conversation in the app’s own words, or nothing', () => {
334
+ render(<ConversationLayout threads="beside" items={[]} empty={<p>The relay could not be reached.</p>} />)
335
+ expect(screen.getByText('The relay could not be reached.')).toBeTruthy()
336
+ cleanup()
337
+ render(<ConversationLayout threads="beside" items={[]} empty={null} />)
338
+ expect(screen.queryByText('No comments yet.')).toBeNull()
339
+ })
340
+ })
@@ -1,9 +1,12 @@
1
- import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
1
+ import { Fragment, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type Ref, type UIEventHandler } from 'react'
2
2
  import { Card } from './Card'
3
3
  import { Chip } from './Chip'
4
4
  import { CollapsibleSection } from './CollapsibleSection'
5
5
  import { cn } from './cn'
6
+ import { ContainerHeader } from './ContainerHeader'
7
+ import { Divider } from './Divider'
6
8
  import { EmptyState } from './EmptyState'
9
+ import { ErrorBoundary } from './ErrorBoundary'
7
10
  import { Panel } from './Panel'
8
11
  import { ScrollArea } from './ScrollArea'
9
12
  import { SkeletonConversation } from './Skeleton'
@@ -20,6 +23,10 @@ export interface ConversationItem {
20
23
  resolved?: boolean
21
24
  /** What it was on was deleted from the page. In one column it waits under "On deleted blocks", closed, before "Resolved"; a resolved one is under "Resolved". */
22
25
  gone?: boolean
26
+ /** Two columns: the day it was written, in the app's words ("Today", "Monday"). Comments of one day are one stretch under a line naming it, which stays at the top while its stretch scrolls under it. */
27
+ day?: string
28
+ /** Two columns: drawn just above it, 8px off, inside its day: the app's "New" line over the first comment not read. */
29
+ before?: ReactNode
23
30
  }
24
31
 
25
32
  export interface ConversationLayoutProps {
@@ -36,15 +43,23 @@ export interface ConversationLayoutProps {
36
43
  onOpenChange?: (id: string | undefined) => void
37
44
  /** The box a new comment is written in, under the comments. */
38
45
  box?: ReactNode
39
- /** Above the comments, inside their list: a `ReactionHorizon`, a note. */
46
+ /** Above the comments, inside their list: placeholders while older comments are read, a note. */
40
47
  above?: ReactNode
48
+ /** Two columns: under the comments, inside their list, or under the empty line: a `ReactionHorizon`. Not while the comments are read. */
49
+ below?: ReactNode
50
+ /** Two columns: at the top of the column however few the comments are, over the room a short conversation leaves: an `ArchivedNotice`. */
51
+ top?: ReactNode
41
52
  /** Still reading the comments. */
42
53
  loading?: boolean
43
- /** What an empty conversation says. */
44
- empty?: string
54
+ /** What an empty conversation says: words, or the app's own `EmptyState` (a read that failed says so). `null`: nothing. */
55
+ empty?: ReactNode
56
+ /** Two columns: the comments' scrolling box, for an app that keeps its own place in it (where it was left, its "New" line, following what arrives). */
57
+ bodyRef?: Ref<HTMLDivElement>
58
+ /** Two columns: the comments' box scrolled. */
59
+ onBodyScroll?: UIEventHandler<HTMLDivElement>
45
60
  /** Two columns: the comments' own header, a `PageHeader`, over their column only, so the thread beside them runs the page's full height (Peek's way). */
46
61
  header?: ReactNode
47
- /** One column: its name, in its header. */
62
+ /** Its name: one column's, in its header. Two columns, said with the message if the column breaks (the page's own bar is `header`). */
48
63
  title?: ReactNode
49
64
  /** One column: its header's actions, as a `Panel`'s. */
50
65
  actions?: ReactNode
@@ -58,7 +73,7 @@ interface ListProps {
58
73
  under: boolean
59
74
  above?: ReactNode
60
75
  loading: boolean
61
- empty: string
76
+ empty: ReactNode
62
77
  /** Asked to open or close: `id` is the comment pressed, `next` what is open after; `reply`, asked by Reply. */
63
78
  change?: (id: string, next: string | undefined, reply?: boolean) => void
64
79
  /** How many times a thread has opened: its box takes the caret each time. */
@@ -68,7 +83,7 @@ interface ListProps {
68
83
  /** The list's own room: placeholders, the empty line, or the comments 8px apart. */
69
84
  function List({ items, open, under, above, loading, empty, change, caret }: ListProps) {
70
85
  if (loading) return <SkeletonConversation />
71
- if (items.length === 0) return <EmptyState scope="section" message={empty} />
86
+ if (items.length === 0) return typeof empty === 'string' ? <EmptyState scope="section" message={empty} /> : <>{empty}</>
72
87
  // How each card opens its thread: only one that has a thread, and only when the app keeps `open`.
73
88
  const stateOf = (item: ConversationItem): ConversationItemState | null =>
74
89
  change && item.thread
@@ -82,18 +97,47 @@ function List({ items, open, under, above, loading, empty, change, caret }: List
82
97
  const draw = (item: ConversationItem) => {
83
98
  if (!under) {
84
99
  return (
85
- <div key={item.id} data-conversation-item={item.id} className="flex flex-col">
86
- <InConversationItem.Provider value={stateOf(item)}>{item.card}</InConversationItem.Provider>
87
- </div>
100
+ <Fragment key={item.id}>
101
+ {item.before}
102
+ <div data-conversation-item={item.id} className="flex flex-col">
103
+ <InConversationItem.Provider value={stateOf(item)}>{item.card}</InConversationItem.Provider>
104
+ </div>
105
+ </Fragment>
88
106
  )
89
107
  }
90
108
  return <UnderItem key={item.id} item={item} isOpen={open === item.id && !!item.thread} state={stateOf(item)} caret={caret} />
91
109
  }
92
110
  if (!under) {
111
+ // Two columns: a day's comments are one stretch under its line, so the line stays at the top only while its own
112
+ // stretch scrolls under it, and the next day's pushes it away (Peek's day lines).
113
+ // Keyed by its day, not its place, so older comments arriving at the top redraw nothing under them; a day that
114
+ // comes back further down (an app's own order) is that day's second stretch.
115
+ const stretches: { key: string; day?: string; items: ConversationItem[] }[] = []
116
+ const seen = new Map<string, number>()
117
+ for (const item of items) {
118
+ const last = stretches[stretches.length - 1]
119
+ if (last && last.day === item.day) {
120
+ last.items.push(item)
121
+ continue
122
+ }
123
+ const name = item.day ?? ''
124
+ const count = (seen.get(name) ?? 0) + 1
125
+ seen.set(name, count)
126
+ stretches.push({ key: `${item.day === undefined ? 'no-day' : `day:${name}`}#${count}`, day: item.day, items: [item] })
127
+ }
93
128
  return (
94
129
  <>
95
130
  {above}
96
- {items.map(draw)}
131
+ {stretches.map((stretch) =>
132
+ stretch.day === undefined ? (
133
+ <Fragment key={stretch.key}>{stretch.items.map(draw)}</Fragment>
134
+ ) : (
135
+ <div key={stretch.key} className="flex flex-col gap-2">
136
+ <Divider look="section" label={stretch.day} sticky />
137
+ {stretch.items.map(draw)}
138
+ </div>
139
+ ),
140
+ )}
97
141
  </>
98
142
  )
99
143
  }
@@ -171,7 +215,24 @@ function UnderItem({ item, isOpen, state, caret }: { item: ConversationItem; isO
171
215
  * comments are the 384px column beside the page, and a thread opens under its comment, the two one card. The right column is 384px in
172
216
  * every app (Katerina, 31 October). With two columns the thread runs the full height, beside the comments' header.
173
217
  */
174
- export function ConversationLayout({ threads, items, open, onOpenChange, box, above, loading = false, empty = 'No comments yet.', header, title = 'Comments', actions, className }: ConversationLayoutProps) {
218
+ export function ConversationLayout({
219
+ threads,
220
+ items,
221
+ open,
222
+ onOpenChange,
223
+ box,
224
+ above,
225
+ below,
226
+ top,
227
+ loading = false,
228
+ empty = 'No comments yet.',
229
+ header,
230
+ title = 'Comments',
231
+ actions,
232
+ bodyRef,
233
+ onBodyScroll,
234
+ className,
235
+ }: ConversationLayoutProps) {
175
236
  // One column: the pressed comment stays where it was on screen. Opening one thread closes the other, and when that
176
237
  // one stood above it, everything under it would rise by its height (Katerina, 31 October). Where it was is noted at
177
238
  // the press; once the change is drawn, before it is painted, the column scrolls by however far it went.
@@ -215,14 +276,31 @@ export function ConversationLayout({ threads, items, open, onOpenChange, box, ab
215
276
  const opened = items.find((item) => item.id === open)?.thread
216
277
  return (
217
278
  <div className={cn('flex min-h-0 min-w-0 flex-1', className)}>
218
- <div className="flex min-h-0 min-w-0 flex-1 flex-col">
219
- {header}
220
- <ScrollArea className="min-h-0 flex-1" contentClassName="flex flex-col gap-2 p-4">
221
- <List items={items} open={open} under={false} above={above} loading={loading} empty={empty} change={change} caret={caret} />
222
- </ScrollArea>
223
- {/* Peek's composer room: 12px all round (useFileConversationView's `p-3`), under the list's 16px. */}
224
- {box && <div className="shrink-0 p-3">{box}</div>}
225
- </div>
279
+ {/* If the column throws, its name stays with the message, as a Panel's does; the thread beside it stays. */}
280
+ <ErrorBoundary
281
+ label="conversation"
282
+ frame={(message) => (
283
+ <div className="flex min-h-0 min-w-0 flex-1 flex-col">
284
+ <ContainerHeader title={title} />
285
+ <div className="flex min-h-0 flex-1 flex-col px-4">{message}</div>
286
+ </div>
287
+ )}
288
+ >
289
+ <div className="flex min-h-0 min-w-0 flex-1 flex-col">
290
+ {header}
291
+ <ScrollArea className="min-h-0 flex-1" viewportRef={bodyRef} onScroll={onBodyScroll} contentClassName="flex min-h-full flex-col">
292
+ {top != null && top !== false && top !== '' && <div className="shrink-0 px-4 pt-4">{top}</div>}
293
+ {/* A short conversation sits on its box, as a chat does: the newest comment by the box (Peek's way). */}
294
+ <div className="min-h-0 flex-1" />
295
+ <div className="flex shrink-0 flex-col gap-2 p-4">
296
+ <List items={items} open={open} under={false} above={above} loading={loading} empty={empty} change={change} caret={caret} />
297
+ {!loading && below}
298
+ </div>
299
+ </ScrollArea>
300
+ {/* Peek's composer room: 12px all round (useFileConversationView's `p-3`), under the list's 16px. */}
301
+ {box && <div className="shrink-0 p-3">{box}</div>}
302
+ </div>
303
+ </ErrorBoundary>
226
304
  {opened && (
227
305
  <div className="flex w-[384px] shrink-0 flex-col border-l border-border-subtle">
228
306
  <caretOnOpen.Provider value={caret}>{opened}</caretOnOpen.Provider>
@@ -5,14 +5,17 @@ import * as Stories from './ConversationMenu.stories'
5
5
 
6
6
  # ConversationMenu
7
7
 
8
- The ⋯ menu of a comment or a reply: Resolve or Reopen, the app's own rows, then Edit and Delete on your own.
8
+ The ⋯ menu of a comment or a reply: Resolve or Reopen and the app's own rows; then Edit on your own; then Delete on your own, apart.
9
9
 
10
10
  <Canvas of={Stories.Yours} />
11
11
 
12
12
  ## When
13
13
 
14
14
  - Inside **ConversationCard** and **ReplyCard**, which draw it for you.
15
- - Its `children` are the app's own rows.
15
+ - Its `children` are the app's own rows, after Resolve; `after`, its rows after Edit.
16
+ - In the app's own words: `label` heads the first rows, `resolveHint` stands beside Resolve, `editLabel` is Edit's word. Peek's menu reads as it did with them (Katerina, 1 November).
17
+
18
+ <Canvas of={Stories.InAnAppsWords} />
16
19
 
17
20
  <Canvas of={Stories.Theirs} />
18
21
 
@@ -13,7 +13,7 @@ const meta = {
13
13
  component: ConversationMenu,
14
14
  parameters: { layout: 'padded' },
15
15
  args: { trigger: <Button variant="outlined">Open the menu</Button> },
16
- argTypes: { trigger: { control: false }, children: { control: false } },
16
+ argTypes: { trigger: { control: false }, children: { control: false }, after: { control: false } },
17
17
  decorators: [(Story) => <div className="flex min-h-[220px] items-start pl-[200px] pt-2">{Story()}</div>],
18
18
  play: async ({ canvasElement }) => {
19
19
  await userEvent.click(within(canvasElement).getByRole('button', { name: 'Open the menu' }))
@@ -40,3 +40,21 @@ export const MoreRows: Story = {
40
40
  name: 'More rows',
41
41
  args: { onResolve: () => {}, onEdit: () => {}, onDelete: () => {}, children: <MenuItem label="Item one" onClick={() => {}} /> },
42
42
  }
43
+
44
+ /**
45
+ * In an app's own words, as Peek's menu reads (Katerina, 1 November): a heading over the first rows, the key that
46
+ * resolves from its box beside Resolve, its word for Edit, and a row of its own after Edit. Delete stays apart.
47
+ */
48
+ export const InAnAppsWords: Story = {
49
+ name: "In an app's words",
50
+ args: {
51
+ label: 'Heading',
52
+ resolveHint: '->',
53
+ onResolve: () => {},
54
+ onEdit: () => {},
55
+ editLabel: 'Edit message',
56
+ after: <MenuItem label="Item two" onClick={() => {}} />,
57
+ onDelete: () => {},
58
+ children: <MenuItem label="Item one" onClick={() => {}} />,
59
+ },
60
+ }
@@ -15,7 +15,7 @@ async function open() {
15
15
  const names = () => screen.getAllByRole('menuitem').map((row) => row.textContent)
16
16
 
17
17
  describe('ConversationMenu', () => {
18
- it('offers Resolve, then the app’s rows, then Edit and Delete, the last two apart', async () => {
18
+ it('offers Resolve and the app’s rows, then Edit, then Delete apart: three groups', async () => {
19
19
  const onResolve = vi.fn()
20
20
  render(
21
21
  <ConversationMenu onResolve={onResolve} onEdit={() => {}} onDelete={() => {}}>
@@ -24,7 +24,7 @@ describe('ConversationMenu', () => {
24
24
  )
25
25
  await open()
26
26
  expect(names()).toEqual(['Resolve', 'Open work', 'Edit', 'Delete'])
27
- expect(screen.getAllByRole('separator').length).toBe(1)
27
+ expect(screen.getAllByRole('separator').length).toBe(2)
28
28
  fireEvent.click(screen.getByRole('menuitem', { name: 'Resolve' }))
29
29
  expect(onResolve).toHaveBeenCalledOnce()
30
30
  })
@@ -38,10 +38,23 @@ describe('ConversationMenu', () => {
38
38
  expect(onReopen).toHaveBeenCalledOnce()
39
39
  })
40
40
 
41
- it('offers Edit and Delete only when given, with no line before them alone', async () => {
41
+ it('offers Edit and Delete only when given, Delete apart, and no line before the first group', async () => {
42
42
  render(<ConversationMenu onEdit={() => {}} onDelete={() => {}} />)
43
43
  await open()
44
44
  expect(names()).toEqual(['Edit', 'Delete'])
45
- expect(screen.queryByRole('separator')).toBeNull()
45
+ expect(screen.getAllByRole('separator').length).toBe(1)
46
+ })
47
+
48
+ it('reads as Peek’s did, with Peek’s words passed in: a heading, the Resolve hint, "Edit message", "View details" (Katerina, 1 November)', async () => {
49
+ render(
50
+ <ConversationMenu label="Utilities" resolveHint="->" onResolve={() => {}} onEdit={() => {}} editLabel="Edit message" after={<MenuItem label="View details" onClick={() => {}} />} onDelete={() => {}}>
51
+ <MenuItem label="Open work" onClick={() => {}} />
52
+ </ConversationMenu>,
53
+ )
54
+ await open()
55
+ expect(names().map((n) => n?.replace('->', '').trim())).toEqual(['Resolve', 'Open work', 'Edit message', 'View details', 'Delete'])
56
+ expect(screen.getByText('Utilities')).toBeTruthy()
57
+ expect(screen.getByText('->')).toBeTruthy()
58
+ expect(screen.getAllByRole('separator').length).toBe(2)
46
59
  })
47
60
  })
@@ -1,17 +1,25 @@
1
1
  import type { ReactElement, ReactNode } from 'react'
2
2
  import { IconCircleCheck, IconCircleDashed, IconDotsVertical } from '@tabler/icons-react'
3
3
  import { IconButton } from './IconButton'
4
- import { Menu, MenuItem, MenuSeparator } from './Menu'
4
+ import { Menu, MenuItem, MenuSection, MenuSeparator } from './Menu'
5
5
 
6
6
  export interface ConversationMenuProps {
7
7
  /** Resolved: the menu offers Reopen in place of Resolve. */
8
8
  resolved?: boolean
9
9
  onResolve?: () => void
10
10
  onReopen?: () => void
11
- /** The app's own rows, between Resolve and Edit: `MenuItem`s. */
11
+ /** Beside Resolve, how the app's box resolves too, as its key hint: Peek's "->". */
12
+ resolveHint?: string
13
+ /** The app's own rows, after Resolve: `MenuItem`s. */
12
14
  children?: ReactNode
15
+ /** A heading over Resolve and the app's rows, in the app's words: Peek's "Utilities". */
16
+ label?: string
13
17
  /** Offered on your own only. */
14
18
  onEdit?: () => void
19
+ /** Edit's words: "Edit" by default; Peek's "Edit message". */
20
+ editLabel?: string
21
+ /** The app's own rows after Edit, before Delete: Peek's "View details". */
22
+ after?: ReactNode
15
23
  /** Offered on your own only; the card asks before it deletes. */
16
24
  onDelete?: () => void
17
25
  open?: boolean
@@ -21,12 +29,30 @@ export interface ConversationMenuProps {
21
29
  }
22
30
 
23
31
  /**
24
- * The ⋯ menu of a comment or a reply: Resolve or Reopen and the app's own rows, then Edit and Delete on your own.
25
- * A card offers it only when it has a row to show.
26
- * Peek's, moved with the conversation; its "Utilities" heading went, as the kit names no app's furniture.
32
+ * The ⋯ menu of a comment or a reply, in up to three groups: Resolve or Reopen and the app's rows; Edit on your own
33
+ * and the app's rows after it; Delete on your own, apart, as it is destructive. A card offers it only when it has a
34
+ * row to show. Peek's, moved with the conversation; what is Peek's own (its heading, its hint, its words, its rows)
35
+ * Peek passes in, so its menu reads as it did (Katerina, 1 November).
27
36
  */
28
- export function ConversationMenu({ resolved = false, onResolve, onReopen, children, onEdit, onDelete, open, onOpenChange, trigger }: ConversationMenuProps) {
37
+ export function ConversationMenu({ resolved = false, onResolve, onReopen, resolveHint, children, label, onEdit, editLabel = 'Edit', after, onDelete, open, onOpenChange, trigger }: ConversationMenuProps) {
29
38
  const resolves = resolved ? onReopen : onResolve
39
+ const first = (resolves || children) && (
40
+ <>
41
+ {resolves &&
42
+ (resolved ? (
43
+ <MenuItem leading={<IconCircleDashed size={16} stroke={1.5} className="text-text-secondary" />} label="Reopen" onClick={onReopen} />
44
+ ) : (
45
+ <MenuItem leading={<IconCircleCheck size={16} stroke={1.5} className="text-text-secondary" />} label="Resolve" shortcut={resolveHint} onClick={onResolve} />
46
+ ))}
47
+ {children}
48
+ </>
49
+ )
50
+ const middle = (onEdit || after) && (
51
+ <>
52
+ {onEdit && <MenuItem label={editLabel} onClick={onEdit} />}
53
+ {after}
54
+ </>
55
+ )
30
56
  return (
31
57
  <Menu
32
58
  trigger={
@@ -41,16 +67,11 @@ export function ConversationMenu({ resolved = false, onResolve, onReopen, childr
41
67
  onOpenChange={onOpenChange}
42
68
  className="w-[244px]"
43
69
  >
44
- {resolves &&
45
- (resolved ? (
46
- <MenuItem leading={<IconCircleDashed size={16} stroke={1.5} className="text-text-secondary" />} label="Reopen" onClick={onReopen} />
47
- ) : (
48
- <MenuItem leading={<IconCircleCheck size={16} stroke={1.5} className="text-text-secondary" />} label="Resolve" onClick={onResolve} />
49
- ))}
50
- {children}
51
- {/* Edit and Delete are one group, as in Peek; the line only between two groups that are both there. */}
52
- {(resolves || children) && (onEdit || onDelete) && <MenuSeparator />}
53
- {onEdit && <MenuItem label="Edit" onClick={onEdit} />}
70
+ {first && (label ? <MenuSection label={label}>{first}</MenuSection> : first)}
71
+ {/* A line only between two groups that are both there. */}
72
+ {first && middle && <MenuSeparator />}
73
+ {middle}
74
+ {onDelete && (first || middle) && <MenuSeparator />}
54
75
  {onDelete && <MenuItem label="Delete" destructive onClick={onDelete} />}
55
76
  </Menu>
56
77
  )
package/src/Thread.mdx CHANGED
@@ -39,6 +39,8 @@ import { ReplyCard, Thread } from '@estiva-app/ui'
39
39
 
40
40
  - Its replies are yours to put in time order. Who resolved it is said on the comment, not among them.
41
41
  - Still reading: `loading`. Nobody replied yet: nothing in `children`.
42
+ - An app whose empty thread said nothing keeps its silence with `empty={null}`; `closeLabel` names Close in its words for a screen reader.
43
+ - `start.id` is put on the pinned comment as `data-thread-start`, for a link that names the comment, as ConversationLayout's comments carry `data-conversation-item`.
42
44
 
43
45
  ## What it owns
44
46
 
@@ -37,6 +37,23 @@ describe('Thread, beside (the right column)', () => {
37
37
  expect(onClose).toHaveBeenCalledOnce()
38
38
  })
39
39
 
40
+ it('says nothing in an empty thread when the app asks for silence (empty={null})', () => {
41
+ render(<Thread start={START} empty={null} />)
42
+ expect(screen.queryByText('No replies yet.')).toBeNull()
43
+ })
44
+
45
+ it('carries the comment’s id on the pinned comment, for a link that names it', () => {
46
+ const { container } = render(<Thread start={{ ...START, id: 'c1' }} />)
47
+ expect(container.querySelector('[data-thread-start="c1"]')?.textContent).toContain('The comment it answers')
48
+ })
49
+
50
+ it('names Close in the app’s words for a screen reader, its tooltip still "Close"', () => {
51
+ const onClose = vi.fn()
52
+ render(<Thread start={START} onClose={onClose} closeLabel="Close thread" />)
53
+ fireEvent.click(screen.getByRole('button', { name: 'Close thread' }))
54
+ expect(onClose).toHaveBeenCalledOnce()
55
+ })
56
+
40
57
  it('says why no reply can be written in place of the box', () => {
41
58
  render(<Thread start={START} box={<p>The box</p>} notice={<p>This file is archived.</p>} />)
42
59
  expect(screen.getByText('This file is archived.')).toBeTruthy()