@attraccess/plugin-rabbitmq 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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() {
@@ -61,8 +60,9 @@ function createPluginApiClient(basePath = "") {
61
60
  }
62
61
  };
63
62
  }
64
- //#endregion
65
- //#region ../../../node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react-jsx-runtime.production.js
63
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.license.ts
64
+ var { useCallback: useCallback$5, useEffect: useEffect$7, useState: useState$8 } = await importShared("react");
65
+ // ../../../node_modules/.pnpm/react@19.3.1/node_modules/react/cjs/react-jsx-runtime.production.js
66
66
  /**
67
67
  * @license React
68
68
  * react-jsx-runtime.production.js
@@ -96,27 +96,28 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((expor
96
96
  exports.jsx = jsxProd;
97
97
  exports.jsxs = jsxProd;
98
98
  }));
99
- //#endregion
100
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.live-updates.tsx
99
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.live-updates.tsx
101
100
  var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
102
101
  module.exports = require_react_jsx_runtime_production();
103
102
  })))();
104
- var { createContext, useCallback: useCallback$4, useContext, useEffect: useEffect$6, useRef: useRef$2 } = await importShared("react");
103
+ var { createContext, useCallback: useCallback$4, useContext, useEffect: useEffect$6, useRef: useRef$4 } = await importShared("react");
105
104
  var contextKey = Symbol.for("attraccess.plugin.live-updates.context");
106
105
  var contexts = globalThis;
107
106
  contexts[contextKey] ??= createContext(null);
108
107
  var identityKey = Symbol.for("attraccess.plugin.live-updates.identity");
109
108
  var identities = globalThis;
110
109
  identities[identityKey] ??= createContext(null);
111
- //#endregion
112
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-drawer.tsx
110
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.pluggable.ts
111
+ /** Whether the signed-in user holds `permission`. False when signed out or when the host sends no permissions. */
112
+ function hasPluginAuthPermission(authData, permission) {
113
+ return (authData?.effectivePermissions ?? (authData?.user)?.effectivePermissions)?.includes(permission) ?? false;
114
+ }
115
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-drawer.tsx
113
116
  var { StandardDrawer: SharedStandardDrawer } = await importShared("@attraccess/plugins-frontend-ui");
114
- //#endregion
115
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-modal.tsx
117
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-modal.tsx
116
118
  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");
119
+ // frontend/src/detection/detection.ts
120
+ var { useCallback: useCallback$3, useEffect: useEffect$5, useState: useState$7 } = await importShared("react");
120
121
  var api$4 = createPluginApiClient("/api/rabbitmq/detection");
