search endpoints

This commit is contained in:
Qiuxia Fan 2022-03-23 15:46:34 +08:00
parent 5bdc31012c
commit 27defa862a
2 changed files with 14 additions and 11 deletions

View File

@ -101,6 +101,7 @@ export const selectorStore = defineStore({
keyword?: string; keyword?: string;
serviceId?: string; serviceId?: string;
isRelation?: boolean; isRelation?: boolean;
limit?: number;
}): Promise<Nullable<AxiosResponse>> { }): Promise<Nullable<AxiosResponse>> {
if (!params) { if (!params) {
params = {}; params = {};
@ -113,6 +114,7 @@ export const selectorStore = defineStore({
serviceId, serviceId,
duration: this.durationTime, duration: this.durationTime,
keyword: params.keyword || "", keyword: params.keyword || "",
limit: params.limit,
}); });
if (!res.data.errors) { if (!res.data.errors) {
if (params.isRelation) { if (params.isRelation) {

View File

@ -92,6 +92,7 @@ import Card from "./Card.vue";
import { EntityType } from "../data"; import { EntityType } from "../data";
import router from "@/router"; import router from "@/router";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { number } from "echarts/core";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -121,11 +122,14 @@ const pageSize = 5;
const searchText = ref<string>(""); const searchText = ref<string>("");
if (props.needQuery) { if (props.needQuery) {
queryEndpoints(); queryEndpoints(10);
} }
async function queryEndpoints() { async function queryEndpoints(limit?: number) {
chartLoading.value = true; chartLoading.value = true;
const resp = await selectorStore.getEndpoints(); const resp = await selectorStore.getEndpoints({
limit,
keyword: searchText.value,
});
chartLoading.value = false; chartLoading.value = false;
if (resp.errors) { if (resp.errors) {
@ -134,7 +138,7 @@ async function queryEndpoints() {
} }
searchEndpoints.value = selectorStore.pods; searchEndpoints.value = selectorStore.pods;
endpoints.value = selectorStore.pods.splice(0, pageSize); endpoints.value = selectorStore.pods.splice(0, pageSize);
if (props.config.isEdit) { if (props.config.isEdit || !endpoints.value.length) {
return; return;
} }
queryEndpointMetrics(endpoints.value); queryEndpointMetrics(endpoints.value);
@ -179,12 +183,9 @@ function changePage(pageIndex: number) {
pageSize * (pageIndex || 1) pageSize * (pageIndex || 1)
); );
} }
function searchList() { async function searchList() {
const currentEndpoints = selectorStore.pods.filter((d: { label: string }) => const limit = searchText.value ? undefined : 10;
d.label.includes(searchText.value) await queryEndpoints(limit);
);
searchEndpoints.value = currentEndpoints;
endpoints.value = currentEndpoints.splice(0, pageSize);
} }
watch( watch(
() => [props.config.metricTypes, props.config.metrics], () => [props.config.metricTypes, props.config.metrics],
@ -197,7 +198,7 @@ watch(
watch( watch(
() => selectorStore.currentService, () => selectorStore.currentService,
() => { () => {
queryEndpoints(); queryEndpoints(10);
} }
); );
</script> </script>