@attraccess/plugin-rabbitmq 0.1.0 → 0.2.0-nightly.1200.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
- import { r as importShared } from "./_virtual___federation_fn_import-BXODRNto.js";
2
- //#region \0rolldown/runtime.js
3
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
4
- //#endregion
5
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.api-client.ts
1
+ import { r as importShared } from "./_virtual___federation_fn_import-D2E5es2p.js";
2
+ // \0rolldown/runtime.js
3
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
4
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.api-client.ts
6
5
  var BASE_URL_GLOBAL = "__ATTRACCESS_API_BASE_URL__";
7
6
  /** The API origin the host is talking to. Falls back to the current origin. */
8
7
  function getApiBaseUrl() {
@@ -16,10 +15,20 @@ var PluginApiError = class extends Error {
16
15
  this.name = "PluginApiError";
17
16
  }
18
17
  };
18
+ /**
19
+ * Joins validation messages into one text. Messages that already end a sentence are separated by a space, so
20
+ * "The URL is too long." and "The token is short." never become "long., token".
21
+ */
22
+ function joinErrorMessages(parts) {
23
+ return parts.map((part) => part.trim()).filter(Boolean).reduce((joined, part) => {
24
+ if (joined === "") return part;
25
+ return /[.!?]$/.test(joined) ? `${joined} ${part}` : `${joined}, ${part}`;
26
+ }, "");
27
+ }
19
28
  async function toError(res) {
20
29
  try {
21
30
  const body = await res.json();
22
- const message = Array.isArray(body.message) ? body.message.join(", ") : body.message;
31
+ const message = Array.isArray(body.message) ? joinErrorMessages(body.message) : body.message;
23
32
  if (message) return new PluginApiError(message, res.status);
24
33
  } catch {}
25
34
  return new PluginApiError(`Request failed (HTTP ${res.status}).`, res.status);
@@ -61,8 +70,9 @@ function createPluginApiClient(basePath = "") {
61
70
  }
62
71
  };
63
72
  }
64
- //#endregion
65
- //#region ../../../node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react-jsx-runtime.production.js
73
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.license.ts
74
+ var { useCallback: useCallback$5, useEffect: useEffect$7, useState: useState$8 } = await importShared("react");
75
+ // ../../../node_modules/.pnpm/react@19.3.1/node_modules/react/cjs/react-jsx-runtime.production.js
66
76
  /**
67
77
  * @license React
68
78
  * react-jsx-runtime.production.js
@@ -96,27 +106,28 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((expor
96
106
  exports.jsx = jsxProd;
97
107
  exports.jsxs = jsxProd;
98
108
  }));
99
- //#endregion
100
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.live-updates.tsx
109
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.live-updates.tsx
101
110
  var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
102
111
  module.exports = require_react_jsx_runtime_production();
103
112
  })))();
104
- var { createContext, useCallback: useCallback$4, useContext, useEffect: useEffect$6, useRef: useRef$2 } = await importShared("react");
113
+ var { createContext, useCallback: useCallback$4, useContext, useEffect: useEffect$6, useRef: useRef$4 } = await importShared("react");
105
114
  var contextKey = Symbol.for("attraccess.plugin.live-updates.context");
106
115
  var contexts = globalThis;
107
116
  contexts[contextKey] ??= createContext(null);
108
117
  var identityKey = Symbol.for("attraccess.plugin.live-updates.identity");
109
118
  var identities = globalThis;
110
119
  identities[identityKey] ??= createContext(null);
111
- //#endregion
112
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-drawer.tsx
120
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.pluggable.ts
121
+ /** Whether the signed-in user holds `permission`. False when signed out or when the host sends no permissions. */
122
+ function hasPluginAuthPermission(authData, permission) {
123
+ return (authData?.effectivePermissions ?? (authData?.user)?.effectivePermissions)?.includes(permission) ?? false;
124
+ }
125
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-drawer.tsx
113
126
  var { StandardDrawer: SharedStandardDrawer } = await importShared("@attraccess/plugins-frontend-ui");
114
- //#endregion
115
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-modal.tsx
127
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-modal.tsx
116
128
  var { StandardModal: SharedStandardModal } = await importShared("@attraccess/plugins-frontend-ui");
117
- //#endregion
118
- //#region frontend/src/detection/detection.ts
119
- var { useCallback: useCallback$3, useEffect: useEffect$5, useState: useState$6 } = await importShared("react");
129
+ // frontend/src/detection/detection.ts
130
+ var { useCallback: useCallback$3, useEffect: useEffect$5, useState: useState$7 } = await importShared("react");
120
131
  var api$4 = createPluginApiClient("/api/rabbitmq/detection");