121
122
  function fetchDetection(mqttServerId, refresh) {
122
123
  return api$4.request(`/${mqttServerId}`, { query: { refresh: refresh ? "true" : void 0 } });
@@ -163,7 +164,7 @@ function ensureLoaded(mqttServerId, refresh) {
163
164
  notify(mqttServerId);
164
165
  }
165
166
  function useDetection(mqttServerId) {
166
- const [, forceRender] = useState$6(0);
167
+ const [, forceRender] = useState$7(0);
167
168
  useEffect$5(() => {
168
169
  const rerender = () => forceRender((n) => n + 1);
169
170
  let set = subscribers.get(mqttServerId);
@@ -187,11 +188,30 @@ function useDetection(mqttServerId) {
187
188
  refresh
188
189
  };
189
190
  }
190
- //#endregion
191
- //#region frontend/src/users/RabbitmqListBadge.tsx
191
+ // backend/permission-keys.ts
192
+ var RABBITMQ_BROKER_READ = "rabbitmq.broker.read";
193
+ // frontend/src/access.ts
194
+ var { useSyncExternalStore } = await importShared("react");
195
+ var authData = null;
196
+ var listeners = /* @__PURE__ */ new Set();
197
+ function setRabbitmqAuthData(next) {
198
+ authData = next;
199
+ for (const listener of listeners) listener();
200
+ }
201
+ var subscribe = (listener) => {
202
+ listeners.add(listener);
203
+ return () => listeners.delete(listener);
204
+ };
205
+ function useCanViewBroker() {
206
+ return hasPluginAuthPermission(useSyncExternalStore(subscribe, () => authData), RABBITMQ_BROKER_READ);
207
+ }
208
+ // frontend/src/users/RabbitmqListBadge.tsx
192
209
  var { Chip: Chip$4 } = await importShared("@heroui/react");
193
210
  var { RabbitIcon: RabbitIcon$1 } = await importShared("lucide-react");
194
211
  function RabbitmqListBadge({ mqttServerId }) {
212
+ return useCanViewBroker() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DetectedBadge, { mqttServerId }) : null;
213
+ }
214
+ function DetectedBadge({ mqttServerId }) {
195
215
  const { result } = useDetection(mqttServerId);
196
216
  if (!result?.isRabbitMQ) return null;
197
217
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Chip$4, {
@@ -222,9 +242,8 @@ var en_default = {
222
242
  "tags": "Tags",
223
243
  "access": "Vhost access",
224
244
  "none": "none",
225
- "edit": "Edit user {{name}}",
226
- "permissions": "Edit permissions of {{name}}",
227
- "delete": "Delete user {{name}}",
245
+ "edit": "Edit user",
246
+ "permissions": "Edit permissions",
228
247
  "deleteTitle": "Delete user",
229
248
  "deleteDescription": "Delete the RabbitMQ user {{name}}? Connected clients using this account will be disconnected and its permissions removed.",
230
249
  "loadError": "Loading users failed.",
@@ -268,7 +287,6 @@ var en_default = {
268
287
  "close": "Close",
269
288
  "save": "Save",
270
289
  "delete": "Delete",
271
- "actions": "Actions",
272
290
  "state": "State",
273
291
  "yes": "Yes",
274
292
  "no": "No"
@@ -286,7 +304,6 @@ var en_default = {
286
304
  "connectedSince": "Connected since",
287
305
  "channels": "Channels",
288
306
  "traffic": "Traffic (received / sent)",
289
- "close": "Close connection {{name}}",
290
307
  "closeTitle": "Close connection",
291
308
  "closeDescription": "Close the connection of {{name}}? The client is disconnected and may reconnect on its own.",
292
309
  "closeConfirm": "Close connection",
@@ -348,9 +365,8 @@ var de_default = {
348
365
  "tags": "Tags",
349
366
  "access": "Vhost-Zugriff",
350
367
  "none": "keine",
351
- "edit": "Benutzer {{name}} bearbeiten",
352
- "permissions": "Berechtigungen von {{name}} bearbeiten",
353
- "delete": "Benutzer {{name}} löschen",
368
+ "edit": "Benutzer bearbeiten",
369
+ "permissions": "Berechtigungen bearbeiten",
354
370
  "deleteTitle": "Benutzer löschen",
355
371
  "deleteDescription": "RabbitMQ-Benutzer {{name}} löschen? Verbundene Clients mit diesem Konto werden getrennt und seine Berechtigungen entfernt.",
356
372
  "loadError": "Benutzer konnten nicht geladen werden.",
@@ -394,7 +410,6 @@ var de_default = {
394
410
  "close": "Schließen",
395
411
  "save": "Speichern",
396
412
  "delete": "Löschen",
397
- "actions": "Aktionen",
398
413
  "state": "Status",
399
414
  "yes": "Ja",
400
415
  "no": "Nein"
@@ -412,7 +427,6 @@ var de_default = {
412
427
  "connectedSince": "Verbunden seit",
413
428
  "channels": "Kanäle",
414
429
  "traffic": "Datenverkehr (empfangen / gesendet)",
415
- "close": "Verbindung {{name}} schließen",
416
430
  "closeTitle": "Verbindung schließen",
417
431
  "closeDescription": "Die Verbindung von {{name}} schließen? Der Client wird getrennt und kann sich selbstständig neu verbinden.",
418
432
  "closeConfirm": "Verbindung schließen",
@@ -454,16 +468,14 @@ var de_default = {
454
468
  "queuesTruncated": "Die ersten {{shown}} von {{total}} Queues werden angezeigt."
455
469
  }
456
470
  };
457
- //#endregion
458
- //#region frontend/src/i18n.ts
471
+ // frontend/src/i18n.ts
459
472
  var { useTranslations } = await importShared("@attraccess/plugins-frontend-ui");
460
473
  var useRabbitmqTranslations = () => useTranslations({
461
474
  en: en_default,
462
475
  de: de_default
463
476
  }, { escapeValues: false });
464
- //#endregion
465
- //#region frontend/src/format.tsx
466
- var { useDateTimeFormatter, useFormatedDuration, useNumberFormatter } = await importShared("@attraccess/plugins-frontend-ui");
477
+ // frontend/src/useRabbitmqFormatters.ts
478
+ var { useDateTimeFormatter, useNumberFormatter } = await importShared("@attraccess/plugins-frontend-ui");
467
479
  var { useCallback: useCallback$2, useMemo } = await importShared("react");
468
480
  var BYTE_UNITS = [
469
481
  "B",
@@ -520,13 +532,8 @@ function useRabbitmqFormatters() {
520
532
  time
521
533
  ]);
522
534
  }
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");
535
+ // frontend/src/detection/RabbitmqStatusPanel.tsx
536
+ var { Button: Button$5 } = await importShared("@attraccess/plugins-frontend-ui");
530
537
  var { Alert: Alert$2, AlertContent: AlertContent$2, AlertDescription: AlertDescription$2, Card: Card$4, Chip: Chip$3 } = await importShared("@heroui/react");
531
538
  var { CheckCircle2Icon, RabbitIcon, RefreshCwIcon: RefreshCwIcon$3, XCircleIcon } = await importShared("lucide-react");
532
539
  function StatusRow({ ok, label, value }) {
@@ -568,7 +575,7 @@ function RabbitmqStatusPanel({ mqttServerId }) {
568
575
  children: t("status.detected")
569
576
  })
570
577
  ]
571
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$6, {
578
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
572
579
  isIconOnly: true,
573
580
  size: "sm",
574
581
  variant: "ghost",
@@ -630,8 +637,7 @@ function RabbitmqStatusPanel({ mqttServerId }) {
630
637
  })]
631
638
  });
632
639
  }
633
- //#endregion
634
- //#region frontend/src/users/users-api.ts
640
+ // frontend/src/users/users-api.ts
635
641
  var DEFAULT_MQTT_PERMISSIONS = {
636
642
  configure: "^mqtt-subscription-.*$",
637
643
  write: "^(amq\\.topic|mqtt-subscription-.*)$",
@@ -662,12 +668,11 @@ function clearPermissions(mqttServerId, username, vhost) {
662
668
  query: { vhost }
663
669
  });
664
670
  }
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");
671
+ // frontend/src/users/permissions/RabbitmqPermissionsModal.tsx
672
+ var { Button: Button$4, EmptyState: EmptyState$2, StandardModal: StandardModal$1 } = await importShared("@attraccess/plugins-frontend-ui");
668
673
  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
674
  var { PlusIcon: PlusIcon$1, Trash2Icon: Trash2Icon$1 } = await importShared("lucide-react");
670
- var { useEffect: useEffect$4, useState: useState$5 } = await importShared("react");
675
+ var { useEffect: useEffect$4, useState: useState$6 } = await importShared("react");
671
676
  function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
672
677
  const { t } = useRabbitmqTranslations();
673
678
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
@@ -683,7 +688,7 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
683
688
  " ",
684
689
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: row.vhost })
685
690
  ]
