update selectors

This commit is contained in:
Fine 2022-08-11 20:27:58 +08:00
parent da851d223f
commit 12dd47affe
3 changed files with 141 additions and 88 deletions

View File

@ -48,16 +48,7 @@ export const Instances = {
} }
`, `,
}; };
export const Endpoints = {
variable: "$serviceId: ID!, $keyword: String!",
query: `
pods: findEndpoint(serviceId: $serviceId, keyword: $keyword, limit: 20) {
id
value: name
label: name
}
`,
};
export const Processes = { export const Processes = {
variable: "$instanceId: ID!, $duration: Duration!", variable: "$instanceId: ID!, $duration: Duration!",
query: ` query: `
@ -71,8 +62,23 @@ export const Processes = {
instanceName instanceName
agentId agentId
detectType detectType
attributes attributes {
name
value
}
labels labels
}
`,
};
export const Endpoints = {
variable: "$serviceId: ID!, $keyword: String!",
query: `
pods: findEndpoint(serviceId: $serviceId, keyword: $keyword, limit: 20) {
id
value: name
label: name
}
`, `,
}; };
@ -133,8 +139,10 @@ export const getProcess = {
instanceName instanceName
agentId agentId
detectType detectType
attributes attributes {
labels name
value
}
} }
`, `,
}; };

View File