121
132
  function fetchDetection(mqttServerId, refresh) {
122
133
  return api$4.request(`/${mqttServerId}`, { query: { refresh: refresh ? "true" : void 0 } });
@@ -163,7 +174,7 @@ function ensureLoaded(mqttServerId, refresh) {
163
174
  notify(mqttServerId);
164
175
  }
165
176
  function useDetection(mqttServerId) {
166
- const [, forceRender] = useState$6(0);
177
+ const [, forceRender] = useState$7(0);
167
178
  useEffect$5(() => {
168
179
  const rerender = () => forceRender((n) => n + 1);
169
180
  let set = subscribers.get(mqttServerId);
@@ -187,11 +198,30 @@ function useDetection(mqttServerId) {
187
198
  refresh
188
199
  };
189
200
  }
190
- //#endregion
191
- //#region frontend/src/users/RabbitmqListBadge.tsx
201
+ // backend/permission-keys.ts
202
+ var RABBITMQ_BROKER_READ = "rabbitmq.broker.read";
203
+ // frontend/src/access.ts
204
+ var { useSyncExternalStore } = await importShared("react");
205
+ var authData = null;
206
+ var listeners = /* @__PURE__ */ new Set();
207
+ function setRabbitmqAuthData(next) {
208
+ authData = next;
209
+ for (const listener of listeners) listener();
210
+ }
211
+ var subscribe = (listener) => {
212
+ listeners.add(listener);
213
+ return () => listeners.delete(listener);
214
+ };
215
+ function useCanViewBroker() {
216
+ return hasPluginAuthPermission(useSyncExternalStore(subscribe, () => authData), RABBITMQ_BROKER_READ);
217
+ }
218
+ // frontend/src/users/RabbitmqListBadge.tsx
192
219
  var { Chip: Chip$4 } = await importShared("@heroui/react");
193
220
  var { RabbitIcon: RabbitIcon$1 } = await importShared("lucide-react");
194
221
  function RabbitmqListBadge({ mqttServerId }) {
222
+ return useCanViewBroker() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DetectedBadge, { mqttServerId }) : null;
223
+ }
224
+ function DetectedBadge({ mqttServerId }) {
195
225
  const { result } = useDetection(mqttServerId);
196
226
  if (!result?.isRabbitMQ) return null;
197
227
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Chip$4, {
@@ -222,9 +252,8 @@ var en_default = {
222
252
  "tags": "Tags",
223
253
  "access": "Vhost access",
224
254
  "none": "none",
225
- "edit": "Edit user {{name}}",
226
- "permissions": "Edit permissions of {{name}}",
227
- "delete": "Delete user {{name}}",
255
+ "edit": "Edit user",
256
+ "permissions": "Edit permissions",
228
257
  "deleteTitle": "Delete user",
229
258
  "deleteDescription": "Delete the RabbitMQ user {{name}}? Connected clients using this account will be disconnected and its permissions removed.",
230
259
  "loadError": "Loading users failed.",
@@ -268,7 +297,6 @@ var en_default = {
268
297
  "close": "Close",
269
298
  "save": "Save",
270
299
  "delete": "Delete",
271
- "actions": "Actions",
272
300
  "state": "State",
273
301
  "yes": "Yes",
274
302
  "no": "No"
@@ -286,7 +314,6 @@ var en_default = {
286
314
  "connectedSince": "Connected since",
287
315
  "channels": "Channels",
288
316
  "traffic": "Traffic (received / sent)",
289
- "close": "Close connection {{name}}",
290
317
  "closeTitle": "Close connection",
291
318
  "closeDescription": "Close the connection of {{name}}? The client is disconnected and may reconnect on its own.",
292
319
  "closeConfirm": "Close connection",
@@ -348,9 +375,8 @@ var de_default = {
348
375
  "tags": "Tags",
349
376
  "access": "Vhost-Zugriff",
350
377
  "none": "keine",
351
- "edit": "Benutzer {{name}} bearbeiten",
352
- "permissions": "Berechtigungen von {{name}} bearbeiten",
353
- "delete": "Benutzer {{name}} löschen",
378
+ "edit": "Benutzer bearbeiten",
379
+ "permissions": "Berechtigungen bearbeiten",
354
380
  "deleteTitle": "Benutzer löschen",
355
381
  "deleteDescription": "RabbitMQ-Benutzer {{name}} löschen? Verbundene Clients mit diesem Konto werden getrennt und seine Berechtigungen entfernt.",
356
382
  "loadError": "Benutzer konnten nicht geladen werden.",
@@ -394,7 +420,6 @@ var de_default = {
394
420
  "close": "Schließen",
395
421
  "save": "Speichern",
396
422
  "delete": "Löschen",
397
- "actions": "Aktionen",
398
423
  "state": "Status",
399
424
  "yes": "Ja",
400
425
  "no": "Nein"
@@ -412,7 +437,6 @@ var de_default = {
412
437
  "connectedSince": "Verbunden seit",
413
438
  "channels": "Kanäle",
414
439
  "traffic": "Datenverkehr (empfangen / gesendet)",
415
- "close": "Verbindung {{name}} schließen",
416
440
  "closeTitle": "Verbindung schließen",
417
441
  "closeDescription": "Die Verbindung von {{name}} schließen? Der Client wird getrennt und kann sich selbstständig neu verbinden.",
418
442
  "closeConfirm": "Verbindung schließen",
@@ -454,16 +478,14 @@ var de_default = {
454
478
  "queuesTruncated": "Die ersten {{shown}} von {{total}} Queues werden angezeigt."
455
479
  }
456
480
  };
457
- //#endregion
458
- //#region frontend/src/i18n.ts
481
+ // frontend/src/i18n.ts
459
482
  var { useTranslations } = await importShared("@attraccess/plugins-frontend-ui");
460
483
  var useRabbitmqTranslations = () => useTranslations({
461
484
  en: en_default,
462
485
  de: de_default
463
486
  }, { escapeValues: false });
464
- //#endregion
465
- //#region frontend/src/format.tsx
466
- var { useDateTimeFormatter, useFormatedDuration, useNumberFormatter } = await importShared("@attraccess/plugins-frontend-ui");
487
+ // frontend/src/useRabbitmqFormatters.ts
488
+ var { useDateTimeFormatter, useNumberFormatter } = await importShared("@attraccess/plugins-frontend-ui");
467
489
  var { useCallback: useCallback$2, useMemo } = await importShared("react");
468
490
  var BYTE_UNITS = [
469
491
  "B",
@@ -520,13 +542,8 @@ function useRabbitmqFormatters() {
520
542
  time
521
543
  ]);
522
544
  }
523
- function Duration({ ms }) {
524
- const formatted = useFormatedDuration(ms == null ? 0 : Math.floor(ms / 6e4));
525
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: ms == null ? "—" : formatted });
526
- }
527
- //#endregion
528
- //#region frontend/src/detection/RabbitmqStatusPanel.tsx
529
- var { Button: Button$6 } = await importShared("@attraccess/plugins-frontend-ui");
545
+ // frontend/src/detection/RabbitmqStatusPanel.tsx
546
+ var { Button: Button$5 } = await importShared("@attraccess/plugins-frontend-ui");
530
547
  var { Alert: Alert$2, AlertContent: AlertContent$2, AlertDescription: AlertDescription$2, Card: Card$4, Chip: Chip$3 } = await importShared("@heroui/react");
531
548
  var { CheckCircle2Icon, RabbitIcon, RefreshCwIcon: RefreshCwIcon$3, XCircleIcon } = await importShared("lucide-react");
532
549
  function StatusRow({ ok, label, value }) {
@@ -568,7 +585,7 @@ function RabbitmqStatusPanel({ mqttServerId }) {
568
585
  children: t("status.detected")
569
586
  })
570
587
  ]
571
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$6, {
588
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
572
589
  isIconOnly: true,
573
590
  size: "sm",
574
591
  variant: "ghost",
@@ -630,8 +647,7 @@ function RabbitmqStatusPanel({ mqttServerId }) {
630
647
  })]
631
648
  });
632
649
  }
633
- //#endregion
634
- //#region frontend/src/users/users-api.ts
650
+ // frontend/src/users/users-api.ts
635
651
  var DEFAULT_MQTT_PERMISSIONS = {
636
652
  configure: "^mqtt-subscription-.*$",
637
653
  write: "^(amq\\.topic|mqtt-subscription-.*)$",
@@ -662,12 +678,11 @@ function clearPermissions(mqttServerId, username, vhost) {
662
678
  query: { vhost }
663
679
  });
664
680
  }
665
- //#endregion
666
- //#region frontend/src/users/permissions/RabbitmqPermissionsModal.tsx
667
- var { Button: Button$5, EmptyState: EmptyState$2, StandardModal: StandardModal$1 } = await importShared("@attraccess/plugins-frontend-ui");
681
+ // frontend/src/users/permissions/RabbitmqPermissionsModal.tsx
682
+ var { Button: Button$4, EmptyState: EmptyState$2, StandardModal: StandardModal$1 } = await importShared("@attraccess/plugins-frontend-ui");
668
683
  var { Alert: Alert$1, AlertContent: AlertContent$1, AlertDescription: AlertDescription$1, Input: Input$2, Label: Label$2, ModalBody: ModalBody$1, ModalFooter: ModalFooter$1, ModalHeader: ModalHeader$1, ModalHeading: ModalHeading$1, TextField: TextField$2 } = await importShared("@heroui/react");
669
684
  var { PlusIcon: PlusIcon$1, Trash2Icon: Trash2Icon$1 } = await importShared("lucide-react");
670
- var { useEffect: useEffect$4, useState: useState$5 } = await importShared("react");
685
+ var { useEffect: useEffect$4, useState: useState$6 } = await importShared("react");
671
686
  function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
672
687
  const { t } = useRabbitmqTranslations();
673
688
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
@@ -683,7 +698,7 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
683
698
  " ",
684
699
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: row.vhost })
685
700
  ]
686
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
701
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
687
702
  isIconOnly: true,
688
703
  size: "sm",
689
704
  variant: "ghost",
@@ -734,7 +749,7 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
734
749
  }),
735
750
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
736
751
  className: "rmq:flex rmq:flex-wrap rmq:justify-end rmq:gap-2",
737
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
752
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
738
753
  size: "sm",
739
754
  variant: "ghost",
740
755
  onPress: () => onChange({
@@ -744,7 +759,7 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
744
759
  isDisabled: busy,
745
760
  "data-cy": `rabbitmq-permissions-mqtt-defaults-button-${row.vhost}`,
746
761
  children: t("permissions.defaults")
747
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
762
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
748
763
  size: "sm",
749
764
  variant: "primary",
750
765
  onPress: onSave,
@@ -758,10 +773,10 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
758
773
  }
759
774
  function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose, onSaved }) {
760
775
  const { t, tMessage } = useRabbitmqTranslations();
761
- const [rows, setRows] = useState$5([]);
762
- const [newVhost, setNewVhost] = useState$5("");
763
- const [busyVhost, setBusyVhost] = useState$5(null);
764
- const [error, setError] = useState$5(null);
776
+ const [rows, setRows] = useState$6([]);
777
+ const [newVhost, setNewVhost] = useState$6("");
778
+ const [busyVhost, setBusyVhost] = useState$6(null);
779
+ const [error, setError] = useState$6(null);
765
780
  useEffect$4(() => {
766
781
  if (!isOpen) return;
767
782
  setRows((user?.permissions ?? []).map((permission) => ({
@@ -869,7 +884,7 @@ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose,
869
884
  autoComplete: "off",
870
885
  "data-cy": "rabbitmq-permissions-add-vhost-input"
871
886
  })]
872
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$5, {
887
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$4, {
873
888
  variant: "secondary",
874
889
  onPress: addVhost,
875
890
  isDisabled: newVhost.trim().length === 0,
@@ -884,7 +899,7 @@ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose,
884
899
  })
885
900
  ]
886
901
  }),
887
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
902
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
888
903
  variant: "secondary",
889
904
  onPress: onClose,
890
905
  "data-cy": "rabbitmq-permissions-close-button",
@@ -893,19 +908,23 @@ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose,
893
908
  ] })
