@qoretechnologies/reqraft 0.10.13-pr.74.gccefa54 → 0.10.13

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 (125) hide show
  1. package/.claude/CLAUDE.md +8 -11
  2. package/dist/components/form/engine/FormEngine.d.ts +1 -1
  3. package/dist/helpers/common.d.ts +0 -5
  4. package/dist/helpers/common.d.ts.map +1 -1
  5. package/dist/helpers/common.js +1 -20
  6. package/dist/helpers/common.js.map +1 -1
  7. package/dist/index.d.ts +0 -5
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -7
  10. package/dist/index.js.map +1 -1
  11. package/dist/providers/StorageProvider.d.ts +13 -0
  12. package/dist/providers/StorageProvider.d.ts.map +1 -1
  13. package/dist/providers/StorageProvider.js +29 -5
  14. package/dist/providers/StorageProvider.js.map +1 -1
  15. package/package.json +3 -3
  16. package/src/helpers/common.ts +0 -19
  17. package/src/hooks/useStorage/useStorage.stories.tsx +52 -0
  18. package/src/index.tsx +0 -5
  19. package/src/providers/StorageProvider.tsx +30 -4
  20. package/dist/components/composer/Composer.d.ts +0 -108
  21. package/dist/components/composer/Composer.d.ts.map +0 -1
  22. package/dist/components/composer/Composer.js +0 -238
  23. package/dist/components/composer/Composer.js.map +0 -1
  24. package/dist/components/composer/helpers.d.ts +0 -21
  25. package/dist/components/composer/helpers.d.ts.map +0 -1
  26. package/dist/components/composer/helpers.js +0 -75
  27. package/dist/components/composer/helpers.js.map +0 -1
  28. package/dist/components/composer/index.d.ts +0 -3
  29. package/dist/components/composer/index.d.ts.map +0 -1
  30. package/dist/components/composer/index.js +0 -19
  31. package/dist/components/composer/index.js.map +0 -1
  32. package/dist/components/imageLightbox/ImageLightbox.d.ts +0 -17
  33. package/dist/components/imageLightbox/ImageLightbox.d.ts.map +0 -1
  34. package/dist/components/imageLightbox/ImageLightbox.js +0 -129
  35. package/dist/components/imageLightbox/ImageLightbox.js.map +0 -1
  36. package/dist/components/imageLightbox/index.d.ts +0 -2
  37. package/dist/components/imageLightbox/index.d.ts.map +0 -1
  38. package/dist/components/imageLightbox/index.js +0 -18
  39. package/dist/components/imageLightbox/index.js.map +0 -1
  40. package/dist/components/supportTicket/AttachmentChips.d.ts +0 -10
  41. package/dist/components/supportTicket/AttachmentChips.d.ts.map +0 -1
  42. package/dist/components/supportTicket/AttachmentChips.js +0 -119
  43. package/dist/components/supportTicket/AttachmentChips.js.map +0 -1
  44. package/dist/components/supportTicket/InterfaceReferenceTags.d.ts +0 -35
  45. package/dist/components/supportTicket/InterfaceReferenceTags.d.ts.map +0 -1
  46. package/dist/components/supportTicket/InterfaceReferenceTags.js +0 -31
  47. package/dist/components/supportTicket/InterfaceReferenceTags.js.map +0 -1
  48. package/dist/components/supportTicket/ReferencePicker.d.ts +0 -41
  49. package/dist/components/supportTicket/ReferencePicker.d.ts.map +0 -1
  50. package/dist/components/supportTicket/ReferencePicker.js +0 -86
  51. package/dist/components/supportTicket/ReferencePicker.js.map +0 -1
  52. package/dist/components/supportTicket/TicketHeader.d.ts +0 -86
  53. package/dist/components/supportTicket/TicketHeader.d.ts.map +0 -1
  54. package/dist/components/supportTicket/TicketHeader.js +0 -149
  55. package/dist/components/supportTicket/TicketHeader.js.map +0 -1
  56. package/dist/components/supportTicket/TicketMetaTags.d.ts +0 -32
  57. package/dist/components/supportTicket/TicketMetaTags.d.ts.map +0 -1
  58. package/dist/components/supportTicket/TicketMetaTags.js +0 -21
  59. package/dist/components/supportTicket/TicketMetaTags.js.map +0 -1
  60. package/dist/components/supportTicket/TicketReplyBox.d.ts +0 -63
  61. package/dist/components/supportTicket/TicketReplyBox.d.ts.map +0 -1
  62. package/dist/components/supportTicket/TicketReplyBox.js +0 -115
  63. package/dist/components/supportTicket/TicketReplyBox.js.map +0 -1
  64. package/dist/components/supportTicket/fileToAttachment.d.ts +0 -9
  65. package/dist/components/supportTicket/fileToAttachment.d.ts.map +0 -1
  66. package/dist/components/supportTicket/fileToAttachment.js +0 -28
  67. package/dist/components/supportTicket/fileToAttachment.js.map +0 -1
  68. package/dist/components/supportTicket/index.d.ts +0 -9
  69. package/dist/components/supportTicket/index.d.ts.map +0 -1
  70. package/dist/components/supportTicket/index.js +0 -25
  71. package/dist/components/supportTicket/index.js.map +0 -1
  72. package/dist/components/supportTicket/meta.d.ts +0 -63
  73. package/dist/components/supportTicket/meta.d.ts.map +0 -1
  74. package/dist/components/supportTicket/meta.js +0 -79
  75. package/dist/components/supportTicket/meta.js.map +0 -1
  76. package/dist/components/ticketReferences/TicketReferences.d.ts +0 -52
  77. package/dist/components/ticketReferences/TicketReferences.d.ts.map +0 -1
  78. package/dist/components/ticketReferences/TicketReferences.js +0 -453
  79. package/dist/components/ticketReferences/TicketReferences.js.map +0 -1
  80. package/dist/components/ticketReferences/index.d.ts +0 -3
  81. package/dist/components/ticketReferences/index.d.ts.map +0 -1
  82. package/dist/components/ticketReferences/index.js +0 -6
  83. package/dist/components/ticketReferences/index.js.map +0 -1
  84. package/dist/components/ticketThread/TicketThread.d.ts +0 -52
  85. package/dist/components/ticketThread/TicketThread.d.ts.map +0 -1
  86. package/dist/components/ticketThread/TicketThread.js +0 -248
  87. package/dist/components/ticketThread/TicketThread.js.map +0 -1
  88. package/dist/components/ticketThread/index.d.ts +0 -3
  89. package/dist/components/ticketThread/index.d.ts.map +0 -1
  90. package/dist/components/ticketThread/index.js +0 -7
  91. package/dist/components/ticketThread/index.js.map +0 -1
  92. package/dist/helpers/scrollbar.d.ts +0 -2
  93. package/dist/helpers/scrollbar.d.ts.map +0 -1
  94. package/dist/helpers/scrollbar.js +0 -25
  95. package/dist/helpers/scrollbar.js.map +0 -1
  96. package/src/components/composer/Composer.stories.tsx +0 -238
  97. package/src/components/composer/Composer.tsx +0 -545
  98. package/src/components/composer/helpers.ts +0 -74
  99. package/src/components/composer/index.ts +0 -2
  100. package/src/components/imageLightbox/ImageLightbox.stories.tsx +0 -156
  101. package/src/components/imageLightbox/ImageLightbox.tsx +0 -169
  102. package/src/components/imageLightbox/index.ts +0 -1
  103. package/src/components/supportTicket/AttachmentChips.stories.tsx +0 -122
  104. package/src/components/supportTicket/AttachmentChips.tsx +0 -142
  105. package/src/components/supportTicket/InterfaceReferenceTags.stories.tsx +0 -134
  106. package/src/components/supportTicket/InterfaceReferenceTags.tsx +0 -85
  107. package/src/components/supportTicket/ReferencePicker.stories.tsx +0 -296
  108. package/src/components/supportTicket/ReferencePicker.tsx +0 -237
  109. package/src/components/supportTicket/TicketConversation.stories.tsx +0 -122
  110. package/src/components/supportTicket/TicketHeader.stories.tsx +0 -183
  111. package/src/components/supportTicket/TicketHeader.tsx +0 -247
  112. package/src/components/supportTicket/TicketMetaTags.stories.tsx +0 -103
  113. package/src/components/supportTicket/TicketMetaTags.tsx +0 -85
  114. package/src/components/supportTicket/TicketReplyBox.stories.tsx +0 -355
  115. package/src/components/supportTicket/TicketReplyBox.tsx +0 -146
  116. package/src/components/supportTicket/fileToAttachment.ts +0 -24
  117. package/src/components/supportTicket/index.ts +0 -8
  118. package/src/components/supportTicket/meta.ts +0 -145
  119. package/src/components/ticketReferences/TicketReferences.stories.tsx +0 -301
  120. package/src/components/ticketReferences/TicketReferences.tsx +0 -899
  121. package/src/components/ticketReferences/index.ts +0 -2
  122. package/src/components/ticketThread/TicketThread.stories.tsx +0 -751
  123. package/src/components/ticketThread/TicketThread.tsx +0 -650
  124. package/src/components/ticketThread/index.ts +0 -6
  125. package/src/helpers/scrollbar.ts +0 -32
