feat: update metric config

This commit is contained in:
Qiuxia Fan
2021-12-29 16:22:23 +08:00
parent 809fcff859
commit 4b9d1dd362
4 changed files with 45 additions and 12 deletions

View File

@@ -15,9 +15,9 @@ limitations under the License. -->
<template>
<div class="graph">No Data</div>
<div class="config">
<div class="metric-config item">
<div class="metrics item">
<label>Graph your metric</label>
<div class="name">Metrics</div>
<div class="name">Metrics Name</div>
<Selector
:value="states.metrics"
:options="metricOpts"
@@ -28,12 +28,12 @@ limitations under the License. -->
class="selectors"
/>
<Selector
:value="states.metrics"
:options="metricOpts"
:multiple="true"
v-show="states.valueType"
:value="states.valueType"
:options="states.valueTypes"
size="mini"
placeholder="Select a metric"
@change="changeMetrics"
@change="changeValueType"
class="selectors"
/>
</div>
@@ -53,12 +53,36 @@ limitations under the License. -->
</template>
<script lang="ts" setup>
import { reactive } from "vue";
import { useDashboardStore } from "@/store/modules/dashboard";
import { ElMessage } from "element-plus";
import { ValuesTypes, MetricQueryTypes } from "../data";
import { Option } from "@/types/app";
const states = reactive<any>({
const states = reactive<{
metrics: string;
valueTypes: Option[];
valueType: string;
metricQueryType: string;
}>({
metrics: "",
valueTypes: [],
valueType: "",
metricQueryType: "",
});
function changeMetrics(val: string[]) {
console.log(val);
const dashboardStore = useDashboardStore();
async function changeMetrics(val: Option[]) {
const resp = await dashboardStore.fetchMetricType(val[0].value);
if (resp.error) {
ElMessage.error(resp.data.error);
return;
}
const { typeOfMetrics } = resp.data;
states.valueTypes = ValuesTypes[typeOfMetrics];
states.valueType = ValuesTypes[typeOfMetrics][0].value;
}
function changeValueType(val: Option[]) {
states.valueType = String(val[0].value);
states.metricQueryType = (MetricQueryTypes as any)[states.valueType];
}
const metricOpts = [
{ value: "service_apdex", label: "service_apdex" },

View File

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export enum QueryTypes {
export enum MetricQueryTypes {
ReadMetricsValue = "readMetricsValue",
ReadMetricsValues = "readMetricsValues",
SortMetrics = "sortMetrics",
@@ -29,7 +29,7 @@ export enum MetricsType {
HEATMAP = "HEATMAP",
SAMPLED_RECORD = "SAMPLED_RECORD",
}
export const QueryMetricTypes: {
export const ValuesTypes: {
[key: string]: Array<{ label: string; value: string }>;
} = {
REGULAR_VALUE: [