894
909
  });
895
910
  }
896
- //#endregion
897
- //#region frontend/src/users/useRabbitmqUserFormModalState.tsx
898
- var { useEffect: useEffect$3, useState: useState$4 } = await importShared("react");
899
- function useRabbitmqUserFormModalState({ mqttServerId, isOpen, user, vhosts, existingUsernames = [], onClose, onSaved }) {
911
+ // frontend/src/users/RabbitmqUserFormModal.tsx
912
+ var { Button: Button$3, StandardModal } = await importShared("@attraccess/plugins-frontend-ui");
913
+ var { Alert, AlertContent, AlertDescription, Checkbox, Form, Input: Input$1, Label: Label$1, ModalBody, ModalFooter, ModalHeader, ModalHeading, TextField: TextField$1 } = await importShared("@heroui/react");
914
+ var { useEffect: useEffect$3, useState: useState$5 } = await importShared("react");
915
+ function parseTags(value) {
916
+ return value.split(",").map((tag) => tag.trim()).filter((tag) => tag.length > 0);
917
+ }
918
+ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUsernames = [], onClose, onSaved }) {
900
919
  const { t, tMessage } = useRabbitmqTranslations();
901
920
  const isEdit = user !== null;
902
- const [username, setUsername] = useState$4("");
903
- const [password, setPassword] = useState$4("");
904
- const [tags, setTags] = useState$4("");
905
- const [grantMqttDefaults, setGrantMqttDefaults] = useState$4(true);
906
- const [vhost, setVhost] = useState$4("/");
907
- const [saving, setSaving] = useState$4(false);
908
- const [error, setError] = useState$4(null);
921
+ const [username, setUsername] = useState$5("");
922
+ const [password, setPassword] = useState$5("");
923
+ const [tags, setTags] = useState$5("");
924
+ const [grantMqttDefaults, setGrantMqttDefaults] = useState$5(true);
925
+ const [vhost, setVhost] = useState$5("/");
926
+ const [saving, setSaving] = useState$5(false);
927
+ const [error, setError] = useState$5(null);
909
928
  useEffect$3(() => {
910
929
  if (!isOpen) return;
911
930
  setUsername(user?.name ?? "");
@@ -952,44 +971,6 @@ function useRabbitmqUserFormModalState({ mqttServerId, isOpen, user, vhosts, exi
952
971
  setSaving(false);
953
972
  }
954
973
  };
955
- return {
956
- t,
957
- tMessage,
958
- isEdit,
959
- username,
960
- setUsername,
961
- password,
962
- setPassword,
963
- tags,
964
- setTags,
965
- grantMqttDefaults,
966
- setGrantMqttDefaults,
967
- vhost,
968
- setVhost,
969
- saving,
970
- error,
971
- handleSubmit,
972
- mqttServerId,
973
- isOpen,
974
- user,
975
- vhosts,
976
- onClose
977
- };
978
- }
979
- //#endregion
980
- //#region frontend/src/users/RabbitmqUserFormModal.tsx
981
- var { Button: Button$4, StandardModal } = await importShared("@attraccess/plugins-frontend-ui");
982
- var { Alert, AlertContent, AlertDescription, Checkbox, Form, Input: Input$1, Label: Label$1, ModalBody, ModalFooter, ModalHeader, ModalHeading, TextField: TextField$1 } = await importShared("@heroui/react");
983
- function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUsernames, onClose, onSaved }) {
984
- const { t, tMessage, isEdit, username, setUsername, password, setPassword, tags, setTags, grantMqttDefaults, setGrantMqttDefaults, vhost, setVhost, saving, error, handleSubmit } = useRabbitmqUserFormModalState({
985
- mqttServerId,
986
- isOpen,
987
- user,
988
- vhosts,
989
- existingUsernames,
990
- onClose,
991
- onSaved
992
- });
993
974
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandardModal, {
994
975
  size: "md",
995
976
  isOpen,
@@ -1074,12 +1055,12 @@ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUse
1074
1055
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription, { children: tMessage(error) }) })
1075
1056
  })
1076
1057
  ]
1077
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
1058
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1078
1059
  variant: "secondary",
1079
1060
  onPress: onClose,
1080
1061
  "data-cy": "rabbitmq-user-form-cancel-button",
1081
1062
  children: t("common.cancel")
1082
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
1063
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1083
1064
  variant: "primary",
1084
1065
  type: "submit",
1085
1066
  isPending: saving,
@@ -1089,95 +1070,12 @@ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUse
1089
1070
  })] })
1090
1071
  });
1091
1072
  }
1092
- function parseTags(value) {
1093
- return value.split(",").map((tag) => tag.trim()).filter((tag) => tag.length > 0);
1094
- }
1095
- //#endregion
1096
- //#region frontend/src/users/useRabbitmqUserPanelState.tsx
1097
- var { useCallback: useCallback$1, useEffect: useEffect$2, useRef: useRef$1, useState: useState$3 } = await importShared("react");
1098
- function useRabbitmqUserPanelState({ mqttServerId }) {
1099
- const { t, tMessage, language } = useRabbitmqTranslations();
1100
- const { result } = useDetection(mqttServerId);
1101
- const [data, setData] = useState$3(null);
1102
- const [loading, setLoading] = useState$3(false);
1103
- const [loadError, setLoadError] = useState$3(null);
1104
- const [formOpen, setFormOpen] = useState$3(false);
1105
- const [formUser, setFormUser] = useState$3(null);
1106
- const [permissionsUser, setPermissionsUser] = useState$3(null);
1107
- const [userToDelete, setUserToDelete] = useState$3(null);
1108
- const [deleting, setDeleting] = useState$3(false);
1109
- const [deleteError, setDeleteError] = useState$3(null);
1110
- const mounted = useRef$1(true);
1111
- useEffect$2(() => {
1112
- mounted.current = true;
1113
- return () => {
1114
- mounted.current = false;
1115
- };
1116
- }, []);
1117
- const confirmDelete = async () => {
1118
- if (!userToDelete) return;
1119
- setDeleting(true);
1120
- setDeleteError(null);
1121
- try {
1122
- await deleteUser(mqttServerId, userToDelete.name);
1123
- setUserToDelete(null);
1124
- reload();
1125
- } catch (err) {
1126
- setDeleteError(err instanceof Error ? err.message : { key: "users.deleteError" });
1127
- } finally {
1128
- setDeleting(false);
1129
- }
1130
- };
1131
- const reload = useCallback$1(async () => {
1132
- setLoading(true);
1133
- setLoadError(null);
1134
- try {
1135
- const list = await fetchUsers(mqttServerId);
1136
- if (mounted.current) {
1137
- setData(list);
1138
- setPermissionsUser((current) => current ? list.users.find((user) => user.name === current.name) ?? current : null);
1139
- }
1140
- } catch (err) {
1141
- if (mounted.current) setLoadError(err instanceof Error ? err.message : { key: "users.loadError" });
1142
- } finally {
1143
- if (mounted.current) setLoading(false);
1144
- }
1145
- }, [mqttServerId]);
1146
- const manageable = result?.isRabbitMQ === true && result.authOk;
1147
- useEffect$2(() => {
1148
- if (manageable) reload();
1149
- }, [manageable, reload]);
1150
- return {
1151
- t,
1152
- tMessage,
1153
- language,
1154
- data,
1155
- loading,
1156
- loadError,
1157
- formOpen,
1158
- setFormOpen,
1159
- formUser,
1160
- setFormUser,
1161
- permissionsUser,
1162
- setPermissionsUser,
1163
- userToDelete,
1164
- setUserToDelete,
1165
- deleting,
1166
- setDeleting,
1167
- deleteError,
1168
- setDeleteError,
1169
- reload,
1170
- manageable,
1171
- mqttServerId,
1172
- confirmDelete
1173
- };
1174
- }
1175
- //#endregion
1176
- //#region frontend/src/users/RabbitmqUserPanelCardHeader.tsx
1177
- var { Button: Button$3 } = await importShared("@attraccess/plugins-frontend-ui");
1073
+ // frontend/src/users/RabbitmqUserPanelCardHeader.tsx
1074
+ var { Button: Button$2 } = await importShared("@attraccess/plugins-frontend-ui");
1178
1075
  var { Card: Card$3 } = await importShared("@heroui/react");
