@kong-ui-public/entities-consumer-groups 4.10.1-pr.4063.f9e4f8cdb.0 → 4.10.2

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,983 +1,970 @@
1
- import { Fragment as e, Teleport as t, computed as n, createBlock as r, createCommentVNode as i, createElementBlock as a, createElementVNode as o, createSlots as s, createTextVNode as c, createVNode as l, defineComponent as u, onBeforeMount as d, openBlock as f, reactive as p, ref as m, renderList as h, renderSlot as g, resolveComponent as _, toDisplayString as v, unref as y, watch as b, withCtx as x } from "vue";
2
- import { EntityBaseConfigCard as S, EntityBaseForm as C, EntityBaseFormType as w, EntityBaseTable as ee, EntityConfigCardView as T, EntityDeleteModal as E, EntityFilter as D, EntityFormSection as O, EntityTypes as k, FetcherStatus as A, PermissionsWrapper as j, SupportedEntityType as M, TableTags as N, getManagedByLabel as P, useAxios as te, useDebouncedFilter as ne, useDeleteUrlBuilder as F, useErrors as re, useFetcher as ie, useManagedByColumn as I, useTableState as L, useValidators as R } from "@kong-ui-public/entities-shared";
3
- import { createI18n as z, i18nTComponent as B } from "@kong-ui-public/i18n";
4
- import { useRouter as ae } from "vue-router";
5
- import { AddIcon as oe, BookIcon as V, TeamIcon as H } from "@kong/icons";
6
- var U = { consumer_groups: {
7
- list: {
8
- table_headers: {
9
- name: "Name",
10
- consumers_count: "Consumers",
11
- tags: "Tags",
12
- id: "ID"
13
- },
14
- empty_state: {
15
- title: "Configure a new consumer group",
16
- description: "Use consumer groups to manage custom rate limiting configuration for subsets of consumers.",
17
- title_for_consumer: "Add to a consumer group"
18
- },
19
- empty_state_v2: {
20
- title: "Configure your first consumer group",
21
- group: "Consumer groups created in gateways within this group will automatically appear here.",
22
- description: "Organize consumers into groups to easily apply policies like rate limiting and authentication across the entire group.",
23
- learn_more: "Learn more"
24
- },
25
- toolbar_actions: { new_consumer_group: "New consumer group" }
26
- },
27
- title: "Consumer groups",
28
- search: { placeholder: "Filter by exact name or ID" },
29
- actions: {
30
- add_to_group: "Add to consumer group",
31
- create: "New consumer group",
32
- copy_id: "Copy ID",
33
- copy_json: "Copy JSON",
34
- edit: "Edit",
35
- delete: "Delete",
36
- exit: "Exit",
37
- view: "View details"
38
- },
39
- delete: {
40
- title: "Delete a consumer group",
41
- description: "Deleting this group will remove all its plugins and rate limit configuration. This action cannot be reversed."
42
- },
43
- consumers: {
44
- add: {
45
- title: "Add to consumer groups",
46
- ctaText: "Add this consumer to consumer groups",
47
- consumer_groups_label: "Consumer groups",
48
- consumer_group_placeholder: "Add to consumer groups",
49
- footer: "Search by exact name or ID to find consumer groups not included in the list"
50
- },
51
- exit: {
52
- title: "Exit from a consumer group",
53
- confirmation: "Are you sure you want to remove consumer {consumer} from consumer group {consumerGroup}?",
54
- confirmationNoUsername: "Are you sure you want this consumer to exit from consumer group {consumerGroup}?",
55
- description: "Exiting from the group could change the rate limit policy applied to this consumer."
56
- }
57
- },
58
- errors: {
59
- general: "Consumer groups could not be retrieved",
60
- delete: "The consumer group could not be deleted at this time.",
61
- copy: "Failed to copy to clipboard",
62
- add: "The consumer could not be added to some groups at this time.",
63
- already_added: "The consumer is already in this consumer group",
64
- add_consumer: "An unexpected error occurred while adding consumers. Please try again.",
65
- remove_consumer: "An unexpected error occurred while removing consumers. Please try again."
66
- },
67
- copy: {
68
- success: "Copied {val} to clipboard",
69
- success_brief: "Successfully copied to clipboard"
70
- },
71
- form: {
72
- general_info: {
73
- title: "General information",
74
- description: "General information will help identify and manage this consumer group."
75
- },
76
- consumers: {
77
- title: "Consumers",
78
- description: "Add or remove consumers from this group"
79
- },
80
- fields: {
81
- name: {
82
- label: "Name",
83
- placeholder: "Enter a unique name for this consumer group "
84
- },
85
- tags: {
86
- label: "Tags",
87
- placeholder: "Enter a list of tags separated by comma",
88
- help: "e.g. tag1, tag2, tag3",
89
- tooltip: "An optional set of strings for grouping and filtering, separated by commas."
90
- },
91
- consumers: {
92
- label: "Consumers",
93
- placeholder: "Select one or more consumers"
94
- }
95
- }
96
- }
97
- } };
98
- // src/composables/useI18n.ts
99
- function se() {
100
- let e = z("en-us", U);
101
- return {
102
- i18n: e,
103
- i18nT: B(e)
104
- };
1
+ import { defineComponent as ce, ref as v, openBlock as w, createElementBlock as N, createVNode as l, unref as o, createSlots as me, withCtx as c, renderSlot as xe, computed as h, watch as _e, resolveComponent as K, createBlock as L, createElementVNode as V, toDisplayString as C, Fragment as Qe, renderList as He, createCommentVNode as O, onBeforeMount as Ve, createTextVNode as q, Teleport as Je, reactive as Ge } from "vue";
2
+ import { EntityConfigCardView as ze, SupportedEntityType as be, useAxios as Ce, useDebouncedFilter as Be, useManagedByColumn as We, useTableState as Xe, useFetcher as Ye, useDeleteUrlBuilder as Ze, FetcherStatus as eo, EntityBaseTable as oo, PermissionsWrapper as de, getManagedByLabel as to, TableTags as so, EntityFilter as ro, EntityDeleteModal as no, EntityTypes as ao, useErrors as io, useValidators as uo, EntityBaseFormType as he, EntityBaseForm as co, EntityFormSection as Te, EntityBaseConfigCard as lo } from "@kong-ui-public/entities-shared";
3
+ import { createI18n as mo, i18nTComponent as po } from "@kong-ui-public/i18n";
4
+ import { useRouter as Fe } from "vue-router";
5
+ import { BookIcon as Ae, AddIcon as Pe, TeamIcon as go } from "@kong/icons";
6
+ const fo = { list: { table_headers: { name: "Name", consumers_count: "Consumers", tags: "Tags", id: "ID" }, empty_state: { title: "Configure a new consumer group", description: "Use consumer groups to manage custom rate limiting configuration for subsets of consumers.", title_for_consumer: "Add to a consumer group" }, empty_state_v2: { title: "Configure your first consumer group", group: "Consumer groups created in gateways within this group will automatically appear here.", description: "Organize consumers into groups to easily apply policies like rate limiting and authentication across the entire group.", learn_more: "Learn more" }, toolbar_actions: { new_consumer_group: "New consumer group" } }, title: "Consumer groups", search: { placeholder: "Filter by exact name or ID" }, actions: { add_to_group: "Add to consumer group", create: "New consumer group", copy_id: "Copy ID", copy_json: "Copy JSON", edit: "Edit", delete: "Delete", exit: "Exit", view: "View details" }, delete: { title: "Delete a consumer group", description: "Deleting this group will remove all its plugins and rate limit configuration. This action cannot be reversed." }, consumers: { add: { title: "Add to consumer groups", ctaText: "Add this consumer to consumer groups", consumer_groups_label: "Consumer groups", consumer_group_placeholder: "Add to consumer groups", footer: "Search by exact name or ID to find consumer groups not included in the list" }, exit: { title: "Exit from a consumer group", confirmation: "Are you sure you want to remove consumer {consumer} from consumer group {consumerGroup}?", confirmationNoUsername: "Are you sure you want this consumer to exit from consumer group {consumerGroup}?", description: "Exiting from the group could change the rate limit policy applied to this consumer." } }, errors: { general: "Consumer groups could not be retrieved", delete: "The consumer group could not be deleted at this time.", copy: "Failed to copy to clipboard", add: "The consumer could not be added to some groups at this time.", already_added: "The consumer is already in this consumer group", add_consumer: "An unexpected error occurred while adding consumers. Please try again.", remove_consumer: "An unexpected error occurred while removing consumers. Please try again." }, copy: { success: "Copied {val} to clipboard", success_brief: "Successfully copied to clipboard" }, form: { general_info: { title: "General information", description: "General information will help identify and manage this consumer group." }, consumers: { title: "Consumers", description: "Add or remove consumers from this group" }, fields: { name: { label: "Name", placeholder: "Enter a unique name for this consumer group " }, tags: { label: "Tags", placeholder: "Enter a list of tags separated by comma", help: "e.g. tag1, tag2, tag3", tooltip: "An optional set of strings for grouping and filtering, separated by commas." }, consumers: { label: "Consumers", placeholder: "Select one or more consumers" } } } }, yo = {
7
+ consumer_groups: fo
8
+ };
9
+ function vo() {
10
+ const e = mo("en-us", yo);
11
+ return {
12
+ i18n: e,
13
+ i18nT: po(e)
14
+ // Translation component <i18n-t>
15
+ };
105
16
  }
106
- // src/composables/index.ts
107
- var W = { useI18n: se }, G = /* @__PURE__ */ u({
108
- __name: "ConsumerGroupConfigCardView",
109
- props: {
110
- record: {
111
- type: Object,
112
- required: !0
113
- },
114
- config: {
115
- type: Object,
116
- default: () => ({})
117
- },
118
- hideTitle: {
119
- type: Boolean,
120
- default: !1
121
- }
122
- },
123
- setup(e) {
124
- let { i18n: { t } } = W.useI18n(), n = m({
125
- id: {},
126
- name: {},
127
- created_at: {},
128
- updated_at: {},
129
- tags: { tooltip: t("consumer_groups.form.fields.tags.tooltip") }
130
- });
131
- return (t, r) => (f(), a("div", null, [l(y(T), {
132
- config: e.config,
133
- "config-schema": n.value,
134
- "entity-type": y(M).ConsumerGroup,
135
- "hide-title": e.hideTitle,
136
- record: e.record
137
- }, s({ _: 2 }, [t.$slots.title ? {
138
- name: "title",
139
- fn: x(() => [g(t.$slots, "title")]),
140
- key: "0"
141
- } : void 0, t.$slots.actions ? {
142
- name: "actions",
143
- fn: x(() => [g(t.$slots, "actions")]),
144
- key: "1"
145
- } : void 0]), 1032, [
146
- "config",
147
- "config-schema",
148
- "entity-type",
149
- "hide-title",
150
- "record"
151
- ])]));
152
- }
153
- }), K = "/v2/control-planes/{controlPlaneId}/core-entities/{workspace}", q = "/{workspace}", J = {
154
- list: {
155
- konnect: {
156
- all: `${K}/consumer_groups`,
157
- forModal: `${K}/consumer_groups`,
158
- forConsumer: `${K}/consumers/{consumerId}/consumer_groups`,
159
- oneForConsumer: `${K}/consumers/{consumerId}/consumer_groups/{consumerGroupId}`
160
- },
161
- kongManager: {
162
- all: `${q}/consumer_groups?counter=true`,
163
- forModal: `${q}/consumer_groups`,
164
- forConsumer: `${q}/consumers/{consumerId}/consumer_groups`,
165
- oneForConsumer: `${q}/consumers/{consumerId}/consumer_groups/{consumerGroupId}`
166
- }
167
- },
168
- form: {
169
- konnect: {
170
- consumersList: `${K}/consumers`,
171
- create: `${K}/consumer_groups`,
172
- edit: `${K}/consumer_groups/{id}`,
173
- addConsumer: `${K}/consumer_groups/{id}/consumers`,
174
- removeConsumer: `${K}/consumer_groups/{id}/consumers/{consumerId}`,
175
- getConsumers: `${K}/consumer_groups/{id}/consumers`
176
- },
177
- kongManager: {
178
- consumersList: `${q}/consumers`,
179
- create: `${q}/consumer_groups`,
180
- edit: `${q}/consumer_groups/{id}`,
181
- addConsumer: `${q}/consumer_groups/{id}/consumers`,
182
- removeConsumer: `${q}/consumer_groups/{id}/consumers/{consumerId}`,
183
- getConsumers: `${q}/consumer_groups/{id}/consumers`
184
- }
185
- },
186
- item: {
187
- konnect: `${K}/consumer_groups/{id}?list_consumers=false`,
188
- kongManager: `${q}/consumer_groups/{id}?list_consumers=false`
189
- }
190
- }, ce = { class: "add-to-group-form-container" }, le = { class: "add-to-group-cta-text" }, ue = {
191
- key: 0,
192
- class: "kong-ui-entity-add-to-groups-error"
193
- }, de = { key: 0 }, Y = /*@__PURE__*/ u({
194
- __name: "AddToGroupModal",
195
- props: {
196
- config: {
197
- type: Object,
198
- required: !0,
199
- validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || !e.consumerId)
200
- },
201
- visible: {
202
- type: Boolean,
203
- required: !0
204
- }
205
- },
206
- emits: [
207
- "cancel",
208
- "add:success",
209
- "add:partial-success",
210
- "error"
211
- ],
212
- setup(t, { emit: s }) {
213
- let { i18n: { t: c } } = W.useI18n(), u = t, d = s, { axiosInstance: p } = te(u.config?.axiosRequestConfig), g = m([]), { debouncedQueryChange: S, loading: C, allRecords: w, error: ee, loadItems: T, results: E } = ne(u.config, J.list[u.config.app].forModal, "", {
214
- fetchedItemsKey: "data",
215
- searchKeys: ["name", "id"]
216
- }), D = n(() => ee.value ? c("consumer_groups.errors.general") : ""), O = m(0), k = n(() => w.value === void 0), A = n(() => E.value.map((e) => ({
217
- label: e.name,
218
- value: e.id,
219
- selected: g.value.includes(e.id),
220
- data: e
221
- }))), j = (e) => {
222
- let t = k.value ? E.value.find((t) => t.id === e) : w.value?.find((t) => t.id === e);
223
- return t ? t.name : e;
224
- }, M = () => {
225
- F.value = "", N.value = [], L.value = [], d("cancel");
226
- }, N = m([]), P = m(!1), F = m(""), re = async () => {
227
- if (!g.value.length) F.value = "", L.value = [], d("cancel");
228
- else {
229
- P.value = !0, F.value = "", N.value = [], L.value = [];
230
- try {
231
- let e = g.value.map((e) => I(e)), t = await Promise.allSettled(e), n = !0;
232
- t.forEach((e) => {
233
- e.status !== "fulfilled" && (n = !1);
234
- }), n ? (N.value = [], L.value = [], d("add:success", g.value), g.value = []) : (N.value.length && d("add:partial-success", N.value), g.value = [], R(t));
235
- } catch {
236
- F.value = c("consumer_groups.errors.add"), d("error", F.value);
237
- } finally {
238
- P.value = !1;
239
- }
240
- }
241
- }, ie = n(() => {
242
- let e = `${u.config.apiBaseUrl}${J.list[u.config.app].forConsumer}`;
243
- return u.config.app === "konnect" && (e = e.replace(/{controlPlaneId}/gi, u.config?.controlPlaneId || "")), e.replace(/\/{workspace}/gi, u.config?.workspace ? `/${u.config.workspace}` : "").replace(/{consumerId}/gi, u.config?.consumerId || "");
244
- }), I = async (e) => {
245
- let t = { group: e };
246
- try {
247
- let n = await p.post(ie.value, t);
248
- return N.value.push(e), n;
249
- } catch (t) {
250
- let n = `${j(e)} - ${t.message}`;
251
- return t.response.status === 409 && (n = `${j(e)} - ${c("consumer_groups.errors.already_added")}`), Promise.reject(Error(n));
252
- }
253
- }, L = m([]), R = (e) => {
254
- L.value = e.map((e) => e.reason?.message).filter(Boolean);
255
- };
256
- return b(A, () => {
257
- O.value++;
258
- }, {
259
- immediate: !0,
260
- deep: !0
261
- }), b(() => u.visible, () => {
262
- u.visible && T();
263
- }, { immediate: !0 }), (n, s) => {
264
- let u = _("KMultiselect"), d = _("KAlert"), p = _("KPrompt");
265
- return f(), r(p, {
266
- "action-button-disabled": P.value,
267
- class: "kong-ui-entities-add-to-groups-modal",
268
- "data-testid": "add-to-group-modal",
269
- title: y(c)("consumer_groups.consumers.add.title"),
270
- visible: t.visible,
271
- onCancel: M,
272
- onProceed: re
273
- }, {
274
- default: x(() => [o("div", ce, [
275
- o("p", le, v(y(c)("consumer_groups.consumers.add.ctaText")), 1),
276
- l(u, {
277
- modelValue: g.value,
278
- "onUpdate:modelValue": s[0] ||= (e) => g.value = e,
279
- autosuggest: "",
280
- "data-testid": "add-to-groups-multiselect",
281
- "dropdown-footer-text": k.value ? y(c)("consumer_groups.consumers.add.footer") : void 0,
282
- items: A.value,
283
- label: y(c)("consumer_groups.consumers.add.consumer_groups_label"),
284
- loading: y(C),
285
- placeholder: y(c)("consumer_groups.consumers.add.consumer_group_placeholder"),
286
- readonly: P.value,
287
- required: "",
288
- width: "100%",
289
- onQueryChange: y(S)
290
- }, null, 8, [
291
- "modelValue",
292
- "dropdown-footer-text",
293
- "items",
294
- "label",
295
- "loading",
296
- "placeholder",
297
- "readonly",
298
- "onQueryChange"
299
- ]),
300
- F.value || D.value || L.value.length ? (f(), a("div", ue, [l(d, { appearance: "danger" }, {
301
- default: x(() => [
302
- o("p", null, v(y(c)("consumer_groups.errors.add")), 1),
303
- L.value.length ? (f(), a("ul", de, [(f(!0), a(e, null, h(L.value, (e, t) => (f(), a("li", { key: t }, v(e), 1))), 128))])) : i("", !0),
304
- o("div", null, v(F.value || D.value), 1)
305
- ]),
306
- _: 1
307
- })])) : i("", !0)
308
- ])]),
309
- _: 1
310
- }, 8, [
311
- "action-button-disabled",
312
- "title",
313
- "visible"
314
- ]);
315
- };
316
- }
317
- }), X = (e, t) => {
318
- let n = e.__vccOpts || e;
319
- for (let [e, r] of t) n[e] = r;
320
- return n;
321
- }, fe = /*#__PURE__*/ X(Y, [["__scopeId", "data-v-54887165"]]), pe = { class: "kong-ui-entities-consumer-groups-list" }, me = { class: "button-row" }, he = /*#__PURE__*/ X(/* @__PURE__ */ u({
322
- __name: "ConsumerGroupList",
323
- props: {
324
- config: {
325
- type: Object,
326
- required: !0,
327
- validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || !e.createRoute || !e.getViewRoute || !e.getEditRoute || e.app === "kongManager" && !e.isExactMatch && !e.filterSchema)
328
- },
329
- cacheIdentifier: {
330
- type: String,
331
- default: ""
332
- },
333
- canCreate: {
334
- type: Function,
335
- required: !1,
336
- default: async () => !0
337
- },
338
- canDelete: {
339
- type: Function,
340
- required: !1,
341
- default: async () => !0
342
- },
343
- canEdit: {
344
- type: Function,
345
- required: !1,
346
- default: async () => !0
347
- },
348
- canRetrieve: {
349
- type: Function,
350
- required: !1,
351
- default: async () => !0
352
- },
353
- useActionOutside: {
354
- type: Boolean,
355
- default: !1
356
- }
357
- },
358
- emits: [
359
- "error",
360
- "click:learn-more",
361
- "copy:success",
362
- "copy:error",
363
- "delete:success",
364
- "add:success",
365
- "remove:success"
366
- ],
367
- setup(e, { emit: u }) {
368
- let p = u, h = e, { i18nT: g, i18n: { t: S } } = W.useI18n(), C = ae(), { axiosInstance: w } = te(h.config?.axiosRequestConfig), T = n(() => h.config.app !== "kongManager" || !!h.config.disableSorting), O = { name: {
369
- label: S("consumer_groups.list.table_headers.name"),
370
- searchable: !0,
371
- sortable: !0,
372
- hidable: !1
373
- } };
374
- h.config.app === "kongManager" && (O.consumers_count = {
375
- label: S("consumer_groups.list.table_headers.consumers_count"),
376
- searchable: !1,
377
- sortable: !1
378
- }), O.tags = {
379
- label: S("consumer_groups.list.table_headers.tags"),
380
- sortable: !1
381
- };
382
- let { defaultTablePreferences: M, tableHeaders: ne } = I(O), re = (e) => ({ "data-testid": e.username ?? e.custom_id ?? e.id }), R = () => {
383
- h.config.consumerId ? ke() : C.push(h.config.createRoute);
384
- }, z = n(() => {
385
- let e = `${h.config.apiBaseUrl}${J.list[h.config.app][q.value ? "forConsumer" : "all"]}`;
386
- return h.config.app === "konnect" && (e = e.replace(/{controlPlaneId}/gi, h.config?.controlPlaneId || ""), B.value && h.config.isExactMatch && (e += "?list_consumers=false")), e.replace(/\/{workspace}/gi, h.config?.workspace ? `/${h.config.workspace}` : "").replace(/{consumerId}/gi, h.config?.consumerId || "");
387
- }), B = m(""), U = n(() => {
388
- let e = h.config.app === "konnect" || h.config.isExactMatch;
389
- return e ? {
390
- isExactMatch: e,
391
- fields: {
392
- username: O.name,
393
- id: { label: S("consumer_groups.list.table_headers.id") }
394
- },
395
- placeholder: S("consumer_groups.search.placeholder")
396
- } : {
397
- isExactMatch: e,
398
- fields: { name: O.name },
399
- schema: h.config.filterSchema
400
- };
401
- }), { hasRecords: se, handleStateChange: G } = L(B), K = n(() => se.value && h.config.app === "konnect"), q = n(() => !!h.config.consumerId), ce = n(() => q.value ? "kong-ui-entities-consumer-groups-list-in-consumer-page" : "kong-ui-entities-consumer-groups-list"), le = n(() => h.config.app === "konnect" && B.value ? "consumer_group" : q.value && !h.config.paginatedEndpoint ? "consumer_groups" : void 0), { fetcher: ue, fetcherState: de, fetcherCacheKey: Y } = ie(n(() => ({
402
- ...h.config,
403
- cacheIdentifier: h.cacheIdentifier
404
- })), z, le), X = () => {
405
- B.value = "";
406
- }, he = () => {
407
- Y.value++;
408
- }, Z = m(null), ge = async (e, t) => {
409
- let n = e.id;
410
- await t(n) ? p("copy:success", {
411
- entity: e,
412
- field: "id",
413
- message: S("consumer_groups.copy.success", { val: n })
414
- }) : p("copy:error", {
415
- entity: e,
416
- field: "id",
417
- message: S("consumer_groups.errors.copy")
418
- });
419
- }, _e = async (e, t) => {
420
- await t(JSON.stringify(e)) ? p("copy:success", {
421
- entity: e,
422
- message: S("consumer_groups.copy.success_brief")
423
- }) : p("copy:error", {
424
- entity: e,
425
- message: S("consumer_groups.errors.copy")
426
- });
427
- }, ve = async (e) => {
428
- await h.canRetrieve?.(e) && C.push(h.config.getViewRoute(e.id));
429
- }, ye = (e) => ({
430
- label: S("consumer_groups.actions.view"),
431
- to: h.config.getViewRoute(e)
432
- }), be = (e) => ({
433
- label: S("consumer_groups.actions.edit"),
434
- to: h.config.getEditRoute(e)
435
- }), Q = m(void 0), xe = m(!1), Se = m(!1), Ce = m(""), we = F(h.config, z.value), Te = (e) => {
436
- Q.value = e, xe.value = !0;
437
- }, Ee = () => {
438
- xe.value = !1;
439
- }, De = async () => {
440
- if (Q.value?.id) {
441
- Se.value = !0;
442
- try {
443
- await w.delete(we(Q.value.id)), Se.value = !1, xe.value = !1, Y.value++, p("delete:success", Q.value);
444
- } catch (e) {
445
- Ce.value = e.response?.data?.message || e.message || S("consumer_groups.errors.delete"), p("error", e);
446
- } finally {
447
- Se.value = !1;
448
- }
449
- }
450
- }, Oe = m(!1), ke = () => {
451
- Oe.value = !0;
452
- }, Ae = () => {
453
- Oe.value = !1;
454
- }, je = (e, t) => {
455
- t || Ae(), Y.value++, p("add:success", e);
456
- }, Me = () => {
457
- q.value && ke();
458
- }, $ = m(void 0), Ne = m(!1), Pe = m(""), Fe = (e) => {
459
- $.value = e, Ne.value = !0;
460
- }, Ie = () => {
461
- Ne.value = !1, $.value = void 0;
462
- }, Le = n(() => {
463
- let e = `${h.config.apiBaseUrl}${J.list[h.config.app].oneForConsumer}`;
464
- return h.config.app === "konnect" && (e = e.replace(/{controlPlaneId}/gi, h.config?.controlPlaneId || "")), e.replace(/\/{workspace}/gi, h.config?.workspace ? `/${h.config.workspace}` : "").replace(/{consumerId}/gi, h.config?.consumerId || "");
465
- }), Re = m(!1), ze = async () => {
466
- if ($.value) {
467
- Re.value = !0;
468
- try {
469
- let e = Le.value.replace(/{consumerGroupId}/gi, $.value.id);
470
- await w.delete(e), p("remove:success", $.value), Ie(), Y.value++;
471
- } catch (e) {
472
- Pe.value = e.message || S("consumer_groups.errors.delete"), p("error", e);
473
- } finally {
474
- Re.value = !1;
475
- }
476
- }
477
- };
478
- b(de, (e) => {
479
- e.status === A.Error ? (Z.value = { title: S("consumer_groups.errors.general") }, e.error?.response?.data?.message && (Z.value.message = e.error.response.data.message), p("error", e.error)) : Z.value = null;
480
- });
481
- let Be = m({
482
- ctaPath: q.value ? void 0 : h.config.createRoute,
483
- ctaText: void 0,
484
- message: `${S("consumer_groups.list.empty_state.description")}${h.config.additionMessageForEmptyState ? ` ${h.config.additionMessageForEmptyState}` : ""}`,
485
- title: S("consumer_groups.title")
486
- }), Ve = m(!1);
487
- return d(async () => {
488
- Ve.value = await h.canCreate(), Ve.value && (Be.value.title = q.value ? S("consumer_groups.list.empty_state.title_for_consumer") : S("consumer_groups.list.empty_state.title"), Be.value.ctaText = q.value ? S("consumer_groups.actions.add_to_group") : S("consumer_groups.actions.create"));
489
- }), (n, u) => {
490
- let d = _("KButton"), p = _("KEmptyState"), m = _("KDropdownItem"), h = _("KClipboardProvider"), b = _("KPrompt");
491
- return f(), a("div", pe, [
492
- l(y(ee), {
493
- "cache-identifier": e.cacheIdentifier,
494
- "default-table-preferences": y(M),
495
- "disable-pagination": q.value && !e.config.paginatedEndpoint,
496
- "disable-sorting": T.value,
497
- "empty-state-options": Be.value,
498
- "enable-entity-actions": "",
499
- "error-message": Z.value,
500
- fetcher: y(ue),
501
- "fetcher-cache-key": y(Y),
502
- "pagination-type": "offset",
503
- "preferences-storage-key": ce.value,
504
- query: B.value,
505
- "row-attributes": re,
506
- "table-headers": y(ne),
507
- onClearSearchInput: X,
508
- "onClick:row": u[3] ||= (e) => ve(e),
509
- onEmptyStateCtaClicked: Me,
510
- onSort: he,
511
- onState: y(G)
512
- }, s({
513
- "toolbar-filter": x(() => [q.value ? i("", !0) : (f(), r(y(D), {
514
- key: 0,
515
- modelValue: B.value,
516
- "onUpdate:modelValue": u[0] ||= (e) => B.value = e,
517
- config: U.value
518
- }, null, 8, ["modelValue", "config"]))]),
519
- "toolbar-button": x(() => [(f(), r(t, {
520
- disabled: !e.useActionOutside,
521
- to: "#kong-ui-app-page-header-action-button"
522
- }, [o("div", me, [K.value ? (f(), r(d, {
523
- key: 0,
524
- appearance: "secondary",
525
- class: "open-learning-hub",
526
- "data-testid": "consumer-groups-learn-more-button",
527
- icon: "",
528
- onClick: u[1] ||= (e) => n.$emit("click:learn-more")
529
- }, {
530
- default: x(() => [l(y(V), { decorative: "" })]),
531
- _: 1
532
- })) : i("", !0), l(y(j), { "auth-function": () => e.canCreate() }, {
533
- default: x(() => [l(d, {
534
- appearance: "primary",
535
- "data-testid": "toolbar-add-consumer-group",
536
- size: e.useActionOutside ? "medium" : "large",
537
- onClick: R
538
- }, {
539
- default: x(() => [l(y(oe)), c(" " + v(e.config.consumerId ? y(S)("consumer_groups.actions.add_to_group") : y(S)("consumer_groups.list.toolbar_actions.new_consumer_group")), 1)]),
540
- _: 1
541
- }, 8, ["size"])]),
542
- _: 1
543
- }, 8, ["auth-function"])])], 8, ["disabled"]))]),
544
- name: x(({ rowValue: e }) => [o("b", null, v(e ?? "-"), 1)]),
545
- consumers_count: x(({ rowValue: e }) => [c(v(e ?? "-"), 1)]),
546
- tags: x(({ rowValue: e }) => [l(y(N), { tags: e }, null, 8, ["tags"])]),
547
- managed_by: x(({ rowValue: e }) => [c(v(y(P)(e) ?? "-"), 1)]),
548
- actions: x(({ row: t }) => [
549
- l(h, null, {
550
- default: x(({ copyToClipboard: e }) => [l(m, {
551
- "data-testid": "action-entity-copy-id",
552
- onClick: (n) => ge(t, e)
553
- }, {
554
- default: x(() => [c(v(y(S)("consumer_groups.actions.copy_id")), 1)]),
555
- _: 1
556
- }, 8, ["onClick"])]),
557
- _: 2
558
- }, 1024),
559
- l(h, null, {
560
- default: x(({ copyToClipboard: e }) => [l(m, {
561
- "data-testid": "action-entity-copy-json",
562
- onClick: (n) => _e(t, e)
563
- }, {
564
- default: x(() => [c(v(y(S)("consumer_groups.actions.copy_json")), 1)]),
565
- _: 1
566
- }, 8, ["onClick"])]),
567
- _: 2
568
- }, 1024),
569
- l(y(j), { "auth-function": () => e.canRetrieve(t) }, {
570
- default: x(() => [l(m, {
571
- "data-testid": "action-entity-view",
572
- "has-divider": "",
573
- item: ye(t.id)
574
- }, null, 8, ["item"])]),
575
- _: 2
576
- }, 1032, ["auth-function"]),
577
- l(y(j), { "auth-function": () => e.canEdit(t) }, {
578
- default: x(() => [l(m, {
579
- "data-testid": "action-entity-edit",
580
- item: be(t.id)
581
- }, null, 8, ["item"])]),
582
- _: 2
583
- }, 1032, ["auth-function"]),
584
- l(y(j), { "auth-function": () => e.canDelete(t) }, {
585
- default: x(() => [l(m, {
586
- danger: "",
587
- "data-testid": "action-entity-delete",
588
- "has-divider": "",
589
- onClick: () => e.config.consumerId ? Fe(t) : Te(t)
590
- }, {
591
- default: x(() => [c(v(e.config.consumerId ? y(S)("consumer_groups.actions.exit") : y(S)("consumer_groups.actions.delete")), 1)]),
592
- _: 1
593
- }, 8, ["onClick"])]),
594
- _: 2
595
- }, 1032, ["auth-function"])
596
- ]),
597
- _: 2
598
- }, [!B.value && e.config.app === "konnect" ? {
599
- name: "empty-state",
600
- fn: x(() => [l(p, {
601
- "data-testid": "consumer-groups-entity-empty-state",
602
- "icon-background": "",
603
- message: y(S)("consumer_groups.list.empty_state_v2.description"),
604
- title: y(S)("consumer_groups.list.empty_state_v2.title")
605
- }, s({
606
- icon: x(() => [l(y(H), { decorative: "" })]),
607
- action: x(() => [Ve.value ? (f(), r(d, {
608
- key: 0,
609
- "data-testid": "entity-create-button",
610
- onClick: R
611
- }, {
612
- default: x(() => [l(y(oe), { decorative: "" }), c(" " + v(y(S)("consumer_groups.list.toolbar_actions.new_consumer_group")), 1)]),
613
- _: 1
614
- })) : i("", !0), l(d, {
615
- appearance: "secondary",
616
- "data-testid": "entity-learn-more-button",
617
- onClick: u[2] ||= (e) => n.$emit("click:learn-more")
618
- }, {
619
- default: x(() => [l(y(V), { decorative: "" }), c(" " + v(y(S)("consumer_groups.list.empty_state_v2.learn_more")), 1)]),
620
- _: 1
621
- })]),
622
- _: 2
623
- }, [e.config?.isControlPlaneGroup ? {
624
- name: "default",
625
- fn: x(() => [c(v(y(S)("consumer_groups.list.empty_state_v2.group")), 1)]),
626
- key: "0"
627
- } : void 0]), 1032, ["message", "title"])]),
628
- key: "0"
629
- } : void 0]), 1032, [
630
- "cache-identifier",
631
- "default-table-preferences",
632
- "disable-pagination",
633
- "disable-sorting",
634
- "empty-state-options",
635
- "error-message",
636
- "fetcher",
637
- "fetcher-cache-key",
638
- "preferences-storage-key",
639
- "query",
640
- "table-headers",
641
- "onState"
642
- ]),
643
- l(y(E), {
644
- "action-pending": Se.value,
645
- "data-testid": "delete-consumer-group-modal",
646
- description: y(S)("consumer_groups.delete.description"),
647
- "entity-name": Q.value && (Q.value.name || Q.value.id),
648
- "entity-type": y(k).ConsumerGroup,
649
- error: Ce.value,
650
- title: y(S)("consumer_groups.delete.title"),
651
- visible: xe.value,
652
- onCancel: Ee,
653
- onProceed: De
654
- }, null, 8, [
655
- "action-pending",
656
- "description",
657
- "entity-name",
658
- "entity-type",
659
- "error",
660
- "title",
661
- "visible"
662
- ]),
663
- e.config.consumerId ? (f(), r(fe, {
664
- key: 0,
665
- config: e.config,
666
- "data-testid": "add-to-group-modal",
667
- visible: Oe.value,
668
- "onAdd:partialSuccess": u[4] ||= (e) => je(e, !0),
669
- "onAdd:success": u[5] ||= (e) => je(e),
670
- onCancel: Ae
671
- }, null, 8, ["config", "visible"])) : i("", !0),
672
- e.config.consumerId && $.value ? (f(), r(b, {
673
- key: 1,
674
- "action-button-appearance": "danger",
675
- "data-testid": "exit-group-modal",
676
- title: y(S)("consumer_groups.consumers.exit.title"),
677
- visible: Ne.value,
678
- onCancel: Ie,
679
- onProceed: ze
680
- }, {
681
- default: x(() => [l(y(g), {
682
- class: "exit-modal-message",
683
- keypath: e.config.consumerUsername ? "consumer_groups.consumers.exit.confirmation" : "consumer_groups.consumers.exit.confirmationNoUsername",
684
- tag: "p"
685
- }, s({
686
- consumerGroup: x(() => [o("strong", null, v($.value.name || $.value.id), 1)]),
687
- _: 2
688
- }, [e.config.consumerUsername ? {
689
- name: "consumer",
690
- fn: x(() => [o("strong", null, v(e.config.consumerUsername), 1)]),
691
- key: "0"
692
- } : void 0]), 1032, ["keypath"]), o("p", null, v(y(S)("consumer_groups.consumers.exit.description")), 1)]),
693
- _: 1
694
- }, 8, ["title", "visible"])) : i("", !0)
695
- ]);
696
- };
697
- }
698
- }), [["__scopeId", "data-v-0da0fd50"]]), Z = { class: "kong-ui-entities-consumer-group-form" }, ge = { class: "select-item-container" }, _e = { class: "select-item-label" }, ve = {
699
- key: 0,
700
- class: "select-item-description"
701
- }, ye = /*#__PURE__*/ X(/* @__PURE__ */ u({
702
- __name: "ConsumerGroupForm",
703
- props: {
704
- config: {
705
- type: Object,
706
- required: !0,
707
- validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || e?.app === "konnect" && !e?.controlPlaneId || e?.app === "kongManager" && typeof e?.workspace != "string" || !e?.cancelRoute)
708
- },
709
- consumerGroupId: {
710
- type: String,
711
- required: !1,
712
- default: null
713
- },
714
- hideConsumers: {
715
- type: Boolean,
716
- default: !1
717
- }
718
- },
719
- emits: [
720
- "update",
721
- "error",
722
- "loading"
723
- ],
724
- setup(e, { emit: t }) {
725
- let s = e, c = t, { i18n: { t: u } } = W.useI18n(), m = ae(), h = p({
726
- fields: {
727
- name: "",
728
- tags: "",
729
- consumers: []
730
- },
731
- errorMessage: "",
732
- readonly: !1
733
- }), g = p({
734
- name: "",
735
- tags: "",
736
- consumers: []
737
- }), { debouncedQueryChange: b, loading: S, error: ee, loadItems: T, results: E } = ne(s.config, J.form[s.config?.app]?.consumersList, "", {
738
- fetchedItemsKey: "data",
739
- searchKeys: [
740
- "username",
741
- "custom_id",
742
- "id"
743
- ]
744
- }), { axiosInstance: D } = te(s.config?.axiosRequestConfig), { getMessageFromError: k } = re(), A = R(), j = n(() => E.value.map((e) => ({
745
- label: e.username || e.custom_id,
746
- value: e.id,
747
- selected: h.fields.consumers.includes(e.id),
748
- data: e
749
- }))), N = n(() => J.form[s.config?.app].edit), P = n(() => s.consumerGroupId ? w.Edit : w.Create), F = n(() => !!h.fields.name && !V.value), ie = n(() => JSON.stringify(h.fields) !== JSON.stringify(g)), I = (e, t = "", n = "") => {
750
- let r = `${s.config?.apiBaseUrl}${J.form[s.config?.app][e]}`;
751
- return s.config?.app === "konnect" && (r = r.replace(/{controlPlaneId}/gi, s.config?.controlPlaneId || "")), r = r.replace(/\/{workspace}/gi, s.config?.workspace ? `/${s.config.workspace}` : "").replace(/{id}/gi, (t || s.consumerGroupId) ?? ""), (e === "addConsumer" || e === "removeConsumer") && (r = r.replace(/{consumerId}/gi, n)), r;
752
- }, L = () => {
753
- m.push(s.config?.cancelRoute || { name: "consumer-group-list" });
754
- }, z = (e) => {
755
- c("error", e);
756
- }, B = (e) => {
757
- c("loading", e);
758
- }, oe = async (e) => {
759
- h.fields.name = e?.item?.name || e?.consumer_group?.name || e?.name || "";
760
- let t = e?.item?.tags || e?.consumer_group.tags || e?.tags || [];
761
- if (h.fields.tags = t?.join(", ") || "", "consumers" in e) h.fields.consumers = e?.consumers?.map((e) => e.id) || [];
762
- else try {
763
- let { data: e } = await D.get(I("getConsumers"));
764
- h.fields.consumers = "consumers" in e ? e?.consumers?.map((e) => e.id) : [];
765
- } catch (e) {
766
- G(e);
767
- }
768
- Object.assign(g, h.fields);
769
- }, V = n(() => A.utf8Name(h.fields.name)), H = n(() => ({
770
- name: h.fields.name,
771
- tags: h.fields.tags.split(",")?.map((e) => String(e || "").trim())?.filter((e) => e !== "")
772
- })), U = async (e, t = "") => await D.post(I("addConsumer", t, e), { consumer: e }), se = async (e, t = "") => await D.delete(I("removeConsumer", t, e)), G = (e) => {
773
- h.errorMessage = k(e), c("error", e);
774
- }, K = (e = s.consumerGroupId ?? "") => {
775
- Object.assign(g, h.fields), c("update", {
776
- ...h.fields,
777
- id: e
778
- });
779
- }, q = (e, t, n = s.consumerGroupId ?? "") => {
780
- let r = e?.find((e) => e.status !== "fulfilled");
781
- r ? G({
782
- code: r.status,
783
- message: t
784
- }) : K(n);
785
- }, ce = async () => {
786
- let e = "";
787
- try {
788
- let { data: t } = await D.post(I("create"), H.value);
789
- e = "item" in t ? t.item.id : t.id;
790
- } catch (e) {
791
- G(e);
792
- }
793
- if (h.fields.consumers.length > 0 && e) try {
794
- let t = h.fields.consumers.map((t) => U(t, e)), n = await Promise.allSettled(t);
795
- q(n, u("consumer_groups.errors.add_consumer"), e);
796
- } catch (e) {
797
- G(e);
798
- }
799
- else h.fields.consumers.length === 0 && e && K(e);
800
- }, le = async () => {
801
- try {
802
- s.config?.app === "konnect" ? await D.put(I("edit"), H.value) : await D.patch(I("edit"), H.value);
803
- } catch (e) {
804
- G(e);
805
- }
806
- let e = h.fields.consumers.filter((e) => !g.consumers.includes(e)), t = g.consumers.filter((e) => !h.fields.consumers.includes(e));
807
- if (t.length === 0 && e.length === 0) K();
808
- else {
809
- if (t.length > 0) try {
810
- let e = t.map((e) => se(e)), n = await Promise.allSettled(e);
811
- q(n, u("consumer_groups.errors.remove_consumer"));
812
- } catch (e) {
813
- G(e);
814
- }
815
- if (e.length > 0) try {
816
- let t = e.map((e) => U(e)), n = await Promise.allSettled(t);
817
- q(n, u("consumer_groups.errors.add_consumer"));
818
- } catch (e) {
819
- G(e);
820
- }
821
- }
822
- }, ue = async () => {
823
- try {
824
- h.readonly = !0, P.value === w.Create ? await ce() : await le();
825
- } finally {
826
- h.readonly = !1;
827
- }
828
- };
829
- return d(async () => {
830
- s.hideConsumers || await T();
831
- }), (t, n) => {
832
- let s = _("KInput"), c = _("KMultiselect");
833
- return f(), a("div", Z, [l(y(C), {
834
- "can-submit": F.value && ie.value,
835
- config: e.config,
836
- "edit-id": e.consumerGroupId,
837
- "entity-type": y(M).ConsumerGroup,
838
- "error-message": h.errorMessage || y(ee) || V.value,
839
- "fetch-url": N.value,
840
- "form-fields": H.value,
841
- "is-readonly": h.readonly,
842
- onCancel: L,
843
- "onFetch:error": n[3] ||= (e) => z(e),
844
- "onFetch:success": oe,
845
- onLoading: n[4] ||= (e) => B(e),
846
- onSubmit: ue
847
- }, {
848
- default: x(() => [l(y(O), {
849
- description: y(u)("consumer_groups.form.general_info.description"),
850
- title: y(u)("consumer_groups.form.general_info.title")
851
- }, {
852
- default: x(() => [l(s, {
853
- modelValue: h.fields.name,
854
- "onUpdate:modelValue": n[0] ||= (e) => h.fields.name = e,
855
- modelModifiers: { trim: !0 },
856
- autocomplete: "off",
857
- "data-testid": "consumer-group-form-name",
858
- label: y(u)("consumer_groups.form.fields.name.label"),
859
- placeholder: y(u)("consumer_groups.form.fields.name.placeholder"),
860
- required: "",
861
- type: "text"
862
- }, null, 8, [
863
- "modelValue",
864
- "label",
865
- "placeholder"
866
- ]), l(s, {
867
- modelValue: h.fields.tags,
868
- "onUpdate:modelValue": n[1] ||= (e) => h.fields.tags = e,
869
- modelModifiers: { trim: !0 },
870
- autocomplete: "off",
871
- "data-testid": "consumer-group-form-tags",
872
- help: y(u)("consumer_groups.form.fields.tags.help"),
873
- label: y(u)("consumer_groups.form.fields.tags.label"),
874
- "label-attributes": {
875
- info: y(u)("consumer_groups.form.fields.tags.tooltip"),
876
- tooltipAttributes: { maxWidth: "400" }
877
- },
878
- placeholder: y(u)("consumer_groups.form.fields.tags.placeholder"),
879
- type: "text"
880
- }, null, 8, [
881
- "modelValue",
882
- "help",
883
- "label",
884
- "label-attributes",
885
- "placeholder"
886
- ])]),
887
- _: 1
888
- }, 8, ["description", "title"]), e.hideConsumers ? i("", !0) : (f(), r(y(O), {
889
- key: 0,
890
- description: y(u)("consumer_groups.form.consumers.description"),
891
- "has-divider": "",
892
- title: y(u)("consumer_groups.form.consumers.title")
893
- }, {
894
- default: x(() => [l(c, {
895
- modelValue: h.fields.consumers,
896
- "onUpdate:modelValue": n[2] ||= (e) => h.fields.consumers = e,
897
- appearance: "select",
898
- autosuggest: "",
899
- items: j.value,
900
- label: y(u)("consumer_groups.form.fields.consumers.label"),
901
- loading: y(S),
902
- placeholder: y(u)("consumer_groups.form.fields.consumers.placeholder"),
903
- width: "auto",
904
- onQueryChange: y(b)
905
- }, {
906
- "item-template": x(({ item: e }) => [o("div", ge, [o("div", _e, v(e.label), 1), e?.data?.username && e?.data?.custom_id ? (f(), a("div", ve, v(e?.data?.custom_id), 1)) : i("", !0)])]),
907
- _: 1
908
- }, 8, [
909
- "modelValue",
910
- "items",
911
- "label",
912
- "loading",
913
- "placeholder",
914
- "onQueryChange"
915
- ])]),
916
- _: 1
917
- }, 8, ["description", "title"]))]),
918
- _: 1
919
- }, 8, [
920
- "can-submit",
921
- "config",
922
- "edit-id",
923
- "entity-type",
924
- "error-message",
925
- "fetch-url",
926
- "form-fields",
927
- "is-readonly"
928
- ])]);
929
- };
930
- }
931
- }), [["__scopeId", "data-v-9c98b878"]]), be = { class: "kong-ui-consumer-group-entity-config-card" }, Q = /* @__PURE__ */ u({
932
- __name: "ConsumerGroupConfigCard",
933
- props: {
934
- config: {
935
- type: Object,
936
- required: !0,
937
- validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || e.app === "konnect" && !e.controlPlaneId || e.app === "kongManager" && typeof e.workspace != "string" || !e.entityId)
938
- },
939
- configCardDoc: {
940
- type: String,
941
- default: "",
942
- required: !1
943
- },
944
- hideTitle: {
945
- type: Boolean,
946
- default: !1
947
- }
948
- },
949
- emits: [
950
- "loading",
951
- "fetch:error",
952
- "fetch:success"
953
- ],
954
- setup(e) {
955
- let t = e, { i18n: { t: r } } = W.useI18n(), i = n(() => J.item[t.config.app]), o = m({
956
- id: {},
957
- name: {},
958
- created_at: {},
959
- updated_at: {},
960
- tags: { tooltip: r("consumer_groups.form.fields.tags.tooltip") }
961
- });
962
- return (t, n) => (f(), a("div", be, [l(y(S), {
963
- config: e.config,
964
- "config-card-doc": e.configCardDoc,
965
- "config-schema": o.value,
966
- "data-key": "consumer_group",
967
- "entity-type": y(M).ConsumerGroup,
968
- "fetch-url": i.value,
969
- "hide-title": e.hideTitle,
970
- "onFetch:error": n[0] ||= (e) => t.$emit("fetch:error", e),
971
- "onFetch:success": n[1] ||= (e) => t.$emit("fetch:success", e),
972
- onLoading: n[2] ||= (e) => t.$emit("loading", e)
973
- }, null, 8, [
974
- "config",
975
- "config-card-doc",
976
- "config-schema",
977
- "entity-type",
978
- "fetch-url",
979
- "hide-title"
980
- ])]));
981
- }
17
+ const le = {
18
+ useI18n: vo
19
+ }, Do = /* @__PURE__ */ ce({
20
+ __name: "ConsumerGroupConfigCardView",
21
+ props: {
22
+ record: { type: Object, required: !0 },
23
+ config: {
24
+ type: Object,
25
+ default: () => ({})
26
+ },
27
+ /**
28
+ * Control visibility of card title content
29
+ */
30
+ hideTitle: {
31
+ type: Boolean,
32
+ default: !1
33
+ }
34
+ },
35
+ setup(e) {
36
+ const { i18n: { t: T } } = le.useI18n(), a = v({
37
+ id: {},
38
+ name: {},
39
+ created_at: {},
40
+ updated_at: {},
41
+ tags: {
42
+ tooltip: T("consumer_groups.form.fields.tags.tooltip")
43
+ }
44
+ });
45
+ return (t, p) => (w(), N("div", null, [
46
+ l(o(ze), {
47
+ config: e.config,
48
+ "config-schema": a.value,
49
+ "entity-type": o(be).ConsumerGroup,
50
+ "hide-title": e.hideTitle,
51
+ record: e.record
52
+ }, me({ _: 2 }, [
53
+ t.$slots.title ? {
54
+ name: "title",
55
+ fn: c(() => [
56
+ xe(t.$slots, "title")
57
+ ]),
58
+ key: "0"
59
+ } : void 0,
60
+ t.$slots.actions ? {
61
+ name: "actions",
62
+ fn: c(() => [
63
+ xe(t.$slots, "actions")
64
+ ]),
65
+ key: "1"
66
+ } : void 0
67
+ ]), 1032, ["config", "config-schema", "entity-type", "hide-title", "record"])
68
+ ]));
69
+ }
70
+ }), A = "/v2/control-planes/{controlPlaneId}/core-entities/{workspace}", P = "/{workspace}", Q = {
71
+ list: {
72
+ konnect: {
73
+ all: `${A}/consumer_groups`,
74
+ forModal: `${A}/consumer_groups`,
75
+ forConsumer: `${A}/consumers/{consumerId}/consumer_groups`,
76
+ oneForConsumer: `${A}/consumers/{consumerId}/consumer_groups/{consumerGroupId}`
77
+ },
78
+ kongManager: {
79
+ all: `${P}/consumer_groups?counter=true`,
80
+ // we need counter=true to get consumers_count in consumer group list
81
+ forModal: `${P}/consumer_groups`,
82
+ forConsumer: `${P}/consumers/{consumerId}/consumer_groups`,
83
+ oneForConsumer: `${P}/consumers/{consumerId}/consumer_groups/{consumerGroupId}`
84
+ }
85
+ },
86
+ form: {
87
+ konnect: {
88
+ consumersList: `${A}/consumers`,
89
+ create: `${A}/consumer_groups`,
90
+ edit: `${A}/consumer_groups/{id}`,
91
+ addConsumer: `${A}/consumer_groups/{id}/consumers`,
92
+ removeConsumer: `${A}/consumer_groups/{id}/consumers/{consumerId}`,
93
+ getConsumers: `${A}/consumer_groups/{id}/consumers`
94
+ },
95
+ kongManager: {
96
+ consumersList: `${P}/consumers`,
97
+ create: `${P}/consumer_groups`,
98
+ edit: `${P}/consumer_groups/{id}`,
99
+ addConsumer: `${P}/consumer_groups/{id}/consumers`,
100
+ removeConsumer: `${P}/consumer_groups/{id}/consumers/{consumerId}`,
101
+ getConsumers: `${P}/consumer_groups/{id}/consumers`
102
+ }
103
+ },
104
+ item: {
105
+ konnect: `${A}/consumer_groups/{id}?list_consumers=false`,
106
+ kongManager: `${P}/consumer_groups/{id}?list_consumers=false`
107
+ }
108
+ }, ho = { class: "add-to-group-form-container" }, _o = { class: "add-to-group-cta-text" }, bo = {
109
+ key: 0,
110
+ class: "kong-ui-entity-add-to-groups-error"
111
+ }, Co = { key: 0 }, ko = /* @__PURE__ */ ce({
112
+ __name: "AddToGroupModal",
113
+ props: {
114
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
115
+ config: {
116
+ type: Object,
117
+ required: !0,
118
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || !e.consumerId)
119
+ },
120
+ visible: {
121
+ type: Boolean,
122
+ required: !0
123
+ }
124
+ },
125
+ emits: ["cancel", "add:success", "add:partial-success", "error"],
126
+ setup(e, { emit: T }) {
127
+ const { i18n: { t: a } } = le.useI18n(), t = e, p = T, { axiosInstance: i } = Ce(t.config?.axiosRequestConfig), n = v([]), {
128
+ debouncedQueryChange: $,
129
+ loading: ee,
130
+ allRecords: B,
131
+ error: oe,
132
+ loadItems: te,
133
+ results: J
134
+ } = Be(
135
+ t.config,
136
+ Q.list[t.config.app].forModal,
137
+ "",
138
+ {
139
+ fetchedItemsKey: "data",
140
+ searchKeys: ["name", "id"]
141
+ }
142
+ ), G = h(() => oe.value ? a("consumer_groups.errors.general") : ""), z = v(0), x = h(() => B.value === void 0), W = h(() => J.value.map((m) => ({
143
+ label: m.name,
144
+ value: m.id,
145
+ selected: n.value.includes(m.id),
146
+ data: m
147
+ // we need this to determine whether or not to show the description text
148
+ }))), X = (m) => {
149
+ const _ = x.value ? J.value.find((I) => I.id === m) : B.value?.find((I) => I.id === m);
150
+ return _ ? _.name : m;
151
+ }, se = () => {
152
+ M.value = "", F.value = [], S.value = [], p("cancel");
153
+ }, F = v([]), E = v(!1), M = v(""), re = async () => {
154
+ if (!n.value.length) {
155
+ M.value = "", S.value = [], p("cancel");
156
+ return;
157
+ }
158
+ E.value = !0, M.value = "", F.value = [], S.value = [];
159
+ try {
160
+ const m = n.value.map((k) => ae(k)), _ = await Promise.allSettled(m);
161
+ let I = !0;
162
+ _.forEach((k) => {
163
+ k.status !== "fulfilled" && (I = !1);
164
+ }), I ? (F.value = [], S.value = [], p("add:success", n.value), n.value = []) : (F.value.length && p("add:partial-success", F.value), n.value = [], Y(_));
165
+ } catch {
166
+ M.value = a("consumer_groups.errors.add"), p("error", M.value);
167
+ } finally {
168
+ E.value = !1;
169
+ }
170
+ }, ne = h(() => {
171
+ let m = `${t.config.apiBaseUrl}${Q.list[t.config.app].forConsumer}`;
172
+ return t.config.app === "konnect" && (m = m.replace(/{controlPlaneId}/gi, t.config?.controlPlaneId || "")), m.replace(/\/{workspace}/gi, t.config?.workspace ? `/${t.config.workspace}` : "").replace(/{consumerId}/gi, t.config?.consumerId || "");
173
+ }), ae = async (m) => {
174
+ const _ = {
175
+ group: m
176
+ };
177
+ try {
178
+ const I = await i.post(ne.value, _);
179
+ return F.value.push(m), I;
180
+ } catch (I) {
181
+ let k = `${X(m)} - ${I.message}`;
182
+ return I.response.status === 409 && (k = `${X(m)} - ${a("consumer_groups.errors.already_added")}`), Promise.reject(Error(k));
183
+ }
184
+ }, S = v([]), Y = (m) => {
185
+ S.value = m.map((_) => _.reason?.message).filter(Boolean);
186
+ };
187
+ return _e(W, () => {
188
+ z.value++;
189
+ }, { immediate: !0, deep: !0 }), _e(() => t.visible, () => {
190
+ t.visible && te();
191
+ }, { immediate: !0 }), (m, _) => {
192
+ const I = K("KMultiselect"), k = K("KAlert"), H = K("KPrompt");
193
+ return w(), L(H, {
194
+ "action-button-disabled": E.value,
195
+ class: "kong-ui-entities-add-to-groups-modal",
196
+ "data-testid": "add-to-group-modal",
197
+ title: o(a)("consumer_groups.consumers.add.title"),
198
+ visible: e.visible,
199
+ onCancel: se,
200
+ onProceed: re
201
+ }, {
202
+ default: c(() => [
203
+ V("div", ho, [
204
+ V("p", _o, C(o(a)("consumer_groups.consumers.add.ctaText")), 1),
205
+ l(I, {
206
+ modelValue: n.value,
207
+ "onUpdate:modelValue": _[0] || (_[0] = (D) => n.value = D),
208
+ autosuggest: "",
209
+ "data-testid": "add-to-groups-multiselect",
210
+ "dropdown-footer-text": x.value ? o(a)("consumer_groups.consumers.add.footer") : void 0,
211
+ items: W.value,
212
+ label: o(a)("consumer_groups.consumers.add.consumer_groups_label"),
213
+ loading: o(ee),
214
+ placeholder: o(a)("consumer_groups.consumers.add.consumer_group_placeholder"),
215
+ readonly: E.value,
216
+ required: "",
217
+ width: "100%",
218
+ onQueryChange: o($)
219
+ }, null, 8, ["modelValue", "dropdown-footer-text", "items", "label", "loading", "placeholder", "readonly", "onQueryChange"]),
220
+ M.value || G.value || S.value.length ? (w(), N("div", bo, [
221
+ l(k, { appearance: "danger" }, {
222
+ default: c(() => [
223
+ V("p", null, C(o(a)("consumer_groups.errors.add")), 1),
224
+ S.value.length ? (w(), N("ul", Co, [
225
+ (w(!0), N(Qe, null, He(S.value, (D, ie) => (w(), N("li", { key: ie }, C(D), 1))), 128))
226
+ ])) : O("", !0),
227
+ V("div", null, C(M.value || G.value), 1)
228
+ ]),
229
+ _: 1
230
+ })
231
+ ])) : O("", !0)
232
+ ])
233
+ ]),
234
+ _: 1
235
+ }, 8, ["action-button-disabled", "title", "visible"]);
236
+ };
237
+ }
238
+ }), ke = (e, T) => {
239
+ const a = e.__vccOpts || e;
240
+ for (const [t, p] of T)
241
+ a[t] = p;
242
+ return a;
243
+ }, Io = /* @__PURE__ */ ke(ko, [["__scopeId", "data-v-54887165"]]), wo = { class: "kong-ui-entities-consumer-groups-list" }, $o = { class: "button-row" }, Eo = /* @__PURE__ */ ce({
244
+ __name: "ConsumerGroupList",
245
+ props: {
246
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
247
+ config: {
248
+ type: Object,
249
+ required: !0,
250
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || !e.createRoute || !e.getViewRoute || !e.getEditRoute || e.app === "kongManager" && !e.isExactMatch && !e.filterSchema)
251
+ },
252
+ // used to override the default identifier for the cache entry
253
+ cacheIdentifier: {
254
+ type: String,
255
+ default: ""
256
+ },
257
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can create a new entity */
258
+ canCreate: {
259
+ type: Function,
260
+ required: !1,
261
+ default: async () => !0
262
+ },
263
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can delete a given entity */
264
+ canDelete: {
265
+ type: Function,
266
+ required: !1,
267
+ default: async () => !0
268
+ },
269
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can edit a given entity */
270
+ canEdit: {
271
+ type: Function,
272
+ required: !1,
273
+ default: async () => !0
274
+ },
275
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can retrieve (view details) a given entity */
276
+ canRetrieve: {
277
+ type: Function,
278
+ required: !1,
279
+ default: async () => !0
280
+ },
281
+ /** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
282
+ useActionOutside: {
283
+ type: Boolean,
284
+ default: !1
285
+ }
286
+ },
287
+ emits: ["error", "click:learn-more", "copy:success", "copy:error", "delete:success", "add:success", "remove:success"],
288
+ setup(e, { emit: T }) {
289
+ const a = T, t = e, { i18nT: p, i18n: { t: i } } = le.useI18n(), n = Fe(), { axiosInstance: $ } = Ce(t.config?.axiosRequestConfig), ee = h(() => t.config.app !== "kongManager" || !!t.config.disableSorting), B = {
290
+ // the Name column is non-hidable
291
+ name: { label: i("consumer_groups.list.table_headers.name"), searchable: !0, sortable: !0, hidable: !1 }
292
+ };
293
+ t.config.app === "kongManager" && (B.consumers_count = { label: i("consumer_groups.list.table_headers.consumers_count"), searchable: !1, sortable: !1 }), B.tags = { label: i("consumer_groups.list.table_headers.tags"), sortable: !1 };
294
+ const { defaultTablePreferences: oe, tableHeaders: te } = We(B), J = (r) => ({
295
+ "data-testid": r.username ?? r.custom_id ?? r.id
296
+ }), G = () => {
297
+ t.config.consumerId ? Ie() : n.push(t.config.createRoute);
298
+ }, z = h(() => {
299
+ let r = `${t.config.apiBaseUrl}${Q.list[t.config.app][E.value ? "forConsumer" : "all"]}`;
300
+ return t.config.app === "konnect" && (r = r.replace(/{controlPlaneId}/gi, t.config?.controlPlaneId || ""), x.value && t.config.isExactMatch && (r += "?list_consumers=false")), r.replace(/\/{workspace}/gi, t.config?.workspace ? `/${t.config.workspace}` : "").replace(/{consumerId}/gi, t.config?.consumerId || "");
301
+ }), x = v(""), W = h(() => {
302
+ const r = t.config.app === "konnect" || t.config.isExactMatch;
303
+ return r ? {
304
+ isExactMatch: r,
305
+ fields: {
306
+ username: B.name,
307
+ id: { label: i("consumer_groups.list.table_headers.id") }
308
+ },
309
+ placeholder: i("consumer_groups.search.placeholder")
310
+ } : {
311
+ isExactMatch: r,
312
+ fields: {
313
+ name: B.name
314
+ },
315
+ schema: t.config.filterSchema
316
+ };
317
+ }), { hasRecords: X, handleStateChange: se } = Xe(x), F = h(() => X.value && t.config.app === "konnect"), E = h(() => !!t.config.consumerId), M = h(
318
+ () => E.value ? "kong-ui-entities-consumer-groups-list-in-consumer-page" : "kong-ui-entities-consumer-groups-list"
319
+ ), re = h(() => t.config.app === "konnect" && x.value ? "consumer_group" : E.value && !t.config.paginatedEndpoint ? "consumer_groups" : void 0), {
320
+ fetcher: ne,
321
+ fetcherState: ae,
322
+ fetcherCacheKey: S
323
+ } = Ye(h(() => ({ ...t.config, cacheIdentifier: t.cacheIdentifier })), z, re), Y = () => {
324
+ x.value = "";
325
+ }, m = () => {
326
+ S.value++;
327
+ }, _ = v(null), I = async (r, b) => {
328
+ const R = r.id;
329
+ if (!await b(R)) {
330
+ a("copy:error", {
331
+ entity: r,
332
+ field: "id",
333
+ message: i("consumer_groups.errors.copy")
334
+ });
335
+ return;
336
+ }
337
+ a("copy:success", {
338
+ entity: r,
339
+ field: "id",
340
+ message: i("consumer_groups.copy.success", { val: R })
341
+ });
342
+ }, k = async (r, b) => {
343
+ const R = JSON.stringify(r);
344
+ if (!await b(R)) {
345
+ a("copy:error", {
346
+ entity: r,
347
+ message: i("consumer_groups.errors.copy")
348
+ });
349
+ return;
350
+ }
351
+ a("copy:success", {
352
+ entity: r,
353
+ message: i("consumer_groups.copy.success_brief")
354
+ });
355
+ }, H = async (r) => {
356
+ await t.canRetrieve?.(r) && n.push(t.config.getViewRoute(r.id));
357
+ }, D = (r) => ({
358
+ label: i("consumer_groups.actions.view"),
359
+ to: t.config.getViewRoute(r)
360
+ }), ie = (r) => ({
361
+ label: i("consumer_groups.actions.edit"),
362
+ to: t.config.getEditRoute(r)
363
+ }), U = v(void 0), Z = v(!1), s = v(!1), u = v(""), d = Ze(t.config, z.value), f = (r) => {
364
+ U.value = r, Z.value = !0;
365
+ }, y = () => {
366
+ Z.value = !1;
367
+ }, Ke = async () => {
368
+ if (U.value?.id) {
369
+ s.value = !0;
370
+ try {
371
+ await $.delete(d(U.value.id)), s.value = !1, Z.value = !1, S.value++, a("delete:success", U.value);
372
+ } catch (r) {
373
+ u.value = r.response?.data?.message || r.message || i("consumer_groups.errors.delete"), a("error", r);
374
+ } finally {
375
+ s.value = !1;
376
+ }
377
+ }
378
+ }, pe = v(!1), Ie = () => {
379
+ pe.value = !0;
380
+ }, we = () => {
381
+ pe.value = !1;
382
+ }, $e = (r, b) => {
383
+ b || we(), S.value++, a("add:success", r);
384
+ }, De = () => {
385
+ E.value && Ie();
386
+ }, j = v(void 0), ge = v(!1), Ue = v(""), Re = (r) => {
387
+ j.value = r, ge.value = !0;
388
+ }, Ee = () => {
389
+ ge.value = !1, j.value = void 0;
390
+ }, qe = h(() => {
391
+ let r = `${t.config.apiBaseUrl}${Q.list[t.config.app].oneForConsumer}`;
392
+ return t.config.app === "konnect" && (r = r.replace(/{controlPlaneId}/gi, t.config?.controlPlaneId || "")), r.replace(/\/{workspace}/gi, t.config?.workspace ? `/${t.config.workspace}` : "").replace(/{consumerId}/gi, t.config?.consumerId || "");
393
+ }), Me = v(!1), Oe = async () => {
394
+ if (j.value) {
395
+ Me.value = !0;
396
+ try {
397
+ const r = qe.value.replace(/{consumerGroupId}/gi, j.value.id);
398
+ await $.delete(r), a("remove:success", j.value), Ee(), S.value++;
399
+ } catch (r) {
400
+ Ue.value = r.message || i("consumer_groups.errors.delete"), a("error", r);
401
+ } finally {
402
+ Me.value = !1;
403
+ }
404
+ }
405
+ };
406
+ _e(ae, (r) => {
407
+ if (r.status === eo.Error) {
408
+ _.value = {
409
+ title: i("consumer_groups.errors.general")
410
+ }, r.error?.response?.data?.message && (_.value.message = r.error.response.data.message), a("error", r.error);
411
+ return;
412
+ }
413
+ _.value = null;
414
+ });
415
+ const fe = v({
416
+ ctaPath: E.value ? void 0 : t.config.createRoute,
417
+ ctaText: void 0,
418
+ message: `${i("consumer_groups.list.empty_state.description")}${t.config.additionMessageForEmptyState ? ` ${t.config.additionMessageForEmptyState}` : ""}`,
419
+ title: i("consumer_groups.title")
420
+ }), ye = v(!1);
421
+ return Ve(async () => {
422
+ ye.value = await t.canCreate(), ye.value && (fe.value.title = E.value ? i("consumer_groups.list.empty_state.title_for_consumer") : i("consumer_groups.list.empty_state.title"), fe.value.ctaText = E.value ? i("consumer_groups.actions.add_to_group") : i("consumer_groups.actions.create"));
423
+ }), (r, b) => {
424
+ const R = K("KButton"), Ne = K("KEmptyState"), ue = K("KDropdownItem"), Se = K("KClipboardProvider"), je = K("KPrompt");
425
+ return w(), N("div", wo, [
426
+ l(o(oo), {
427
+ "cache-identifier": e.cacheIdentifier,
428
+ "default-table-preferences": o(oe),
429
+ "disable-pagination": E.value && !e.config.paginatedEndpoint,
430
+ "disable-sorting": ee.value,
431
+ "empty-state-options": fe.value,
432
+ "enable-entity-actions": "",
433
+ "error-message": _.value,
434
+ fetcher: o(ne),
435
+ "fetcher-cache-key": o(S),
436
+ "pagination-type": "offset",
437
+ "preferences-storage-key": M.value,
438
+ query: x.value,
439
+ "row-attributes": J,
440
+ "table-headers": o(te),
441
+ onClearSearchInput: Y,
442
+ "onClick:row": b[3] || (b[3] = (g) => H(g)),
443
+ onEmptyStateCtaClicked: De,
444
+ onSort: m,
445
+ onState: o(se)
446
+ }, me({
447
+ "toolbar-filter": c(() => [
448
+ E.value ? O("", !0) : (w(), L(o(ro), {
449
+ key: 0,
450
+ modelValue: x.value,
451
+ "onUpdate:modelValue": b[0] || (b[0] = (g) => x.value = g),
452
+ config: W.value
453
+ }, null, 8, ["modelValue", "config"]))
454
+ ]),
455
+ "toolbar-button": c(() => [
456
+ (w(), L(Je, {
457
+ disabled: !e.useActionOutside,
458
+ to: "#kong-ui-app-page-header-action-button"
459
+ }, [
460
+ V("div", $o, [
461
+ F.value ? (w(), L(R, {
462
+ key: 0,
463
+ appearance: "secondary",
464
+ class: "open-learning-hub",
465
+ "data-testid": "consumer-groups-learn-more-button",
466
+ icon: "",
467
+ onClick: b[1] || (b[1] = (g) => r.$emit("click:learn-more"))
468
+ }, {
469
+ default: c(() => [
470
+ l(o(Ae), { decorative: "" })
471
+ ]),
472
+ _: 1
473
+ })) : O("", !0),
474
+ l(o(de), {
475
+ "auth-function": () => e.canCreate()
476
+ }, {
477
+ default: c(() => [
478
+ l(R, {
479
+ appearance: "primary",
480
+ "data-testid": "toolbar-add-consumer-group",
481
+ size: e.useActionOutside ? "medium" : "large",
482
+ onClick: G
483
+ }, {
484
+ default: c(() => [
485
+ l(o(Pe)),
486
+ q(" " + C(e.config.consumerId ? o(i)("consumer_groups.actions.add_to_group") : o(i)("consumer_groups.list.toolbar_actions.new_consumer_group")), 1)
487
+ ]),
488
+ _: 1
489
+ }, 8, ["size"])
490
+ ]),
491
+ _: 1
492
+ }, 8, ["auth-function"])
493
+ ])
494
+ ], 8, ["disabled"]))
495
+ ]),
496
+ name: c(({ rowValue: g }) => [
497
+ V("b", null, C(g ?? "-"), 1)
498
+ ]),
499
+ consumers_count: c(({ rowValue: g }) => [
500
+ q(C(g ?? "-"), 1)
501
+ ]),
502
+ tags: c(({ rowValue: g }) => [
503
+ l(o(so), { tags: g }, null, 8, ["tags"])
504
+ ]),
505
+ managed_by: c(({ rowValue: g }) => [
506
+ q(C(o(to)(g) ?? "-"), 1)
507
+ ]),
508
+ actions: c(({ row: g }) => [
509
+ l(Se, null, {
510
+ default: c(({ copyToClipboard: ve }) => [
511
+ l(ue, {
512
+ "data-testid": "action-entity-copy-id",
513
+ onClick: (Le) => I(g, ve)
514
+ }, {
515
+ default: c(() => [
516
+ q(C(o(i)("consumer_groups.actions.copy_id")), 1)
517
+ ]),
518
+ _: 1
519
+ }, 8, ["onClick"])
520
+ ]),
521
+ _: 2
522
+ }, 1024),
523
+ l(Se, null, {
524
+ default: c(({ copyToClipboard: ve }) => [
525
+ l(ue, {
526
+ "data-testid": "action-entity-copy-json",
527
+ onClick: (Le) => k(g, ve)
528
+ }, {
529
+ default: c(() => [
530
+ q(C(o(i)("consumer_groups.actions.copy_json")), 1)
531
+ ]),
532
+ _: 1
533
+ }, 8, ["onClick"])
534
+ ]),
535
+ _: 2
536
+ }, 1024),
537
+ l(o(de), {
538
+ "auth-function": () => e.canRetrieve(g)
539
+ }, {
540
+ default: c(() => [
541
+ l(ue, {
542
+ "data-testid": "action-entity-view",
543
+ "has-divider": "",
544
+ item: D(g.id)
545
+ }, null, 8, ["item"])
546
+ ]),
547
+ _: 2
548
+ }, 1032, ["auth-function"]),
549
+ l(o(de), {
550
+ "auth-function": () => e.canEdit(g)
551
+ }, {
552
+ default: c(() => [
553
+ l(ue, {
554
+ "data-testid": "action-entity-edit",
555
+ item: ie(g.id)
556
+ }, null, 8, ["item"])
557
+ ]),
558
+ _: 2
559
+ }, 1032, ["auth-function"]),
560
+ l(o(de), {
561
+ "auth-function": () => e.canDelete(g)
562
+ }, {
563
+ default: c(() => [
564
+ l(ue, {
565
+ danger: "",
566
+ "data-testid": "action-entity-delete",
567
+ "has-divider": "",
568
+ onClick: () => e.config.consumerId ? Re(g) : f(g)
569
+ }, {
570
+ default: c(() => [
571
+ q(C(e.config.consumerId ? o(i)("consumer_groups.actions.exit") : o(i)("consumer_groups.actions.delete")), 1)
572
+ ]),
573
+ _: 1
574
+ }, 8, ["onClick"])
575
+ ]),
576
+ _: 2
577
+ }, 1032, ["auth-function"])
578
+ ]),
579
+ _: 2
580
+ }, [
581
+ !x.value && e.config.app === "konnect" ? {
582
+ name: "empty-state",
583
+ fn: c(() => [
584
+ l(Ne, {
585
+ "data-testid": "consumer-groups-entity-empty-state",
586
+ "icon-background": "",
587
+ message: o(i)("consumer_groups.list.empty_state_v2.description"),
588
+ title: o(i)("consumer_groups.list.empty_state_v2.title")
589
+ }, me({
590
+ icon: c(() => [
591
+ l(o(go), { decorative: "" })
592
+ ]),
593
+ action: c(() => [
594
+ ye.value ? (w(), L(R, {
595
+ key: 0,
596
+ "data-testid": "entity-create-button",
597
+ onClick: G
598
+ }, {
599
+ default: c(() => [
600
+ l(o(Pe), { decorative: "" }),
601
+ q(" " + C(o(i)("consumer_groups.list.toolbar_actions.new_consumer_group")), 1)
602
+ ]),
603
+ _: 1
604
+ })) : O("", !0),
605
+ l(R, {
606
+ appearance: "secondary",
607
+ "data-testid": "entity-learn-more-button",
608
+ onClick: b[2] || (b[2] = (g) => r.$emit("click:learn-more"))
609
+ }, {
610
+ default: c(() => [
611
+ l(o(Ae), { decorative: "" }),
612
+ q(" " + C(o(i)("consumer_groups.list.empty_state_v2.learn_more")), 1)
613
+ ]),
614
+ _: 1
615
+ })
616
+ ]),
617
+ _: 2
618
+ }, [
619
+ e.config?.isControlPlaneGroup ? {
620
+ name: "default",
621
+ fn: c(() => [
622
+ q(C(o(i)("consumer_groups.list.empty_state_v2.group")), 1)
623
+ ]),
624
+ key: "0"
625
+ } : void 0
626
+ ]), 1032, ["message", "title"])
627
+ ]),
628
+ key: "0"
629
+ } : void 0
630
+ ]), 1032, ["cache-identifier", "default-table-preferences", "disable-pagination", "disable-sorting", "empty-state-options", "error-message", "fetcher", "fetcher-cache-key", "preferences-storage-key", "query", "table-headers", "onState"]),
631
+ l(o(no), {
632
+ "action-pending": s.value,
633
+ "data-testid": "delete-consumer-group-modal",
634
+ description: o(i)("consumer_groups.delete.description"),
635
+ "entity-name": U.value && (U.value.name || U.value.id),
636
+ "entity-type": o(ao).ConsumerGroup,
637
+ error: u.value,
638
+ title: o(i)("consumer_groups.delete.title"),
639
+ visible: Z.value,
640
+ onCancel: y,
641
+ onProceed: Ke
642
+ }, null, 8, ["action-pending", "description", "entity-name", "entity-type", "error", "title", "visible"]),
643
+ e.config.consumerId ? (w(), L(Io, {
644
+ key: 0,
645
+ config: e.config,
646
+ "data-testid": "add-to-group-modal",
647
+ visible: pe.value,
648
+ "onAdd:partialSuccess": b[4] || (b[4] = (g) => $e(g, !0)),
649
+ "onAdd:success": b[5] || (b[5] = (g) => $e(g)),
650
+ onCancel: we
651
+ }, null, 8, ["config", "visible"])) : O("", !0),
652
+ e.config.consumerId && j.value ? (w(), L(je, {
653
+ key: 1,
654
+ "action-button-appearance": "danger",
655
+ "data-testid": "exit-group-modal",
656
+ title: o(i)("consumer_groups.consumers.exit.title"),
657
+ visible: ge.value,
658
+ onCancel: Ee,
659
+ onProceed: Oe
660
+ }, {
661
+ default: c(() => [
662
+ l(o(p), {
663
+ class: "exit-modal-message",
664
+ keypath: e.config.consumerUsername ? "consumer_groups.consumers.exit.confirmation" : "consumer_groups.consumers.exit.confirmationNoUsername",
665
+ tag: "p"
666
+ }, me({
667
+ consumerGroup: c(() => [
668
+ V("strong", null, C(j.value.name || j.value.id), 1)
669
+ ]),
670
+ _: 2
671
+ }, [
672
+ e.config.consumerUsername ? {
673
+ name: "consumer",
674
+ fn: c(() => [
675
+ V("strong", null, C(e.config.consumerUsername), 1)
676
+ ]),
677
+ key: "0"
678
+ } : void 0
679
+ ]), 1032, ["keypath"]),
680
+ V("p", null, C(o(i)("consumer_groups.consumers.exit.description")), 1)
681
+ ]),
682
+ _: 1
683
+ }, 8, ["title", "visible"])) : O("", !0)
684
+ ]);
685
+ };
686
+ }
687
+ }), Uo = /* @__PURE__ */ ke(Eo, [["__scopeId", "data-v-0da0fd50"]]), Mo = { class: "kong-ui-entities-consumer-group-form" }, So = { class: "select-item-container" }, xo = { class: "select-item-label" }, Go = {
688
+ key: 0,
689
+ class: "select-item-description"
690
+ }, To = /* @__PURE__ */ ce({
691
+ __name: "ConsumerGroupForm",
692
+ props: {
693
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
694
+ config: {
695
+ type: Object,
696
+ required: !0,
697
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || e?.app === "konnect" && !e?.controlPlaneId || e?.app === "kongManager" && typeof e?.workspace != "string" || !e?.cancelRoute)
698
+ },
699
+ /** If a valid consumerGroupId is provided, it will put the form in Edit mode instead of Create */
700
+ consumerGroupId: {
701
+ type: String,
702
+ required: !1,
703
+ default: null
704
+ },
705
+ hideConsumers: {
706
+ type: Boolean,
707
+ default: !1
708
+ }
709
+ },
710
+ emits: ["update", "error", "loading"],
711
+ setup(e, { emit: T }) {
712
+ const a = e, t = T, { i18n: { t: p } } = le.useI18n(), i = Fe(), n = Ge({
713
+ fields: {
714
+ name: "",
715
+ tags: "",
716
+ consumers: []
717
+ },
718
+ errorMessage: "",
719
+ readonly: !1
720
+ }), $ = Ge({
721
+ name: "",
722
+ tags: "",
723
+ consumers: []
724
+ }), {
725
+ debouncedQueryChange: ee,
726
+ loading: B,
727
+ error: oe,
728
+ loadItems: te,
729
+ results: J
730
+ } = Be(a.config, Q.form[a.config?.app]?.consumersList, "", {
731
+ fetchedItemsKey: "data",
732
+ searchKeys: ["username", "custom_id", "id"]
733
+ }), { axiosInstance: G } = Ce(a.config?.axiosRequestConfig), { getMessageFromError: z } = io(), x = uo(), W = h(() => J.value.map((s) => ({
734
+ label: s.username || s.custom_id,
735
+ value: s.id,
736
+ selected: n.fields.consumers.includes(s.id),
737
+ data: s
738
+ // we need this to determine whether or not to show the description text
739
+ }))), X = h(() => Q.form[a.config?.app].edit), se = h(() => a.consumerGroupId ? he.Edit : he.Create), F = h(() => !!n.fields.name && !Y.value), E = h(() => JSON.stringify(n.fields) !== JSON.stringify($)), M = (s, u = "", d = "") => {
740
+ let f = `${a.config?.apiBaseUrl}${Q.form[a.config?.app][s]}`;
741
+ return a.config?.app === "konnect" && (f = f.replace(/{controlPlaneId}/gi, a.config?.controlPlaneId || "")), f = f.replace(/\/{workspace}/gi, a.config?.workspace ? `/${a.config.workspace}` : "").replace(/{id}/gi, (u || a.consumerGroupId) ?? ""), (s === "addConsumer" || s === "removeConsumer") && (f = f.replace(/{consumerId}/gi, d)), f;
742
+ }, re = () => {
743
+ i.push(a.config?.cancelRoute || { name: "consumer-group-list" });
744
+ }, ne = (s) => {
745
+ t("error", s);
746
+ }, ae = (s) => {
747
+ t("loading", s);
748
+ }, S = async (s) => {
749
+ n.fields.name = s?.item?.name || s?.consumer_group?.name || s?.name || "";
750
+ const u = s?.item?.tags || s?.consumer_group.tags || s?.tags || [];
751
+ if (n.fields.tags = u?.join(", ") || "", "consumers" in s)
752
+ n.fields.consumers = s?.consumers?.map((d) => d.id) || [];
753
+ else
754
+ try {
755
+ const { data: d } = await G.get(M("getConsumers"));
756
+ n.fields.consumers = "consumers" in d ? d?.consumers?.map((f) => f.id) : [];
757
+ } catch (d) {
758
+ k(d);
759
+ }
760
+ Object.assign($, n.fields);
761
+ }, Y = h(() => x.utf8Name(n.fields.name)), m = h(() => ({
762
+ name: n.fields.name,
763
+ tags: n.fields.tags.split(",")?.map((s) => String(s || "").trim())?.filter((s) => s !== "")
764
+ })), _ = async (s, u = "") => await G.post(M("addConsumer", u, s), { consumer: s }), I = async (s, u = "") => await G.delete(M("removeConsumer", u, s)), k = (s) => {
765
+ n.errorMessage = z(s), t("error", s);
766
+ }, H = (s = a.consumerGroupId ?? "") => {
767
+ Object.assign($, n.fields), t("update", { ...n.fields, id: s });
768
+ }, D = (s, u, d = a.consumerGroupId ?? "") => {
769
+ const f = s?.find((y) => y.status !== "fulfilled");
770
+ f ? k({
771
+ code: f.status,
772
+ message: u
773
+ }) : H(d);
774
+ }, ie = async () => {
775
+ let s = "";
776
+ try {
777
+ const { data: u } = await G.post(M("create"), m.value);
778
+ s = "item" in u ? u.item.id : u.id;
779
+ } catch (u) {
780
+ k(u);
781
+ }
782
+ if (n.fields.consumers.length > 0 && s)
783
+ try {
784
+ const u = n.fields.consumers.map((f) => _(f, s)), d = await Promise.allSettled(u);
785
+ D(d, p("consumer_groups.errors.add_consumer"), s);
786
+ } catch (u) {
787
+ k(u);
788
+ }
789
+ else n.fields.consumers.length === 0 && s && H(s);
790
+ }, U = async () => {
791
+ try {
792
+ a.config?.app === "konnect" ? await G.put(M("edit"), m.value) : await G.patch(M("edit"), m.value);
793
+ } catch (d) {
794
+ k(d);
795
+ }
796
+ const s = n.fields.consumers.filter((d) => !$.consumers.includes(d)), u = $.consumers.filter((d) => !n.fields.consumers.includes(d));
797
+ if (u.length === 0 && s.length === 0)
798
+ H();
799
+ else {
800
+ if (u.length > 0)
801
+ try {
802
+ const d = u.map((y) => I(y)), f = await Promise.allSettled(d);
803
+ D(f, p("consumer_groups.errors.remove_consumer"));
804
+ } catch (d) {
805
+ k(d);
806
+ }
807
+ if (s.length > 0)
808
+ try {
809
+ const d = s.map((y) => _(y)), f = await Promise.allSettled(d);
810
+ D(f, p("consumer_groups.errors.add_consumer"));
811
+ } catch (d) {
812
+ k(d);
813
+ }
814
+ }
815
+ }, Z = async () => {
816
+ try {
817
+ n.readonly = !0, se.value === he.Create ? await ie() : await U();
818
+ } finally {
819
+ n.readonly = !1;
820
+ }
821
+ };
822
+ return Ve(async () => {
823
+ a.hideConsumers || await te();
824
+ }), (s, u) => {
825
+ const d = K("KInput"), f = K("KMultiselect");
826
+ return w(), N("div", Mo, [
827
+ l(o(co), {
828
+ "can-submit": F.value && E.value,
829
+ config: e.config,
830
+ "edit-id": e.consumerGroupId,
831
+ "entity-type": o(be).ConsumerGroup,
832
+ "error-message": n.errorMessage || o(oe) || Y.value,
833
+ "fetch-url": X.value,
834
+ "form-fields": m.value,
835
+ "is-readonly": n.readonly,
836
+ onCancel: re,
837
+ "onFetch:error": u[3] || (u[3] = (y) => ne(y)),
838
+ "onFetch:success": S,
839
+ onLoading: u[4] || (u[4] = (y) => ae(y)),
840
+ onSubmit: Z
841
+ }, {
842
+ default: c(() => [
843
+ l(o(Te), {
844
+ description: o(p)("consumer_groups.form.general_info.description"),
845
+ title: o(p)("consumer_groups.form.general_info.title")
846
+ }, {
847
+ default: c(() => [
848
+ l(d, {
849
+ modelValue: n.fields.name,
850
+ "onUpdate:modelValue": u[0] || (u[0] = (y) => n.fields.name = y),
851
+ modelModifiers: { trim: !0 },
852
+ autocomplete: "off",
853
+ "data-testid": "consumer-group-form-name",
854
+ label: o(p)("consumer_groups.form.fields.name.label"),
855
+ placeholder: o(p)("consumer_groups.form.fields.name.placeholder"),
856
+ required: "",
857
+ type: "text"
858
+ }, null, 8, ["modelValue", "label", "placeholder"]),
859
+ l(d, {
860
+ modelValue: n.fields.tags,
861
+ "onUpdate:modelValue": u[1] || (u[1] = (y) => n.fields.tags = y),
862
+ modelModifiers: { trim: !0 },
863
+ autocomplete: "off",
864
+ "data-testid": "consumer-group-form-tags",
865
+ help: o(p)("consumer_groups.form.fields.tags.help"),
866
+ label: o(p)("consumer_groups.form.fields.tags.label"),
867
+ "label-attributes": {
868
+ info: o(p)("consumer_groups.form.fields.tags.tooltip"),
869
+ tooltipAttributes: { maxWidth: "400" }
870
+ },
871
+ placeholder: o(p)("consumer_groups.form.fields.tags.placeholder"),
872
+ type: "text"
873
+ }, null, 8, ["modelValue", "help", "label", "label-attributes", "placeholder"])
874
+ ]),
875
+ _: 1
876
+ }, 8, ["description", "title"]),
877
+ e.hideConsumers ? O("", !0) : (w(), L(o(Te), {
878
+ key: 0,
879
+ description: o(p)("consumer_groups.form.consumers.description"),
880
+ "has-divider": "",
881
+ title: o(p)("consumer_groups.form.consumers.title")
882
+ }, {
883
+ default: c(() => [
884
+ l(f, {
885
+ modelValue: n.fields.consumers,
886
+ "onUpdate:modelValue": u[2] || (u[2] = (y) => n.fields.consumers = y),
887
+ appearance: "select",
888
+ autosuggest: "",
889
+ items: W.value,
890
+ label: o(p)("consumer_groups.form.fields.consumers.label"),
891
+ loading: o(B),
892
+ placeholder: o(p)("consumer_groups.form.fields.consumers.placeholder"),
893
+ width: "auto",
894
+ onQueryChange: o(ee)
895
+ }, {
896
+ "item-template": c(({ item: y }) => [
897
+ V("div", So, [
898
+ V("div", xo, C(y.label), 1),
899
+ y?.data?.username && y?.data?.custom_id ? (w(), N("div", Go, C(y?.data?.custom_id), 1)) : O("", !0)
900
+ ])
901
+ ]),
902
+ _: 1
903
+ }, 8, ["modelValue", "items", "label", "loading", "placeholder", "onQueryChange"])
904
+ ]),
905
+ _: 1
906
+ }, 8, ["description", "title"]))
907
+ ]),
908
+ _: 1
909
+ }, 8, ["can-submit", "config", "edit-id", "entity-type", "error-message", "fetch-url", "form-fields", "is-readonly"])
910
+ ]);
911
+ };
912
+ }
913
+ }), Ro = /* @__PURE__ */ ke(To, [["__scopeId", "data-v-9c98b878"]]), Ao = { class: "kong-ui-consumer-group-entity-config-card" }, qo = /* @__PURE__ */ ce({
914
+ __name: "ConsumerGroupConfigCard",
915
+ props: {
916
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
917
+ config: {
918
+ type: Object,
919
+ required: !0,
920
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || e.app === "konnect" && !e.controlPlaneId || e.app === "kongManager" && typeof e.workspace != "string" || !e.entityId)
921
+ },
922
+ /**
923
+ * External link for documentation that determines visibility of Documentation button
924
+ */
925
+ configCardDoc: {
926
+ type: String,
927
+ default: "",
928
+ required: !1
929
+ },
930
+ /**
931
+ * Control visibility of card title content
932
+ */
933
+ hideTitle: {
934
+ type: Boolean,
935
+ default: !1
936
+ }
937
+ },
938
+ emits: ["loading", "fetch:error", "fetch:success"],
939
+ setup(e) {
940
+ const T = e, { i18n: { t: a } } = le.useI18n(), t = h(() => Q.item[T.config.app]), p = v({
941
+ id: {},
942
+ name: {},
943
+ created_at: {},
944
+ updated_at: {},
945
+ tags: {
946
+ tooltip: a("consumer_groups.form.fields.tags.tooltip")
947
+ }
948
+ });
949
+ return (i, n) => (w(), N("div", Ao, [
950
+ l(o(lo), {
951
+ config: e.config,
952
+ "config-card-doc": e.configCardDoc,
953
+ "config-schema": p.value,
954
+ "data-key": "consumer_group",
955
+ "entity-type": o(be).ConsumerGroup,
956
+ "fetch-url": t.value,
957
+ "hide-title": e.hideTitle,
958
+ "onFetch:error": n[0] || (n[0] = ($) => i.$emit("fetch:error", $)),
959
+ "onFetch:success": n[1] || (n[1] = ($) => i.$emit("fetch:success", $)),
960
+ onLoading: n[2] || (n[2] = ($) => i.$emit("loading", $))
961
+ }, null, 8, ["config", "config-card-doc", "config-schema", "entity-type", "fetch-url", "hide-title"])
962
+ ]));
963
+ }
982
964
  });
983
- export { Q as ConsumerGroupConfigCard, G as ConsumerGroupConfigCardView, ye as ConsumerGroupForm, he as ConsumerGroupList };
965
+ export {
966
+ qo as ConsumerGroupConfigCard,
967
+ Do as ConsumerGroupConfigCardView,
968
+ Ro as ConsumerGroupForm,
969
+ Uo as ConsumerGroupList
970
+ };