mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-02 06:34:01 +00:00
refactor: update selectors structure
This commit is contained in:
parent
31765e5df3
commit
3968c2c13f
@ -33,7 +33,7 @@ export function useQueryProcessor(config: any) {
|
|||||||
const variables: string[] = [`$duration: Duration!`];
|
const variables: string[] = [`$duration: Duration!`];
|
||||||
const { currentPod, currentService, currentDestPod, currentDestService } =
|
const { currentPod, currentService, currentDestPod, currentDestService } =
|
||||||
selectorStore;
|
selectorStore;
|
||||||
const { normal, destNormal, entity } = dashboardStore;
|
const { entity } = dashboardStore;
|
||||||
const isRelation = [
|
const isRelation = [
|
||||||
"ServiceRelation",
|
"ServiceRelation",
|
||||||
"ServiceInstanceRelation",
|
"ServiceInstanceRelation",
|
||||||
@ -53,8 +53,8 @@ export function useQueryProcessor(config: any) {
|
|||||||
name,
|
name,
|
||||||
parentService: ["Service", "All"].includes(entity)
|
parentService: ["Service", "All"].includes(entity)
|
||||||
? null
|
? null
|
||||||
: currentService,
|
: currentService.value,
|
||||||
normal: normal,
|
normal: currentService.normal,
|
||||||
scope: entity,
|
scope: entity,
|
||||||
topN: 10,
|
topN: 10,
|
||||||
order: "DES",
|
order: "DES",
|
||||||
@ -69,14 +69,14 @@ export function useQueryProcessor(config: any) {
|
|||||||
name,
|
name,
|
||||||
entity: {
|
entity: {
|
||||||
scope: entity,
|
scope: entity,
|
||||||
serviceName: entity === "All" ? undefined : currentService,
|
serviceName: entity === "All" ? undefined : currentService.value,
|
||||||
normal: entity === "All" ? undefined : normal,
|
normal: entity === "All" ? undefined : currentService.normal,
|
||||||
serviceInstanceName: entity.includes("ServiceInstance")
|
serviceInstanceName: entity.includes("ServiceInstance")
|
||||||
? currentPod
|
? currentPod
|
||||||
: undefined,
|
: undefined,
|
||||||
endpointName: entity.includes("Endpoint") ? currentPod : undefined,
|
endpointName: entity.includes("Endpoint") ? currentPod : undefined,
|
||||||
destNormal: entity === "All" ? undefined : undefined,
|
destNormal: isRelation ? currentDestService.normal : undefined,
|
||||||
destServiceName: isRelation ? currentDestService : undefined,
|
destServiceName: isRelation ? currentDestService.value : undefined,
|
||||||
destServiceInstanceName:
|
destServiceInstanceName:
|
||||||
entity === "ServiceInstanceRelation" ? currentDestPod : undefined,
|
entity === "ServiceInstanceRelation" ? currentDestPod : undefined,
|
||||||
destEndpointName:
|
destEndpointName:
|
||||||
|
@ -34,8 +34,6 @@ interface DashboardState {
|
|||||||
activedGridItem: string;
|
activedGridItem: string;
|
||||||
durationTime: Duration;
|
durationTime: Duration;
|
||||||
selectorStore: any;
|
selectorStore: any;
|
||||||
normal: boolean;
|
|
||||||
destNormal: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const dashboardStore = defineStore({
|
export const dashboardStore = defineStore({
|
||||||
@ -49,8 +47,6 @@ export const dashboardStore = defineStore({
|
|||||||
activedGridItem: "",
|
activedGridItem: "",
|
||||||
durationTime: useAppStoreWithOut().durationTime,
|
durationTime: useAppStoreWithOut().durationTime,
|
||||||
selectorStore: useSelectorStore(),
|
selectorStore: useSelectorStore(),
|
||||||
normal: true,
|
|
||||||
destNormal: true,
|
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setLayout(data: LayoutConfig[]) {
|
setLayout(data: LayoutConfig[]) {
|
||||||
|
@ -16,19 +16,20 @@
|
|||||||
*/
|
*/
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { Option, Duration } from "@/types/app";
|
import { Option, Duration } from "@/types/app";
|
||||||
|
import { Service } from "@/types/selector";
|
||||||
import { store } from "@/store";
|
import { store } from "@/store";
|
||||||
import graph from "@/graph";
|
import graph from "@/graph";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
import { useAppStoreWithOut } from "@/store/modules/app";
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
|
|
||||||
interface SelectorState {
|
interface SelectorState {
|
||||||
services: Option[];
|
services: Service[];
|
||||||
instances: Option[];
|
instances: Option[];
|
||||||
pods: Option[];
|
pods: Option[];
|
||||||
endpoints: Option[];
|
endpoints: Option[];
|
||||||
currentService: string;
|
currentService: Nullable<Service>;
|
||||||
currentPod: string;
|
currentPod: string;
|
||||||
currentDestService: string;
|
currentDestService: Nullable<Service>;
|
||||||
currentDestPod: string;
|
currentDestPod: string;
|
||||||
durationTime: Duration;
|
durationTime: Duration;
|
||||||
}
|
}
|
||||||
@ -40,14 +41,14 @@ export const selectorStore = defineStore({
|
|||||||
instances: [],
|
instances: [],
|
||||||
pods: [],
|
pods: [],
|
||||||
endpoints: [],
|
endpoints: [],
|
||||||
currentService: "",
|
currentService: null,
|
||||||
currentPod: "",
|
currentPod: "",
|
||||||
currentDestService: "",
|
currentDestService: null,
|
||||||
currentDestPod: "",
|
currentDestPod: "",
|
||||||
durationTime: useAppStoreWithOut().durationTime,
|
durationTime: useAppStoreWithOut().durationTime,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setCurrentService(service: string) {
|
setCurrentService(service: Service) {
|
||||||
this.currentService = service;
|
this.currentService = service;
|
||||||
},
|
},
|
||||||
setCurrentPod(pod: string) {
|
setCurrentPod(pod: string) {
|
||||||
@ -65,17 +66,19 @@ export const selectorStore = defineStore({
|
|||||||
|
|
||||||
if (!res.data.errors) {
|
if (!res.data.errors) {
|
||||||
this.services = res.data.data.services || [];
|
this.services = res.data.data.services || [];
|
||||||
this.currentService = this.services.length
|
this.currentService = this.services.length ? this.services[0] : null;
|
||||||
? this.services[0].value
|
|
||||||
: "";
|
|
||||||
}
|
}
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
async getServiceInstances(param?: {
|
async getServiceInstances(param?: {
|
||||||
serviceId: string;
|
serviceId: string;
|
||||||
}): Promise<AxiosResponse> {
|
}): Promise<Nullable<AxiosResponse>> {
|
||||||
|
const serviceId = param ? param.serviceId : this.currentService?.id;
|
||||||
|
if (!serviceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const res: AxiosResponse = await graph.query("queryInstances").params({
|
const res: AxiosResponse = await graph.query("queryInstances").params({
|
||||||
serviceId: param ? param.serviceId : this.currentService,
|
serviceId,
|
||||||
duration: this.durationTime,
|
duration: this.durationTime,
|
||||||
});
|
});
|
||||||
if (!res.data.errors) {
|
if (!res.data.errors) {
|
||||||
@ -88,15 +91,19 @@ export const selectorStore = defineStore({
|
|||||||
async getEndpoints(params?: {
|
async getEndpoints(params?: {
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
serviceId?: string;
|
serviceId?: string;
|
||||||
}): Promise<AxiosResponse> {
|
}): Promise<Nullable<AxiosResponse>> {
|
||||||
if (!params) {
|
if (!params) {
|
||||||
params = {};
|
params = {};
|
||||||
}
|
}
|
||||||
if (!params.keyword) {
|
if (!params.keyword) {
|
||||||
params.keyword = "";
|
params.keyword = "";
|
||||||
}
|
}
|
||||||
|
const serviceId = params.serviceId || this.currentService?.id;
|
||||||
|
if (!serviceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const res: AxiosResponse = await graph.query("queryEndpoints").params({
|
const res: AxiosResponse = await graph.query("queryEndpoints").params({
|
||||||
serviceId: params.serviceId || this.currentService,
|
serviceId,
|
||||||
duration: this.durationTime,
|
duration: this.durationTime,
|
||||||
keyword: params.keyword,
|
keyword: params.keyword,
|
||||||
});
|
});
|
||||||
|
24
src/types/selector.d.ts
vendored
Normal file
24
src/types/selector.d.ts
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
export type Service = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
layers: string[];
|
||||||
|
normal: boolean;
|
||||||
|
group: string;
|
||||||
|
};
|
@ -39,7 +39,7 @@ limitations under the License. -->
|
|||||||
<router-link
|
<router-link
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="link"
|
class="link"
|
||||||
:to="`/dashboard/${scope.row.layer}/endpoint/${selectorStore.currentService}/${scope.row.value}/${config.dashboardName}`"
|
:to="`/dashboard/${scope.row.layer}/endpoint/${selectorStore.currentService.value}/${scope.row.value}/${config.dashboardName}`"
|
||||||
:style="{ fontSize: `${config.fontSize}px` }"
|
:style="{ fontSize: `${config.fontSize}px` }"
|
||||||
>
|
>
|
||||||
{{ scope.row.label }}
|
{{ scope.row.label }}
|
||||||
|
@ -39,7 +39,7 @@ limitations under the License. -->
|
|||||||
<router-link
|
<router-link
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="link"
|
class="link"
|
||||||
:to="`/dashboard/${scope.row.layer}/serviceInstance/${selectorStore.currentService}/${scope.row.value}/${config.dashboardName}`"
|
:to="`/dashboard/${scope.row.layer}/serviceInstance/${selectorStore.currentService.value}/${scope.row.value}/${config.dashboardName}`"
|
||||||
:style="{ fontSize: `${config.fontSize}px` }"
|
:style="{ fontSize: `${config.fontSize}px` }"
|
||||||
>
|
>
|
||||||
{{ scope.row.label }}
|
{{ scope.row.label }}
|
||||||
|
@ -39,7 +39,7 @@ limitations under the License. -->
|
|||||||
<router-link
|
<router-link
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="link"
|
class="link"
|
||||||
:to="`/dashboard/${scope.row.layer}/service/${selectorStore.currentService}/${config.dashboardName}`"
|
:to="`/dashboard/${scope.row.layer}/service/${selectorStore.currentService.value}/${config.dashboardName}`"
|
||||||
:style="{ fontSize: `${config.fontSize}px` }"
|
:style="{ fontSize: `${config.fontSize}px` }"
|
||||||
>
|
>
|
||||||
{{ scope.row.label }}
|
{{ scope.row.label }}
|
||||||
|
@ -18,7 +18,7 @@ limitations under the License. -->
|
|||||||
<div class="selectors-item">
|
<div class="selectors-item">
|
||||||
<span class="label">$Service</span>
|
<span class="label">$Service</span>
|
||||||
<Selector
|
<Selector
|
||||||
v-model="selectorStore.currentService"
|
v-model="states.currentService"
|
||||||
:options="selectorStore.services"
|
:options="selectorStore.services"
|
||||||
size="mini"
|
size="mini"
|
||||||
placeholder="Select a service"
|
placeholder="Select a service"
|
||||||
@ -82,13 +82,14 @@ limitations under the License. -->
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { reactive, onBeforeMount } from "vue";
|
import { reactive } from "vue";
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
import { EntityType, ToolIcons } from "../data";
|
import { EntityType, ToolIcons } from "../data";
|
||||||
import { useSelectorStore } from "@/store/modules/selectors";
|
import { useSelectorStore } from "@/store/modules/selectors";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { Option } from "@/types/app";
|
import { Option } from "@/types/app";
|
||||||
|
import { Service } from "@/types/selector";
|
||||||
|
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
const selectorStore = useSelectorStore();
|
const selectorStore = useSelectorStore();
|
||||||
@ -99,12 +100,15 @@ const states = reactive<{
|
|||||||
destService: string;
|
destService: string;
|
||||||
destPod: string;
|
destPod: string;
|
||||||
key: number;
|
key: number;
|
||||||
|
currentService: string;
|
||||||
}>({
|
}>({
|
||||||
destService: "",
|
destService: "",
|
||||||
destPod: "",
|
destPod: "",
|
||||||
key: EntityType.filter((d: Option) => d.value === params.entity)[0].key || 0,
|
key: EntityType.filter((d: Option) => d.value === params.entity)[0].key || 0,
|
||||||
entity: String(params.entity),
|
entity: String(params.entity),
|
||||||
layerId: params.layerId,
|
layerId: params.layerId,
|
||||||
|
currentService:
|
||||||
|
(selectorStore.currentService && selectorStore.currentService.value) || "",
|
||||||
});
|
});
|
||||||
dashboardStore.setLayer(states.layerId);
|
dashboardStore.setLayer(states.layerId);
|
||||||
dashboardStore.setEntity(states.entity);
|
dashboardStore.setEntity(states.entity);
|
||||||
@ -123,9 +127,9 @@ async function getServices() {
|
|||||||
fetchPods(states.entity);
|
fetchPods(states.entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeService(service: Option[]) {
|
async function changeService(service: Service[]) {
|
||||||
if (service[0]) {
|
if (service[0]) {
|
||||||
selectorStore.setCurrentService(service[0].value);
|
selectorStore.setCurrentService(service[0]);
|
||||||
fetchPods(states.entity);
|
fetchPods(states.entity);
|
||||||
} else {
|
} else {
|
||||||
selectorStore.setCurrentService("");
|
selectorStore.setCurrentService("");
|
||||||
|
Loading…
Reference in New Issue
Block a user