1179
1076
  var { PlusIcon, RefreshCwIcon: RefreshCwIcon$2, UsersIcon } = await importShared("lucide-react");
1180
- function RabbitmqUserPanelCardHeader({ t, reload, loading, mqttServerId, setFormUser, setFormOpen, canManage }) {
1077
+ function RabbitmqUserPanelCardHeader({ reload, loading, mqttServerId, onCreate, canManage }) {
1078
+ const { t } = useRabbitmqTranslations();
1181
1079
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$3.Header, {
1182
1080
  className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1183
1081
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
@@ -1188,7 +1086,7 @@ function RabbitmqUserPanelCardHeader({ t, reload, loading, mqttServerId, setForm
1188
1086
  })]
1189
1087
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1190
1088
  className: "rmq:flex rmq:items-center rmq:gap-2",
1191
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1089
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$2, {
1192
1090
  isIconOnly: true,
1193
1091
  size: "sm",
1194
1092
  variant: "ghost",
@@ -1197,24 +1095,42 @@ function RabbitmqUserPanelCardHeader({ t, reload, loading, mqttServerId, setForm
1197
1095
  isPending: loading,
1198
1096
  "data-cy": `rabbitmq-user-panel-reload-${mqttServerId}`,
1199
1097
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$2, { className: "rmq:w-4 rmq:h-4" })
1200
- }), canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$3, {
1098
+ }), canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$2, {
1201
1099
  size: "sm",
1202
1100
  variant: "primary",
1203
- onPress: () => {
1204
- setFormUser(null);
1205
- setFormOpen(true);
1206
- },
1101
+ onPress: onCreate,
1207
1102
  "data-cy": `rabbitmq-user-panel-create-button-${mqttServerId}`,
1208
1103
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlusIcon, { className: "rmq:w-4 rmq:h-4" }), t("users.add")]
1209
1104
  })]
1210
1105
  })]
1211
1106
  });
1212
1107
  }
1213
- //#endregion
1214
- //#region frontend/src/users/RabbitmqUserPanel.tsx
1215
- var { StatusAlert: StatusAlert$2, StatusDialog: StatusDialog$1, TableDataLoadingIndicator: TableDataLoadingIndicator$2 } = await importShared("@attraccess/plugins-frontend-ui");
1216
- var { Button: Button$2, Card: Card$2, Chip: Chip$2, Table: Table$2, TableBody: TableBody$2, TableCell: TableCell$2, TableColumn: TableColumn$2, TableContent: TableContent$2, TableHeader: TableHeader$2, TableRow: TableRow$2, TableScrollContainer: TableScrollContainer$2 } = await importShared("@heroui/react");
1108
+ // frontend/src/users/errorTitle.ts
1109
+ function errorTitle(error, title) {
1110
+ return typeof error === "string" ? title : void 0;
1111
+ }
1112
+ // frontend/src/users/RabbitmqUserDeleteMessage.tsx
1113
+ var { StatusAlert: StatusAlert$4 } = await importShared("@attraccess/plugins-frontend-ui");
1114
+ var { useImperativeHandle: useImperativeHandle$1, useState: useState$4 } = await importShared("react");
1115
+ function RabbitmqUserDeleteMessage({ name, ref }) {
1116
+ const { t, tMessage } = useRabbitmqTranslations();
1117
+ const [error, setError] = useState$4(null);
1118
+ useImperativeHandle$1(ref, () => ({ showError: setError }), []);
1119
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1120
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1121
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("users.deleteDescription", { name }) }), error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$4, {
1122
+ status: "danger",
1123
+ title: errorTitle(error, t("users.deleteError")),
1124
+ "data-cy": "rabbitmq-user-delete-error-alert",
1125
+ children: tMessage(error)
1126
+ })]
1127
+ });
1128
+ }
1129
+ // frontend/src/users/RabbitmqUserTable.tsx
1130
+ var { TableActionsColumnHeader: TableActionsColumnHeader$1, TableRowActions: TableRowActions$1 } = await importShared("@attraccess/plugins-frontend-ui");
1131
+ var { Chip: Chip$2, Table: Table$2, TableBody: TableBody$2, TableCell: TableCell$2, TableColumn: TableColumn$2, TableContent: TableContent$2, TableHeader: TableHeader$2, TableRow: TableRow$2, TableScrollContainer: TableScrollContainer$2 } = await importShared("@heroui/react");
1217
1132
  var { KeyRoundIcon, PencilIcon, Trash2Icon } = await importShared("lucide-react");
1133
+ var { useRef: useRef$3 } = await importShared("react");
1218
1134
  function PermissionChips({ user }) {
1219
1135
  const { t } = useRabbitmqTranslations();
1220
1136
  if (user.permissions.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
@@ -1231,170 +1147,210 @@ function PermissionChips({ user }) {
1231
1147
  }, permission.vhost))
1232
1148
  });
1233
1149
  }
1234
- function errorTitle(error, title) {
1235
- return typeof error === "string" ? title : void 0;
1150
+ function RabbitmqUserTable({ users, canManage, onEdit, onPermissions, onDelete }) {
1151
+ const { t, language } = useRabbitmqTranslations();
1152
+ const deleteMessage = useRef$3(null);
1153
+ const confirmDelete = async (user) => {
1154
+ deleteMessage.current?.showError(null);
1155
+ try {
1156
+ await onDelete(user);
1157
+ } catch (err) {
1158
+ deleteMessage.current?.showError(err instanceof Error ? err.message : { key: "users.deleteError" });
1159
+ throw err;
1160
+ }
1161
+ };
1162
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$2, {
1163
+ "data-cy": "rabbitmq-user-panel-table",
1164
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$2, {
1165
+ "aria-label": t("users.title"),
1166
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$2, { children: [
1167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1168
+ isRowHeader: true,
1169
+ children: t("users.username")
1170
+ }),
1171
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: t("users.tags") }),
1172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: t("users.access") }),
1173
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1174
+ id: "actions",
1175
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableActionsColumnHeader$1, {})
1176
+ })
1177
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$2, {
1178
+ items: users,
1179
+ dependencies: [language],
1180
+ children: (user) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$2, {
1181
+ id: user.name,
1182
+ children: [
1183
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, {
1184
+ className: "rmq:whitespace-nowrap rmq:font-medium",
1185
+ children: user.name
1186
+ }),
1187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: user.tags.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1188
+ className: "rmq:text-xs rmq:text-default-400",
1189
+ children: t("users.none")
1190
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1191
+ className: "rmq:flex rmq:flex-wrap rmq:gap-1",
1192
+ children: user.tags.map((tag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$2, {
1193
+ size: "sm",
1194
+ color: "accent",
1195
+ variant: "soft",
1196
+ children: tag
1197
+ }, tag))
1198
+ }) }),
1199
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PermissionChips, { user }) }),
1200
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRowActions$1, {
1201
+ itemName: user.name,
1202
+ actions: [
1203
+ {
1204
+ key: "edit",
1205
+ label: t("users.edit"),
1206
+ icon: PencilIcon,
1207
+ onPress: () => onEdit(user),
1208
+ "data-cy": `rabbitmq-user-edit-button-${user.name}`
1209
+ },
1210
+ {
1211
+ key: "permissions",
1212
+ label: t("users.permissions"),
1213
+ icon: KeyRoundIcon,
1214
+ onPress: () => onPermissions(user),
1215
+ "data-cy": `rabbitmq-user-permissions-button-${user.name}`
1216
+ },
1217
+ {
1218
+ key: "delete",
1219
+ label: t("users.deleteTitle"),
1220
+ icon: Trash2Icon,
1221
+ tone: "danger",
1222
+ onPress: () => confirmDelete(user),
1223
+ "data-cy": `rabbitmq-user-delete-button-${user.name}`,
1224
+ confirm: {
1225
+ title: t("users.deleteTitle"),
1226
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserDeleteMessage, {
1227
+ name: user.name,
1228
+ ref: deleteMessage
1229
+ }),
1230
+ confirmLabel: t("common.delete"),
1231
+ cancelLabel: t("common.cancel"),
1232
+ "data-cy": `rabbitmq-user-delete-modal-${user.name}`,
1233
+ confirmDataCy: "rabbitmq-user-delete-confirm-button",
1234
+ cancelDataCy: "rabbitmq-user-delete-cancel-button"
1235
+ }
1236
+ }
1237
+ ]
1238
+ }) })
1239
+ ]
1240
+ }, user.name)
1241
+ })]
1242
+ }) })
1243
+ });
1236
1244
  }
