feat: Add menus in side bar (#30)

This commit is contained in:
Fine0830
2022-03-21 15:36:56 +08:00
committed by GitHub
parent 42d8e909f6
commit 61f82c54df
21 changed files with 386 additions and 95 deletions

View File

@@ -34,6 +34,11 @@ const routeNames = [
"MeshServices",
"ControlPanel",
"DataPanel",
"Linux",
"SkyWalkingServer",
"Satellite",
"Functions",
"Browser",
];
const layer = ref<string>("GENERAL");
getDashboard();
@@ -69,6 +74,21 @@ function setLayer(n: string) {
case routeNames[4]:
layer.value = "MESH_DP";
break;
case routeNames[5]:
layer.value = "OS_LINUX";
break;
case routeNames[6]:
layer.value = "SO11Y_OAP";
break;
case routeNames[7]:
layer.value = "SO11Y_SATELLITE";
break;
case routeNames[8]:
layer.value = "FAAS";
break;
case routeNames[9]:
layer.value = "BROWSER";
break;
default:
layer.value = "GENERAL";
break;

View File

@@ -57,7 +57,7 @@ limitations under the License. -->
<el-table-column label="Operations">
<template #default="scope">
<el-button size="small" @click="handleView(scope.row)">
{{ t("view") }}
{{ t("edit") }}
</el-button>
<el-button size="small" @click="handleEdit(scope.row)">
{{ t("rename") }}

View File

@@ -90,12 +90,11 @@ import { useDashboardStore } from "@/store/modules/dashboard";
import {
MetricTypes,
ListChartTypes,
MetricCatalog,
DefaultGraphConfig,
EntityType,
ChartTypes,
PodsChartTypes,
ListEntity,
MetricsType,
} from "../../data";
import { ElMessage } from "element-plus";
import Icon from "@/components/Icon.vue";
@@ -134,13 +133,8 @@ states.visTypes = setVisTypes();
setDashboards();
setMetricType();
async function setMetricType(catalog?: string) {
async function setMetricType() {
const { graph } = dashboardStore.selectedGrid;
if (states.isList) {
catalog = catalog || ListEntity[graph.type];
} else {
catalog = catalog || dashboardStore.entity;
}
const json = await dashboardStore.fetchMetricList();
if (json.errors) {
ElMessage.error(json.errors);
@@ -149,16 +143,11 @@ async function setMetricType(catalog?: string) {
states.metricList = (json.data.metrics || []).filter(
(d: { catalog: string; type: string }) => {
if (states.isList || graph.type === "Table") {
if (
d.type === "REGULAR_VALUE" &&
catalog === (MetricCatalog as any)[d.catalog]
) {
if (d.type === MetricsType.REGULAR_VALUE) {
return d;
}
} else {
if (catalog === (MetricCatalog as any)[d.catalog]) {
return d;
}
return d;
}
}
);
@@ -253,12 +242,7 @@ function changeChartType(item: Option) {
states.metrics = [""];
states.metricTypes = [""];
}
const catalog: { [key: string]: string } = {
InstanceList: EntityType[3].value,
EndpointList: EntityType[2].value,
ServiceList: EntityType[0].value,
};
setMetricType(catalog[graph.type]);
setMetricType();
setDashboards();
states.dashboardName = "";
}
@@ -367,7 +351,7 @@ function deleteMetric(index: number) {
states.metricTypes.splice(index, 1);
}
function setMetricTypeList(type: string) {
if (type !== "REGULAR_VALUE") {
if (type !== MetricsType.REGULAR_VALUE) {
return MetricTypes[type];
}
if (states.isList || dashboardStore.selectedGrid.graph.type === "Table") {

View File

@@ -213,7 +213,7 @@ function handleNodeClick(d: Node & { x: number; y: number }) {
topologyStore.setNode(d);
topologyStore.setLink(null);
operationsPos.x = d.x;
operationsPos.y = d.y + 30;
operationsPos.y = d.y - 70;
if (d.layer === String(dashboardStore.layerId)) {
return;
}
@@ -239,7 +239,9 @@ function handleLinkClick(event: any, d: Call) {
dashboardStore.entity === EntityType[1].value
? EntityType[0].value
: dashboardStore.entity;
const path = `/dashboard/${dashboardStore.layerId}/${e}Relation/${d.source.id}/${d.target.id}/${settings.value.linkDashboard}`;
const path = `/dashboard/${dashboardStore.layerId}/${e}Relation/${
d.source.id
}/${d.target.id}/${settings.value.linkDashboard.split(" ").join("-")}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
}
@@ -371,19 +373,25 @@ async function handleInspect() {
update();
}
function handleGoEndpoint(name: string) {
const path = `/dashboard/${dashboardStore.layerId}/Endpoint/${topologyStore.node.id}/${name}`;
const path = `/dashboard/${dashboardStore.layerId}/Endpoint/${
topologyStore.node.id
}/${name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
}
function handleGoInstance(name: string) {
const path = `/dashboard/${dashboardStore.layerId}/ServiceInstance/${topologyStore.node.id}/${name}`;
const path = `/dashboard/${dashboardStore.layerId}/ServiceInstance/${
topologyStore.node.id
}/${name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
}
function handleGoDashboard(name: string) {
const path = `/dashboard/${dashboardStore.layerId}/Service/${topologyStore.node.id}/${name}`;
const path = `/dashboard/${dashboardStore.layerId}/Service/${
topologyStore.node.id
}/${name.split(" ").join("-")}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");

View File

@@ -189,8 +189,8 @@ function selectNodeLink(d: any) {
}
topologyStore.setNode(d.data);
topologyStore.setLink(null);
operationsPos.x = d.event.event.clientX;
operationsPos.y = d.event.event.clientY;
operationsPos.x = d.event.event.clientX - 200;
operationsPos.y = d.event.event.clientY - 150;
}
async function changeDepth(opt: Option[] | any) {

View File

@@ -16,11 +16,12 @@ limitations under the License. -->
<div class="link-settings">
<h5 class="title">{{ t("callSettings") }}</h5>
<div class="label">{{ t("linkDashboard") }}</div>
<el-input
v-model="states.linkDashboard"
placeholder="Please input a dashboard name for calls"
@change="updateSettings"
<Selector
:value="states.linkDashboard"
:options="states.linkDashboards"
size="small"
placeholder="Please input a dashboard name for calls"
@change="changeLinkDashboard"
class="inputs"
/>
<div class="label">{{ t("linkServerMetrics") }}</div>
@@ -51,16 +52,17 @@ limitations under the License. -->
<div class="node-settings">
<h5 class="title">{{ t("nodeSettings") }}</h5>
<div class="label">{{ t("nodeDashboard") }}</div>
<el-input
v-show="!isServer"
v-model="states.nodeDashboard"
placeholder="Please input a dashboard name for nodes"
@change="updateSettings"
<Selector
v-show="!isService"
:value="states.nodeDashboard"
:options="states.nodeDashboards"
size="small"
placeholder="Please input a dashboard name for nodes"
@change="changeNodeDashboard"
class="inputs"
/>
<div
v-show="isServer"
v-show="isService"
v-for="(item, index) in items"
:key="index"
class="metric-item"
@@ -73,11 +75,12 @@ limitations under the License. -->
@change="changeScope(index, $event)"
class="item mr-5"
/>
<el-input
v-model="item.dashboard"
<Selector
:value="item.dashboard"
:options="states.nodeDashboards"
size="small"
placeholder="Please input a dashboard name for nodes"
@change="updateNodeDashboards(index, $event)"
size="small"
class="item mr-5"
/>
<span>
@@ -108,7 +111,7 @@ limitations under the License. -->
@change="changeNodeMetrics"
/>
</div>
<div class="legend-settings" v-show="isServer">
<div class="legend-settings" v-show="isService">
<h5 class="title">{{ t("legendSettings") }}</h5>
<div class="label">{{ t("conditions") }}</div>
<div v-for="(metric, index) of legend.metric" :key="metric.name + index">
@@ -184,7 +187,8 @@ import { MetricCatalog, ScopeType, MetricConditions } from "../../../data";
import { Option } from "@/types/app";
import { useQueryTopologyMetrics } from "@/hooks/useProcessor";
import { Node, Call } from "@/types/topology";
import { EntityType, LegendOpt } from "../../../data";
import { DashboardItem } from "@/types/dashboard";
import { EntityType, LegendOpt, MetricsType } from "../../../data";
/*global defineEmits */
const emit = defineEmits(["update", "updateNodes"]);
@@ -208,6 +212,8 @@ const states = reactive<{
nodeMetrics: string[];
nodeMetricList: Option[];
linkMetricList: Option[];
linkDashboards: (DashboardItem & { label: string; value: string })[];
nodeDashboards: (DashboardItem & { label: string; value: string })[];
}>({
linkDashboard: "",
nodeDashboard: [],
@@ -216,8 +222,10 @@ const states = reactive<{
nodeMetrics: [],
nodeMetricList: [],
linkMetricList: [],
linkDashboards: [],
nodeDashboards: [],
});
const isServer = [EntityType[0].value, EntityType[1].value].includes(
const isService = [EntityType[0].value, EntityType[1].value].includes(
dashboardStore.entity
);
const legend = reactive<{
@@ -226,6 +234,7 @@ const legend = reactive<{
getMetricList();
async function getMetricList() {
const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]");
const json = await dashboardStore.fetchMetricList();
if (json.errors) {
ElMessage.error(json.errors);
@@ -237,18 +246,28 @@ async function getMetricList() {
: dashboardStore.entity === EntityType[4].value
? EntityType[3].value
: dashboardStore.entity;
states.nodeMetricList = (json.data.metrics || []).filter(
(d: { catalog: string }) => entity === (MetricCatalog as any)[d.catalog]
states.linkDashboards = list.reduce(
(
prev: (DashboardItem & { label: string; value: string })[],
d: DashboardItem
) => {
if (
d.layer === dashboardStore.layerId &&
d.entity === entity + "Relation"
) {
prev.push({ ...d, label: d.name, value: d.name });
}
return prev;
},
[]
);
states.nodeMetricList = (json.data.metrics || []).filter(
(d: { type: string }) => d.type === MetricsType.REGULAR_VALUE
);
const e =
dashboardStore.entity === EntityType[1].value
? EntityType[0].value
: dashboardStore.entity === EntityType[4].value
? EntityType[3].value
: dashboardStore.entity;
states.linkMetricList = (json.data.metrics || []).filter(
(d: { catalog: string }) =>
e + "Relation" === (MetricCatalog as any)[d.catalog]
(d: { catalog: string; type: string }) =>
entity + "Relation" === (MetricCatalog as any)[d.catalog] &&
d.type === MetricsType.REGULAR_VALUE
);
}
async function setLegend() {
@@ -259,7 +278,7 @@ async function setLegend() {
emit("update", {
linkDashboard: states.linkDashboard,
nodeDashboard: isServer
nodeDashboard: isService
? items.filter((d: { scope: string; dashboard: string }) => d.dashboard)
: states.nodeDashboard,
linkServerMetrics: states.linkServerMetrics,
@@ -276,15 +295,34 @@ async function setLegend() {
}
emit("updateNodes");
}
function changeNodeDashboard(opt: any) {
states.nodeDashboard = opt[0].value;
}
function changeLinkDashboard(opt: any) {
states.linkDashboard = opt[0].value;
}
function changeLegend(type: string, opt: any, index: number) {
(legend.metric[index] as any)[type] = opt[0].value || opt;
}
function changeScope(index: number, opt: Option[]) {
function changeScope(index: number, opt: Option[] | any) {
items[index].scope = opt[0].value;
items[index].dashboard = "";
const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]");
states.nodeDashboards = list.reduce(
(
prev: (DashboardItem & { label: string; value: string })[],
d: DashboardItem
) => {
if (d.layer === dashboardStore.layerId && d.entity === opt[0].value) {
prev.push({ ...d, label: d.name, value: d.name });
}
return prev;
},
[]
);
items[index].dashboard = states.nodeDashboards[0].value;
}
function updateNodeDashboards(index: number, content: string) {
items[index].dashboard = content;
function updateNodeDashboards(index: number, content: Option[] | any) {
items[index].dashboard = content[0].value;
updateSettings();
}
function addItem() {
@@ -297,7 +335,7 @@ function deleteItem(index: number) {
function updateSettings() {
emit("update", {
linkDashboard: states.linkDashboard,
nodeDashboard: isServer
nodeDashboard: isService
? items.filter((d: { scope: string; dashboard: string }) => d.dashboard)
: states.nodeDashboard,
linkServerMetrics: states.linkServerMetrics,
@@ -306,7 +344,7 @@ function updateSettings() {
legend: legend.metric,
});
}
async function changeLinkServerMetrics(options: Option[]) {
async function changeLinkServerMetrics(options: Option[] | any) {
states.linkServerMetrics = options.map((d: Option) => d.value);
updateSettings();
if (!states.linkServerMetrics.length) {
@@ -323,7 +361,7 @@ async function changeLinkServerMetrics(options: Option[]) {
ElMessage.error(res.errors);
}
}
async function changeLinkClientMetrics(options: Option[]) {
async function changeLinkClientMetrics(options: Option[] | any) {
states.linkClientMetrics = options.map((d: Option) => d.value);
updateSettings();
if (!states.linkClientMetrics.length) {
@@ -340,7 +378,7 @@ async function changeLinkClientMetrics(options: Option[]) {
ElMessage.error(res.errors);
}
}
async function changeNodeMetrics(options: Option[]) {
async function changeNodeMetrics(options: Option[] | any) {
states.nodeMetrics = options.map((d: Option) => d.value);
updateSettings();
if (!states.nodeMetrics.length) {