update top list config

This commit is contained in:
Qiuxia Fan 2022-03-29 15:51:19 +08:00
parent d6b25f3746
commit cdf12af672
7 changed files with 70 additions and 56 deletions

View File

@ -66,7 +66,7 @@ export function useQueryProcessor(config: any) {
? selectorStore.currentService.normal ? selectorStore.currentService.normal
: true, : true,
scope: config.catalog || dashboardStore.entity, scope: config.catalog || dashboardStore.entity,
topN: 10, topN: c.topN || 10,
order: c.sortOrder || "DES", order: c.sortOrder || "DES",
}; };
} else { } else {

View File

@ -45,6 +45,7 @@ export type MetricConfigOpt = {
calculation: string; calculation: string;
labelsIndex: string; labelsIndex: string;
sortOrder: string; sortOrder: string;
topN?: number;
}; };
export interface WidgetConfig { export interface WidgetConfig {

View File

@ -16,9 +16,9 @@ limitations under the License. -->
<div class="widget-config flex-v"> <div class="widget-config flex-v">
<div class="graph" v-loading="loading"> <div class="graph" v-loading="loading">
<div class="header"> <div class="header">
<span>{{ dashboardStore.selectedGrid.widget.title }}</span> <span>{{ dashboardStore.selectedGrid.widget.title || "" }}</span>
<div class="tips" v-show="dashboardStore.selectedGrid.widget.tips"> <div class="tips" v-show="dashboardStore.selectedGrid.widget.tips">
<el-tooltip :content="dashboardStore.selectedGrid.widget.tips"> <el-tooltip :content="dashboardStore.selectedGrid.widget.tips || ''">
<Icon iconName="info_outline" size="sm" /> <Icon iconName="info_outline" size="sm" />
</el-tooltip> </el-tooltip>
</div> </div>

View File

@ -13,17 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div> <div class="item">
<span class="label">{{ t("maxItemNum") }}</span> <span class="label">{{ t("backgroundColors") }}</span>
<el-input <Selector
class="input" :value="color"
v-model="topN" :options="Colors"
size="small" size="small"
placeholder="none" placeholder="Select a color"
type="number" class="input"
:min="1" @change="updateConfig({ color: $event[0].value })"
:max="100"
@change="updateConfig({ topN })"
/> />
</div> </div>
</template> </template>
@ -35,14 +33,24 @@ import { useDashboardStore } from "@/store/modules/dashboard";
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const { selectedGrid } = dashboardStore; const { selectedGrid } = dashboardStore;
const topN = ref(selectedGrid.graph.topN); const color = ref(selectedGrid.graph.color || "purple");
const Colors = [
{ label: "Purple", value: "purple" },
{
label: "Green",
value: "green",
},
{ label: "Blue", value: "blue" },
{ label: "Red", value: "red" },
{ label: "Orange", value: "orange" },
];
function updateConfig(param: { [key: string]: unknown }) { function updateConfig(param: { [key: string]: unknown }) {
const graph = { const graph = {
...selectedGrid.graph, ...dashboardStore.selectedGrid.graph,
...param, ...param,
}; };
dashboardStore.selectWidget({ ...selectedGrid, graph }); dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph });
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -52,4 +60,8 @@ function updateConfig(param: { [key: string]: unknown }) {
display: block; display: block;
margin-bottom: 5px; margin-bottom: 5px;
} }
.input {
width: 500px;
}
</style> </style>

View File

@ -56,10 +56,7 @@ limitations under the License. -->
:clearable="true" :clearable="true"
/> />
</div> </div>
<div <div class="item" v-show="isTopn">
class="item"
v-show="['sortMetrics', 'readSampledRecords'].includes(metricType)"
>
<span class="label">{{ t("sortOrder") }}</span> <span class="label">{{ t("sortOrder") }}</span>
<SelectSingle <SelectSingle
:value="currentMetric.sortOrder || 'DES'" :value="currentMetric.sortOrder || 'DES'"
@ -68,10 +65,22 @@ limitations under the License. -->
@change="changeConfigs(index, { sortOrder: $event })" @change="changeConfigs(index, { sortOrder: $event })"
/> />
</div> </div>
<div class="item" v-show="isTopn">
<span class="label">{{ t("maxItemNum") }}</span>
<el-input-number
class="selectors"
v-model="currentMetric.topN"
size="small"
placeholder="none"
:min="1"
:max="100"
@change="changeConfigs(index, { topN: currentMetric.topN || 10 })"
/>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch } from "vue"; import { ref, watch, computed } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { SortOrder, CalculationOpts } from "../../../data"; import { SortOrder, CalculationOpts } from "../../../data";
@ -89,12 +98,22 @@ const props = defineProps({
const { t } = useI18n(); const { t } = useI18n();
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const currentMetric = ref<MetricConfigOpt>(props.currentMetricConfig); const currentMetric = ref<MetricConfigOpt>({
...props.currentMetricConfig,
topN: props.currentMetricConfig.topN || 10,
});
const metricType = ref<string>( const metricType = ref<string>(
dashboardStore.selectedGrid.metricTypes[props.index] dashboardStore.selectedGrid.metricTypes[props.index]
); );
const isTopn = computed(() =>
function changeConfigs(index: number, param: { [key: string]: string }) { ["sortMetrics", "readSampledRecords"].includes(
dashboardStore.selectedGrid.metricTypes[props.index]
)
);
function changeConfigs(
index: number,
param: { [key: string]: string | number }
) {
const metricConfig = dashboardStore.selectedGrid.metricConfig || []; const metricConfig = dashboardStore.selectedGrid.metricConfig || [];
metricConfig[index] = { ...metricConfig[index], ...param }; metricConfig[index] = { ...metricConfig[index], ...param };
@ -107,7 +126,10 @@ function changeConfigs(index: number, param: { [key: string]: string }) {
watch( watch(
() => props.currentMetricConfig, () => props.currentMetricConfig,
() => { () => {
currentMetric.value = props.currentMetricConfig; currentMetric.value = {
...props.currentMetricConfig,
topN: props.currentMetricConfig.topN || 10,
};
} }
); );
</script> </script>

View File

@ -77,6 +77,7 @@ export const DefaultGraphConfig: { [key: string]: any } = {
}, },
TopList: { TopList: {
type: "TopList", type: "TopList",
color: "purple",
}, },
InstanceList: { InstanceList: {
type: "InstanceList", type: "InstanceList",
@ -263,6 +264,7 @@ export const TextColors: { [key: string]: string } = {
white: "#fff", white: "#fff",
black: "#000", black: "#000",
orange: "#E6A23C", orange: "#E6A23C",
purple: "#bf99f8",
}; };
export const CalculationOpts = [ export const CalculationOpts = [

View File

@ -15,12 +15,12 @@ limitations under the License. -->
<template> <template>
<div class="top-list"> <div class="top-list">
<div class="chart-slow-i" v-for="(i, index) in datas" :key="index"> <div class="chart-slow-i" v-for="(i, index) in data[key]" :key="index">
<div class="ell tools flex-h"> <div class="ell tools flex-h">
<div> <div>
<span class="calls mr-10">{{ i.value }}</span> <span class="calls mr-10">{{ i.value }}</span>
<span class="cp mr-20"> <span class="cp mr-20">
{{ i.name + getTraceId(i) }} {{ i.name }}
</span> </span>
</div> </div>
<div> <div>
@ -28,14 +28,14 @@ limitations under the License. -->
iconName="review-list" iconName="review-list"
size="middle" size="middle"
class="cp" class="cp"
@click="handleClick((i.traceIds && i.traceIds[0]) || i.name)" @click="handleClick(i.name)"
/> />
</div> </div>
</div> </div>
<el-progress <el-progress
:stroke-width="6" :stroke-width="6"
:percentage="(i.value / maxValue) * 100" :percentage="(i.value / maxValue) * 100"
color="#bf99f8" :color="TextColors[config.color]"
:show-text="false" :show-text="false"
/> />
</div> </div>
@ -45,6 +45,7 @@ limitations under the License. -->
import type { PropType } from "vue"; import type { PropType } from "vue";
import { computed } from "vue"; import { computed } from "vue";
import copy from "@/utils/copy"; import copy from "@/utils/copy";
import { TextColors } from "@/views/dashboard/data";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
data: { data: {
@ -54,12 +55,12 @@ const props = defineProps({
default: () => ({}), default: () => ({}),
}, },
config: { config: {
type: Object as PropType<{ sortOrder: string }>, type: Object as PropType<{ color: string }>,
default: () => ({}), default: () => ({ color: "purple" }),
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
}); });
const key = computed(() => Object.keys(props.data)[0]); const key = computed(() => Object.keys(props.data)[0] || "");
const maxValue = computed(() => { const maxValue = computed(() => {
if (!(props.data[key.value] && props.data[key.value].length)) { if (!(props.data[key.value] && props.data[key.value].length)) {
return 0; return 0;
@ -67,30 +68,6 @@ const maxValue = computed(() => {
const temp: number[] = props.data[key.value].map((i: any) => i.value); const temp: number[] = props.data[key.value].map((i: any) => i.value);
return Math.max.apply(null, temp); return Math.max.apply(null, temp);
}); });
const getTraceId = (i: { [key: string]: (number | string)[] }): string => {
return i.traceIds && i.traceIds[0] ? ` - ${i.traceIds[0]}` : "";
};
const datas = computed(() => {
if (!(props.data[key.value] && props.data[key.value].length)) {
return [];
}
const { sortOrder } = props.config;
const val: any = props.data[key.value];
switch (sortOrder) {
case "DES":
val.sort((a: any, b: any) => b.value - a.value);
break;
case "ASC":
val.sort((a: any, b: any) => a.value - b.value);
break;
default:
val.sort((a: any, b: any) => b.value - a.value);
break;
}
return val;
});
function handleClick(i: string) { function handleClick(i: string) {
copy(i); copy(i);
} }