686
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
691
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
687
692
  isIconOnly: true,
688
693
  size: "sm",
689
694
  variant: "ghost",
@@ -734,7 +739,7 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
734
739
  }),
735
740
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
736
741
  className: "rmq:flex rmq:flex-wrap rmq:justify-end rmq:gap-2",
737
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
742
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
738
743
  size: "sm",
739
744
  variant: "ghost",
740
745
  onPress: () => onChange({
@@ -744,7 +749,7 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
744
749
  isDisabled: busy,
745
750
  "data-cy": `rabbitmq-permissions-mqtt-defaults-button-${row.vhost}`,
746
751
  children: t("permissions.defaults")
747
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
752
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
748
753
  size: "sm",
749
754
  variant: "primary",
750
755
  onPress: onSave,
@@ -758,10 +763,10 @@ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
758
763
  }
759
764
  function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose, onSaved }) {
760
765
  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);
766
+ const [rows, setRows] = useState$6([]);
767
+ const [newVhost, setNewVhost] = useState$6("");
768
+ const [busyVhost, setBusyVhost] = useState$6(null);
769
+ const [error, setError] = useState$6(null);
765
770
  useEffect$4(() => {
766
771
  if (!isOpen) return;
767
772
  setRows((user?.permissions ?? []).map((permission) => ({
@@ -869,7 +874,7 @@ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose,
869
874
  autoComplete: "off",
870
875
  "data-cy": "rabbitmq-permissions-add-vhost-input"
871
876
  })]
872
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$5, {
877
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$4, {
873
878
  variant: "secondary",
874
879
  onPress: addVhost,
875
880
  isDisabled: newVhost.trim().length === 0,
@@ -884,7 +889,7 @@ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose,
884
889
  })
885
890
  ]
886
891
  }),
887
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
892
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
888
893
  variant: "secondary",
889
894
  onPress: onClose,
890
895
  "data-cy": "rabbitmq-permissions-close-button",
@@ -893,19 +898,23 @@ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose,
893
898
  ] })
894
899
  });
895
900
  }
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 }) {
901
+ // frontend/src/users/RabbitmqUserFormModal.tsx
902
+ var { Button: Button$3, StandardModal } = await importShared("@attraccess/plugins-frontend-ui");
903
+ var { Alert, AlertContent, AlertDescription, Checkbox, Form, Input: Input$1, Label: Label$1, ModalBody, ModalFooter, ModalHeader, ModalHeading, TextField: TextField$1 } = await importShared("@heroui/react");
904
+ var { useEffect: useEffect$3, useState: useState$5 } = await importShared("react");
905
+ function parseTags(value) {
906
+ return value.split(",").map((tag) => tag.trim()).filter((tag) => tag.length > 0);
907
+ }
908
+ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUsernames = [], onClose, onSaved }) {
900
909
  const { t, tMessage } = useRabbitmqTranslations();
901
910
  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);
911
+ const [username, setUsername] = useState$5("");
912
+ const [password, setPassword] = useState$5("");
913
+ const [tags, setTags] = useState$5("");
914
+ const [grantMqttDefaults, setGrantMqttDefaults] = useState$5(true);
915
+ const [vhost, setVhost] = useState$5("/");
916
+ const [saving, setSaving] = useState$5(false);
917
+ const [error, setError] = useState$5(null);
909
918
  useEffect$3(() => {
910
919
  if (!isOpen) return;
911
920
  setUsername(user?.name ?? "");
@@ -952,44 +961,6 @@ function useRabbitmqUserFormModalState({ mqttServerId, isOpen, user, vhosts, exi
952
961
  setSaving(false);
953
962
  }
954
963
  };
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
964
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandardModal, {
994
965
  size: "md",
995
966
  isOpen,
@@ -1074,12 +1045,12 @@ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUse
1074
1045
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription, { children: tMessage(error) }) })
1075
1046
  })
1076
1047
  ]
1077
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
1048
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1078
1049
  variant: "secondary",
1079
1050
  onPress: onClose,
1080
1051
  "data-cy": "rabbitmq-user-form-cancel-button",
1081
1052
  children: t("common.cancel")
1082
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
1053
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1083
1054
  variant: "primary",
1084
1055
  type: "submit",
1085
1056
  isPending: saving,
@@ -1089,95 +1060,12 @@ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUse
1089
1060
  })] })
1090
1061
  });
1091
1062
  }
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");
1063
+ // frontend/src/users/RabbitmqUserPanelCardHeader.tsx
1064
+ var { Button: Button$2 } = await importShared("@attraccess/plugins-frontend-ui");
1178
1065
  var { Card: Card$3 } = await importShared("@heroui/react");
1179
1066
  var { PlusIcon, RefreshCwIcon: RefreshCwIcon$2, UsersIcon } = await importShared("lucide-react");
