mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-12 15:52:57 +00:00
feat: watch dashboard change
This commit is contained in:
parent
6dbb072360
commit
7ebb2ff48a
@ -28,8 +28,8 @@ limitations under the License. -->
|
|||||||
:filterable="filterable"
|
:filterable="filterable"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in options"
|
v-for="(item, index) in options"
|
||||||
:key="item.value || ''"
|
:key="item.value + index"
|
||||||
:label="item.label || ''"
|
:label="item.label || ''"
|
||||||
:value="item.value || ''"
|
:value="item.value || ''"
|
||||||
:disabled="item.disabled || false"
|
:disabled="item.disabled || false"
|
||||||
|
@ -88,7 +88,7 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function expressionsSource(config: Indexable, resp: { errors: string; data: Indexable }) {
|
function expressionsSource(config: Indexable, resp: { errors: string; data: Indexable | any }) {
|
||||||
if (resp.errors) {
|
if (resp.errors) {
|
||||||
ElMessage.error(resp.errors);
|
ElMessage.error(resp.errors);
|
||||||
return { source: {}, tips: [], typesOfMQE: [] };
|
return { source: {}, tips: [], typesOfMQE: [] };
|
||||||
@ -97,6 +97,10 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
|
|||||||
ElMessage.error("The query is wrong");
|
ElMessage.error("The query is wrong");
|
||||||
return { source: {}, tips: [], typesOfMQE: [] };
|
return { source: {}, tips: [], typesOfMQE: [] };
|
||||||
}
|
}
|
||||||
|
if (resp.data.error) {
|
||||||
|
ElMessage.error(resp.data.error);
|
||||||
|
return { source: {}, tips: [], typesOfMQE: [] };
|
||||||
|
}
|
||||||
const tips: string[] = [];
|
const tips: string[] = [];
|
||||||
const source: { [key: string]: unknown } = {};
|
const source: { [key: string]: unknown } = {};
|
||||||
const keys = Object.keys(resp.data);
|
const keys = Object.keys(resp.data);
|
||||||
@ -162,12 +166,16 @@ export async function useDashboardQueryProcessor(configArr: Indexable[]) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const pageData: Recordable = {};
|
const pageData: Recordable = {};
|
||||||
|
|
||||||
for (let i = 0; i < configArr.length; i++) {
|
for (let i = 0; i < configArr.length; i++) {
|
||||||
const data = expressionsSource(configArr[i], json);
|
const resp: any = {};
|
||||||
|
for (let m = 0; m < configArr[i].metrics.length; m++) {
|
||||||
pageData[i] = data;
|
resp[`expression${i}${m}`] = json.data[`expression${i}${m}`];
|
||||||
|
}
|
||||||
|
const data = expressionsSource(configArr[i], { ...json, data: resp });
|
||||||
|
const id = configArr[i].id;
|
||||||
|
pageData[id] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pageData;
|
return pageData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -113,6 +113,7 @@ limitations under the License. -->
|
|||||||
:data="item"
|
:data="item"
|
||||||
:activeIndex="`${data.i}-${activeTabIndex}-${item.i}`"
|
:activeIndex="`${data.i}-${activeTabIndex}-${item.i}`"
|
||||||
:needQuery="needQuery"
|
:needQuery="needQuery"
|
||||||
|
:metricsValues="metricsValues"
|
||||||
/>
|
/>
|
||||||
</grid-item>
|
</grid-item>
|
||||||
</grid-layout>
|
</grid-layout>
|
||||||
@ -136,6 +137,10 @@ limitations under the License. -->
|
|||||||
type: Object as PropType<LayoutConfig>,
|
type: Object as PropType<LayoutConfig>,
|
||||||
default: () => ({ children: [] }),
|
default: () => ({ children: [] }),
|
||||||
},
|
},
|
||||||
|
metricsValues: {
|
||||||
|
type: Object as PropType<any>,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
active: { type: Boolean, default: false },
|
active: { type: Boolean, default: false },
|
||||||
};
|
};
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
@ -88,6 +88,10 @@ limitations under the License. -->
|
|||||||
type: Object as PropType<LayoutConfig>,
|
type: Object as PropType<LayoutConfig>,
|
||||||
default: () => ({ widget: {}, graph: {} }),
|
default: () => ({ widget: {}, graph: {} }),
|
||||||
},
|
},
|
||||||
|
metricsValues: {
|
||||||
|
type: Object as PropType<any>,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
activeIndex: { type: String, default: "" },
|
activeIndex: { type: String, default: "" },
|
||||||
needQuery: { type: Boolean, default: false },
|
needQuery: { type: Boolean, default: false },
|
||||||
};
|
};
|
||||||
@ -111,10 +115,6 @@ limitations under the License. -->
|
|||||||
const isList = computed(() => ListChartTypes.includes((props.data.graph && props.data.graph.type) || ""));
|
const isList = computed(() => ListChartTypes.includes((props.data.graph && props.data.graph.type) || ""));
|
||||||
const typesOfMQE = ref<string[]>([]);
|
const typesOfMQE = ref<string[]>([]);
|
||||||
|
|
||||||
// if ((props.needQuery || !dashboardStore.currentDashboard.id) && !isList.value) {
|
|
||||||
// queryMetrics();
|
|
||||||
// }
|
|
||||||
|
|
||||||
async function queryMetrics() {
|
async function queryMetrics() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const e = {
|
const e = {
|
||||||
@ -176,48 +176,15 @@ limitations under the License. -->
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
watch(
|
watch(
|
||||||
() => [selectorStore.currentService, selectorStore.currentDestService],
|
() => props.metricsValues,
|
||||||
() => {
|
() => {
|
||||||
if (isList.value) {
|
loading.value = true;
|
||||||
return;
|
const params = props.metricsValues[data.value.i];
|
||||||
}
|
if (params) {
|
||||||
if ([EntityType[0].value, EntityType[4].value].includes(dashboardStore.entity)) {
|
state.source = params.source || {};
|
||||||
queryMetrics();
|
typesOfMQE.value = params.typesOfMQE;
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
watch(
|
|
||||||
() => [selectorStore.currentPod, selectorStore.currentDestPod],
|
|
||||||
() => {
|
|
||||||
if ([EntityType[0].value, EntityType[7].value, EntityType[8].value].includes(dashboardStore.entity)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isList.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
queryMetrics();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
watch(
|
|
||||||
() => [selectorStore.currentProcess, selectorStore.currentDestProcess],
|
|
||||||
() => {
|
|
||||||
if (isList.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ([EntityType[7].value, EntityType[8].value].includes(dashboardStore.entity)) {
|
|
||||||
queryMetrics();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
watch(
|
|
||||||
() => appStore.durationTime,
|
|
||||||
() => {
|
|
||||||
if (isList.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (dashboardStore.entity === EntityType[1].value) {
|
|
||||||
queryMetrics();
|
|
||||||
}
|
}
|
||||||
|
loading.value = false;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,19 +33,20 @@ limitations under the License. -->
|
|||||||
:class="{ active: dashboardStore.activedGridItem === item.i }"
|
:class="{ active: dashboardStore.activedGridItem === item.i }"
|
||||||
:drag-ignore-from="dragIgnoreFrom"
|
:drag-ignore-from="dragIgnoreFrom"
|
||||||
>
|
>
|
||||||
<component :is="item.type" :data="item" />
|
<component :is="item.type" :data="item" :metricsValues="metricsValues" />
|
||||||
</grid-item>
|
</grid-item>
|
||||||
</grid-layout>
|
</grid-layout>
|
||||||
<div class="no-data-tips" v-else>{{ t("noWidget") }}</div>
|
<div class="no-data-tips" v-else>{{ t("noWidget") }}</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onBeforeUnmount, watch } from "vue";
|
import { defineComponent, onBeforeUnmount, watch, ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
import { useSelectorStore } from "@/store/modules/selectors";
|
import { useSelectorStore } from "@/store/modules/selectors";
|
||||||
import type { LayoutConfig } from "@/types/dashboard";
|
import type { LayoutConfig } from "@/types/dashboard";
|
||||||
import controls from "../controls/index";
|
import controls from "../controls/index";
|
||||||
import { dragIgnoreFrom } from "../data";
|
import { dragIgnoreFrom, ListChartTypes, WidgetType } from "../data";
|
||||||
import { useDashboardQueryProcessor } from "@/hooks/useExpressionsProcessor";
|
import { useDashboardQueryProcessor } from "@/hooks/useExpressionsProcessor";
|
||||||
import { EntityType } from "../data";
|
import { EntityType } from "../data";
|
||||||
|
|
||||||
@ -54,14 +55,16 @@ limitations under the License. -->
|
|||||||
components: { ...controls },
|
components: { ...controls },
|
||||||
setup() {
|
setup() {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const appStore = useAppStoreWithOut();
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
const selectorStore = useSelectorStore();
|
const selectorStore = useSelectorStore();
|
||||||
|
const metricsValues = ref();
|
||||||
|
|
||||||
function clickGrid(item: LayoutConfig, event: Event) {
|
function clickGrid(item: LayoutConfig, event: Event) {
|
||||||
dashboardStore.activeGridItem(item.i);
|
dashboardStore.activeGridItem(item.i);
|
||||||
dashboardStore.selectWidget(item);
|
dashboardStore.selectWidget(item);
|
||||||
if (
|
if (
|
||||||
item.type === "Tab" &&
|
item.type === WidgetType.Tab &&
|
||||||
!["operations", "tab-layout"].includes((event.target as HTMLDivElement)?.className) &&
|
!["operations", "tab-layout"].includes((event.target as HTMLDivElement)?.className) &&
|
||||||
(event.target as HTMLDivElement)?.classList[2] !== "icon-tool" &&
|
(event.target as HTMLDivElement)?.classList[2] !== "icon-tool" &&
|
||||||
(event.target as HTMLDivElement)?.nodeName !== "use"
|
(event.target as HTMLDivElement)?.nodeName !== "use"
|
||||||
@ -71,11 +74,13 @@ limitations under the License. -->
|
|||||||
}
|
}
|
||||||
async function queryMetrics() {
|
async function queryMetrics() {
|
||||||
const widgets = [];
|
const widgets = [];
|
||||||
|
|
||||||
for (const item of dashboardStore.layout) {
|
for (const item of dashboardStore.layout) {
|
||||||
if (item.type === "Widget") {
|
const isList = ListChartTypes.includes(item.type || "");
|
||||||
|
if (item.type === WidgetType.Widget && !isList) {
|
||||||
widgets.push(item);
|
widgets.push(item);
|
||||||
}
|
}
|
||||||
if (item.type === "Tab") {
|
if (item.type === WidgetType.Tab) {
|
||||||
const index = isNaN(item.activedTabIndex) ? 0 : item.activedTabIndex;
|
const index = isNaN(item.activedTabIndex) ? 0 : item.activedTabIndex;
|
||||||
widgets.push(...item.children[index].children);
|
widgets.push(...item.children[index].children);
|
||||||
}
|
}
|
||||||
@ -83,10 +88,14 @@ limitations under the License. -->
|
|||||||
const configList = widgets.map((d: any) => ({
|
const configList = widgets.map((d: any) => ({
|
||||||
metrics: d.expressions || [],
|
metrics: d.expressions || [],
|
||||||
metricConfig: d.metricConfig || [],
|
metricConfig: d.metricConfig || [],
|
||||||
|
id: d.i,
|
||||||
}));
|
}));
|
||||||
const params = (await useDashboardQueryProcessor(configList)) || {};
|
if (!widgets.length) {
|
||||||
console.log(params);
|
return {};
|
||||||
|
}
|
||||||
|
metricsValues.value = (await useDashboardQueryProcessor(configList)) || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
dashboardStore.setLayout([]);
|
dashboardStore.setLayout([]);
|
||||||
selectorStore.setCurrentService(null);
|
selectorStore.setCurrentService(null);
|
||||||
@ -94,6 +103,7 @@ limitations under the License. -->
|
|||||||
dashboardStore.setEntity("");
|
dashboardStore.setEntity("");
|
||||||
dashboardStore.setConfigPanel(false);
|
dashboardStore.setConfigPanel(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [selectorStore.currentService, selectorStore.currentDestService],
|
() => [selectorStore.currentService, selectorStore.currentDestService],
|
||||||
() => {
|
() => {
|
||||||
@ -102,11 +112,37 @@ limitations under the License. -->
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
watch(
|
||||||
|
() => [selectorStore.currentPod, selectorStore.currentDestPod],
|
||||||
|
() => {
|
||||||
|
if ([EntityType[0].value, EntityType[7].value, EntityType[8].value].includes(dashboardStore.entity)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
queryMetrics();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
watch(
|
||||||
|
() => [selectorStore.currentProcess, selectorStore.currentDestProcess],
|
||||||
|
() => {
|
||||||
|
if ([EntityType[7].value, EntityType[8].value].includes(dashboardStore.entity)) {
|
||||||
|
queryMetrics();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
watch(
|
||||||
|
() => appStore.durationTime,
|
||||||
|
() => {
|
||||||
|
if (dashboardStore.entity === EntityType[1].value) {
|
||||||
|
queryMetrics();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
dashboardStore,
|
dashboardStore,
|
||||||
clickGrid,
|
clickGrid,
|
||||||
t,
|
t,
|
||||||
dragIgnoreFrom,
|
dragIgnoreFrom,
|
||||||
|
metricsValues,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user