Skip to content

Commit d9f819d

Browse files
authored
fix: correct services and instances when changing page numbers (#409)
1 parent 3c8b316 commit d9f819d

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/views/dashboard/graphs/InstanceList.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ limitations under the License. -->
6767
<el-pagination
6868
class="pagination flex-h"
6969
layout="prev, pager, next"
70+
:current-page="currentPage"
7071
:page-size="pageSize"
71-
:total="pods.length"
72+
:total="searchText ? pods.filter((d: any) => d.label.includes(searchText)).length : pods.length"
7273
@current-change="changePage"
7374
@prev-click="changePage"
7475
@next-click="changePage"
@@ -122,6 +123,7 @@ limitations under the License. -->
122123
const dashboardStore = useDashboardStore();
123124
const chartLoading = ref<boolean>(false);
124125
const instances = ref<Instance[]>([]); // current instances
126+
const currentPage = ref<number>(1);
125127
const pageSize = 10;
126128
const searchText = ref<string>("");
127129
const colMetrics = ref<string[]>([]);
@@ -213,18 +215,22 @@ limitations under the License. -->
213215
}
214216
215217
function changePage(pageIndex: number) {
216-
instances.value = pods.value.filter((d: unknown, index: number) => {
217-
if (index >= (pageIndex - 1) * pageSize && index < pageIndex * pageSize) {
218-
return d;
219-
}
220-
});
218+
let podList = pods.value;
219+
if (searchText.value) {
220+
podList = pods.value.filter((d: { label: string }) => d.label.includes(searchText.value));
221+
}
222+
instances.value = podList.filter(
223+
(_, index: number) => index >= (pageIndex - 1) * pageSize && index < pageIndex * pageSize,
224+
);
221225
queryInstanceMetrics(instances.value);
226+
currentPage.value = pageIndex;
222227
}
223228
224229
function searchList() {
225230
const searchInstances = pods.value.filter((d: { label: string }) => d.label.includes(searchText.value));
226-
instances.value = searchInstances.filter((d: unknown, index: number) => index < pageSize);
231+
instances.value = searchInstances.filter((_, index: number) => index < pageSize);
227232
queryInstanceMetrics(instances.value);
233+
currentPage.value = 1;
228234
}
229235
230236
watch(

src/views/dashboard/graphs/ServiceList.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ limitations under the License. -->
6060
<el-pagination
6161
class="pagination flex-h"
6262
layout="prev, pager, next"
63+
:current-page="currentPage"
6364
:page-size="pageSize"
64-
:total="selectorStore.services.length"
65+
:total="searchText ? sortServices.filter((d: any) => d.label.includes(searchText)).length : sortServices.length"
6566
@current-change="changePage"
6667
@prev-click="changePage"
6768
@next-click="changePage"
@@ -112,6 +113,7 @@ limitations under the License. -->
112113
const dashboardStore = useDashboardStore();
113114
const appStore = useAppStoreWithOut();
114115
const chartLoading = ref<boolean>(false);
116+
const currentPage = ref<number>(1);
115117
const pageSize = 10;
116118
const services = ref<Service[]>([]);
117119
const colMetrics = ref<string[]>([]);
@@ -248,18 +250,24 @@ limitations under the License. -->
248250
return { rowspan: groups.value[param.row.group], colspan: 1 };
249251
}
250252
function changePage(pageIndex: number) {
251-
const arr = sortServices.value.filter((d: Service, index: number) => {
253+
let services = sortServices.value;
254+
if (searchText.value) {
255+
services = sortServices.value.filter((d: { label: string }) => d.label.includes(searchText.value));
256+
}
257+
const arr = services.filter((d: Service, index: number) => {
252258
if (index >= (pageIndex - 1) * pageSize && index < pageSize * pageIndex) {
253259
return d;
254260
}
255261
});
256262
257263
setServices(arr);
264+
currentPage.value = pageIndex;
258265
}
259266
function searchList() {
260267
const searchServices = sortServices.value.filter((d: { label: string }) => d.label.includes(searchText.value));
261-
const services = searchServices.filter((d: unknown, index: number) => index < pageSize);
268+
const services = searchServices.filter((_, index: number) => index < pageSize);
262269
setServices(services);
270+
currentPage.value = 1;
263271
}
264272
265273
watch(

0 commit comments

Comments
 (0)