1180
- function RabbitmqUserPanelCardHeader({ t, reload, loading, mqttServerId, setFormUser, setFormOpen, canManage }) {
1067
+ function RabbitmqUserPanelCardHeader({ reload, loading, mqttServerId, onCreate, canManage }) {
1068
+ const { t } = useRabbitmqTranslations();
1181
1069
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$3.Header, {
1182
1070
  className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1183
1071
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
@@ -1188,7 +1076,7 @@ function RabbitmqUserPanelCardHeader({ t, reload, loading, mqttServerId, setForm
1188
1076
  })]
1189
1077
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1190
1078
  className: "rmq:flex rmq:items-center rmq:gap-2",
1191
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1079
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$2, {
1192
1080
  isIconOnly: true,
1193
1081
  size: "sm",
1194
1082
  variant: "ghost",
@@ -1197,24 +1085,42 @@ function RabbitmqUserPanelCardHeader({ t, reload, loading, mqttServerId, setForm
1197
1085
  isPending: loading,
1198
1086
  "data-cy": `rabbitmq-user-panel-reload-${mqttServerId}`,
1199
1087
  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, {
1088
+ }), canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$2, {
1201
1089
  size: "sm",
1202
1090
  variant: "primary",
1203
- onPress: () => {
1204
- setFormUser(null);
1205
- setFormOpen(true);
1206
- },
1091
+ onPress: onCreate,
1207
1092
  "data-cy": `rabbitmq-user-panel-create-button-${mqttServerId}`,
1208
1093
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlusIcon, { className: "rmq:w-4 rmq:h-4" }), t("users.add")]
1209
1094
  })]
1210
1095
  })]
1211
1096
  });
1212
1097
  }
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");
1098
+ // frontend/src/users/errorTitle.ts
1099
+ function errorTitle(error, title) {
1100
+ return typeof error === "string" ? title : void 0;
1101
+ }
1102
+ // frontend/src/users/RabbitmqUserDeleteMessage.tsx
1103
+ var { StatusAlert: StatusAlert$4 } = await importShared("@attraccess/plugins-frontend-ui");
1104
+ var { useImperativeHandle: useImperativeHandle$1, useState: useState$4 } = await importShared("react");
1105
+ function RabbitmqUserDeleteMessage({ name, ref }) {
1106
+ const { t, tMessage } = useRabbitmqTranslations();
1107
+ const [error, setError] = useState$4(null);
1108
+ useImperativeHandle$1(ref, () => ({ showError: setError }), []);
1109
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1110
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1111
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("users.deleteDescription", { name }) }), error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$4, {
1112
+ status: "danger",
1113
+ title: errorTitle(error, t("users.deleteError")),
1114
+ "data-cy": "rabbitmq-user-delete-error-alert",
1115
+ children: tMessage(error)
1116
+ })]
1117
+ });
1118
+ }
1119
+ // frontend/src/users/RabbitmqUserTable.tsx
1120
+ var { TableActionsColumnHeader: TableActionsColumnHeader$1, TableRowActions: TableRowActions$1 } = await importShared("@attraccess/plugins-frontend-ui");
1121
+ 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
1122
  var { KeyRoundIcon, PencilIcon, Trash2Icon } = await importShared("lucide-react");
1123
+ var { useRef: useRef$3 } = await importShared("react");
1218
1124
  function PermissionChips({ user }) {
1219
1125
  const { t } = useRabbitmqTranslations();
1220
1126
  if (user.permissions.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
@@ -1231,170 +1137,210 @@ function PermissionChips({ user }) {
1231
1137
  }, permission.vhost))
1232
1138
  });
1233
1139
  }
1234
- function errorTitle(error, title) {
1235
- return typeof error === "string" ? title : void 0;
1140
+ function RabbitmqUserTable({ users, canManage, onEdit, onPermissions, onDelete }) {
1141
+ const { t, language } = useRabbitmqTranslations();
1142
+ const deleteMessage = useRef$3(null);
1143
+ const confirmDelete = async (user) => {
1144
+ deleteMessage.current?.showError(null);
1145
+ try {
1146
+ await onDelete(user);
1147
+ } catch (err) {
1148
+ deleteMessage.current?.showError(err instanceof Error ? err.message : { key: "users.deleteError" });
1149
+ throw err;
1150
+ }
1151
+ };
1152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$2, {
1153
+ "data-cy": "rabbitmq-user-panel-table",
1154
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$2, {
1155
+ "aria-label": t("users.title"),
1156
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$2, { children: [
1157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1158
+ isRowHeader: true,
1159
+ children: t("users.username")
1160
+ }),
1161
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: t("users.tags") }),
1162
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: t("users.access") }),
1163
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1164
+ id: "actions",
1165
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableActionsColumnHeader$1, {})
1166
+ })
1167
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$2, {
1168
+ items: users,
1169
+ dependencies: [language],
1170
+ children: (user) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$2, {
1171
+ id: user.name,
1172
+ children: [
1173
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, {
1174
+ className: "rmq:whitespace-nowrap rmq:font-medium",
1175
+ children: user.name
1176
+ }),
1177
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: user.tags.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1178
+ className: "rmq:text-xs rmq:text-default-400",
1179
+ children: t("users.none")
1180
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1181
+ className: "rmq:flex rmq:flex-wrap rmq:gap-1",
1182
+ children: user.tags.map((tag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$2, {
1183
+ size: "sm",
1184
+ color: "accent",
1185
+ variant: "soft",
1186
+ children: tag
1187
+ }, tag))
1188
+ }) }),
1189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PermissionChips, { user }) }),
1190
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRowActions$1, {
1191
+ itemName: user.name,
1192
+ actions: [
1193
+ {
1194
+ key: "edit",
1195
+ label: t("users.edit"),
1196
+ icon: PencilIcon,
1197
+ onPress: () => onEdit(user),
1198
+ "data-cy": `rabbitmq-user-edit-button-${user.name}`
1199
+ },
1200
+ {
1201
+ key: "permissions",
1202
+ label: t("users.permissions"),
1203
+ icon: KeyRoundIcon,
1204
+ onPress: () => onPermissions(user),
1205
+ "data-cy": `rabbitmq-user-permissions-button-${user.name}`
1206
+ },
1207
+ {
1208
+ key: "delete",
1209
+ label: t("users.deleteTitle"),
1210
+ icon: Trash2Icon,
1211
+ tone: "danger",
1212
+ onPress: () => confirmDelete(user),
1213
+ "data-cy": `rabbitmq-user-delete-button-${user.name}`,
1214
+ confirm: {
1215
+ title: t("users.deleteTitle"),
1216
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserDeleteMessage, {
1217
+ name: user.name,
1218
+ ref: deleteMessage
1219
+ }),
1220
+ confirmLabel: t("common.delete"),
1221
+ cancelLabel: t("common.cancel"),
1222
+ "data-cy": `rabbitmq-user-delete-modal-${user.name}`,
1223
+ confirmDataCy: "rabbitmq-user-delete-confirm-button",
1224
+ cancelDataCy: "rabbitmq-user-delete-cancel-button"
1225
+ }
1226
+ }
1227
+ ]
1228
+ }) })
1229
+ ]
1230
+ }, user.name)
1231
+ })]
1232
+ }) })
1233
+ });
1236
1234
  }
