fix: update components, save templates (#35)

This commit is contained in:
Fine0830 2022-03-23 19:06:20 +08:00 committed by GitHub
parent 93161b6ec9
commit 33365f2a14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 114 additions and 57 deletions

View File

@ -318,11 +318,11 @@ function aggregation(val: number, standard: any): number | string {
data = val - Number(standard.plus); data = val - Number(standard.plus);
return data; return data;
} }
if (!isNaN(standard.multiply)) { if (!isNaN(standard.multiply) && standard.divide !== 0) {
data = val * Number(standard.multiply); data = val * Number(standard.multiply);
return data; return data;
} }
if (!isNaN(standard.divide)) { if (!isNaN(standard.divide) && standard.divide !== 0) {
data = val / Number(standard.divide); data = val / Number(standard.divide);
return data; return data;
} }

View File

@ -293,7 +293,7 @@ export const dashboardStore = defineStore({
return res.data; return res.data;
} }
const data = res.data.data.getAllTemplates; const data = res.data.data.getAllTemplates;
const list = []; let list = [];
for (const t of data) { for (const t of data) {
const c = JSON.parse(t.configuration); const c = JSON.parse(t.configuration);
const key = [c.layer, c.entity, c.name].join("_"); const key = [c.layer, c.entity, c.name].join("_");
@ -310,6 +310,17 @@ export const dashboardStore = defineStore({
JSON.stringify({ id: t.id, configuration: c }) JSON.stringify({ id: t.id, configuration: c })
); );
} }
list = list.sort((a, b) => {
const nameA = a.name.toUpperCase();
const nameB = b.name.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
sessionStorage.setItem("dashboards", JSON.stringify(list)); sessionStorage.setItem("dashboards", JSON.stringify(list));
return res.data; return res.data;
}, },

View File