1245
+ // frontend/src/users/RabbitmqUserPanel.tsx
1246
+ var { StatusAlert: StatusAlert$3, TableDataLoadingIndicator: TableDataLoadingIndicator$2 } = await importShared("@attraccess/plugins-frontend-ui");
1247
+ var { Card: Card$2 } = await importShared("@heroui/react");
1248
+ var { useCallback: useCallback$1, useEffect: useEffect$2, useRef: useRef$2, useState: useState$3 } = await importShared("react");
1237
1249
  function RabbitmqUserPanel({ mqttServerId, canManage = false }) {
1238
- const model = useRabbitmqUserPanelState({ mqttServerId });
1239
- if (!model.manageable) return null;
1250
+ const { t, tMessage } = useRabbitmqTranslations();
1251
+ const { result } = useDetection(mqttServerId);
1252
+ const [data, setData] = useState$3(null);
1253
+ const [loading, setLoading] = useState$3(false);
1254
+ const [loadError, setLoadError] = useState$3(null);
1255
+ const [formOpen, setFormOpen] = useState$3(false);
1256
+ const [formUser, setFormUser] = useState$3(null);
1257
+ const [permissionsUser, setPermissionsUser] = useState$3(null);
1258
+ const mounted = useRef$2(true);
1259
+ useEffect$2(() => {
1260
+ mounted.current = true;
1261
+ return () => {
1262
+ mounted.current = false;
1263
+ };
1264
+ }, []);
1265
+ const reload = useCallback$1(async () => {
1266
+ setLoading(true);
1267
+ setLoadError(null);
1268
+ try {
1269
+ const list = await fetchUsers(mqttServerId);
1270
+ if (mounted.current) {
1271
+ setData(list);
1272
+ setPermissionsUser((current) => current ? list.users.find((user) => user.name === current.name) ?? current : null);
1273
+ }
1274
+ } catch (err) {
1275
+ if (mounted.current) setLoadError(err instanceof Error ? err.message : { key: "users.loadError" });
1276
+ } finally {
1277
+ if (mounted.current) setLoading(false);
1278
+ }
1279
+ }, [mqttServerId]);
1280
+ const manageable = result?.isRabbitMQ === true && result.authOk;
1281
+ useEffect$2(() => {
1282
+ if (manageable) reload();
1283
+ }, [manageable, reload]);
1284
+ if (!manageable) return null;
1240
1285
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$2, {
1241
1286
  "data-cy": `rabbitmq-user-panel-${mqttServerId}`,
1242
1287
  className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
1243
1288
  children: [
1244
1289
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserPanelCardHeader, {
1245
- t: model.t,
1246
- reload: model.reload,
1247
- loading: model.loading,
1290
+ reload,
1291
+ loading,
1248
1292
  mqttServerId,
1249
- setFormUser: model.setFormUser,
1250
- setFormOpen: model.setFormOpen,
1293
+ onCreate: () => {
1294
+ setFormUser(null);
1295
+ setFormOpen(true);
1296
+ },
1251
1297
  canManage
1252
1298
  }),
1253
1299
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$2.Content, {
1254
1300
  className: "rmq:flex rmq:flex-col rmq:gap-3",
1255
1301
  children: [
1256
- model.loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$2, {
1302
+ loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$3, {
1257
1303
  status: "danger",
1258
- title: errorTitle(model.loadError, model.t("users.loadError")),
1304
+ title: errorTitle(loadError, t("users.loadError")),
1259
1305
  "data-cy": "rabbitmq-user-panel-error-alert",
1260
- children: model.tMessage(model.loadError)
1306
+ children: tMessage(loadError)
1261
1307
  }),
1262
- !model.data && !model.loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1308
+ !data && !loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1263
1309
  "data-cy": "rabbitmq-user-panel-loading-spinner",
1264
1310
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$2, {})
1265
1311
  }),
1266
- model.data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$2, {
1267
- "data-cy": "rabbitmq-user-panel-table",
1268
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$2, {
1269
- "aria-label": model.t("users.title"),
1270
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$2, { children: [
1271
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1272
- isRowHeader: true,
1273
- children: model.t("users.username")
1274
- }),
1275
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: model.t("users.tags") }),
1276
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: model.t("users.access") }),
1277
- canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: model.t("common.actions") })
1278
- ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$2, {
1279
- items: model.data.users,
1280
- dependencies: [model.language],
1281
- children: (user) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$2, {
1282
- id: user.name,
1283
- children: [
1284
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, {
1285
- className: "rmq:whitespace-nowrap rmq:font-medium",
1286
- children: user.name
1287
- }),
1288
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: user.tags.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1289
- className: "rmq:text-xs rmq:text-default-400",
1290
- children: model.t("users.none")
1291
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1292
- className: "rmq:flex rmq:flex-wrap rmq:gap-1",
1293
- children: user.tags.map((tag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$2, {
1294
- size: "sm",
1295
- color: "accent",
1296
- variant: "soft",
1297
- children: tag
1298
- }, tag))
1299
- }) }),
1300
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PermissionChips, { user }) }),
1301
- canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1302
- className: "rmq:flex rmq:flex-row rmq:gap-1",
1303
- children: [
1304
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$2, {
1305
- isIconOnly: true,
1306
- size: "sm",
1307
- variant: "ghost",
1308
- "aria-label": model.t("users.edit", { name: user.name }),
1309
- onPress: () => {
1310
- model.setFormUser(user);
1311
- model.setFormOpen(true);
1312
- },
1313
- "data-cy": `rabbitmq-user-edit-button-${user.name}`,
1314
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PencilIcon, { className: "rmq:w-4 rmq:h-4" })
1315
- }),
1316
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$2, {
1317
- isIconOnly: true,
1318
- size: "sm",
1319
- variant: "ghost",
1320
- "aria-label": model.t("users.permissions", { name: user.name }),
1321
- onPress: () => model.setPermissionsUser(user),
1322
- "data-cy": `rabbitmq-user-permissions-button-${user.name}`,
1323
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KeyRoundIcon, { className: "rmq:w-4 rmq:h-4" })
1324
- }),
1325
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$2, {
1326
- isIconOnly: true,
1327
- size: "sm",
1328
- variant: "ghost",
1329
- "aria-label": model.t("users.delete", { name: user.name }),
1330
- onPress: () => {
1331
- model.setDeleteError(null);
1332
- model.setUserToDelete(user);
1333
- },
1334
- "data-cy": `rabbitmq-user-delete-button-${user.name}`,
1335
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trash2Icon, { className: "rmq:w-4 rmq:h-4 rmq:text-danger" })
1336
- })
1337
- ]
1338
- }) })
1339
- ]
1340
- }, user.name)
1341
- })]
1342
- }) })
1312
+ data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserTable, {
1313
+ users: data.users,
1314
+ canManage,
1315
+ onEdit: (user) => {
1316
+ setFormUser(user);
1317
+ setFormOpen(true);
1318
+ },
1319
+ onPermissions: setPermissionsUser,
1320
+ onDelete: async (user) => {
1321
+ await deleteUser(mqttServerId, user.name);
1322
+ reload();
1323
+ }
1343
1324
  })
1344
1325
  ]
1345
1326
  }),
1346
1327
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserFormModal, {
1347
1328
  mqttServerId,
1348
- isOpen: model.formOpen,
1349
- user: model.formUser,
1350
- vhosts: model.data?.vhosts ?? [],
1351
- existingUsernames: model.data?.users.map((user) => user.name),
1352
- onClose: () => model.setFormOpen(false),
1353
- onSaved: () => void model.reload()
1329
+ isOpen: formOpen,
1330
+ user: formUser,
1331
+ vhosts: data?.vhosts ?? [],
1332
+ existingUsernames: data?.users.map((user) => user.name),
1333
+ onClose: () => setFormOpen(false),
1334
+ onSaved: () => void reload()
1354
1335
  }),