1235
+ // frontend/src/users/RabbitmqUserPanel.tsx
1236
+ var { StatusAlert: StatusAlert$3, TableDataLoadingIndicator: TableDataLoadingIndicator$2 } = await importShared("@attraccess/plugins-frontend-ui");
1237
+ var { Card: Card$2 } = await importShared("@heroui/react");
1238
+ var { useCallback: useCallback$1, useEffect: useEffect$2, useRef: useRef$2, useState: useState$3 } = await importShared("react");
1237
1239
  function RabbitmqUserPanel({ mqttServerId, canManage = false }) {
1238
- const model = useRabbitmqUserPanelState({ mqttServerId });
1239
- if (!model.manageable) return null;
1240
+ const { t, tMessage } = useRabbitmqTranslations();
1241
+ const { result } = useDetection(mqttServerId);
1242
+ const [data, setData] = useState$3(null);
1243
+ const [loading, setLoading] = useState$3(false);
1244
+ const [loadError, setLoadError] = useState$3(null);
1245
+ const [formOpen, setFormOpen] = useState$3(false);
1246
+ const [formUser, setFormUser] = useState$3(null);
1247
+ const [permissionsUser, setPermissionsUser] = useState$3(null);
1248
+ const mounted = useRef$2(true);
1249
+ useEffect$2(() => {
1250
+ mounted.current = true;
1251
+ return () => {
1252
+ mounted.current = false;
1253
+ };
1254
+ }, []);
1255
+ const reload = useCallback$1(async () => {
1256
+ setLoading(true);
1257
+ setLoadError(null);
1258
+ try {
1259
+ const list = await fetchUsers(mqttServerId);
1260
+ if (mounted.current) {
1261
+ setData(list);
1262
+ setPermissionsUser((current) => current ? list.users.find((user) => user.name === current.name) ?? current : null);
1263
+ }
1264
+ } catch (err) {
1265
+ if (mounted.current) setLoadError(err instanceof Error ? err.message : { key: "users.loadError" });
1266
+ } finally {
1267
+ if (mounted.current) setLoading(false);
1268
+ }
1269
+ }, [mqttServerId]);
1270
+ const manageable = result?.isRabbitMQ === true && result.authOk;
1271
+ useEffect$2(() => {
1272
+ if (manageable) reload();
1273
+ }, [manageable, reload]);
1274
+ if (!manageable) return null;
1240
1275
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$2, {
1241
1276
  "data-cy": `rabbitmq-user-panel-${mqttServerId}`,
1242
1277
  className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
1243
1278
  children: [
1244
1279
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserPanelCardHeader, {
1245
- t: model.t,
1246
- reload: model.reload,
1247
- loading: model.loading,
1280
+ reload,
1281
+ loading,
1248
1282
  mqttServerId,
1249
- setFormUser: model.setFormUser,
1250
- setFormOpen: model.setFormOpen,
1283
+ onCreate: () => {
1284
+ setFormUser(null);
1285
+ setFormOpen(true);
1286
+ },
1251
1287
  canManage
1252
1288
  }),
1253
1289
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$2.Content, {
1254
1290
  className: "rmq:flex rmq:flex-col rmq:gap-3",
1255
1291
  children: [
1256
- model.loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$2, {
1292
+ loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$3, {
1257
1293
  status: "danger",
1258
- title: errorTitle(model.loadError, model.t("users.loadError")),
1294
+ title: errorTitle(loadError, t("users.loadError")),
1259
1295
  "data-cy": "rabbitmq-user-panel-error-alert",
1260
- children: model.tMessage(model.loadError)
1296
+ children: tMessage(loadError)
1261
1297
  }),
1262
- !model.data && !model.loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1298
+ !data && !loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1263
1299
  "data-cy": "rabbitmq-user-panel-loading-spinner",
1264
1300
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$2, {})
1265
1301
  }),
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
- }) })
1302
+ data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserTable, {
1303
+ users: data.users,
1304
+ canManage,
1305
+ onEdit: (user) => {
1306
+ setFormUser(user);
1307
+ setFormOpen(true);
1308
+ },
1309
+ onPermissions: setPermissionsUser,
1310
+ onDelete: async (user) => {
1311
+ await deleteUser(mqttServerId, user.name);
1312
+ reload();
1313
+ }
1343
1314
  })
