Skip to content

Commit

Permalink
fix: correct services and instances when changing page numbers (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fine0830 authored Aug 16, 2024
1 parent 3c8b316 commit d9f819d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/views/dashboard/graphs/InstanceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ limitations under the License. -->
<el-pagination
class="pagination flex-h"
layout="prev, pager, next"
:current-page="currentPage"
:page-size="pageSize"
:total="pods.length"
:total="searchText ? pods.filter((d: any) => d.label.includes(searchText)).length : pods.length"
@current-change="changePage"
@prev-click="changePage"
@next-click="changePage"
Expand Down Expand Up @@ -122,6 +123,7 @@ limitations under the License. -->
const dashboardStore = useDashboardStore();
const chartLoading = ref<boolean>(false);
const instances = ref<Instance[]>([]); // current instances
const currentPage = ref<number>(1);
const pageSize = 10;
const searchText = ref<string>("");
const colMetrics = ref<string[]>([]);
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 11 additions & 3 deletions src/views/dashboard/graphs/ServiceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ limitations under the License. -->
<el-pagination
class="pagination flex-h"
layout="prev, pager, next"
:current-page="currentPage"
:page-size="pageSize"
:total="selectorStore.services.length"
:total="searchText ? sortServices.filter((d: any) => d.label.includes(searchText)).length : sortServices.length"
@current-change="changePage"
@prev-click="changePage"
@next-click="changePage"
Expand Down Expand Up @@ -112,6 +113,7 @@ limitations under the License. -->
const dashboardStore = useDashboardStore();
const appStore = useAppStoreWithOut();
const chartLoading = ref<boolean>(false);
const currentPage = ref<number>(1);
const pageSize = 10;
const services = ref<Service[]>([]);
const colMetrics = ref<string[]>([]);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d9f819d

Please sign in to comment.