fix(rabbitmq): add bounded paging for queue and exchange management lists
Closes #8879
This commit is contained in:
1 parent
33f212a452
commit
725b1ee252
22 files changed
+1445
-67
No files matched your search
@@ -1,13 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { MqBindingInfo, MqExchangeInfo, MqExchangeType, NamespaceRef, TopicInfo } from "@/types/mq";
|
||||
import { mqBind, mqCreateExchange, mqDeleteExchange, mqListBindings, mqListExchanges, mqListTopics, mqUnbind } from "@/lib/backend/api";
|
||||
import type { MqBindingInfo, MqExchangeInfo, MqExchangeType, MqListPageRequest, NamespaceRef, TopicInfo } from "@/types/mq";
|
||||
import { mqBind, mqCreateExchange, mqDeleteExchange, mqListBindings, mqListExchangesPage, mqListTopicsPage, mqUnbind } from "@/lib/backend/api";
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
import { isBuiltinRabbitMqExchange, rabbitMqExchangeDisplayName, RABBITMQ_EXCHANGE_TYPES } from "@/lib/mq/rabbitmqExchanges";
|
||||
import { isAllVhostsNamespace, resolveMqRowNamespace } from "@/lib/mq/mqConsoleDefaults";
|
||||
import { useMqMutationGuard } from "@/composables/useMqMutationGuard";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
import MqListPagination from "./shared/MqListPagination.vue";
|
||||
|
||||
const RABBITMQ_DEFAULT_PAGE_SIZE = 100;
|
||||
const RABBITMQ_SEARCH_DEBOUNCE_MS = 250;
|
||||
|
||||
interface Props {
|
||||
connectionId: string;
|
||||
@@ -25,6 +29,12 @@ const loading = ref(false);
|
||||
const error = ref<string>();
|
||||
const exchangeSearch = ref("");
|
||||
const selectedExchange = ref<MqExchangeInfo>();
|
||||
const exchangePage = ref(1);
|
||||
const exchangePageSize = ref(RABBITMQ_DEFAULT_PAGE_SIZE);
|
||||
const exchangeTotalCount = ref(0);
|
||||
const exchangeHasMore = ref(false);
|
||||
let exchangeLoadSequence = 0;
|
||||
let exchangeSearchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const bindings = ref<MqBindingInfo[]>([]);
|
||||
const bindingsLoading = ref(false);
|
||||
@@ -58,6 +68,9 @@ const unbindTarget = ref<MqBindingInfo>();
|
||||
const unbinding = ref(false);
|
||||
|
||||
const availableQueues = ref<TopicInfo[]>([]);
|
||||
const availableQueueTotal = ref(0);
|
||||
let queueLoadSequence = 0;
|
||||
let queueSearchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const filteredExchanges = computed(() => {
|
||||
const query = exchangeSearch.value.trim().toLowerCase();
|
||||
@@ -92,24 +105,60 @@ async function guardWritable(operation: string): Promise<boolean> {
|
||||
async function loadExchanges() {
|
||||
const ns = nsRef();
|
||||
if (!ns) {
|
||||
exchangeLoadSequence += 1;
|
||||
exchanges.value = [];
|
||||
exchangeTotalCount.value = 0;
|
||||
exchangeHasMore.value = false;
|
||||
return;
|
||||
}
|
||||
const loadSequence = ++exchangeLoadSequence;
|
||||
loading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
exchanges.value = await mqListExchanges(props.connectionId, ns);
|
||||
const pagination: MqListPageRequest = {
|
||||
page: exchangePage.value,
|
||||
pageSize: exchangePageSize.value,
|
||||
search: exchangeSearch.value.trim() || undefined,
|
||||
sort: "name",
|
||||
sortDescending: false,
|
||||
};
|
||||
const result = await mqListExchangesPage(props.connectionId, ns, pagination);
|
||||
if (loadSequence !== exchangeLoadSequence) return;
|
||||
const lastPage = Math.max(1, Math.ceil(result.totalCount / result.pageSize));
|
||||
if (result.page > lastPage) {
|
||||
exchangePage.value = lastPage;
|
||||
void loadExchanges();
|
||||
return;
|
||||
}
|
||||
exchanges.value = result.items;
|
||||
exchangePage.value = result.page;
|
||||
exchangePageSize.value = result.pageSize;
|
||||
exchangeTotalCount.value = result.totalCount;
|
||||
exchangeHasMore.value = result.hasMore;
|
||||
if (selectedExchange.value && !exchanges.value.some((exchange) => exchange.name === selectedExchange.value?.name && exchange.namespace === selectedExchange.value?.namespace)) {
|
||||
selectedExchange.value = undefined;
|
||||
bindings.value = [];
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
if (loadSequence !== exchangeLoadSequence) return;
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (loadSequence === exchangeLoadSequence) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function changeExchangePage(page: number) {
|
||||
if (page < 1 || page === exchangePage.value) return;
|
||||
exchangePage.value = page;
|
||||
void loadExchanges();
|
||||
}
|
||||
|
||||
function changeExchangePageSize(pageSize: number) {
|
||||
exchangePageSize.value = pageSize;
|
||||
exchangePage.value = 1;
|
||||
void loadExchanges();
|
||||
}
|
||||
|
||||
async function loadBindings(exchange: MqExchangeInfo) {
|
||||
const ns = nsRefFor(exchange);
|
||||
if (!ns) return;
|
||||
@@ -124,12 +173,28 @@ async function loadBindings(exchange: MqExchangeInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadQueues() {
|
||||
async function loadQueues(search = "") {
|
||||
const ns = nsRefFor(selectedExchange.value);
|
||||
if (!ns) return;
|
||||
const loadSequence = ++queueLoadSequence;
|
||||
try {
|
||||
availableQueues.value = await mqListTopics(props.connectionId, ns, { includeNonPersistent: false });
|
||||
const result = await mqListTopicsPage(
|
||||
props.connectionId,
|
||||
ns,
|
||||
{ includeNonPersistent: false },
|
||||
{
|
||||
page: 1,
|
||||
pageSize: RABBITMQ_DEFAULT_PAGE_SIZE,
|
||||
search: search.trim() || undefined,
|
||||
sort: "name",
|
||||
sortDescending: false,
|
||||
},
|
||||
);
|
||||
if (loadSequence !== queueLoadSequence) return;
|
||||
availableQueues.value = result.items;
|
||||
availableQueueTotal.value = result.totalCount;
|
||||
} catch (e: unknown) {
|
||||
if (loadSequence !== queueLoadSequence) return;
|
||||
console.warn("[DBX] Failed to load queues for binding dialog:", e);
|
||||
}
|
||||
}
|
||||
@@ -224,7 +289,6 @@ function openBindDialog() {
|
||||
if (!selectedExchange.value) return;
|
||||
dialogError.value = undefined;
|
||||
bindForm.value = { destinationType: "queue", destination: "", routingKey: "", argumentsText: "" };
|
||||
void loadQueues();
|
||||
showBindDialog.value = true;
|
||||
}
|
||||
|
||||
@@ -312,20 +376,50 @@ function formatBindingArguments(bindingRow: MqBindingInfo): string {
|
||||
watch(
|
||||
() => [props.tenant, props.namespace],
|
||||
() => {
|
||||
if (exchangeSearchTimer) clearTimeout(exchangeSearchTimer);
|
||||
exchangePage.value = 1;
|
||||
selectedExchange.value = undefined;
|
||||
bindings.value = [];
|
||||
loadExchanges();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch(exchangeSearch, () => {
|
||||
if (exchangeSearchTimer) clearTimeout(exchangeSearchTimer);
|
||||
exchangeSearchTimer = setTimeout(() => {
|
||||
exchangeSearchTimer = undefined;
|
||||
exchangePage.value = 1;
|
||||
void loadExchanges();
|
||||
}, RABBITMQ_SEARCH_DEBOUNCE_MS);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => [bindForm.value.destination, bindForm.value.destinationType, showBindDialog.value] as const,
|
||||
([destination, destinationType, open]) => {
|
||||
if (queueSearchTimer) clearTimeout(queueSearchTimer);
|
||||
if (!open || destinationType !== "queue") return;
|
||||
queueSearchTimer = setTimeout(() => {
|
||||
queueSearchTimer = undefined;
|
||||
void loadQueues(destination);
|
||||
}, RABBITMQ_SEARCH_DEBOUNCE_MS);
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
exchangeLoadSequence += 1;
|
||||
queueLoadSequence += 1;
|
||||
if (exchangeSearchTimer) clearTimeout(exchangeSearchTimer);
|
||||
if (queueSearchTimer) clearTimeout(queueSearchTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="exchanges-panel">
|
||||
<div class="panel-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<input v-model="exchangeSearch" type="search" class="exchange-search" :placeholder="t('mqExchanges.searchPlaceholder')" :disabled="loading && !exchanges.length" />
|
||||
<span v-if="exchanges.length" class="exchange-count">{{ filteredExchanges.length }} / {{ exchanges.length }}</span>
|
||||
<input v-model="exchangeSearch" type="search" class="exchange-search" :placeholder="t('mqExchanges.searchPlaceholder')" :disabled="loading && !exchanges.length && !exchangeSearch" />
|
||||
<span v-if="exchanges.length" class="exchange-count">{{ filteredExchanges.length }} / {{ exchangeTotalCount }}</span>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<button @click="loadExchanges" :disabled="loading || !tenant || !namespace" class="btn-secondary">
|
||||
@@ -341,7 +435,7 @@ watch(
|
||||
|
||||
<div v-else-if="loading && !exchanges.length" class="panel-loading">{{ t("mqExchanges.loading") }}</div>
|
||||
|
||||
<div v-else-if="!exchanges.length" class="panel-placeholder">{{ t("mqExchanges.noExchanges") }}</div>
|
||||
<div v-else-if="!exchanges.length" class="panel-placeholder">{{ exchangeSearch.trim() ? t("mqExchanges.noMatches") : t("mqExchanges.noExchanges") }}</div>
|
||||
|
||||
<div v-else-if="!filteredExchanges.length" class="panel-placeholder">{{ t("mqExchanges.noMatches") }}</div>
|
||||
|
||||
@@ -382,6 +476,8 @@ watch(
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<MqListPagination v-if="exchangeTotalCount > exchangePageSize || exchangePage > 1" :page="exchangePage" :page-size="exchangePageSize" :total-count="exchangeTotalCount" :has-more="exchangeHasMore" :loading="loading" @page-change="changeExchangePage" @page-size-change="changeExchangePageSize" />
|
||||
|
||||
<!-- Bindings of the selected exchange -->
|
||||
<div v-if="selectedExchange" class="bindings-section">
|
||||
<div class="bindings-header">
|
||||
@@ -495,6 +591,7 @@ watch(
|
||||
<datalist id="mq-exchange-bind-queues">
|
||||
<option v-for="queue in availableQueues" :key="queue.name" :value="queue.shortName" />
|
||||
</datalist>
|
||||
<small v-if="bindForm.destinationType === 'queue' && availableQueueTotal > availableQueues.length" class="queue-suggestion-count">{{ availableQueues.length }} / {{ availableQueueTotal }}</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqExchanges.routingKey") }}</label>
|
||||
@@ -591,6 +688,13 @@ watch(
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.queue-suggestion-count {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.panel-placeholder,
|
||||
.panel-error,
|
||||
.panel-loading {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from "vue";
|
||||
import { ref, watch, computed, onBeforeUnmount } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { RecycleScroller } from "vue-virtual-scroller";
|
||||
import "vue-virtual-scroller/dist/vue-virtual-scroller.css";
|
||||
import type { NamespaceRef, TopicRef, TopicInfo, ListTopicsOpts, MqSystemKind, RocketMqTopicMessageType } from "@/types/mq";
|
||||
import { mqListTopics, mqCreateTopic, mqDeleteTopic, mqUpdatePartitions, mqGetClusterInfo } from "@/lib/backend/api";
|
||||
import type { NamespaceRef, TopicRef, TopicInfo, ListTopicsOpts, MqListPageRequest, MqSystemKind, RocketMqTopicMessageType } from "@/types/mq";
|
||||
import { mqListTopics, mqListTopicsPage, mqCreateTopic, mqDeleteTopic, mqUpdatePartitions, mqGetClusterInfo } from "@/lib/backend/api";
|
||||
import type { ClusterInfo } from "@/types/mq";
|
||||
import RocketMqTopicDialogs, { type RocketMqTopicDialogKind } from "./rocketmq/RocketMqTopicDialogs.vue";
|
||||
import SendMessagePanel from "./SendMessagePanel.vue";
|
||||
@@ -17,8 +17,11 @@ import { formatError } from "@/lib/backend/errorUtils";
|
||||
import { DEFAULT_ROCKETMQ_TOPIC_TYPE_FILTERS, isProtectedRocketMqTopic, isRocketMqBusinessMessageType, matchesRocketMqTypeFilters, resolveRocketMqMessageType, ROCKETMQ_CREATABLE_TOPIC_MESSAGE_TYPES, ROCKETMQ_TOPIC_MESSAGE_TYPES } from "@/lib/mq/rocketmqTopicTypes";
|
||||
import { useMqMutationGuard } from "@/composables/useMqMutationGuard";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
import MqListPagination from "./shared/MqListPagination.vue";
|
||||
|
||||
const TOPIC_ROW_HEIGHT = 44;
|
||||
const RABBITMQ_DEFAULT_PAGE_SIZE = 100;
|
||||
const RABBITMQ_SEARCH_DEBOUNCE_MS = 250;
|
||||
|
||||
type VirtualTopicRow = {
|
||||
id: string;
|
||||
@@ -98,6 +101,12 @@ const showNamespaceColumn = computed(() => isRabbitMqCluster.value && isAllVhost
|
||||
const showRabbitMqSubTabs = computed(() => isRabbitMqCluster.value && props.supportsExchanges === true);
|
||||
const rabbitMqSubTab = ref<"queues" | "exchanges">("queues");
|
||||
const rabbitMqMessageSort = ref<"asc" | "desc" | null>(null);
|
||||
const rabbitMqPage = ref(1);
|
||||
const rabbitMqPageSize = ref(RABBITMQ_DEFAULT_PAGE_SIZE);
|
||||
const rabbitMqTotalCount = ref(0);
|
||||
const rabbitMqHasMore = ref(false);
|
||||
let topicLoadSequence = 0;
|
||||
let topicSearchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const rocketMqTopicTypeOptions = ROCKETMQ_TOPIC_MESSAGE_TYPES;
|
||||
const rocketMqCreatableTopicTypes = ROCKETMQ_CREATABLE_TOPIC_MESSAGE_TYPES;
|
||||
const rocketMqClusterName = computed(() => clusterInfo.value?.clusterId ?? "-");
|
||||
@@ -224,6 +233,8 @@ function rabbitMqRatesTitle(): string {
|
||||
|
||||
function toggleRabbitMqMessageSort() {
|
||||
rabbitMqMessageSort.value = rabbitMqMessageSort.value === "desc" ? "asc" : "desc";
|
||||
rabbitMqPage.value = 1;
|
||||
void loadTopics();
|
||||
}
|
||||
|
||||
function topicTypeLabel(topic: TopicInfo): string {
|
||||
@@ -269,9 +280,13 @@ async function guardWritable(operation: string): Promise<boolean> {
|
||||
|
||||
async function loadTopics() {
|
||||
if (!props.tenant || !props.namespace) {
|
||||
topicLoadSequence += 1;
|
||||
topics.value = [];
|
||||
rabbitMqTotalCount.value = 0;
|
||||
rabbitMqHasMore.value = false;
|
||||
return;
|
||||
}
|
||||
const loadSequence = ++topicLoadSequence;
|
||||
loading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
@@ -282,14 +297,53 @@ async function loadTopics() {
|
||||
const opts: ListTopicsOpts = {
|
||||
includeNonPersistent: includeNonPersistent.value,
|
||||
};
|
||||
topics.value = await mqListTopics(props.connectionId, ns, opts);
|
||||
if (isRabbitMqCluster.value) {
|
||||
const pagination: MqListPageRequest = {
|
||||
page: rabbitMqPage.value,
|
||||
pageSize: rabbitMqPageSize.value,
|
||||
search: topicSearch.value.trim() || undefined,
|
||||
sort: rabbitMqMessageSort.value ? "messagesReady" : "name",
|
||||
sortDescending: rabbitMqMessageSort.value === "desc",
|
||||
};
|
||||
const result = await mqListTopicsPage(props.connectionId, ns, opts, pagination);
|
||||
if (loadSequence !== topicLoadSequence) return;
|
||||
const lastPage = Math.max(1, Math.ceil(result.totalCount / result.pageSize));
|
||||
if (result.page > lastPage) {
|
||||
rabbitMqPage.value = lastPage;
|
||||
void loadTopics();
|
||||
return;
|
||||
}
|
||||
topics.value = result.items;
|
||||
rabbitMqPage.value = result.page;
|
||||
rabbitMqPageSize.value = result.pageSize;
|
||||
rabbitMqTotalCount.value = result.totalCount;
|
||||
rabbitMqHasMore.value = result.hasMore;
|
||||
} else {
|
||||
topics.value = await mqListTopics(props.connectionId, ns, opts);
|
||||
if (loadSequence !== topicLoadSequence) return;
|
||||
rabbitMqTotalCount.value = topics.value.length;
|
||||
rabbitMqHasMore.value = false;
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
if (loadSequence !== topicLoadSequence) return;
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (loadSequence === topicLoadSequence) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function changeRabbitMqPage(page: number) {
|
||||
if (page < 1 || page === rabbitMqPage.value) return;
|
||||
rabbitMqPage.value = page;
|
||||
void loadTopics();
|
||||
}
|
||||
|
||||
function changeRabbitMqPageSize(pageSize: number) {
|
||||
rabbitMqPageSize.value = pageSize;
|
||||
rabbitMqPage.value = 1;
|
||||
void loadTopics();
|
||||
}
|
||||
|
||||
async function loadClusterInfo() {
|
||||
if (!isRocketMqCluster.value) return;
|
||||
try {
|
||||
@@ -513,6 +567,8 @@ function normalizePartitionInput() {
|
||||
watch(
|
||||
() => [props.tenant, props.namespace],
|
||||
() => {
|
||||
if (topicSearchTimer) clearTimeout(topicSearchTimer);
|
||||
rabbitMqPage.value = 1;
|
||||
selectedTopic.value = undefined;
|
||||
loadTopics();
|
||||
if (isRocketMqCluster.value) void loadClusterInfo();
|
||||
@@ -529,14 +585,30 @@ watch(
|
||||
);
|
||||
|
||||
watch(includeNonPersistent, () => {
|
||||
rabbitMqPage.value = 1;
|
||||
loadTopics();
|
||||
});
|
||||
|
||||
watch(topicSearch, () => {
|
||||
if (!isRabbitMqCluster.value) return;
|
||||
if (topicSearchTimer) clearTimeout(topicSearchTimer);
|
||||
topicSearchTimer = setTimeout(() => {
|
||||
topicSearchTimer = undefined;
|
||||
rabbitMqPage.value = 1;
|
||||
void loadTopics();
|
||||
}, RABBITMQ_SEARCH_DEBOUNCE_MS);
|
||||
});
|
||||
|
||||
watch(newPartitions, () => {
|
||||
if (dialogError.value === t("mqTopics.partitionMustIncrease") && canSubmitPartitionUpdate.value) {
|
||||
dialogError.value = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
topicLoadSequence += 1;
|
||||
if (topicSearchTimer) clearTimeout(topicSearchTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -552,8 +624,8 @@ watch(newPartitions, () => {
|
||||
<div class="panel-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<h3>{{ t("mqTopics.title") }}</h3>
|
||||
<input v-model="topicSearch" type="search" class="topic-search" :placeholder="t('mqTopics.searchPlaceholder')" :disabled="loading && !topics.length" />
|
||||
<span v-if="topics.length" class="topic-count"> {{ filteredTopics.length }} / {{ typeFilteredTopics.length }} </span>
|
||||
<input v-model="topicSearch" type="search" class="topic-search" :placeholder="t('mqTopics.searchPlaceholder')" :disabled="loading && !topics.length && !topicSearch" />
|
||||
<span v-if="topics.length" class="topic-count"> {{ filteredTopics.length }} / {{ isRabbitMqCluster ? rabbitMqTotalCount : typeFilteredTopics.length }} </span>
|
||||
<label v-if="isKafkaCluster" class="checkbox-label">
|
||||
<input v-model="includeSystemTopics" type="checkbox" />
|
||||
{{ t("mqTopics.includeSystemTopics") }}
|
||||
@@ -584,7 +656,7 @@ watch(newPartitions, () => {
|
||||
|
||||
<div v-else-if="loading && !topics.length" class="panel-loading">{{ t("mqTopics.loading") }}</div>
|
||||
|
||||
<div v-else-if="!topics.length" class="panel-placeholder">{{ t("mqTopics.noTopics") }}</div>
|
||||
<div v-else-if="!topics.length" class="panel-placeholder">{{ isRabbitMqCluster && topicSearch.trim() ? t("mqTopics.noMatches") : t("mqTopics.noTopics") }}</div>
|
||||
|
||||
<div v-else-if="!filteredTopics.length" class="panel-placeholder">
|
||||
{{ isRocketMqCluster && userTopicCount === 0 ? t("mqTopics.noUserTopics") : isKafkaCluster && !includeSystemTopics && userTopicCount === 0 ? t("mqTopics.noUserTopics") : t("mqTopics.noMatches") }}
|
||||
@@ -690,6 +762,17 @@ watch(newPartitions, () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MqListPagination
|
||||
v-if="isRabbitMqCluster && (rabbitMqTotalCount > rabbitMqPageSize || rabbitMqPage > 1)"
|
||||
:page="rabbitMqPage"
|
||||
:page-size="rabbitMqPageSize"
|
||||
:total-count="rabbitMqTotalCount"
|
||||
:has-more="rabbitMqHasMore"
|
||||
:loading="loading"
|
||||
@page-change="changeRabbitMqPage"
|
||||
@page-size-change="changeRabbitMqPageSize"
|
||||
/>
|
||||
|
||||
<!-- Create Dialog -->
|
||||
<div v-if="showCreateDialog" class="dialog-overlay" @click="showCreateDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
||||
|
||||
const backend = vi.hoisted(() => ({
|
||||
mqBind: vi.fn(),
|
||||
mqCreateExchange: vi.fn(),
|
||||
mqDeleteExchange: vi.fn(),
|
||||
mqListBindings: vi.fn(),
|
||||
mqListExchangesPage: vi.fn(),
|
||||
mqListTopicsPage: vi.fn(),
|
||||
mqUnbind: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string, params?: { page?: number }) => (params?.page ? `${key}:${params.page}` : key) }),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/backend/api", () => backend);
|
||||
|
||||
vi.mock("@/composables/useMqMutationGuard", () => ({
|
||||
useMqMutationGuard: () => ({ confirmMqWrite: vi.fn().mockResolvedValue(true) }),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/editor/DangerConfirmDialog.vue", () => ({
|
||||
default: defineComponent({ setup: () => () => h("div") }),
|
||||
}));
|
||||
|
||||
import ExchangesPanel from "@/components/mq/ExchangesPanel.vue";
|
||||
|
||||
let app: App<Element> | null = null;
|
||||
let root: HTMLDivElement | null = null;
|
||||
|
||||
async function flushUi() {
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
async function mountPanel(namespace = "/") {
|
||||
root = document.createElement("div");
|
||||
document.body.appendChild(root);
|
||||
app = createApp(ExchangesPanel, {
|
||||
connectionId: "rabbit-1",
|
||||
tenant: "_rabbitmq",
|
||||
namespace,
|
||||
});
|
||||
app.mount(root);
|
||||
await flushUi();
|
||||
return root;
|
||||
}
|
||||
|
||||
function exchangeNames(container: ParentNode): string[] {
|
||||
return [...container.querySelectorAll<HTMLElement>(".exchange-name-cell > span:first-child")].map((item) => item.textContent ?? "");
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useRealTimers();
|
||||
Object.values(backend).forEach((mock) => mock.mockReset());
|
||||
backend.mqListBindings.mockResolvedValue([]);
|
||||
backend.mqListTopicsPage.mockResolvedValue({ items: [], page: 1, pageSize: 100, totalCount: 0, hasMore: false });
|
||||
backend.mqListExchangesPage.mockResolvedValue({
|
||||
items: [{ name: "events", type: "topic", durable: true, autoDelete: false, internal: false }],
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
totalCount: 1,
|
||||
hasMore: false,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
app?.unmount();
|
||||
app = null;
|
||||
root?.remove();
|
||||
root = null;
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("ExchangesPanel RabbitMQ pagination", () => {
|
||||
it("requests one page at a time and retains all-vhost row identity", async () => {
|
||||
backend.mqListExchangesPage
|
||||
.mockResolvedValueOnce({
|
||||
items: [{ name: "events", namespace: "/", type: "topic", durable: true, autoDelete: false, internal: false }],
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
totalCount: 101,
|
||||
hasMore: true,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
items: [{ name: "events", namespace: "/staging", type: "topic", durable: true, autoDelete: false, internal: false }],
|
||||
page: 2,
|
||||
pageSize: 100,
|
||||
totalCount: 101,
|
||||
hasMore: false,
|
||||
});
|
||||
const panel = await mountPanel("*");
|
||||
|
||||
expect(exchangeNames(panel)).toEqual(["events"]);
|
||||
expect(panel.querySelector("tbody td:nth-child(2)")?.textContent?.trim()).toBe("/");
|
||||
const next = panel.querySelector<HTMLButtonElement>('[data-testid="mq-list-next"]');
|
||||
if (!next) throw new Error("next page button not found");
|
||||
next.click();
|
||||
await flushUi();
|
||||
|
||||
expect(panel.querySelector("tbody td:nth-child(2)")?.textContent?.trim()).toBe("/staging");
|
||||
expect(backend.mqListExchangesPage).toHaveBeenLastCalledWith("rabbit-1", { tenant: "_rabbitmq", namespace: "*" }, expect.objectContaining({ page: 2, pageSize: 100, sort: "name" }));
|
||||
});
|
||||
|
||||
it("debounces search into the server-side page request", async () => {
|
||||
vi.useFakeTimers();
|
||||
const panel = await mountPanel();
|
||||
backend.mqListExchangesPage.mockClear();
|
||||
backend.mqListExchangesPage.mockResolvedValue({ items: [], page: 1, pageSize: 100, totalCount: 0, hasMore: false });
|
||||
|
||||
const search = panel.querySelector<HTMLInputElement>(".exchange-search");
|
||||
if (!search) throw new Error("exchange search not found");
|
||||
search.value = "orders";
|
||||
search.dispatchEvent(new Event("input"));
|
||||
await nextTick();
|
||||
expect(backend.mqListExchangesPage).not.toHaveBeenCalled();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(250);
|
||||
await flushUi();
|
||||
expect(backend.mqListExchangesPage).toHaveBeenCalledWith("rabbit-1", { tenant: "_rabbitmq", namespace: "/" }, expect.objectContaining({ page: 1, search: "orders" }));
|
||||
});
|
||||
});
|
||||
+123
-36
@@ -5,6 +5,7 @@ import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
||||
|
||||
const backend = vi.hoisted(() => ({
|
||||
mqListTopics: vi.fn(),
|
||||
mqListTopicsPage: vi.fn(),
|
||||
mqCreateTopic: vi.fn(),
|
||||
mqDeleteTopic: vi.fn(),
|
||||
mqUpdatePartitions: vi.fn(),
|
||||
@@ -99,42 +100,64 @@ async function mountRabbitMqAllVhostsPanel() {
|
||||
return root;
|
||||
}
|
||||
|
||||
async function mountKafkaPanel() {
|
||||
root = document.createElement("div");
|
||||
document.body.appendChild(root);
|
||||
app = createApp(TopicsPanel, {
|
||||
connectionId: "kafka-1",
|
||||
tenant: "_flat_mq",
|
||||
namespace: "_flat_mq",
|
||||
mqSystemKind: "kafka",
|
||||
isFlatMqCluster: true,
|
||||
});
|
||||
app.mount(root);
|
||||
await flushUi();
|
||||
return root;
|
||||
}
|
||||
|
||||
function rowNames(container: ParentNode): string[] {
|
||||
return [...container.querySelectorAll<HTMLElement>(".topic-name-text")].map((item) => item.textContent ?? "");
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useRealTimers();
|
||||
Object.values(backend).forEach((mock) => mock.mockReset());
|
||||
backend.mqListTopics.mockResolvedValue([
|
||||
{
|
||||
name: "alpha",
|
||||
shortName: "alpha",
|
||||
partitioned: false,
|
||||
persistent: true,
|
||||
messageCount: 4,
|
||||
messagesReady: 3,
|
||||
messagesUnacked: 1,
|
||||
queueType: "quorum",
|
||||
state: "running",
|
||||
autoDelete: true,
|
||||
consumerCount: 2,
|
||||
arguments: { "x-queue-type": "quorum", "x-message-ttl": 60000, "x-dead-letter-exchange": "dlx" },
|
||||
publishRate: 12.5,
|
||||
deliverRate: 11.8,
|
||||
ackRate: 11.2,
|
||||
},
|
||||
{
|
||||
name: "beta",
|
||||
shortName: "beta",
|
||||
partitioned: false,
|
||||
persistent: true,
|
||||
messageCount: 12,
|
||||
messagesReady: 12,
|
||||
messagesUnacked: 0,
|
||||
// No queue type, no arguments, and no message_stats sample:
|
||||
// type stays unknown, rates render as "-" (never fabricated zeros).
|
||||
},
|
||||
]);
|
||||
backend.mqListTopicsPage.mockResolvedValue({
|
||||
items: [
|
||||
{
|
||||
name: "alpha",
|
||||
shortName: "alpha",
|
||||
partitioned: false,
|
||||
persistent: true,
|
||||
messageCount: 4,
|
||||
messagesReady: 3,
|
||||
messagesUnacked: 1,
|
||||
queueType: "quorum",
|
||||
state: "running",
|
||||
autoDelete: true,
|
||||
consumerCount: 2,
|
||||
arguments: { "x-queue-type": "quorum", "x-message-ttl": 60000, "x-dead-letter-exchange": "dlx" },
|
||||
publishRate: 12.5,
|
||||
deliverRate: 11.8,
|
||||
ackRate: 11.2,
|
||||
},
|
||||
{
|
||||
name: "beta",
|
||||
shortName: "beta",
|
||||
partitioned: false,
|
||||
persistent: true,
|
||||
messageCount: 12,
|
||||
messagesReady: 12,
|
||||
messagesUnacked: 0,
|
||||
// No queue type, no arguments, and no message_stats sample:
|
||||
// type stays unknown, rates render as "-" (never fabricated zeros).
|
||||
},
|
||||
],
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
totalCount: 2,
|
||||
hasMore: false,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -142,6 +165,7 @@ afterEach(() => {
|
||||
app = null;
|
||||
root?.remove();
|
||||
root = null;
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("TopicsPanel RabbitMQ queue messages", () => {
|
||||
@@ -155,11 +179,12 @@ describe("TopicsPanel RabbitMQ queue messages", () => {
|
||||
if (!sortButton) throw new Error("RabbitMQ message sort button not found");
|
||||
|
||||
sortButton.click();
|
||||
await nextTick();
|
||||
await flushUi();
|
||||
expect(rowNames(panel)).toEqual(["beta", "alpha"]);
|
||||
expect(backend.mqListTopicsPage).toHaveBeenLastCalledWith("rabbit-1", { tenant: "_rabbitmq", namespace: "/" }, { includeNonPersistent: false }, expect.objectContaining({ page: 1, pageSize: 100, sort: "messagesReady", sortDescending: true }));
|
||||
|
||||
sortButton.click();
|
||||
await nextTick();
|
||||
await flushUi();
|
||||
expect(rowNames(panel)).toEqual(["alpha", "beta"]);
|
||||
});
|
||||
|
||||
@@ -203,10 +228,16 @@ describe("TopicsPanel RabbitMQ queue messages", () => {
|
||||
});
|
||||
|
||||
it("keeps per-queue vhosts separate in all-vhosts mode (#5984 regression guard)", async () => {
|
||||
backend.mqListTopics.mockResolvedValue([
|
||||
{ name: "orders", shortName: "orders", partitioned: false, persistent: true, namespace: "/", messageCount: 3, messagesReady: 3 },
|
||||
{ name: "orders", shortName: "orders", partitioned: false, persistent: true, namespace: "/staging", messageCount: 7, messagesReady: 7 },
|
||||
]);
|
||||
backend.mqListTopicsPage.mockResolvedValue({
|
||||
items: [
|
||||
{ name: "orders", shortName: "orders", partitioned: false, persistent: true, namespace: "/", messageCount: 3, messagesReady: 3 },
|
||||
{ name: "orders", shortName: "orders", partitioned: false, persistent: true, namespace: "/staging", messageCount: 7, messagesReady: 7 },
|
||||
],
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
totalCount: 2,
|
||||
hasMore: false,
|
||||
});
|
||||
const panel = await mountRabbitMqAllVhostsPanel();
|
||||
|
||||
// Both rows are named "orders" but must stay distinct per virtual host;
|
||||
@@ -216,4 +247,60 @@ describe("TopicsPanel RabbitMQ queue messages", () => {
|
||||
const counts = [...panel.querySelectorAll<HTMLElement>('[data-testid="rabbitmq-message-count"]')].map((item) => item.textContent?.trim());
|
||||
expect(counts).toEqual(["3", "7"]);
|
||||
});
|
||||
|
||||
it("loads only the requested RabbitMQ page and keeps the total visible", async () => {
|
||||
backend.mqListTopicsPage
|
||||
.mockResolvedValueOnce({
|
||||
items: [{ name: "page-one", shortName: "page-one", partitioned: false, persistent: true }],
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
totalCount: 101,
|
||||
hasMore: true,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
items: [{ name: "page-two", shortName: "page-two", partitioned: false, persistent: true }],
|
||||
page: 2,
|
||||
pageSize: 100,
|
||||
totalCount: 101,
|
||||
hasMore: false,
|
||||
});
|
||||
const panel = await mountRabbitMqPanel();
|
||||
|
||||
expect(rowNames(panel)).toEqual(["page-one"]);
|
||||
expect(panel.querySelector(".topic-count")?.textContent?.replace(/\s+/g, " ").trim()).toBe("1 / 101");
|
||||
const next = panel.querySelector<HTMLButtonElement>('[data-testid="mq-list-next"]');
|
||||
if (!next) throw new Error("next page button not found");
|
||||
next.click();
|
||||
await flushUi();
|
||||
|
||||
expect(rowNames(panel)).toEqual(["page-two"]);
|
||||
expect(backend.mqListTopicsPage).toHaveBeenLastCalledWith("rabbit-1", { tenant: "_rabbitmq", namespace: "/" }, { includeNonPersistent: false }, expect.objectContaining({ page: 2, pageSize: 100 }));
|
||||
});
|
||||
|
||||
it("debounces queue search into the bounded backend request", async () => {
|
||||
vi.useFakeTimers();
|
||||
const panel = await mountRabbitMqPanel();
|
||||
backend.mqListTopicsPage.mockClear();
|
||||
backend.mqListTopicsPage.mockResolvedValue({ items: [], page: 1, pageSize: 100, totalCount: 0, hasMore: false });
|
||||
|
||||
const search = panel.querySelector<HTMLInputElement>(".topic-search");
|
||||
if (!search) throw new Error("topic search not found");
|
||||
search.value = "orders";
|
||||
search.dispatchEvent(new Event("input"));
|
||||
await nextTick();
|
||||
expect(backend.mqListTopicsPage).not.toHaveBeenCalled();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(250);
|
||||
await flushUi();
|
||||
expect(backend.mqListTopicsPage).toHaveBeenCalledWith("rabbit-1", { tenant: "_rabbitmq", namespace: "/" }, { includeNonPersistent: false }, expect.objectContaining({ page: 1, search: "orders" }));
|
||||
});
|
||||
|
||||
it("keeps non-RabbitMQ providers on the legacy unbounded contract", async () => {
|
||||
backend.mqListTopics.mockResolvedValue([{ name: "orders", shortName: "orders", partitioned: false, persistent: true }]);
|
||||
const panel = await mountKafkaPanel();
|
||||
|
||||
expect(rowNames(panel)).toEqual(["orders"]);
|
||||
expect(backend.mqListTopics).toHaveBeenCalledWith("kafka-1", { tenant: "_flat_mq", namespace: "_flat_mq" }, { includeNonPersistent: false });
|
||||
expect(backend.mqListTopicsPage).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const props = defineProps<{
|
||||
page: number;
|
||||
pageSize: number;
|
||||
totalCount: number;
|
||||
hasMore: boolean;
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
pageChange: [page: number];
|
||||
pageSizeChange: [pageSize: number];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const pageSizeOptions = [50, 100, 200, 500];
|
||||
const pageCount = computed(() => Math.max(1, Math.ceil(props.totalCount / props.pageSize)));
|
||||
const rangeStart = computed(() => (props.totalCount ? (props.page - 1) * props.pageSize + 1 : 0));
|
||||
const rangeEnd = computed(() => Math.min(props.page * props.pageSize, props.totalCount));
|
||||
|
||||
function changePageSize(event: Event) {
|
||||
const pageSize = Number((event.target as HTMLSelectElement).value);
|
||||
if (Number.isSafeInteger(pageSize) && pageSize > 0 && pageSize !== props.pageSize) {
|
||||
emit("pageSizeChange", pageSize);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mq-list-pagination" data-testid="mq-list-pagination">
|
||||
<span class="mq-list-range">{{ rangeStart }}–{{ rangeEnd }} / {{ totalCount }}</span>
|
||||
<label class="mq-list-page-size">
|
||||
<span>{{ t("grid.rowsPerPage") }}</span>
|
||||
<select :value="pageSize" :disabled="loading" @change="changePageSize">
|
||||
<option v-for="size in pageSizeOptions" :key="size" :value="size">{{ size }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<button type="button" class="mq-list-page-button" data-testid="mq-list-previous" :aria-label="t('grid.page', { page: Math.max(1, page - 1) })" :disabled="loading || page <= 1" @click="emit('pageChange', page - 1)">‹</button>
|
||||
<span class="mq-list-page-number">{{ t("grid.page", { page }) }} / {{ pageCount }}</span>
|
||||
<button type="button" class="mq-list-page-button" data-testid="mq-list-next" :aria-label="t('grid.page', { page: page + 1 })" :disabled="loading || !hasMore" @click="emit('pageChange', page + 1)">›</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.mq-list-pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
min-height: 30px;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.mq-list-range,
|
||||
.mq-list-page-number {
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.mq-list-page-size {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.mq-list-page-size select,
|
||||
.mq-list-page-button {
|
||||
height: 28px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--dbx-radius-fixed-4);
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.mq-list-page-size select {
|
||||
padding: 0 6px;
|
||||
}
|
||||
|
||||
.mq-list-page-button {
|
||||
min-width: 30px;
|
||||
padding: 0 8px;
|
||||
cursor: pointer;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.mq-list-page-button:disabled,
|
||||
.mq-list-page-size select:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user