1344
1315
  ]
1345
1316
  }),
1346
1317
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserFormModal, {
1347
1318
  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()
1319
+ isOpen: formOpen,
1320
+ user: formUser,
1321
+ vhosts: data?.vhosts ?? [],
1322
+ existingUsernames: data?.users.map((user) => user.name),
1323
+ onClose: () => setFormOpen(false),
1324
+ onSaved: () => void reload()
1354
1325
  }),
1355
1326
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqPermissionsModal, {
1356
1327
  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
- })
1328
+ isOpen: permissionsUser !== null,
1329
+ user: permissionsUser,
1330
+ vhosts: data?.vhosts ?? [],
1331
+ onClose: () => setPermissionsUser(null),
1332
+ onSaved: () => void reload()
1386
1333
  })
1387
1334
  ]
1388
1335
  });
1389
1336
  }
1390
- //#endregion
1391
- //#region frontend/src/usePolledResource.ts
1392
- var { useCallback, useEffect: useEffect$1, useRef, useState: useState$2 } = await importShared("react");
1337
+ // frontend/src/usePolledResource.ts
1338
+ var { useCallback, useEffect: useEffect$1, useRef: useRef$1, useState: useState$2 } = await importShared("react");
1393
1339
  function usePolledResource(fetcher, intervalMs, fallbackError) {
1394
1340
  const [data, setData] = useState$2(null);
1395
1341
  const [error, setError] = useState$2(null);
1396
1342
  const [loading, setLoading] = useState$2(false);
1397
- const latest = useRef({
1343
+ const latest = useRef$1({
1398
1344
  fetcher,
1399
1345
  fallbackError
1400
1346
  });
@@ -1402,9 +1348,9 @@ function usePolledResource(fetcher, intervalMs, fallbackError) {
1402
1348
  fetcher,
1403
1349
  fallbackError
1404
1350
  };
1405
- const mounted = useRef(true);
1406
- const inFlight = useRef(false);
1407
- const again = useRef(false);
1351
+ const mounted = useRef$1(true);
1352
+ const inFlight = useRef$1(false);
1353
+ const again = useRef$1(false);
1408
1354
  const load = useCallback(async (queueIfBusy) => {
1409
1355
  if (inFlight.current) {
1410
1356
  if (queueIfBusy) again.current = true;
@@ -1455,8 +1401,41 @@ function usePolledResource(fetcher, intervalMs, fallbackError) {
1455
1401
  reload
1456
1402
  };
1457
1403
  }
1458
- //#endregion
1459
- //#region frontend/src/connections/connections-api.ts
1404
+ // frontend/src/connections/RabbitmqConnectionCloseMessage.tsx
1405
+ var { StatusAlert: StatusAlert$2 } = await importShared("@attraccess/plugins-frontend-ui");
1406
+ var { Input, Label, TextField } = await importShared("@heroui/react");
1407
+ var { useImperativeHandle, useState: useState$1 } = await importShared("react");
1408
+ function RabbitmqConnectionCloseMessage({ name, ref }) {
1409
+ const { t } = useRabbitmqTranslations();
1410
+ const [reason, setReason] = useState$1("");
1411
+ const [error, setError] = useState$1(null);
1412
+ useImperativeHandle(ref, () => ({
1413
+ reason,
1414
+ showError: setError
1415
+ }), [reason]);
1416
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1417
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1418
+ children: [
1419
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("connections.closeDescription", { name }) }),
1420
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField, {
1421
+ value: reason,
1422
+ onChange: setReason,
1423
+ className: "rmq:w-full",
1424
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: t("connections.reason") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
1425
+ autoComplete: "off",
1426
+ "data-cy": "rabbitmq-connection-close-reason-input"
1427
+ })]
1428
+ }),
1429
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$2, {
1430
+ status: "danger",
1431
+ title: t("connections.closeError"),
1432
+ "data-cy": "rabbitmq-connection-close-error",
1433
+ children: error === t("connections.closeError") ? void 0 : error
1434
+ })
1435
+ ]
1436
+ });
1437
+ }
1438
+ // frontend/src/connections/connections-api.ts
1460
1439
  var api$2 = createPluginApiClient("/api/rabbitmq/connections");
1461
1440
  function fetchConnections(mqttServerId) {
1462
1441
  return api$2.request(`/${mqttServerId}`);
@@ -1470,226 +1449,196 @@ function closeConnection(mqttServerId, name, reason) {
1470
1449
  }
1471
1450
  });
1472
1451
  }
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");
1452
+ // frontend/src/connections/RabbitmqConnectionsPanel.tsx
1453
+ var { Button: Button$1, EmptyState: EmptyState$1, StatusAlert: StatusAlert$1, TableActionsColumnHeader, TableDataLoadingIndicator: TableDataLoadingIndicator$1, TableRowActions } = await importShared("@attraccess/plugins-frontend-ui");
1454
+ 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
1455
  var { PlugZapIcon, RefreshCwIcon: RefreshCwIcon$1, UnplugIcon } = await importShared("lucide-react");
1478
- var { useState: useState$1 } = await importShared("react");
1456
+ var { useRef } = await importShared("react");
1479
1457
  var CONNECTIONS_POLL_INTERVAL_MS = 1e4;