@ -101,6 +101,7 @@ export const selectorStore = defineStore({
keyword?: string; keyword?: string;
serviceId?: string; serviceId?: string;
isRelation?: boolean; isRelation?: boolean;
limit?: number;
}): Promise<Nullable<AxiosResponse>> { }): Promise<Nullable<AxiosResponse>> {
if (!params) { if (!params) {
params = {}; params = {};
@ -113,6 +114,7 @@ export const selectorStore = defineStore({
serviceId, serviceId,
duration: this.durationTime, duration: this.durationTime,
keyword: params.keyword || "", keyword: params.keyword || "",
limit: params.limit,
}); });
if (!res.data.errors) { if (!res.data.errors) {
if (params.isRelation) { if (params.isRelation) {

View File

@ -46,6 +46,7 @@ limitations under the License. -->
ref="multipleTableRef" ref="multipleTableRef"
:default-sort="{ prop: 'name' }" :default-sort="{ prop: 'name' }"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
height="637px"
> >
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
<el-table-column prop="name" label="Name"> <el-table-column prop="name" label="Name">

View File

@ -144,10 +144,17 @@ async function setMetricType() {
} }
states.metricList = (json.data.metrics || []).filter( states.metricList = (json.data.metrics || []).filter(
(d: { catalog: string; type: string }) => { (d: { catalog: string; type: string }) => {
if (states.isList || graph.type === "Table") { if (states.isList) {
if (d.type === MetricsType.REGULAR_VALUE) { if (d.type === MetricsType.REGULAR_VALUE) {
return d; return d;
} }
} else if (graph.type === "Table") {
if (
d.type === MetricsType.LABELED_VALUE ||
d.type === MetricsType.REGULAR_VALUE
) {
return d;
}
} else { } else {
return d; return d;
} }

View File

@ -33,7 +33,7 @@ limitations under the License. -->
@change="changeStandardOpt({ sortOrder })" @change="changeStandardOpt({ sortOrder })"
/> />
</div> </div>
<div class="item" v-show="percentile"> <div class="item">
<span class="label">{{ t("labels") }}</span> <span class="label">{{ t("labels") }}</span>
<el-input <el-input
class="input" class="input"
@ -43,7 +43,7 @@ limitations under the License. -->
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
<div class="item" v-show="percentile"> <div class="item">
<span class="label">{{ t("labelsIndex") }}</span> <span class="label">{{ t("labelsIndex") }}</span>
<el-input <el-input
class="input" class="input"
@ -55,61 +55,67 @@ limitations under the License. -->
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("plus") }}</span> <span class="label">{{ t("plus") }}</span>
<el-input <el-input-number
class="input" class="input"
v-model="selectedGrid.standard.plus" v-model="selectedGrid.standard.plus"
:min="0"
size="small" size="small"
placeholder="none" placeholder="Please input"
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("minus") }}</span> <span class="label">{{ t("minus") }}</span>
<el-input <el-input-number
class="input" class="input"
v-model="selectedGrid.standard.minus" v-model="selectedGrid.standard.minus"
:min="0"
size="small" size="small"
placeholder="none" placeholder="Please input"
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("multiply") }}</span> <span class="label">{{ t("multiply") }}</span>
<el-input <el-input-number
class="input" class="input"
v-model="selectedGrid.standard.multiply" v-model="selectedGrid.standard.multiply"
:min="1"
size="small" size="small"
placeholder="none" placeholder="Please input"
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("divide") }}</span> <span class="label">{{ t("divide") }}</span>
<el-input <el-input-number
class="input" class="input"
v-model="selectedGrid.standard.divide" v-model="selectedGrid.standard.divide"
size="small" size="small"
placeholder="none" placeholder="Please input"
:min="1"
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("convertToMilliseconds") }}</span> <span class="label">{{ t("convertToMilliseconds") }}</span>
<el-input <el-input-number
class="input" class="input"
:min="0"
v-model="selectedGrid.standard.milliseconds" v-model="selectedGrid.standard.milliseconds"
size="small" size="small"
placeholder="none" placeholder="Please input"
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
<div class="item"> <div class="item">
<span class="label">{{ t("convertToSeconds") }}</span> <span class="label">{{ t("convertToSeconds") }}</span>
<el-input <el-input-number
class="input" class="input"
:min="0"
v-model="selectedGrid.standard.seconds" v-model="selectedGrid.standard.seconds"
size="small" size="small"
placeholder="none" placeholder="Please input"
@change="changeStandardOpt" @change="changeStandardOpt"
/> />
</div> </div>
@ -127,9 +133,6 @@ const { t } = useI18n();
const emit = defineEmits(["update", "loading"]); const emit = defineEmits(["update", "loading"]);
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const { selectedGrid } = dashboardStore; const { selectedGrid } = dashboardStore;
const percentile = ref<boolean>(
selectedGrid.metricTypes.includes("readLabeledMetricsValues")
);
const sortOrder = ref<string>(selectedGrid.standard.sortOrder || "DES"); const sortOrder = ref<string>(selectedGrid.standard.sortOrder || "DES");
function changeStandardOpt(param?: any) { function changeStandardOpt(param?: any) {

View File

@ -66,6 +66,7 @@ limitations under the License. -->
i: data.i, i: data.i,
}" }"
:standard="data.standard" :standard="data.standard"
:needQuery="needQuery"
/> />
</div> </div>
<div v-else class="no-data">{{ t("noData") }}</div> <div v-else class="no-data">{{ t("noData") }}</div>
@ -153,6 +154,7 @@ export default defineComponent({
if (props.data.i !== dashboardStore.selectedGrid.i) { if (props.data.i !== dashboardStore.selectedGrid.i) {
return; return;
} }
const isList = ListChartTypes.includes(props.data.graph.type || "");
if ( if (
ListChartTypes.includes(dashboardStore.selectedGrid.graph.type) || ListChartTypes.includes(dashboardStore.selectedGrid.graph.type) ||
isList isList
@ -165,6 +167,7 @@ export default defineComponent({
watch( watch(
() => [selectorStore.currentService, selectorStore.currentDestService], () => [selectorStore.currentService, selectorStore.currentDestService],
() => { () => {
const isList = ListChartTypes.includes(props.data.graph.type || "");
if (isList) { if (isList) {
return; return;
} }

View File

@ -110,6 +110,7 @@ const props = defineProps({
default: () => ({ dashboardName: "", fontSize: 12, i: "" }), default: () => ({ dashboardName: "", fontSize: 12, i: "" }),
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
needQuery: { type: Boolean, default: false },
}); });
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -117,13 +118,18 @@ const chartLoading = ref<boolean>(false);
const endpoints = ref<Endpoint[]>([]); const endpoints = ref<Endpoint[]>([]);
const searchEndpoints = ref<Endpoint[]>([]); const searchEndpoints = ref<Endpoint[]>([]);
const pageSize = 5; const pageSize = 5;
const total = 10;
const searchText = ref<string>(""); const searchText = ref<string>("");
queryEndpoints(); if (props.needQuery) {
queryEndpoints(total);
async function queryEndpoints() { }
async function queryEndpoints(limit?: number) {
chartLoading.value = true; chartLoading.value = true;
const resp = await selectorStore.getEndpoints(); const resp = await selectorStore.getEndpoints({
limit,
keyword: searchText.value,
});
chartLoading.value = false; chartLoading.value = false;
if (resp.errors) { if (resp.errors) {
@ -132,7 +138,7 @@ async function queryEndpoints() {
} }
searchEndpoints.value = selectorStore.pods; searchEndpoints.value = selectorStore.pods;
endpoints.value = selectorStore.pods.splice(0, pageSize); endpoints.value = selectorStore.pods.splice(0, pageSize);
if (props.config.isEdit) { if (props.config.isEdit || !endpoints.value.length) {
return; return;
} }
queryEndpointMetrics(endpoints.value); queryEndpointMetrics(endpoints.value);
@ -177,12 +183,9 @@ function changePage(pageIndex: number) {
pageSize * (pageIndex || 1) pageSize * (pageIndex || 1)
); );
} }
function searchList() { async function searchList() {
const currentEndpoints = selectorStore.pods.filter((d: { label: string }) => const limit = searchText.value ? undefined : total;
d.label.includes(searchText.value) await queryEndpoints(limit);
);
searchEndpoints.value = currentEndpoints;
endpoints.value = currentEndpoints.splice(0, pageSize);
} }
watch( watch(
() => [props.config.metricTypes, props.config.metrics], () => [props.config.metricTypes, props.config.metrics],
@ -193,9 +196,9 @@ watch(
} }
); );
watch( watch(
() => [selectorStore.currentService], () => selectorStore.currentService,
() => { () => {
queryEndpoints(); queryEndpoints(total);
} }
); );
</script> </script>

View File

@ -42,6 +42,20 @@ limitations under the License. -->
</span> </span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Service Instances">
<template #default="scope">
<div class="attributes" v-if="scope.row.attributes.length">
<div
v-for="(attr, index) in scope.row.attributes"
:key="attr.name + index"
:style="{ fontSize: `${config.fontSize}px` }"
>
{{ attr.name }}: {{ attr.value || null }}
</div>
</div>
<div v-else>No Data</div>
</template>
</el-table-column>
<el-table-column <el-table-column
v-for="(metric, index) in config.metrics" v-for="(metric, index) in config.metrics"
:label="metric" :label="metric"
@ -113,6 +127,7 @@ const props = defineProps({
}), }),
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
needQuery: { type: Boolean, default: false },
}); });
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -122,15 +137,18 @@ const searchInstances = ref<Instance[]>([]); // all instances
const pageSize = 5; const pageSize = 5;
const searchText = ref<string>(""); const searchText = ref<string>("");
queryInstance(); if (props.needQuery) {
queryInstance();
}
async function queryInstance() { async function queryInstance() {
chartLoading.value = true; chartLoading.value = true;
const resp = await selectorStore.getServiceInstances(); const resp = await selectorStore.getServiceInstances();
chartLoading.value = false; chartLoading.value = false;
if (resp.errors) { if (resp && resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
searchInstances.value = [];
instances.value = [];
return; return;
} }
searchInstances.value = selectorStore.pods; searchInstances.value = selectorStore.pods;
@ -178,6 +196,7 @@ function clickInstance(scope: any) {
function changePage(pageIndex: number) { function changePage(pageIndex: number) {
instances.value = searchInstances.value.splice(pageIndex - 1, pageSize); instances.value = searchInstances.value.splice(pageIndex - 1, pageSize);
} }
function searchList() { function searchList() {
searchInstances.value = selectorStore.pods.filter((d: { label: string }) => searchInstances.value = selectorStore.pods.filter((d: { label: string }) =>
d.label.includes(searchText.value) d.label.includes(searchText.value)
@ -193,6 +212,12 @@ watch(
} }
} }
); );
watch(
() => selectorStore.currentService,
() => {
queryInstance();
}
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "./style.scss"; @import "./style.scss";
@ -204,4 +229,9 @@ watch(
.inputs { .inputs {
width: 300px; width: 300px;
} }
.attributes {
max-height: 80px;
overflow: auto;
}
</style> </style>

View File

@ -21,13 +21,13 @@ limitations under the License. -->
:style="`width: ${nameWidth + initWidth}px`" :style="`width: ${nameWidth + initWidth}px`"
> >
<div class="name" :style="`width: ${nameWidth}px`"> <div class="name" :style="`width: ${nameWidth}px`">
{{ config.graph.tableHeaderCol1 || t("name") }} {{ config.tableHeaderCol1 || t("name") }}
<i class="r cp" ref="draggerName"> <i class="r cp" ref="draggerName">
<Icon iconName="settings_ethernet" size="middle" /> <Icon iconName="settings_ethernet" size="middle" />
</i> </i>
</div> </div>
<div class="value-col" v-if="showTableValues"> <div class="value-col" v-if="showTableValues">
{{ config.graph.tableHeaderCol2 || t("value") }} {{ config.tableHeaderCol2 || t("value") }}
</div> </div>
</div> </div>
<div <div
@ -60,11 +60,9 @@ const props = defineProps({
}, },
config: { config: {
type: Object as PropType<{ type: Object as PropType<{
graph: { showTableValues: boolean;
showTableValues: boolean; tableHeaderCol2: string;
tableHeaderCol2: string; tableHeaderCol1: string;
tableHeaderCol1: string;
};
metricTypes: string[]; metricTypes: string[];
}>, }>,
default: () => ({ showTableValues: true }), default: () => ({ showTableValues: true }),
@ -77,15 +75,15 @@ const chartTable = ref<Nullable<HTMLElement>>(null);
const initWidth = ref<number>(0); const initWidth = ref<number>(0);
const nameWidth = ref<number>(0); const nameWidth = ref<number>(0);
const draggerName = ref<Nullable<HTMLElement>>(null); const draggerName = ref<Nullable<HTMLElement>>(null);
const showTableValues = ref<boolean>(props.config.graph.showTableValues); const showTableValues = ref<boolean>(props.config.showTableValues || false);
onMounted(() => { onMounted(() => {
if (!chartTable.value) { if (!chartTable.value) {
return; return;
} }
const width = props.config.graph.showTableValues const width = props.config.showTableValues
? chartTable.value.offsetWidth / 2 ? chartTable.value.offsetWidth / 2
: chartTable.value.offsetWidth; : chartTable.value.offsetWidth;
initWidth.value = props.config.graph.showTableValues initWidth.value = props.config.showTableValues
? chartTable.value.offsetWidth / 2 ? chartTable.value.offsetWidth / 2
: 0; : 0;
nameWidth.value = width - 5; nameWidth.value = width - 5;

View File

@ -72,7 +72,7 @@ limitations under the License. -->
/> />
</div> </div>
</div> </div>
<div class="flex-h tools"> <div class="flex-h tools" v-loading="loading">
<div class="tool-icons flex-h" v-if="dashboardStore.editMode"> <div class="tool-icons flex-h" v-if="dashboardStore.editMode">
<span <span
@click="clickIcons(t)" @click="clickIcons(t)"
@ -118,7 +118,6 @@ import { useSelectorStore } from "@/store/modules/selectors";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { Option } from "@/types/app"; import { Option } from "@/types/app";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useThrottleFn } from "@vueuse/core";
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -128,6 +127,7 @@ const params = useRoute().params;
const toolIcons = ref<{ name: string; content: string; id: string }[]>( const toolIcons = ref<{ name: string; content: string; id: string }[]>(
EndpointRelationTools EndpointRelationTools
); );
const loading = ref<boolean>(false);
const states = reactive<{ const states = reactive<{
destService: string; destService: string;
destPod: string; destPod: string;
@ -145,7 +145,6 @@ const states = reactive<{
currentDestService: "", currentDestService: "",
currentDestPod: "", currentDestPod: "",
}); });
const applyDashboard = useThrottleFn(dashboardStore.saveDashboard, 3000);
setCurrentDashboard(); setCurrentDashboard();
appStore.setEventStack([initSelector]); appStore.setEventStack([initSelector]);
@ -329,7 +328,13 @@ function changeMode() {
ElMessage.warning(t("viewWarning")); ElMessage.warning(t("viewWarning"));
} }
function clickIcons(t: { id: string; content: string; name: string }) { async function clickIcons(t: { id: string; content: string; name: string }) {
if (t.id === "apply") {
loading.value = true;
await dashboardStore.saveDashboard();
loading.value = false;
return;
}
if ( if (
dashboardStore.selectedGrid && dashboardStore.selectedGrid &&
dashboardStore.selectedGrid.type === "Tab" dashboardStore.selectedGrid.type === "Tab"
@ -361,9 +366,6 @@ function setTabControls(id: string) {
case "addTopology": case "addTopology":
dashboardStore.addTabControls("Topology"); dashboardStore.addTabControls("Topology");
break; break;
case "apply":
applyDashboard();
break;
default: default:
ElMessage.info("Don't support this control"); ElMessage.info("Don't support this control");
break; break;
@ -390,9 +392,6 @@ function setControls(id: string) {
case "addTopology": case "addTopology":
dashboardStore.addControl("Topology"); dashboardStore.addControl("Topology");
break; break;
case "apply":
applyDashboard();
break;
default: default:
dashboardStore.addControl("Widget"); dashboardStore.addControl("Widget");
} }