@qoretechnologies/reqraft 0.10.25 → 0.10.27-pr.74.gc5f6ca3

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