1480
1458
  function RabbitmqConnectionsPanel({ mqttServerId, canManage }) {
1481
1459
  const { t } = useRabbitmqTranslations();
1482
1460
  const format = useRabbitmqFormatters();
1483
1461
  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);
1462
+ const closeMessage = useRef(null);
1463
+ const confirmClose = async (connection) => {
1464
+ const message = closeMessage.current;
1465
+ message?.showError(null);
1497
1466
  try {
1498
- await closeConnection(mqttServerId, target.name, reason);
1499
- dismiss();
1467
+ await closeConnection(mqttServerId, connection.name, message?.reason ?? "");
1500
1468
  reload();
1501
1469
  } catch (err) {
1502
- setCloseError(err instanceof Error && err.message ? err.message : t("connections.closeError"));
1470
+ message?.showError(err instanceof Error && err.message ? err.message : t("connections.closeError"));
1503
1471
  reload();
1504
- } finally {
1505
- setClosing(false);
1472
+ throw err;
1506
1473
  }
1507
1474
  };
1508
1475
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1, {
1509
1476
  "data-cy": `rabbitmq-connections-panel-${mqttServerId}`,
1510
1477
  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",
1478
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Header, {
1479
+ className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1480
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1481
+ className: "rmq:flex rmq:items-center rmq:gap-2",
1541
1482
  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
- })
1483
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlugZapIcon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
1485
+ className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
1486
+ children: t("connections.title")
1556
1487
  }),
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
- }) })
1488
+ data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$1, {
1489
+ size: "sm",
1490
+ variant: "soft",
1491
+ children: format.number(data.total)
1644
1492
  })
1645
1493
  ]
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
- ]
1494
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
1495
+ isIconOnly: true,
1496
+ size: "sm",
1497
+ variant: "ghost",
1498
+ "aria-label": t("connections.reload"),
1499
+ onPress: () => void reload(),
1500
+ isPending: loading,
1501
+ "data-cy": `rabbitmq-connections-reload-${mqttServerId}`,
1502
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$1, { className: "rmq:w-4 rmq:h-4" })
1503
+ })]
1504
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Content, {
1505
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1506
+ children: [
1507
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1508
+ status: "danger",
1509
+ title: t("connections.loadError"),
1510
+ "data-cy": "rabbitmq-connections-error-alert",
1511
+ children: error === t("connections.loadError") ? void 0 : error
1512
+ }),
1513
+ !data && !error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$1, {}),
1514
+ data && data.connections.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState$1, { message: t("connections.empty") }),
1515
+ data && data.truncated && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1516
+ status: "warning",
1517
+ children: t("connections.truncated", {
1518
+ shown: format.number(data.connections.length),
1519
+ total: format.number(data.total)
1520
+ })
1521
+ }),
1522
+ data && data.connections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$1, {
1523
+ "data-cy": "rabbitmq-connections-table",
1524
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$1, {
1525
+ "aria-label": t("connections.title"),
1526
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$1, { children: [
1527
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1528
+ isRowHeader: true,
1529
+ children: t("connections.client")
1530
+ }),
1531
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.user") }),
1532
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.peer") }),
1533
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.protocol") }),
1534
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("common.state") }),
1535
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.connectedSince") }),
1536
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.channels") }),
1537
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.traffic") }),
1538
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1539
+ id: "actions",
1540
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableActionsColumnHeader, {})
1541
+ })
1542
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$1, {
1543
+ items: data.connections,
1544
+ children: (connection) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$1, {
1545
+ id: connection.name,
1546
+ children: [
1547
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1548
+ className: "rmq:font-medium rmq:whitespace-nowrap",
1549
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1550
+ title: connection.name,
1551
+ children: connection.clientId ?? connection.name
1552
+ })
1553
+ }),
1554
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.user ?? "—" }),
1555
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1556
+ className: "rmq:whitespace-nowrap",
1557
+ children: connection.peerHost ? `${connection.peerHost}:${connection.peerPort ?? ""}` : "—"
1558
+ }),
1559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1560
+ className: "rmq:whitespace-nowrap",
1561
+ children: connection.protocol ?? "—"
1562
+ }),
1563
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.state ?? "—" }),
1564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1565
+ className: "rmq:whitespace-nowrap",
1566
+ children: format.dateTime(connection.connectedAt)
1567
+ }),
1568
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: format.number(connection.channels) }),
1569
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell$1, {
1570
+ className: "rmq:whitespace-nowrap rmq:text-xs",
1571
+ children: [
1572
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1573
+ "aria-hidden": true,
1574
+ children: "↓ "
1575
+ }),
1576
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1577
+ className: "rmq:sr-only",
1578
+ children: [t("connections.received"), ": "]
1579
+ }),
1580
+ format.bytes(connection.recvBytes),
1581
+ " (",
1582
+ format.rate(connection.recvRate, "B/s"),
1583
+ ")",
1584
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
1585
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1586
+ "aria-hidden": true,
1587
+ children: "↑ "
1588
+ }),
1589
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1590
+ className: "rmq:sr-only",
1591
+ children: [t("connections.sent"), ": "]
1592
+ }),
1593
+ format.bytes(connection.sendBytes),
1594
+ " (",
1595
+ format.rate(connection.sendRate, "B/s"),
1596
+ ")"
1597
+ ]
1598
+ }),
1599
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRowActions, {
1600
+ itemName: connection.clientId ?? connection.name,
1601
+ actions: [{
1602
+ key: "close",
1603
+ label: t("connections.closeTitle"),
1604
+ icon: UnplugIcon,
1605
+ tone: "danger",
1606
+ onPress: () => confirmClose(connection),
1607
+ "data-cy": `rabbitmq-connection-close-button-${connection.name}`,
1608
+ confirm: {
1609
+ title: t("connections.closeTitle"),
1610
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqConnectionCloseMessage, {
1611
+ name: connection.clientId ?? connection.name,
1612
+ ref: closeMessage
1613
+ }),
1614
+ confirmLabel: t("connections.closeConfirm"),
1615
+ cancelLabel: t("common.cancel"),
1616
+ "data-cy": `rabbitmq-connection-close-modal-${mqttServerId}`,
1617
+ confirmDataCy: "rabbitmq-connection-close-confirm-button"
1618
+ }
1619
+ }]
1620
+ }) })
1621
+ ]
1622
+ }, connection.name)
1623
+ })]
1624
+ }) })
1680
1625
  })