@ -1,4 +1,3 @@
import { getProcess } from "./../../graphql/fragments/selector";
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
@ -122,7 +121,7 @@ export const selectorStore = defineStore({
if (!instanceId) { if (!instanceId) {
return null; return null;
} }
const res: AxiosResponse = await graphql.query("queryInstances").params({ const res: AxiosResponse = await graphql.query("queryProcesses").params({
instanceId, instanceId,
duration: useAppStoreWithOut().durationTime, duration: useAppStoreWithOut().durationTime,
}); });

View File

@ -225,6 +225,7 @@ async function setSelector() {
EntityType[3].value, EntityType[3].value,
EntityType[5].value, EntityType[5].value,
EntityType[6].value, EntityType[6].value,
EntityType[7].value,
].includes(String(params.entity)) ].includes(String(params.entity))
) { ) {
setSourceSelector(); setSourceSelector();
@ -278,6 +279,7 @@ async function setSourceSelector() {
if (!(selectorStore.pods.length && selectorStore.pods[0])) { if (!(selectorStore.pods.length && selectorStore.pods[0])) {
selectorStore.setCurrentPod(null); selectorStore.setCurrentPod(null);
states.currentPod = ""; states.currentPod = "";
states.currentProcess = "";
return; return;
} }
const pod = params.podId || selectorStore.pods[0].id; const pod = params.podId || selectorStore.pods[0].id;
@ -289,9 +291,25 @@ async function setSourceSelector() {
} else { } else {
currentPod = selectorStore.pods.find((d: { id: string }) => d.id === pod); currentPod = selectorStore.pods.find((d: { id: string }) => d.id === pod);
} }
if (currentPod) { if (!currentPod) {
return;
}
selectorStore.setCurrentPod(currentPod); selectorStore.setCurrentPod(currentPod);
states.currentPod = currentPod.label; states.currentPod = currentPod.label;
const process = params.processId || selectorStore.processes[0].id;
let currentProcess;
if (states.currentProcess) {
currentProcess = selectorStore.processes.find(
(d: { label: string }) => d.label === states.currentProcess
);
} else {
currentProcess = selectorStore.processes.find(
(d: { id: string }) => d.id === process
);
}
if (currentProcess) {
selectorStore.setCurrentProcess(currentProcess);
states.currentProcess = currentProcess.label;
} }
} }
@ -319,9 +337,25 @@ async function setDestSelector() {
(d: { id: string }) => d.id === destPod (d: { id: string }) => d.id === destPod
); );
} }
if (currentDestPod) { if (!currentDestPod) {
return;
}
selectorStore.setCurrentDestPod(currentDestPod); selectorStore.setCurrentDestPod(currentDestPod);
states.currentDestPod = currentDestPod.label; states.currentDestPod = currentDestPod.label;
const destProcess = params.destProcessId || selectorStore.destProcesses[0].id;
let currentDestProcess;
if (states.currentDestProcess) {
currentDestProcess = selectorStore.destProcesses.find(
(d: { label: string }) => d.label === states.currentProcess
);
} else {
currentDestProcess = selectorStore.destProcesses.find(
(d: { id: string }) => d.id === destProcess
);
}
if (currentDestProcess) {
selectorStore.setCurrentProcess(currentDestProcess);
states.currentProcess = currentDestProcess.label;
} }
} }
@ -365,6 +399,7 @@ async function getServices() {
(d: unknown, index: number) => index === val (d: unknown, index: number) => index === val
); );
} }
selectorStore.setCurrentDestService(d || null); selectorStore.setCurrentDestService(d || null);
if (!selectorStore.currentService) { if (!selectorStore.currentService) {
return; return;
@ -377,9 +412,10 @@ async function getServices() {
EntityType[3].value, EntityType[3].value,
EntityType[5].value, EntityType[5].value,
EntityType[6].value, EntityType[6].value,
EntityType[7].value,
].includes(dashboardStore.entity) ].includes(dashboardStore.entity)
) { ) {
fetchPods(e, selectorStore.currentService.id, true); await fetchPods(e, selectorStore.currentService.id, true);
} }
if (!selectorStore.currentDestService) { if (!selectorStore.currentDestService) {
return; return;
@ -390,48 +426,67 @@ async function getServices() {
dashboardStore.entity dashboardStore.entity
) )
) { ) {
fetchPods(dashboardStore.entity, selectorStore.currentDestService.id, true); await fetchPods(
dashboardStore.entity,
selectorStore.currentDestService.id,
true
);
} }
} }
async function changeService(service: any) { async function changeService(service: Option[]) {
if (service[0]) { if (service[0]) {
states.currentService = service[0].value; states.currentService = service[0].value;
selectorStore.setCurrentService(service[0]); selectorStore.setCurrentService(service[0]);
const e = dashboardStore.entity.split("Relation")[0];
selectorStore.setCurrentPod(null); selectorStore.setCurrentPod(null);
states.currentPod = ""; states.currentPod = "";
fetchPods(e, selectorStore.currentService.id, true); states.currentProcess = "";
if (dashboardStore.entity === EntityType[7].value) {
fetchPods("Process", selectorStore.currentService.id, true);
} else {
fetchPods(dashboardStore.entity, selectorStore.currentService.id, true);
}
} else { } else {
selectorStore.setCurrentService(null); selectorStore.setCurrentService(null);
} }
} }
function changeDestService(service: any) { function changeDestService(service: Option[]) {
if (service[0]) { if (service[0]) {
states.currentDestService = service[0].value; states.currentDestService = service[0].value;
selectorStore.setCurrentDestService(service[0]); selectorStore.setCurrentDestService(service[0]);
selectorStore.setCurrentDestPod(null); selectorStore.setCurrentDestPod(null);
states.currentDestPod = ""; states.currentDestPod = "";
states.currentDestProcess = "";
fetchPods(dashboardStore.entity, selectorStore.currentDestService.id, true); fetchPods(dashboardStore.entity, selectorStore.currentDestService.id, true);
} else { } else {
selectorStore.setCurrentDestService(null); selectorStore.setCurrentDestService(null);
} }
} }
function changePods(pod: any) { async function changePods(pod: Option[]) {
selectorStore.setCurrentPod(pod[0] || null); selectorStore.setCurrentPod(pod[0] || null);
if (dashboardStore.entity === EntityType[7].value) {
selectorStore.setCurrentProcess(null);
states.currentProcess = "";
fetchProcess(true);
}
} }
function changeDestPods(pod: any) { function changeDestPods(pod: Option[]) {
selectorStore.setCurrentDestPod(pod[0] || null); selectorStore.setCurrentDestPod(pod[0] || null);
if (dashboardStore.entity === EntityType[7].value) {
selectorStore.setCurrentDestProcess(null);
states.currentDestProcess = "";
fetchDestProcess(true);
}
} }
function changeDestProcess(pod: any) { function changeDestProcess(pod: Option[]) {
selectorStore.setCurrentDestProcess(pod[0] || null); selectorStore.setCurrentDestProcess(pod[0] || null);
} }
function changeProcess(pod: any) { function changeProcess(pod: Option[]) {
selectorStore.setCurrentProcess(pod[0] || null); selectorStore.setCurrentProcess(pod[0] || null);
} }
@ -626,51 +681,48 @@ async function fetchPods(
} }
break; break;
case EntityType[7].value: case EntityType[7].value:
resp = await selectorStore.getServiceInstances({ serviceId }); await fetchPods(EntityType[5].value, serviceId, setPod, param);
if (setPod) { resp = await fetchDestProcess(setPod);
let p, m; break;
if (states.currentPod) { case "Process":
p = selectorStore.pods.find( await fetchPods(EntityType[3].value, serviceId, setPod, param);
(d: { label: string }) => d.label === states.currentPod resp = await fetchProcess(setPod);
); break;
} else { default:
p = selectorStore.pods.find( resp = {};
(d: { label: string }, index: number) => index === 0
);
} }
selectorStore.setCurrentPod(p || null); if (resp.errors) {
states.currentPod = selectorStore.currentPod.label; ElMessage.error(resp.errors);
selectorStore.setDestPods(selectorStore.pods || []);
if (states.currentDestPod) {
m = selectorStore.destPods.find(
(d: { label: string }) => d.label === states.currentDestPod
);
} else {
m = selectorStore.destPods.find(
(d: { label: string }, index: number) => index === 1
);
} }
selectorStore.setCurrentDestPod(m || null); }
states.currentDestPod = selectorStore.currentDestPod.label;
} async function fetchProcess(setPod: boolean) {
resp = await selectorStore.getProcesses({ const resp = await selectorStore.getProcesses({
instanceId: selectorStore.currentPod.id, instanceId: selectorStore.currentPod.id,
isRelation: true,
}); });
if (setPod) { if (setPod) {
let p, m; let m;
if (states.currentProcess) { if (states.currentProcess) {
p = selectorStore.processes.find( m = selectorStore.processes.find(
(d: { label: string }) => d.label === states.currentProcess (d: { label: string }) => d.label === states.currentProcess
); );
} else { } else {
p = selectorStore.processes.find( m = selectorStore.processes.find(
(d: { label: string }, index: number) => index === 0 (d: { label: string }, index: number) => index === 0
); );
} }
selectorStore.setCurrentProcess(p || null); selectorStore.setCurrentProcess(m || null);
states.currentProcess = selectorStore.currentProcess.label; states.currentProcess = m && m.label;
selectorStore.setDestProcesses(selectorStore.processes || []); }
return resp;
}
async function fetchDestProcess(setPod: boolean) {
const resp = await selectorStore.getProcesses({
instanceId: selectorStore.currentDestPod.id,
isRelation: true,
});
if (setPod) {
let m;
if (states.currentDestProcess) { if (states.currentDestProcess) {
m = selectorStore.destProcesses.find( m = selectorStore.destProcesses.find(
(d: { label: string }) => d.label === states.currentDestProcess (d: { label: string }) => d.label === states.currentDestProcess
@ -681,15 +733,9 @@ async function fetchPods(
); );
} }
selectorStore.setCurrentDestProcess(m || null); selectorStore.setCurrentDestProcess(m || null);
states.currentDestProcess = selectorStore.currentDestProcess.label; states.currentDestProcess = m && m.label;
}
break;
default:
resp = {};
}
if (resp.errors) {
ElMessage.error(resp.errors);
} }
return resp;
} }
function getTools() { function getTools() {
switch (params.entity) { switch (params.entity) {