From c9af35cf1ec21b7e6a8a7db572a536846eda2635 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Thu, 17 Mar 2022 17:32:17 +0800 Subject: [PATCH] query metrics with standard config --- src/views/dashboard/configuration/Widget.vue | 12 ++--- .../configuration/widget/StandardOptions.vue | 47 ++++++++++++++++--- src/views/dashboard/controls/Widget.vue | 2 +- src/views/dashboard/graphs/Line.vue | 6 +-- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/views/dashboard/configuration/Widget.vue b/src/views/dashboard/configuration/Widget.vue index d196ca95..9ca4b448 100644 --- a/src/views/dashboard/configuration/Widget.vue +++ b/src/views/dashboard/configuration/Widget.vue @@ -31,12 +31,7 @@ limitations under the License. --> :is="dashboardStore.selectedGrid.graph.type" :intervalTime="appStoreWithOut.intervalTime" :data="states.source" - :config="{ - ...dashboardStore.selectedGrid.graph, - i: dashboardStore.selectedGrid.i, - metrics: dashboardStore.selectedGrid.metrics, - metricTypes: dashboardStore.selectedGrid.metricTypes, - }" + :config="dashboardStore.selectedGrid" />
{{ t("noData") }} @@ -58,7 +53,7 @@ limitations under the License. --> - +
@@ -101,7 +96,7 @@ export default defineComponent({ const loading = ref(false); const states = reactive<{ activeNames: string; - source: any; + source: unknown; index: string; visType: Option[]; }>({ @@ -120,7 +115,6 @@ export default defineComponent({ } function applyConfig() { - console.log(dashboardStore.selectedGrid); dashboardStore.setConfigs(dashboardStore.selectedGrid); dashboardStore.setConfigPanel(false); } diff --git a/src/views/dashboard/configuration/widget/StandardOptions.vue b/src/views/dashboard/configuration/widget/StandardOptions.vue index fe374d52..255ad1aa 100644 --- a/src/views/dashboard/configuration/widget/StandardOptions.vue +++ b/src/views/dashboard/configuration/widget/StandardOptions.vue @@ -40,6 +40,7 @@ limitations under the License. --> v-model="selectedGrid.standard.metricLabels" size="small" placeholder="auto" + @change="changeStandardOpt" />
@@ -49,6 +50,7 @@ limitations under the License. --> v-model="selectedGrid.standard.labelsIndex" size="small" placeholder="auto" + @change="changeStandardOpt" />
@@ -58,6 +60,7 @@ limitations under the License. --> v-model="selectedGrid.standard.plus" size="small" placeholder="none" + @change="changeStandardOpt" />
@@ -67,6 +70,7 @@ limitations under the License. --> v-model="selectedGrid.standard.minus" size="small" placeholder="none" + @change="changeStandardOpt" />
@@ -76,6 +80,7 @@ limitations under the License. --> v-model="selectedGrid.standard.multiply" size="small" placeholder="none" + @change="changeStandardOpt" />
@@ -85,6 +90,7 @@ limitations under the License. --> v-model="selectedGrid.standard.divide" size="small" placeholder="none" + @change="changeStandardOpt" />
@@ -94,6 +100,7 @@ limitations under the License. --> v-model="selectedGrid.standard.milliseconds" size="small" placeholder="none" + @change="changeStandardOpt" />
@@ -103,6 +110,7 @@ limitations under the License. --> v-model="selectedGrid.standard.seconds" size="small" placeholder="none" + @change="changeStandardOpt" />
@@ -111,21 +119,46 @@ import { ref } from "vue"; import { useI18n } from "vue-i18n"; import { SortOrder } from "../../data"; import { useDashboardStore } from "@/store/modules/dashboard"; +import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor"; +import { ElMessage } from "element-plus"; +/*global defineEmits */ +const { t } = useI18n(); +const emit = defineEmits(["update", "loading"]); const dashboardStore = useDashboardStore(); const { selectedGrid } = dashboardStore; -const { t } = useI18n(); const percentile = ref( selectedGrid.metricTypes.includes("readLabeledMetricsValues") ); const sortOrder = ref(selectedGrid.standard.sortOrder || "DES"); -function changeStandardOpt(param: { [key: string]: unknown }) { - const standard = { - ...selectedGrid.standard, - ...param, - }; - dashboardStore.selectWidget({ ...selectedGrid, standard }); +function changeStandardOpt(param?: any) { + let standard = dashboardStore.selectedGrid.standard; + if (param) { + standard = { + ...dashboardStore.selectedGrid.standard, + ...param, + }; + dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, standard }); + } + queryMetrics(); +} +async function queryMetrics() { + const params = useQueryProcessor(dashboardStore.selectedGrid); + if (!params) { + emit("update", {}); + return; + } + + emit("loading", true); + const json = await dashboardStore.fetchMetricValue(params); + emit("loading", false); + if (json.errors) { + ElMessage.error(json.errors); + return; + } + const source = useSourceProcessor(json, dashboardStore.selectedGrid); + emit("update", source); }