1355
1336
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqPermissionsModal, {
1356
1337
  mqttServerId,
1357
- isOpen: model.permissionsUser !== null,
1358
- user: model.permissionsUser,
1359
- vhosts: model.data?.vhosts ?? [],
1360
- onClose: () => model.setPermissionsUser(null),
1361
- onSaved: () => void model.reload()
1362
- }),
1363
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusDialog$1, {
1364
- isOpen: model.userToDelete !== null,
1365
- onClose: () => model.setUserToDelete(null),
1366
- status: "error",
1367
- title: model.t("users.deleteTitle"),
1368
- action: {
1369
- label: model.t("common.delete"),
1370
- onPress: model.confirmDelete,
1371
- isPending: model.deleting,
1372
- "data-cy": "rabbitmq-user-delete-confirm-button"
1373
- },
1374
- closeLabel: model.t("common.cancel"),
1375
- closeDataCy: "rabbitmq-user-delete-cancel-button",
1376
- "data-cy": `rabbitmq-user-delete-modal-${mqttServerId}`,
1377
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1378
- className: "rmq:flex rmq:flex-col rmq:gap-3",
1379
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: model.t("users.deleteDescription", { name: model.userToDelete?.name }) }), model.deleteError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$2, {
1380
- status: "danger",
1381
- title: errorTitle(model.deleteError, model.t("users.deleteError")),
1382
- "data-cy": "rabbitmq-user-delete-error-alert",
1383
- children: model.tMessage(model.deleteError)
1384
- })]
1385
- })
1338
+ isOpen: permissionsUser !== null,
1339
+ user: permissionsUser,
1340
+ vhosts: data?.vhosts ?? [],
1341
+ onClose: () => setPermissionsUser(null),
1342
+ onSaved: () => void reload()
1386
1343
  })
1387
1344
  ]
1388
1345
  });
1389
1346
  }
1390
- //#endregion
1391
- //#region frontend/src/usePolledResource.ts
1392
- var { useCallback, useEffect: useEffect$1, useRef, useState: useState$2 } = await importShared("react");
1347
+ // frontend/src/usePolledResource.ts
1348
+ var { useCallback, useEffect: useEffect$1, useRef: useRef$1, useState: useState$2 } = await importShared("react");
1393
1349
  function usePolledResource(fetcher, intervalMs, fallbackError) {
1394
1350
  const [data, setData] = useState$2(null);
1395
1351
  const [error, setError] = useState$2(null);
1396
1352
  const [loading, setLoading] = useState$2(false);
1397
- const latest = useRef({
1353
+ const latest = useRef$1({
1398
1354
  fetcher,
1399
1355
  fallbackError
1400
1356
  });
@@ -1402,9 +1358,9 @@ function usePolledResource(fetcher, intervalMs, fallbackError) {
1402
1358
  fetcher,
1403
1359
  fallbackError
1404
1360
  };
1405
- const mounted = useRef(true);
1406
- const inFlight = useRef(false);
1407
- const again = useRef(false);
1361
+ const mounted = useRef$1(true);
1362
+ const inFlight = useRef$1(false);
1363
+ const again = useRef$1(false);
1408
1364
  const load = useCallback(async (queueIfBusy) => {
1409
1365
  if (inFlight.current) {
1410
1366
  if (queueIfBusy) again.current = true;
@@ -1455,8 +1411,41 @@ function usePolledResource(fetcher, intervalMs, fallbackError) {
1455
1411
  reload
1456
1412
  };
1457
1413
  }
1458
- //#endregion
1459
- //#region frontend/src/connections/connections-api.ts
1414
+ // frontend/src/connections/RabbitmqConnectionCloseMessage.tsx
1415
+ var { StatusAlert: StatusAlert$2 } = await importShared("@attraccess/plugins-frontend-ui");
1416
+ var { Input, Label, TextField } = await importShared("@heroui/react");
1417
+ var { useImperativeHandle, useState: useState$1 } = await importShared("react");
1418
+ function RabbitmqConnectionCloseMessage({ name, ref }) {
1419
+ const { t } = useRabbitmqTranslations();
1420
+ const [reason, setReason] = useState$1("");
1421
+ const [error, setError] = useState$1(null);
1422
+ useImperativeHandle(ref, () => ({
1423
+ reason,
1424
+ showError: setError
1425
+ }), [reason]);
1426
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1427
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1428
+ children: [
1429
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("connections.closeDescription", { name }) }),
1430
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField, {
1431
+ value: reason,
1432
+ onChange: setReason,
1433
+ className: "rmq:w-full",
1434
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: t("connections.reason") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
1435
+ autoComplete: "off",
1436
+ "data-cy": "rabbitmq-connection-close-reason-input"
1437
+ })]
1438
+ }),
1439
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$2, {
1440
+ status: "danger",
1441
+ title: t("connections.closeError"),
1442
+ "data-cy": "rabbitmq-connection-close-error",
1443
+ children: error === t("connections.closeError") ? void 0 : error
1444
+ })
1445
+ ]
1446
+ });
1447
+ }
1448
+ // frontend/src/connections/connections-api.ts
1460
1449
  var api$2 = createPluginApiClient("/api/rabbitmq/connections");
1461
1450
  function fetchConnections(mqttServerId) {
1462
1451
  return api$2.request(`/${mqttServerId}`);
@@ -1470,226 +1459,196 @@ function closeConnection(mqttServerId, name, reason) {
1470
1459
  }
1471
1460
  });
1472
1461
  }
1473
- //#endregion
1474
- //#region frontend/src/connections/RabbitmqConnectionsPanel.tsx
1475
- var { Button: Button$1, EmptyState: EmptyState$1, StatusAlert: StatusAlert$1, StatusDialog, TableDataLoadingIndicator: TableDataLoadingIndicator$1 } = await importShared("@attraccess/plugins-frontend-ui");
1476
- var { Card: Card$1, Chip: Chip$1, Input, Label, Table: Table$1, TableBody: TableBody$1, TableCell: TableCell$1, TableColumn: TableColumn$1, TableContent: TableContent$1, TableHeader: TableHeader$1, TableRow: TableRow$1, TableScrollContainer: TableScrollContainer$1, TextField } = await importShared("@heroui/react");
1462
+ // frontend/src/connections/RabbitmqConnectionsPanel.tsx
1463
+ var { Button: Button$1, EmptyState: EmptyState$1, StatusAlert: StatusAlert$1, TableActionsColumnHeader, TableDataLoadingIndicator: TableDataLoadingIndicator$1, TableRowActions } = await importShared("@attraccess/plugins-frontend-ui");
1464
+ var { Card: Card$1, Chip: Chip$1, Table: Table$1, TableBody: TableBody$1, TableCell: TableCell$1, TableColumn: TableColumn$1, TableContent: TableContent$1, TableHeader: TableHeader$1, TableRow: TableRow$1, TableScrollContainer: TableScrollContainer$1 } = await importShared("@heroui/react");
1477
1465
  var { PlugZapIcon, RefreshCwIcon: RefreshCwIcon$1, UnplugIcon } = await importShared("lucide-react");
1478
- var { useState: useState$1 } = await importShared("react");
1466
+ var { useRef } = await importShared("react");
1479
1467
  var CONNECTIONS_POLL_INTERVAL_MS = 1e4;
