From d9f819d14382192acf1f6de1b7aa89a7da2ff0f3 Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Fri, 16 Aug 2024 10:52:52 +0800 Subject: [PATCH] fix: correct services and instances when changing page numbers (#409) --- src/views/dashboard/graphs/InstanceList.vue | 20 +++++++++++++------- src/views/dashboard/graphs/ServiceList.vue | 14 +++++++++++--- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/views/dashboard/graphs/InstanceList.vue b/src/views/dashboard/graphs/InstanceList.vue index f54c8c53..6bb18eb0 100644 --- a/src/views/dashboard/graphs/InstanceList.vue +++ b/src/views/dashboard/graphs/InstanceList.vue @@ -67,8 +67,9 @@ limitations under the License. --> const dashboardStore = useDashboardStore(); const chartLoading = ref(false); const instances = ref([]); // current instances + const currentPage = ref(1); const pageSize = 10; const searchText = ref(""); const colMetrics = ref([]); @@ -213,18 +215,22 @@ limitations under the License. --> } function changePage(pageIndex: number) { - instances.value = pods.value.filter((d: unknown, index: number) => { - if (index >= (pageIndex - 1) * pageSize && index < pageIndex * pageSize) { - return d; - } - }); + let podList = pods.value; + if (searchText.value) { + podList = pods.value.filter((d: { label: string }) => d.label.includes(searchText.value)); + } + instances.value = podList.filter( + (_, index: number) => index >= (pageIndex - 1) * pageSize && index < pageIndex * pageSize, + ); queryInstanceMetrics(instances.value); + currentPage.value = pageIndex; } function searchList() { const searchInstances = pods.value.filter((d: { label: string }) => d.label.includes(searchText.value)); - instances.value = searchInstances.filter((d: unknown, index: number) => index < pageSize); + instances.value = searchInstances.filter((_, index: number) => index < pageSize); queryInstanceMetrics(instances.value); + currentPage.value = 1; } watch( diff --git a/src/views/dashboard/graphs/ServiceList.vue b/src/views/dashboard/graphs/ServiceList.vue index 7a3a8bdd..a2560ea3 100644 --- a/src/views/dashboard/graphs/ServiceList.vue +++ b/src/views/dashboard/graphs/ServiceList.vue @@ -60,8 +60,9 @@ limitations under the License. --> const dashboardStore = useDashboardStore(); const appStore = useAppStoreWithOut(); const chartLoading = ref(false); + const currentPage = ref(1); const pageSize = 10; const services = ref([]); const colMetrics = ref([]); @@ -248,18 +250,24 @@ limitations under the License. --> return { rowspan: groups.value[param.row.group], colspan: 1 }; } function changePage(pageIndex: number) { - const arr = sortServices.value.filter((d: Service, index: number) => { + let services = sortServices.value; + if (searchText.value) { + services = sortServices.value.filter((d: { label: string }) => d.label.includes(searchText.value)); + } + const arr = services.filter((d: Service, index: number) => { if (index >= (pageIndex - 1) * pageSize && index < pageSize * pageIndex) { return d; } }); setServices(arr); + currentPage.value = pageIndex; } function searchList() { const searchServices = sortServices.value.filter((d: { label: string }) => d.label.includes(searchText.value)); - const services = searchServices.filter((d: unknown, index: number) => index < pageSize); + const services = searchServices.filter((_, index: number) => index < pageSize); setServices(services); + currentPage.value = 1; } watch(