@@ -1,899 +0,0 @@
1
- import {
2
- ReqoreButton,
3
- ReqoreColumns,
4
- ReqoreControlGroup,
5
- ReqoreDropdown,
6
- ReqoreEmptyState,
7
- ReqoreEntityRow,
8
- ReqoreInput,
9
- ReqorePanel,
10
- ReqoreSpan,
11
- ReqoreSpinner,
12
- ReqoreTextEffect,
13
- } from '@qoretechnologies/reqore';
14
- import { IReqoreIconName } from '@qoretechnologies/reqore/dist/types/icons';
15
- import { TReqoreEffectColor } from '@qoretechnologies/reqore/dist/components/Effect';
16
- import type { IReqoreEntityRowAction } from '@qoretechnologies/reqore/dist/components/EntityRow';
17
- import type { IReqorePanelSubAction } from '@qoretechnologies/reqore/dist/components/Panel';
18
- import { useCallback, useEffect, useMemo, useState } from 'react';
19
- import timeago from 'epoch-timeago';
20
- import styled from 'styled-components';
21
- import { formatBytes, isImage } from '../../helpers/common';
22
- import { ImageLightbox } from '../imageLightbox';
23
- import {
24
- defaultInterfaceIcon,
25
- IInterfaceReference,
26
- TTicketViewerRole,
27
- } from '../supportTicket/meta';
28
- import type { ITicketThreadAttachment, ITicketThreadMessage } from '../ticketThread/TicketThread';
29
-
30
- /*
31
- * TicketReferences — the consolidated "everything attached to or linked from a
32
- * ticket" surface. It gathers, across the ticket description and every reply:
33
- * • Screenshots — image attachments as a thumbnail grid → a zoom/paging lightbox.
34
- * First: the visual evidence is what a reader scans for.
35
- * • Linked interfaces — the {kind, name} snapshots as rows (kind as metadata),
36
- * sorted by kind then name, matching the file rows below.
37
- * • Files — every other attachment as a type-iconed row with provenance + download.
38
- * None of the mainstream desks (Zendesk/Front/Intercom/…) ship this consolidated
39
- * view, so it's the drawer's differentiator. Rendered as a tab in the staff drawer
40
- * and a panel in the customer modal; only the data + handlers differ by viewer.
41
- */
42
-
43
- /** Attachment metadata as returned by the list endpoint — carries the provenance
44
- * (uploader + timestamp + source message) the message-embedded metadata omits. */
45
- export interface ITicketReferenceAttachment extends ITicketThreadAttachment {
46
- /** the reply this file was attached to; null/absent = ticket-level */
47
- message_id?: string | null;
48
- /** the uploader, resolved + masked like the thread's message author (a staff
49
- * uploader reads as "Qorus Support" on the customer plane, never the raw identity) */
50
- uploaded_by?: string;
51
- /** the kind of party that uploaded the file — lets the viewer label it */
52
- uploader_type?: 'customer' | 'staff';
53
- /** ISO timestamp the file was attached */
54
- created?: string;
55
- }
56
-
57
- export interface ITicketReferencesProps {
58
- /** ticket-level interface references (from `ticket.referenced_interfaces`) */
59
- references?: IInterfaceReference[];
60
- /** the thread — source of message-level references and, as a fallback, attachments */
61
- messages?: ITicketThreadMessage[];
62
- /** the ticket's attachments from the list endpoint; preferred over the message-embedded
63
- * ones because it carries provenance and any ticket-level files. Falls back to `messages`. */
64
- attachments?: ITicketReferenceAttachment[];
65
- viewerRole?: TTicketViewerRole;
66
- /** fetch an attachment's bytes as an object URL, for inline image preview + the lightbox.
67
- * Omitted ⇒ screenshots show as download tiles instead of thumbnails. */
68
- fetchAttachmentUrl?: (attachmentId: string) => Promise<string>;
69
- /** trigger a browser download of an attachment */
70
- onDownloadAttachment?: (attachmentId: string, filename: string) => void;
71
- /** open a referenced interface; reference chips are static (informational) when omitted */
72
- onInterfaceClick?: (reference: IInterfaceReference) => void;
73
- /** Reveal the message a reference or file came from, in the conversation.
74
- * Omitted ⇒ the action is not offered. It is also omitted per-row for anything filed
75
- * against the ticket itself rather than a reply, which has no message to reveal. */
76
- onShowInChat?: (messageId: string) => void;
77
- /** resolve a per-kind icon for a referenced interface (the IDE passes its own vocabulary) */
78
- resolveInterfaceIcon?: (kind: string) => IReqoreIconName;
79
- loading?: boolean;
80
- }
81
-
82
- // ---------------------------------------------------------------------------
83
- // helpers
84
- // ---------------------------------------------------------------------------
85
- // `epoch-timeago` — the same library reqore's `ReqoreTimeAgo` and the IDE's ticket
86
- // list use. This is a string context (a metadata run), so a helper rather than the
87
- // component; it stays consistent with them instead of a bespoke Intl reimplementation.
88
- const timeAgo = (iso?: string): string => {
89
- if (!iso) {
90
- return '';
91
- }
92
- const ms = Date.parse(iso);
93
- return Number.isNaN(ms) ? '' : timeago(ms);
94
- };
95
-
96
- interface IFileType {
97
- icon: IReqoreIconName;
98
- color: TReqoreEffectColor;
99
- label: string;
100
- }
101
- // MIME → a type icon (glyph) + a category tint, Fluent-style: colour distinguishes
102
- // the file family, the glyph its shape. Tints stay moderate for a dark surface.
103
- const fileType = (contentType: string): IFileType => {
104
- const ct = contentType.toLowerCase();
105
- if (ct === 'application/pdf') {
106
- return { icon: 'FilePdf2Line', color: '#f56059', label: 'PDF' };
107
- }
108
- if (ct.includes('zip') || ct.includes('gzip')) {
109
- return { icon: 'FileZipLine', color: '#f2a63c', label: 'Archive' };
110
- }
111
- if (ct === 'text/csv') {
112
- return { icon: 'FileExcel2Line', color: '#46c96f', label: 'CSV' };
113
- }
114
- if (ct.includes('json') || ct.includes('yaml') || ct.includes('xml')) {
115
- return { icon: 'CodeSLine', color: '#55a0ff', label: 'Data' };
116
- }
117
- if (ct.includes('markdown')) {
118
- return { icon: 'MarkdownLine', color: '#55a0ff', label: 'Markdown' };
119
- }
120
- if (ct === 'text/x-log') {
121
- return { icon: 'FileList2Line', color: '#8b8a97', label: 'Log' };
122
- }
123
- if (ct.startsWith('text/')) {
124
- return { icon: 'FileTextLine', color: '#8b8a97', label: 'Text' };
125
- }
126
- return { icon: 'FileLine', color: '#8b8a97', label: 'File' };
127
- };
128
-
129
- // A coarse file family for the type filter. Images are their own section, so this
130
- // only buckets the non-image "Files"; it mirrors fileType's grouping.
131
- type TFileCategory = 'documents' | 'data' | 'logs' | 'archives';
132
- const fileCategory = (contentType: string): TFileCategory => {
133
- const ct = contentType.toLowerCase();
134
- if (ct.includes('zip') || ct.includes('gzip')) {
135
- return 'archives';
136
- }
137
- if (ct === 'text/x-log') {
138
- return 'logs';
139
- }
140
- if (ct === 'text/csv' || ct.includes('json') || ct.includes('yaml') || ct.includes('xml')) {
141
- return 'data';
142
- }
143
- return 'documents';
144
- };
145
-
146
- // The type filter: 'all' plus one option per section / file-family. Empty families
147
- // are hidden from the menu (a ticket with no archives never offers "Archives").
148
- type TRefFilter = 'all' | 'links' | 'screenshots' | TFileCategory;
149
- type TRefSort = 'newest' | 'oldest' | 'name' | 'size';
150
-
151
- const FILTER_META: Record<TRefFilter, { label: string; icon: IReqoreIconName }> = {
152
- all: { label: 'All types', icon: 'Apps2Line' },
153
- links: { label: 'Linked interfaces', icon: 'LinksLine' },
154
- screenshots: { label: 'Screenshots', icon: 'ImageLine' },
155
- documents: { label: 'Documents', icon: 'FileTextLine' },
156
- data: { label: 'Data', icon: 'CodeSLine' },
157
- logs: { label: 'Logs', icon: 'FileList2Line' },
158
- archives: { label: 'Archives', icon: 'FileZipLine' },
159
- };
160
- // the four filter keys that live inside the "Files" section
161
- const FILE_FILTERS: TFileCategory[] = ['documents', 'data', 'logs', 'archives'];
162
- // menu order mirrors the section order on screen: screenshots, links, then files
163
- const FILTER_ORDER: TRefFilter[] = ['all', 'screenshots', 'links', ...FILE_FILTERS];
164
-
165
- const SORT_META: Record<TRefSort, { label: string; icon: IReqoreIconName }> = {
166
- newest: { label: 'Newest first', icon: 'SortDesc' },
167
- oldest: { label: 'Oldest first', icon: 'SortAsc' },
168
- name: { label: 'Name (A–Z)', icon: 'SortAlphabetAsc' },
169
- size: { label: 'Largest first', icon: 'ScalesLine' },
170
- };
171
- const SORT_ORDER: TRefSort[] = ['newest', 'oldest', 'name', 'size'];
172
-
173
- const createdMs = (a: ITicketReferenceAttachment): number =>
174
- a.created ? new Date(a.created).getTime() || 0 : 0;
175
-
176
- /**
177
- * A reference plus where it was cited.
178
- *
179
- * `message_id` is absent for a ticket-level reference — those are filed against the
180
- * ticket itself (`message_id IS NULL` server-side), so there is no message to reveal
181
- * and "show in chat" must not be offered for them.
182
- */
183
- export interface IResolvedInterfaceReference extends IInterfaceReference {
184
- message_id?: string;
185
- }
186
-
187
- // dedupe a mixed run of references (ticket + every message) by identity — the same
188
- // interface referenced ticket-level and in a reply is one entry, not two.
189
- const dedupeRefs = (refs: IResolvedInterfaceReference[]): IResolvedInterfaceReference[] => {
190
- const byKey = new Map<string, IResolvedInterfaceReference>();
191
- for (const r of refs) {
192
- const key = `${r.interface_kind}:${r.interface_name}`;
193
- const kept = byKey.get(key);
194
- if (!kept) {
195
- byKey.set(key, r);
196
- continue;
197
- }
198
- // The ticket-level copy is merged first and carries no message. When the same
199
- // interface also appears in a reply, adopt that linkage instead of discarding it —
200
- // otherwise an interface that demonstrably IS in the thread offers no way to jump
201
- // to it, purely because it happened to be cited on the ticket as well.
202
- if (!kept.message_id && r.message_id) {
203
- byKey.set(key, { ...kept, message_id: r.message_id });
204
- }
205
- }
206
- return Array.from(byKey.values());
207
- };
208
-
209
- const META_EFFECT = { textSize: 'small', opacity: 0.55 } as const;
210
-
211
- // ---------------------------------------------------------------------------
212
- // image URLs — fetch every screenshot's bytes once as an object URL, cached, and
213
- // revoked on unmount / when the set changes. Shared by the grid and the lightbox.
214
- // ---------------------------------------------------------------------------
215
- const useImageUrls = (
216
- ids: string[],
217
- fetchAttachmentUrl?: (attachmentId: string) => Promise<string>
218
- ): Record<string, string | null> => {
219
- const [urls, setUrls] = useState<Record<string, string | null>>({});
220
- const key = ids.join(',');
221
-
222
- useEffect(() => {
223
- if (!fetchAttachmentUrl || !ids.length) {
224
- return undefined;
225
- }
226
- let active = true;
227
- const created: string[] = [];
228
- Promise.allSettled(
229
- ids.map((id) => fetchAttachmentUrl(id).then((url) => ({ id, url })))
230
- ).then((results) => {
231
- if (!active) {
232
- return;
233
- }
234
- const next: Record<string, string | null> = {};
235
- results.forEach((r, i) => {
236
- if (r.status === 'fulfilled') {
237
- next[r.value.id] = r.value.url;
238
- created.push(r.value.url);
239
- } else {
240
- next[ids[i]] = null;
241
- }
242
- });
243
- setUrls(next);
244
- });
245
- return () => {
246
- active = false;
247
- created.forEach((url) => URL.revokeObjectURL(url));
248
- };
249
- // `key` is the stable signature of `ids`; re-run when the image set changes.
250
- }, [key, fetchAttachmentUrl]);
251
-
252
- return urls;
253
- };
254
-
255
- // ---------------------------------------------------------------------------
256
- // styled bits (reqore covers the rest)
257
- // ---------------------------------------------------------------------------
258
- /*
259
- * The search/filter/sort strip reads as part of the list it filters, not as a stray
260
- * row above it: it gets its own tinted, bordered surface and sticks to the top of the
261
- * scroll container. Free-floating, it was easy to lose track of — and scrolling the
262
- * sections took the search box away with them, which is exactly when you want it.
263
- */
264
- const Toolbar = styled.div`
265
- position: sticky;
266
- top: 0;
267
- z-index: 2;
268
- padding: 8px;
269
- border-radius: 8px;
270
- border: 1px solid rgba(255, 255, 255, 0.08);
271
- background: rgba(255, 255, 255, 0.04);
272
- backdrop-filter: blur(6px);
273
- `;
274
-
275
- /*
276
- * A screenshot tile: the image is the button, and the overflow menu is a sibling
277
- * layered over it — a <button> cannot legally contain another button, so the menu
278
- * cannot live inside Thumb. It stays hidden until the tile is hovered or something
279
- * inside it takes focus, so a wall of screenshots still reads as images rather than
280
- * a grid of controls. Hidden by opacity rather than display, so it remains reachable
281
- * by keyboard.
282
- */
283
- const ThumbTile = styled.div`
284
- position: relative;
285
- /*
286
- * A single-cell grid, not flex: a grid child stretches to fill by default, so the
287
- * thumbnail spans the whole tile and the overlay's top-right corner IS the image's
288
- * top-right corner. Under flex the button sized itself from its aspect-ratio, left a
289
- * strip of empty tile beside it, and the menu — anchored to the tile — landed in that
290
- * strip instead of over the image.
291
- */
292
- display: grid;
293
-
294
- > .screenshot-menu {
295
- position: absolute;
296
- top: 5px;
297
- right: 5px;
298
- opacity: 0;
299
- transition: opacity 0.12s ease-out;
300
- }
301
-
302
- &:hover > .screenshot-menu,
303
- &:focus-within > .screenshot-menu {
304
- opacity: 1;
305
- }
306
- `;
307
-
308
- const Thumb = styled.button`
309
- appearance: none;
310
- border: 1px solid rgba(255, 255, 255, 0.1);
311
- border-radius: 8px;
312
- overflow: hidden;
313
- padding: 0;
314
- cursor: pointer;
315
- aspect-ratio: 1 / 1;
316
- background: rgba(255, 255, 255, 0.03);
317
- display: flex;
318
- align-items: center;
319
- justify-content: center;
320
- position: relative;
321
- transition: border-color 0.15s;
322
- &:hover {
323
- border-color: rgba(169, 116, 255, 0.6);
324
- }
325
- &:focus-visible {
326
- outline: 2px solid #a974ff;
327
- outline-offset: 2px;
328
- }
329
- img {
330
- width: 100%;
331
- height: 100%;
332
- object-fit: cover;
333
- display: block;
334
- }
335
- `;
336
- const ThumbCaption = styled.span`
337
- position: absolute;
338
- left: 0;
339
- right: 0;
340
- bottom: 0;
341
- padding: 4px 6px;
342
- font-size: 10px;
343
- color: #fff;
344
- background: linear-gradient(0deg, rgba(0, 0, 0, 0.75), transparent);
345
- white-space: nowrap;
346
- overflow: hidden;
347
- text-overflow: ellipsis;
348
- text-align: left;
349
- `;
350
- // ---------------------------------------------------------------------------
351
- // screenshot thumbnail
352
- // ---------------------------------------------------------------------------
353
- const Screenshot = ({
354
- att,
355
- url,
356
- onOpen,
357
- menu,
358
- }: {
359
- att: ITicketReferenceAttachment;
360
- url: string | null | undefined;
361
- onOpen: () => void;
362
- menu?: IReqorePanelSubAction[];
363
- }) => (
364
- <ThumbTile>
365
- <Thumb type='button' title={att.filename} onClick={onOpen}>
366
- {url ? (
367
- <img src={url} alt={att.filename} />
368
- ) : (
369
- <ReqoreSpan effect={{ opacity: 0.5, textSize: 'small' }}>
370
- {url === null ? att.filename : '…'}
371
- </ReqoreSpan>
372
- )}
373
- <ThumbCaption>{att.filename}</ThumbCaption>
374
- </Thumb>
375
- {/* One action doesn't earn a menu. With a single entry the overlay IS that
376
- action, so a tile and a file row offer the same thing the same way instead of
377
- hiding a download behind a caret on one surface and not the other. */}
378
- {menu?.length === 1 ? (
379
- <ReqoreButton
380
- className='screenshot-menu'
381
- icon={menu[0].icon}
382
- tooltip={menu[0].label as string}
383
- size='small'
384
- flat
385
- minimal
386
- fixed
387
- onClick={(event: React.MouseEvent<HTMLElement>) => {
388
- event.stopPropagation();
389
- menu[0].onClick?.(menu[0]);
390
- }}
391
- />
392
- ) : menu?.length ? (
393
- <ReqoreDropdown
394
- className='screenshot-menu'
395
- icon='More2Line'
396
- tooltip='More actions'
397
- size='small'
398
- flat
399
- minimal
400
- fixed
401
- useTargetWidth={false}
402
- items={menu}
403
- onClick={(event: React.MouseEvent<HTMLElement>) => event.stopPropagation()}
404
- />
405
- ) : null}
406
- </ThumbTile>
407
- );
408
-
409
- // ---------------------------------------------------------------------------
410
- // main
411
- // ---------------------------------------------------------------------------
412
- export const TicketReferences = ({
413
- references = [],
414
- messages = [],
415
- attachments,
416
- viewerRole,
417
- fetchAttachmentUrl,
418
- onDownloadAttachment,
419
- onInterfaceClick,
420
- onShowInChat,
421
- resolveInterfaceIcon,
422
- loading,
423
- }: ITicketReferencesProps) => {
424
- // references: ticket-level + every message's, deduped. Rendered as rows carrying
425
- // their kind as metadata — the same treatment as the files below — so the tab
426
- // reads as one consistent list rather than chips above rows.
427
- const allRefs = useMemo(
428
- () =>
429
- dedupeRefs([
430
- // ticket-level first (no message), then each message's own citations tagged
431
- // with the message they came from
432
- ...references,
433
- ...messages.flatMap((m) =>
434
- (m.referenced_interfaces ?? []).map((r) => ({ ...r, message_id: m.message_id }))
435
- ),
436
- ]),
437
- [references, messages]
438
- );
439
- const resolveIcon = resolveInterfaceIcon ?? defaultInterfaceIcon;
440
-
441
- /**
442
- * The trailing controls for a row: its primary action, plus a "three dots" menu when
443
- * there is anything else to offer. Built in one place so the interface rows and the
444
- * file rows can't drift into different affordances.
445
- *
446
- * The menu is omitted entirely when it would be empty — a row filed against the
447
- * ticket rather than a reply has no message to reveal, and an always-present menu
448
- * that is sometimes empty is worse than no menu.
449
- */
450
- /**
451
- * The reveal action. One definition, used by the reference rows, the file rows and
452
- * the screenshot tiles.
453
- *
454
- * Present on every row, but DISABLED for anything filed against the ticket itself
455
- * rather than a reply — those have no message to jump to. Showing the menu on some
456
- * rows and not others read as breakage rather than as a distinction, and the
457
- * disabled entry says why instead of leaving the reader to infer it.
458
- */
459
- const showInChatItem = (messageId?: string | null): IReqorePanelSubAction[] => {
460
- if (!onShowInChat) {
461
- return [];
462
- }
463
- return messageId
464
- ? [{ label: 'Show in chat', icon: 'Chat1Line', onClick: () => onShowInChat(messageId) }]
465
- : [
466
- {
467
- label: 'Show in chat',
468
- icon: 'Chat1Line',
469
- disabled: true,
470
- description: 'Filed on the ticket, not in a reply',
471
- },
472
- ];
473
- };
474
-
475
- const rowActions = (
476
- primary: IReqoreEntityRowAction | undefined,
477
- messageId?: string | null
478
- ): IReqoreEntityRowAction[] => {
479
- const menu = showInChatItem(messageId);
480
-
481
- return [
482
- ...(primary ? [primary] : []),
483
- ...(menu.length
484
- ? [
485
- {
486
- icon: 'More2Line' as IReqoreIconName,
487
- tooltip: 'More actions',
488
- flat: true,
489
- minimal: true,
490
- actions: menu,
491
- },
492
- ]
493
- : []),
494
- ];
495
- };
496
-
497
- // attachments: the list-endpoint set (with provenance) or, failing that, the
498
- // ones embedded per message (deriving provenance from the carrying message)
499
- const allAttachments = useMemo<ITicketReferenceAttachment[]>(() => {
500
- const source: ITicketReferenceAttachment[] =
501
- attachments ??
502
- messages.flatMap((m) =>
503
- (m.attachments ?? []).map((a) => ({
504
- ...a,
505
- message_id: m.message_id,
506
- uploaded_by: m.author_id,
507
- created: m.created,
508
- }))
509
- );
510
- const seen = new Set<string>();
511
- return source.filter((a) => {
512
- if (seen.has(a.attachment_id)) {
513
- return false;
514
- }
515
- seen.add(a.attachment_id);
516
- return true;
517
- });
518
- }, [attachments, messages]);
519
-
520
- const images = useMemo(
521
- () => allAttachments.filter((a) => isImage(a.content_type)),
522
- [allAttachments]
523
- );
524
- const files = useMemo(
525
- () => allAttachments.filter((a) => !isImage(a.content_type)),
526
- [allAttachments]
527
- );
528
-
529
- const imageIds = useMemo(() => images.map((a) => a.attachment_id), [images]);
530
- const urls = useImageUrls(imageIds, fetchAttachmentUrl);
531
-
532
- const [lightbox, setLightbox] = useState<number | null>(null);
533
-
534
- // --- search / filter / sort ------------------------------------------------
535
- const [search, setSearch] = useState('');
536
- const [filter, setFilter] = useState<TRefFilter>('all');
537
- const [sort, setSort] = useState<TRefSort>('newest');
538
-
539
- const query = search.trim().toLowerCase();
540
- const matchesText = useCallback(
541
- (...fields: (string | undefined)[]) =>
542
- !query || fields.some((f) => f?.toLowerCase().includes(query)),
543
- [query]
544
- );
545
-
546
- const sortAttachments = useCallback(
547
- (arr: ITicketReferenceAttachment[]): ITicketReferenceAttachment[] => {
548
- const next = [...arr];
549
- switch (sort) {
550
- case 'oldest':
551
- return next.sort((a, b) => createdMs(a) - createdMs(b));
552
- case 'name':
553
- return next.sort((a, b) => a.filename.localeCompare(b.filename));
554
- case 'size':
555
- return next.sort((a, b) => (b.size_bytes ?? 0) - (a.size_bytes ?? 0));
556
- case 'newest':
557
- default:
558
- return next.sort((a, b) => createdMs(b) - createdMs(a));
559
- }
560
- },
561
- [sort]
562
- );
563
-
564
- // per-family counts feed the filter menu: empty families are dropped, and the
565
- // surviving ones carry a count badge in their label.
566
- const counts = useMemo(() => {
567
- const byCategory: Record<TFileCategory, number> = {
568
- documents: 0,
569
- data: 0,
570
- logs: 0,
571
- archives: 0,
572
- };
573
- for (const f of files) {
574
- byCategory[fileCategory(f.content_type)] += 1;
575
- }
576
- return {
577
- all: allRefs.length + allAttachments.length,
578
- links: allRefs.length,
579
- screenshots: images.length,
580
- ...byCategory,
581
- } as Record<TRefFilter, number>;
582
- }, [files, images.length, allRefs.length, allAttachments.length]);
583
-
584
- // the three sections after search + type filter are applied. References sort by
585
- // kind then name so like sits with like; "Name" sorts them purely by name.
586
- const visibleRefs = useMemo(() => {
587
- if (filter !== 'all' && filter !== 'links') {
588
- return [] as IResolvedInterfaceReference[];
589
- }
590
- return allRefs
591
- .filter((r) => matchesText(r.interface_name, r.interface_kind))
592
- .sort((a, b) =>
593
- sort === 'name'
594
- ? a.interface_name.localeCompare(b.interface_name)
595
- : a.interface_kind.localeCompare(b.interface_kind) ||
596
- a.interface_name.localeCompare(b.interface_name)
597
- );
598
- }, [allRefs, filter, matchesText, sort]);
599
-
600
- const visibleImages = useMemo(() => {
601
- if (filter !== 'all' && filter !== 'screenshots') {
602
- return [] as ITicketReferenceAttachment[];
603
- }
604
- return sortAttachments(images.filter((a) => matchesText(a.filename)));
605
- }, [images, filter, matchesText, sortAttachments]);
606
-
607
- const visibleFiles = useMemo(() => {
608
- const fileFilter = FILE_FILTERS.includes(filter as TFileCategory);
609
- if (filter !== 'all' && !fileFilter) {
610
- return [] as ITicketReferenceAttachment[];
611
- }
612
- let list = files.filter((a) => matchesText(a.filename));
613
- if (fileFilter) {
614
- list = list.filter((a) => fileCategory(a.content_type) === filter);
615
- }
616
- return sortAttachments(list);
617
- }, [files, filter, matchesText, sortAttachments]);
618
-
619
- // a filtered-out lightbox target would dangle — close it if its index falls away
620
- useEffect(() => {
621
- if (lightbox !== null && lightbox >= visibleImages.length) {
622
- setLightbox(null);
623
- }
624
- }, [visibleImages.length, lightbox]);
625
-
626
- if (loading) {
627
- return (
628
- <ReqoreControlGroup fluid horizontalAlign='center' style={{ padding: '32px 0' }}>
629
- <ReqoreSpinner iconColor='info' size='big'>
630
- Loading references…
631
- </ReqoreSpinner>
632
- </ReqoreControlGroup>
633
- );
634
- }
635
-
636
- if (!allRefs.length && !allAttachments.length) {
637
- return (
638
- <ReqoreEmptyState
639
- icon='FolderInfoLine'
640
- title='No references or files yet'
641
- description='Interface references and any screenshots, documents, or files attached to this ticket will appear here.'
642
- flat
643
- transparent
644
- />
645
- );
646
- }
647
-
648
- // A search + type-filter + sort strip, shown once a ticket carries enough to be
649
- // worth narrowing (any files, or 3+ linked interfaces). Empty type-families are
650
- // dropped from the filter menu so it only ever offers what's actually present.
651
- const showControls = allAttachments.length > 0 || allRefs.length > 2;
652
- const filterOptions = FILTER_ORDER.filter((key) => key === 'all' || counts[key] > 0);
653
- const nothingVisible = !visibleRefs.length && !visibleImages.length && !visibleFiles.length;
654
-
655
- const controlBar = showControls ? (
656
- <Toolbar>
657
- {/* the bar is a filter over the content, not content itself — at the default
658
- size the two dropdowns read as primary actions and crowd the search field */}
659
- <ReqoreControlGroup fluid wrap verticalAlign='center' gapSize='small' size='small'>
660
- <ReqoreInput
661
- icon='Search2Line'
662
- placeholder='Search files and references…'
663
- value={search}
664
- onChange={(e) => setSearch(e.currentTarget.value)}
665
- onClearClick={() => setSearch('')}
666
- minimal
667
- fluid
668
- />
669
- <ReqoreDropdown
670
- icon={FILTER_META[filter].icon}
671
- label={FILTER_META[filter].label}
672
- minimal
673
- fixed
674
- flat
675
- items={filterOptions.map((key) => ({
676
- selected: filter === key,
677
- icon: FILTER_META[key].icon,
678
- label: key === 'all' ? FILTER_META.all.label : `${FILTER_META[key].label} (${counts[key]})`,
679
- onClick: () => setFilter(key),
680
- }))}
681
- />
682
- <ReqoreDropdown
683
- icon='ArrowUpDownLine'
684
- label={SORT_META[sort].label}
685
- minimal
686
- fixed
687
- flat
688
- items={SORT_ORDER.map((key) => ({
689
- selected: sort === key,
690
- icon: SORT_META[key].icon,
691
- label: SORT_META[key].label,
692
- onClick: () => setSort(key),
693
- }))}
694
- />
695
- </ReqoreControlGroup>
696
- </Toolbar>
697
- ) : null;
698
-
699
- return (
700
- <ReqoreControlGroup vertical fluid gapSize='big'>
701
- {controlBar}
702
-
703
- {nothingVisible ? (
704
- <ReqoreEmptyState
705
- icon='Search2Line'
706
- title='No matching references or files'
707
- description={
708
- query
709
- ? `Nothing here matches “${search.trim()}”.`
710
- : 'Nothing matches the current filter.'
711
- }
712
- flat
713
- transparent
714
- actions={
715
- <ReqoreButton
716
- icon='CloseLine'
717
- minimal
718
- onClick={() => {
719
- setSearch('');
720
- setFilter('all');
721
- }}
722
- >
723
- Clear filters
724
- </ReqoreButton>
725
- }
726
- />
727
- ) : null}
728
-
729
- {visibleImages.length ? (
730
- <ReqorePanel
731
- label='Screenshots'
732
- icon='ImageLine'
733
- badge={visibleImages.length}
734
- flat
735
- transparent
736
- size='small'
737
- labelSize={4}
738
- collapsible
739
- >
740
- <ReqoreColumns columns='auto-fill' minColumnWidth='140px' columnsGap='10px'>
741
- {visibleImages.map((att, i) => (
742
- <Screenshot
743
- key={att.attachment_id}
744
- att={att}
745
- url={urls[att.attachment_id]}
746
- onOpen={() =>
747
- urls[att.attachment_id]
748
- ? setLightbox(i)
749
- : onDownloadAttachment?.(att.attachment_id, att.filename)
750
- }
751
- menu={[
752
- ...(onDownloadAttachment
753
- ? [
754
- {
755
- label: 'Download',
756
- icon: 'DownloadLine' as IReqoreIconName,
757
- onClick: () => onDownloadAttachment(att.attachment_id, att.filename),
758
- },
759
- ]
760
- : []),
761
- ...showInChatItem(att.message_id),
762
- ]}
763
- />
764
- ))}
765
- </ReqoreColumns>
766
- </ReqorePanel>
767
- ) : null}
768
-
769
- {visibleRefs.length ? (
770
- <ReqorePanel
771
- label='Linked interfaces'
772
- icon='LinksLine'
773
- badge={visibleRefs.length}
774
- flat
775
- transparent
776
- size='small'
777
- labelSize={4}
778
- collapsible
779
- >
780
- {/* small rows: a reference list is scanned, so density beats presence —
781
- the group's size reaches every row (ControlGroup/index.tsx:436) */}
782
- <ReqoreControlGroup vertical fluid gapSize='small' size='small'>
783
- {visibleRefs.map((reference) => {
784
- // an app-triggered qog carries its trigger app's logo; everything else
785
- // shows its kind glyph — the same vocabulary the reference chips use.
786
- const image = reference.logo;
787
- return (
788
- <ReqoreEntityRow
789
- key={
790
- reference.reference_id ??
791
- `${reference.interface_kind}:${reference.interface_name}`
792
- }
793
- icon={image ? undefined : resolveIcon(reference.interface_kind)}
794
- iconImage={image}
795
- label={reference.interface_name}
796
- metadata={
797
- <ReqoreTextEffect effect={META_EFFECT}>
798
- {reference.interface_kind}
799
- </ReqoreTextEffect>
800
- }
801
- flat
802
- tooltip={
803
- onInterfaceClick
804
- ? `Open ${reference.interface_kind} ${reference.interface_name}`
805
- : undefined
806
- }
807
- actions={rowActions(
808
- onInterfaceClick
809
- ? {
810
- icon: 'ArrowRightUpLine',
811
- tooltip: 'Open',
812
- onClick: () => onInterfaceClick(reference),
813
- }
814
- : undefined,
815
- reference.message_id
816
- )}
817
- />
818
- );
819
- })}
820
- </ReqoreControlGroup>
821
- </ReqorePanel>
822
- ) : null}
823
-
824
- {visibleFiles.length ? (
825
- <ReqorePanel
826
- label='Files'
827
- icon='FileList3Line'
828
- badge={visibleFiles.length}
829
- flat
830
- transparent
831
- size='small'
832
- labelSize={4}
833
- collapsible
834
- actions={
835
- visibleFiles.length > 1 && onDownloadAttachment
836
- ? [
837
- {
838
- icon: 'DownloadCloud2Line',
839
- label: 'Download all',
840
- onClick: () =>
841
- visibleFiles.forEach((f) => onDownloadAttachment(f.attachment_id, f.filename)),
842
- },
843
- ]
844
- : []
845
- }
846
- >
847
- {/* matches the interface rows above — the two lists read as one surface */}
848
- <ReqoreControlGroup vertical fluid gapSize='small' size='small'>
849
- {visibleFiles.map((f) => {
850
- const type = fileType(f.content_type);
851
- // a customer's own upload reads "you"; everything else shows the
852
- // (already server-masked) uploader — "Qorus Support" for staff replies.
853
- const uploader =
854
- viewerRole === 'customer' && f.uploader_type === 'customer' ? 'you' : f.uploaded_by;
855
- const provenance = [
856
- formatBytes(f.size_bytes),
857
- uploader ? `added by ${uploader}` : undefined,
858
- timeAgo(f.created) || undefined,
859
- ]
860
- .filter(Boolean)
861
- .join(' · ');
862
- return (
863
- <ReqoreEntityRow
864
- key={f.attachment_id}
865
- icon={type.icon}
866
- iconColor={type.color}
867
- label={f.filename}
868
- metadata={<ReqoreTextEffect effect={META_EFFECT}>{provenance}</ReqoreTextEffect>}
869
- flat
870
- actions={rowActions(
871
- onDownloadAttachment
872
- ? {
873
- icon: 'DownloadLine',
874
- tooltip: 'Download',
875
- onClick: () => onDownloadAttachment(f.attachment_id, f.filename),
876
- }
877
- : undefined,
878
- f.message_id
879
- )}
880
- />
881
- );
882
- })}
883
- </ReqoreControlGroup>
884
- </ReqorePanel>
885
- ) : null}
886
-
887
- {lightbox !== null && fetchAttachmentUrl ? (
888
- <ImageLightbox
889
- images={visibleImages}
890
- index={lightbox}
891
- onIndex={setLightbox}
892
- onClose={() => setLightbox(null)}
893
- fetchAttachmentUrl={fetchAttachmentUrl}
894
- onDownload={onDownloadAttachment}
895
- />
896
- ) : null}
897
- </ReqoreControlGroup>
898
- );
899
- };