1480
1468
  function RabbitmqConnectionsPanel({ mqttServerId, canManage }) {
1481
1469
  const { t } = useRabbitmqTranslations();
1482
1470
  const format = useRabbitmqFormatters();
1483
1471
  const { data, error, loading, reload } = usePolledResource(() => fetchConnections(mqttServerId), CONNECTIONS_POLL_INTERVAL_MS, t("connections.loadError"));
1484
- const [target, setTarget] = useState$1(null);
1485
- const [reason, setReason] = useState$1("");
1486
- const [closing, setClosing] = useState$1(false);
1487
- const [closeError, setCloseError] = useState$1(null);
1488
- const dismiss = () => {
1489
- setTarget(null);
1490
- setReason("");
1491
- setCloseError(null);
1492
- };
1493
- const confirmClose = async () => {
1494
- if (!target) return;
1495
- setClosing(true);
1496
- setCloseError(null);
1472
+ const closeMessage = useRef(null);
1473
+ const confirmClose = async (connection) => {
1474
+ const message = closeMessage.current;
1475
+ message?.showError(null);
1497
1476
  try {
1498
- await closeConnection(mqttServerId, target.name, reason);
1499
- dismiss();
1477
+ await closeConnection(mqttServerId, connection.name, message?.reason ?? "");
1500
1478
  reload();
1501
1479
  } catch (err) {
1502
- setCloseError(err instanceof Error && err.message ? err.message : t("connections.closeError"));
1480
+ message?.showError(err instanceof Error && err.message ? err.message : t("connections.closeError"));
1503
1481
  reload();
1504
- } finally {
1505
- setClosing(false);
1482
+ throw err;
1506
1483
  }
1507
1484
  };
1508
1485
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1, {
1509
1486
  "data-cy": `rabbitmq-connections-panel-${mqttServerId}`,
1510
1487
  className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
1511
- children: [
1512
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Header, {
1513
- className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1514
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1515
- className: "rmq:flex rmq:items-center rmq:gap-2",
1516
- children: [
1517
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlugZapIcon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }),
1518
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
1519
- className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
1520
- children: t("connections.title")
1521
- }),
1522
- data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$1, {
1523
- size: "sm",
1524
- variant: "soft",
1525
- children: format.number(data.total)
1526
- })
1527
- ]
1528
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
1529
- isIconOnly: true,
1530
- size: "sm",
1531
- variant: "ghost",
1532
- "aria-label": t("connections.reload"),
1533
- onPress: () => void reload(),
1534
- isPending: loading,
1535
- "data-cy": `rabbitmq-connections-reload-${mqttServerId}`,
1536
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$1, { className: "rmq:w-4 rmq:h-4" })
1537
- })]
1538
- }),
1539
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Content, {
1540
- className: "rmq:flex rmq:flex-col rmq:gap-3",
1488
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Header, {
1489
+ className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1490
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1491
+ className: "rmq:flex rmq:items-center rmq:gap-2",
1541
1492
  children: [
1542
- error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1543
- status: "danger",
1544
- title: t("connections.loadError"),
1545
- "data-cy": "rabbitmq-connections-error-alert",
1546
- children: error === t("connections.loadError") ? void 0 : error
1547
- }),
1548
- !data && !error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$1, {}),
1549
- data && data.connections.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState$1, { message: t("connections.empty") }),
1550
- data && data.truncated && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1551
- status: "warning",
1552
- children: t("connections.truncated", {
1553
- shown: format.number(data.connections.length),
1554
- total: format.number(data.total)
1555
- })
1493
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlugZapIcon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }),
1494
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
1495
+ className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
1496
+ children: t("connections.title")
1556
1497
  }),
1557
- data && data.connections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$1, {
1558
- "data-cy": "rabbitmq-connections-table",
1559
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$1, {
1560
- "aria-label": t("connections.title"),
1561
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$1, { children: [
1562
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1563
- isRowHeader: true,
1564
- children: t("connections.client")
1565
- }),
1566
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.user") }),
1567
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.peer") }),
1568
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.protocol") }),
1569
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("common.state") }),
1570
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.connectedSince") }),
1571
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.channels") }),
1572
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.traffic") }),
1573
- canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("common.actions") })
1574
- ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$1, {
1575
- items: data.connections,
1576
- children: (connection) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$1, {
1577
- id: connection.name,
1578
- children: [
1579
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1580
- className: "rmq:font-medium rmq:whitespace-nowrap",
1581
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1582
- title: connection.name,
1583
- children: connection.clientId ?? connection.name
1584
- })
1585
- }),
1586
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.user ?? "—" }),
1587
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1588
- className: "rmq:whitespace-nowrap",
1589
- children: connection.peerHost ? `${connection.peerHost}:${connection.peerPort ?? ""}` : "—"
1590
- }),
1591
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1592
- className: "rmq:whitespace-nowrap",
1593
- children: connection.protocol ?? "—"
1594
- }),
1595
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.state ?? "—" }),
1596
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1597
- className: "rmq:whitespace-nowrap",
1598
- children: format.dateTime(connection.connectedAt)
1599
- }),
1600
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: format.number(connection.channels) }),
1601
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell$1, {
1602
- className: "rmq:whitespace-nowrap rmq:text-xs",
1603
- children: [
1604
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1605
- "aria-hidden": true,
1606
- children: "↓ "
1607
- }),
1608
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1609
- className: "rmq:sr-only",
1610
- children: [t("connections.received"), ": "]
1611
- }),
1612
- format.bytes(connection.recvBytes),
1613
- " (",
1614
- format.rate(connection.recvRate, "B/s"),
1615
- ")",
1616
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
1617
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1618
- "aria-hidden": true,
1619
- children: "↑ "
1620
- }),
1621
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1622
- className: "rmq:sr-only",
1623
- children: [t("connections.sent"), ": "]
1624
- }),
1625
- format.bytes(connection.sendBytes),
1626
- " (",
1627
- format.rate(connection.sendRate, "B/s"),
1628
- ")"
1629
- ]
1630
- }),
1631
- canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
1632
- isIconOnly: true,
1633
- size: "sm",
1634
- variant: "ghost",
1635
- "aria-label": t("connections.close", { name: connection.clientId ?? connection.name }),
1636
- onPress: () => setTarget(connection),
1637
- "data-cy": "rabbitmq-connection-close-button",
1638
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UnplugIcon, { className: "rmq:w-4 rmq:h-4 rmq:text-danger" })
1639
- }) })
1640
- ]
1641
- }, connection.name)
1642
- })]
1643
- }) })
1498
+ data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$1, {
1499
+ size: "sm",
1500
+ variant: "soft",
1501
+ children: format.number(data.total)
1644
1502
  })
1645
1503
  ]