1681
- })
1682
- ]
1626
+ ]
1627
+ })]
1683
1628
  });
1684
1629
  }
1685
- //#endregion
1686
- //#region frontend/src/stats/stats-api.ts
1630
+ // frontend/src/Duration.tsx
1631
+ var { useFormatedDuration } = await importShared("@attraccess/plugins-frontend-ui");
1632
+ function Duration({ ms }) {
1633
+ const formatted = useFormatedDuration(ms == null ? 0 : Math.floor(ms / 6e4));
1634
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: ms == null ? "—" : formatted });
1635
+ }
1636
+ // frontend/src/stats/stats-api.ts
1687
1637
  var api$1 = createPluginApiClient("/api/rabbitmq/stats");
1688
1638
  function fetchStats(mqttServerId) {
1689
1639
  return api$1.request(`/${mqttServerId}`);
1690
1640
  }
1691
- //#endregion
1692
- //#region frontend/src/stats/RabbitmqStatsPanel.tsx
1641
+ // frontend/src/stats/RabbitmqStatsPanel.tsx
1693
1642
  var { Button, EmptyState, StatusAlert, TableDataLoadingIndicator } = await importShared("@attraccess/plugins-frontend-ui");
1694
1643
  var { Card, Chip, Table, TableBody, TableCell, TableColumn, TableContent, TableHeader, TableRow, TableScrollContainer } = await importShared("@heroui/react");
1695
1644
  var { BarChart3Icon, RefreshCwIcon, TriangleAlertIcon } = await importShared("lucide-react");
@@ -1916,8 +1865,7 @@ function RabbitmqStatsPanel({ mqttServerId }) {
1916
1865
  })]
1917
1866
  });
1918
1867
  }
1919
- //#endregion
1920
- //#region frontend/src/capabilities.ts
1868
+ // frontend/src/capabilities.ts
1921
1869
  var { useEffect, useState } = await importShared("react");
1922
1870
  var api = createPluginApiClient("/api/rabbitmq/capabilities");
1923
1871
  function useCapabilities(enabled = true) {
@@ -1934,8 +1882,7 @@ function useCapabilities(enabled = true) {
1934
1882
  }, [enabled]);
1935
1883
  return capabilities;
1936
1884
  }
1937
- //#endregion
1938
- //#region frontend/src/plugin.tsx
1885
+ // frontend/src/plugin.tsx
1939
1886
  var MQTT_SERVER_DETAIL_SLOT = "mqtt.server.detail";
1940
1887
  var MQTT_SERVER_LIST_ROW_SLOT = "mqtt.server.list.row";
1941
1888
  function RabbitmqDataPanels({ mqttServerId, canManage }) {
@@ -1945,6 +1892,9 @@ function RabbitmqDataPanels({ mqttServerId, canManage }) {
1945
1892
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqStatsPanel, { mqttServerId })] });
1946
1893
  }
1947
1894
  function RabbitmqDetailSlot({ mqttServerId }) {
1895
+ return useCanViewBroker() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqDetailPanels, { mqttServerId }) : null;
1896
+ }
1897
+ function RabbitmqDetailPanels({ mqttServerId }) {
1948
1898
  const { result } = useDetection(mqttServerId);
1949
1899
  const { canManage } = useCapabilities(result?.isRabbitMQ === true);
1950
1900
  if (!result?.isRabbitMQ) return null;
@@ -1965,7 +1915,7 @@ function RabbitmqDetailSlot({ mqttServerId }) {
1965
1915
  }
1966
1916
  var RabbitmqPlugin = class {
1967
1917
  getPluginName() {
1968
- return "rabbitmq-plugin@0.1.0";
1918
+ return "rabbitmq-plugin@0.2.0";
1969
1919
  }
1970
1920
  getDependencies() {
1971
1921
  return [];
@@ -1973,7 +1923,9 @@ var RabbitmqPlugin = class {
1973
1923
  init(_store) {}
1974
1924
  activate() {}
1975
1925
  deactivate() {}
1976
- onApiAuthStateChange(_authData) {}
1926
+ onApiAuthStateChange(authData) {
1927
+ setRabbitmqAuthData(authData);
1928
+ }
1977
1929
  onApiEndpointChange(_endpoint) {}
1978
1930
  getSlotContributions() {
1979
1931
  return [{
@@ -1987,5 +1939,4 @@ var RabbitmqPlugin = class {
1987
1939
  }];
1988
1940
  }
1989
1941
  };
1990
- //#endregion
1991
1942
  export { RabbitmqDetailSlot, RabbitmqPlugin as default };