diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 04cdd44f..a01b7089 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -25,7 +25,6 @@ import { NewControl } from "../data"; import { Duration } from "@/types/app"; import axios, { AxiosResponse } from "axios"; import { cancelToken } from "@/utils/cancelToken"; -import { Instance } from "@/types/selector"; interface DashboardState { showConfig: boolean; layout: LayoutConfig[]; @@ -137,8 +136,8 @@ export const dashboardStore = defineStore({ setConfigPanel(show: boolean) { this.showConfig = show; }, - selectWidget(widget: Nullable) { - this.selectedGrid = widget; + selectWidget(item: Nullable) { + this.selectedGrid = item; }, setLayer(id: string) { this.layerId = id; diff --git a/src/views/dashboard/configuration/ConfigEdit.vue b/src/views/dashboard/configuration/ConfigEdit.vue index 91e9aa0c..579941b3 100644 --- a/src/views/dashboard/configuration/ConfigEdit.vue +++ b/src/views/dashboard/configuration/ConfigEdit.vue @@ -16,21 +16,21 @@ limitations under the License. -->
- {{ selectedGrid.widget.title }} -
- + {{ dashboardStore.selectedGrid.widget.title }} +
+
-
+
{{ t("noData") }}
@@ -49,14 +49,16 @@ limitations under the License. --> v-for="(type, index) in states.visType" :key="index" @click="changeChartType(type)" - :class="{ active: type.value === selectedGrid.graph.type }" + :class="{ + active: type.value === dashboardStore.selectedGrid.graph.type, + }" > {{ type.label }}
- + @@ -109,7 +111,6 @@ export default defineComponent({ const { t } = useI18n(); const dashboardStore = useDashboardStore(); const appStoreWithOut = useAppStoreWithOut(); - const { selectedGrid, entity } = dashboardStore; const loading = ref(false); const states = reactive<{ activeNames: string; @@ -120,17 +121,19 @@ export default defineComponent({ }>({ activeNames: "1", source: {}, - index: selectedGrid.i, + index: dashboardStore.selectedGrid.i, visType: [], isTable: false, }); - states.isTable = TableChartTypes.includes(selectedGrid.graph.type || ""); + states.isTable = TableChartTypes.includes( + dashboardStore.selectedGrid.graph.type || "" + ); - if (entity === EntityType[0].value) { + if (dashboardStore.entity === EntityType[0].value) { states.visType = ChartTypes.filter( (d: Option) => d.value !== "serviceList" ); - } else if (entity === EntityType[1].value) { + } else if (dashboardStore.entity === EntityType[1].value) { states.visType = ChartTypes.filter( (d: Option) => !PodsChartTypes.includes(d.value) ); @@ -141,12 +144,9 @@ export default defineComponent({ } function changeChartType(item: Option) { - const graph = { - ...selectedGrid.graph, - ...DefaultGraphConfig[item.value], - }; - states.isTable = TableChartTypes.includes(selectedGrid.graph.type); - dashboardStore.selectWidget({ ...selectedGrid, graph }); + const graph = DefaultGraphConfig[item.value]; + states.isTable = TableChartTypes.includes(graph.type); + dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph }); } function getSource(source: unknown) { @@ -169,7 +169,7 @@ export default defineComponent({ t, appStoreWithOut, configHeight, - selectedGrid, + dashboardStore, applyConfig, getSource, setLoading, diff --git a/src/views/dashboard/configuration/MetricOptions.vue b/src/views/dashboard/configuration/MetricOptions.vue index 611374fc..a6ad0894 100644 --- a/src/views/dashboard/configuration/MetricOptions.vue +++ b/src/views/dashboard/configuration/MetricOptions.vue @@ -16,7 +16,7 @@ limitations under the License. -->
Dashboard
class="selectors" />
+
Metrics
-
Metrics
:value="states.metricTypes[index]" :options="states.metricTypeList[index]" size="mini" - :disabled="states.graph.type && !states.isTable && index !== 0" + :disabled="selectedGrid.graph.type && !states.isTable && index !== 0" @change="changeMetricType(index, $event)" class="selectors" /> @@ -71,7 +71,6 @@ limitations under the License. --> diff --git a/src/views/dashboard/graphs/InstanceList.vue b/src/views/dashboard/graphs/InstanceList.vue index 5a257e43..21213873 100644 --- a/src/views/dashboard/graphs/InstanceList.vue +++ b/src/views/dashboard/graphs/InstanceList.vue @@ -47,7 +47,7 @@ limitations under the License. --> @@ -88,9 +88,7 @@ import { useQueryPodsMetrics, usePodsSource } from "@/hooks/useProcessor"; /*global defineProps */ defineProps({ config: { - type: Object as PropType< - InstanceListConfig & { metrics: string[]; metricTypes: string[] } - >, + type: Object as PropType, default: () => ({ dashboardName: "", fontSize: 12 }), }, intervalTime: { type: Array as PropType, default: () => [] }, @@ -102,7 +100,6 @@ const instances = ref<(Instance | any)[]>([]); // current instances const searchInstances = ref([]); // all instances const pageSize = 5; const searchText = ref(""); -const selectedGrid = dashboardStore.selectedGrid; queryInstance(); @@ -118,15 +115,22 @@ async function queryInstance() { searchInstances.value = selectorStore.instances; const currentInstances = searchInstances.value.splice(0, pageSize); - const params = await useQueryPodsMetrics(currentInstances, selectedGrid); + const params = await useQueryPodsMetrics( + currentInstances, + dashboardStore.selectedGrid + ); const json = await dashboardStore.fetchMetricValue(params); if (json.errors) { ElMessage.error(json.errors); return; } - usePodsSource(currentInstances, json, selectedGrid); - instances.value = usePodsSource(currentInstances, json, selectedGrid); + usePodsSource(currentInstances, json, dashboardStore.selectedGrid); + instances.value = usePodsSource( + currentInstances, + json, + dashboardStore.selectedGrid + ); } function changePage(pageIndex: number) {