1646
- }),
1647
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusDialog, {
1648
- isOpen: target !== null,
1649
- onClose: dismiss,
1650
- status: "error",
1651
- title: t("connections.closeTitle"),
1652
- action: {
1653
- label: t("connections.closeConfirm"),
1654
- onPress: confirmClose,
1655
- isPending: closing,
1656
- "data-cy": "rabbitmq-connection-close-confirm-button"
1657
- },
1658
- closeLabel: t("common.cancel"),
1659
- "data-cy": `rabbitmq-connection-close-modal-${mqttServerId}`,
1660
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1661
- className: "rmq:flex rmq:flex-col rmq:gap-3",
1662
- children: [
1663
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("connections.closeDescription", { name: target?.clientId ?? target?.name ?? "" }) }),
1664
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField, {
1665
- value: reason,
1666
- onChange: setReason,
1667
- className: "rmq:w-full",
1668
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: t("connections.reason") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
1669
- autoComplete: "off",
1670
- "data-cy": "rabbitmq-connection-close-reason-input"
1671
- })]
1672
- }),
1673
- closeError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1674
- status: "danger",
1675
- title: t("connections.closeError"),
1676
- "data-cy": "rabbitmq-connection-close-error",
1677
- children: closeError === t("connections.closeError") ? void 0 : closeError
1678
- })
1679
- ]
1504
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
1505
+ isIconOnly: true,
1506
+ size: "sm",
1507
+ variant: "ghost",
1508
+ "aria-label": t("connections.reload"),
1509
+ onPress: () => void reload(),
1510
+ isPending: loading,
1511
+ "data-cy": `rabbitmq-connections-reload-${mqttServerId}`,
1512
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$1, { className: "rmq:w-4 rmq:h-4" })
1513
+ })]
1514
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Content, {
1515
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1516
+ children: [
1517
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1518
+ status: "danger",
1519
+ title: t("connections.loadError"),
1520
+ "data-cy": "rabbitmq-connections-error-alert",
1521
+ children: error === t("connections.loadError") ? void 0 : error
1522
+ }),
1523
+ !data && !error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$1, {}),
1524
+ data && data.connections.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState$1, { message: t("connections.empty") }),
1525
+ data && data.truncated && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1526
+ status: "warning",
1527
+ children: t("connections.truncated", {
1528
+ shown: format.number(data.connections.length),
1529
+ total: format.number(data.total)
1530
+ })
1531
+ }),
1532
+ data && data.connections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$1, {
1533
+ "data-cy": "rabbitmq-connections-table",
1534
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$1, {
1535
+ "aria-label": t("connections.title"),
1536
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$1, { children: [
1537
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1538
+ isRowHeader: true,
1539
+ children: t("connections.client")
1540
+ }),
1541
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.user") }),
1542
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.peer") }),
1543
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.protocol") }),
1544
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("common.state") }),
1545
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.connectedSince") }),
1546
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.channels") }),
1547
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.traffic") }),
1548
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1549
+ id: "actions",
1550
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableActionsColumnHeader, {})
1551
+ })
1552
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$1, {
1553
+ items: data.connections,
1554
+ children: (connection) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$1, {
1555
+ id: connection.name,
1556
+ children: [
1557
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1558
+ className: "rmq:font-medium rmq:whitespace-nowrap",
1559
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1560
+ title: connection.name,
1561
+ children: connection.clientId ?? connection.name
1562
+ })
1563
+ }),
1564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.user ?? "—" }),
1565
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1566
+ className: "rmq:whitespace-nowrap",
1567
+ children: connection.peerHost ? `${connection.peerHost}:${connection.peerPort ?? ""}` : "—"
1568
+ }),
1569
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1570
+ className: "rmq:whitespace-nowrap",
1571
+ children: connection.protocol ?? "—"
1572
+ }),
1573
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.state ?? "—" }),
1574
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1575
+ className: "rmq:whitespace-nowrap",
1576
+ children: format.dateTime(connection.connectedAt)
1577
+ }),
1578
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: format.number(connection.channels) }),
1579
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell$1, {
1580
+ className: "rmq:whitespace-nowrap rmq:text-xs",
1581
+ children: [
1582
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1583
+ "aria-hidden": true,
1584
+ children: "↓ "
1585
+ }),
1586
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1587
+ className: "rmq:sr-only",
1588
+ children: [t("connections.received"), ": "]
1589
+ }),
1590
+ format.bytes(connection.recvBytes),
1591
+ " (",
1592
+ format.rate(connection.recvRate, "B/s"),
1593
+ ")",
1594
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
1595
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1596
+ "aria-hidden": true,
1597
+ children: "↑ "
1598
+ }),
1599
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1600
+ className: "rmq:sr-only",
1601
+ children: [t("connections.sent"), ": "]
1602
+ }),
1603
+ format.bytes(connection.sendBytes),
1604
+ " (",
1605
+ format.rate(connection.sendRate, "B/s"),
1606
+ ")"
1607
+ ]
1608
+ }),
1609
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRowActions, {
1610
+ itemName: connection.clientId ?? connection.name,
1611
+ actions: [{
1612
+ key: "close",
1613
+ label: t("connections.closeTitle"),
1614
+ icon: UnplugIcon,
1615
+ tone: "danger",
1616
+ onPress: () => confirmClose(connection),
1617
+ "data-cy": `rabbitmq-connection-close-button-${connection.name}`,
1618
+ confirm: {
1619
+ title: t("connections.closeTitle"),
1620
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqConnectionCloseMessage, {
1621
+ name: connection.clientId ?? connection.name,
1622
+ ref: closeMessage
1623
+ }),
1624
+ confirmLabel: t("connections.closeConfirm"),
1625
+ cancelLabel: t("common.cancel"),
1626
+ "data-cy": `rabbitmq-connection-close-modal-${mqttServerId}`,
1627
+ confirmDataCy: "rabbitmq-connection-close-confirm-button"
1628
+ }
1629
+ }]
1630
+ }) })
1631
+ ]
1632
+ }, connection.name)
1633
+ })]
1634
+ }) })
1680
1635
  })
1681
- })
1682
- ]
1636
+ ]
1637
+ })]
1683
1638
  });
1684
1639
  }
1685
- //#endregion
1686
- //#region frontend/src/stats/stats-api.ts
1640
+ // frontend/src/Duration.tsx
1641
+ var { useFormatedDuration } = await importShared("@attraccess/plugins-frontend-ui");
1642
+ function Duration({ ms }) {
1643
+ const formatted = useFormatedDuration(ms == null ? 0 : Math.floor(ms / 6e4));
1644
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: ms == null ? "—" : formatted });
1645
+ }
1646
+ // frontend/src/stats/stats-api.ts
1687
1647
  var api$1 = createPluginApiClient("/api/rabbitmq/stats");
1688
1648
  function fetchStats(mqttServerId) {
1689
1649
  return api$1.request(`/${mqttServerId}`);
1690
1650
  }
1691
- //#endregion
1692
- //#region frontend/src/stats/RabbitmqStatsPanel.tsx
1651
+ // frontend/src/stats/RabbitmqStatsPanel.tsx
1693
1652
  var { Button, EmptyState, StatusAlert, TableDataLoadingIndicator } = await importShared("@attraccess/plugins-frontend-ui");
1694
1653
  var { Card, Chip, Table, TableBody, TableCell, TableColumn, TableContent, TableHeader, TableRow, TableScrollContainer } = await importShared("@heroui/react");
1695
1654
  var { BarChart3Icon, RefreshCwIcon, TriangleAlertIcon } = await importShared("lucide-react");
@@ -1916,8 +1875,7 @@ function RabbitmqStatsPanel({ mqttServerId }) {
1916
1875
  })]
1917
1876
  });
1918
1877
  }
1919
- //#endregion
1920
- //#region frontend/src/capabilities.ts
1878
+ // frontend/src/capabilities.ts
1921
1879
  var { useEffect, useState } = await importShared("react");
1922
1880
  var api = createPluginApiClient("/api/rabbitmq/capabilities");
1923
1881
  function useCapabilities(enabled = true) {
@@ -1934,8 +1892,7 @@ function useCapabilities(enabled = true) {
1934
1892
  }, [enabled]);
1935
1893
  return capabilities;
1936
1894
  }
1937
- //#endregion
1938
- //#region frontend/src/plugin.tsx
1895
+ // frontend/src/plugin.tsx
1939
1896
  var MQTT_SERVER_DETAIL_SLOT = "mqtt.server.detail";
1940
1897
  var MQTT_SERVER_LIST_ROW_SLOT = "mqtt.server.list.row";
1941
1898
  function RabbitmqDataPanels({ mqttServerId, canManage }) {
@@ -1945,6 +1902,9 @@ function RabbitmqDataPanels({ mqttServerId, canManage }) {
1945
1902
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqStatsPanel, { mqttServerId })] });
1946
1903
  }
1947
1904
  function RabbitmqDetailSlot({ mqttServerId }) {
1905
+ return useCanViewBroker() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqDetailPanels, { mqttServerId }) : null;
1906
+ }
1907
+ function RabbitmqDetailPanels({ mqttServerId }) {
1948
1908
  const { result } = useDetection(mqttServerId);
1949
1909
  const { canManage } = useCapabilities(result?.isRabbitMQ === true);
1950
1910
  if (!result?.isRabbitMQ) return null;
@@ -1965,7 +1925,7 @@ function RabbitmqDetailSlot({ mqttServerId }) {
1965
1925
  }
1966
1926
  var RabbitmqPlugin = class {
1967
1927
  getPluginName() {
1968
- return "rabbitmq-plugin@0.1.0";
1928
+ return "rabbitmq-plugin@0.2.0";
1969
1929
  }
1970
1930
  getDependencies() {
1971
1931
  return [];
@@ -1973,7 +1933,9 @@ var RabbitmqPlugin = class {
1973
1933
  init(_store) {}
1974
1934
  activate() {}
1975
1935
  deactivate() {}
1976
- onApiAuthStateChange(_authData) {}
1936
+ onApiAuthStateChange(authData) {
1937
+ setRabbitmqAuthData(authData);
1938
+ }
1977
1939
  onApiEndpointChange(_endpoint) {}
1978
1940
  getSlotContributions() {
1979
1941
  return [{
@@ -1987,5 +1949,4 @@ var RabbitmqPlugin = class {
1987
1949
  }];
1988
1950
  }
1989
1951
  };
1990
- //#endregion
1991
1952
  export { RabbitmqDetailSlot, RabbitmqPlugin as default };