Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Fine0830 committed Oct 17, 2024
1 parent d2a17bb commit 18fdd63
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/types/dashboard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface CardConfig {
fontSize?: number;
showUnit?: boolean;
textAlign?: "center" | "right" | "left";
decorations?: { [key: string]: string };
valueMappings?: { [key: string]: string };
}

export interface TextConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/Widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ limitations under the License. -->
:config="{
i: 0,
...graph,
decorations: graph?.decorations,
valueMappings: graph?.valueMappings,
metricConfig: config.metricConfig,
expressions: config.expressions || [],
typesOfMQE: typesOfMQE || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ limitations under the License. -->

const dashboardStore = useDashboardStore();
const graph = dashboardStore.selectedGrid.graph;
const decorations = ref<{ [key: string]: string }>(graph?.valueMappings || {});
const keys = ref<string[]>(graph.valueMappings ? Object.keys(decorations.value) : [""]);
const valueMappings = ref<{ [key: string]: string }>(graph?.valueMappings || {});
const keys = ref<string[]>(graph.valueMappings ? Object.keys(valueMappings.value) : [""]);

function changeKeys(event: any, index: number) {
const params = event.target.textContent || "";
const list = Object.keys(decorations.value);
const list = Object.keys(valueMappings.value);
if (params) {
decorations.value[params] = decorations.value[list[index]];
valueMappings.value[params] = valueMappings.value[list[index]];
}
delete decorations.value[list[index]];
keys.value = Object.keys(decorations.value);
delete valueMappings.value[list[index]];
keys.value = Object.keys(valueMappings.value);
updateConfig();
}

function changeValues(event: any, key: string) {
decorations.value[key] = event.target.textContent || "";
valueMappings.value[key] = event.target.textContent || "";
updateConfig();
}

Expand All @@ -66,15 +66,15 @@ limitations under the License. -->
if (!keys.value.length) {
return;
}
delete decorations.value[keys.value[index]];
delete valueMappings.value[keys.value[index]];
keys.value.splice(index, 1);
updateConfig();
}

function updateConfig() {
const graph = {
...dashboardStore.selectedGrid.graph,
valueMappings: decorations.value,
valueMappings: valueMappings.value,
};
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph });
}
Expand Down
13 changes: 6 additions & 7 deletions src/views/dashboard/graphs/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ limitations under the License. -->
showUnit: true,
textAlign: "center",
metricConfig: [],
decorations: {},
valueMappings: {},
}),
},
});
const { t } = useI18n();
const metricConfig = computed(() => props.config.metricConfig || []);
const decorations = computed(() => props.config.decorations || {});
const valueMappings = computed(() => props.config.valueMappings || {});
const key = computed(() => Object.keys(props.data)[0]);
const singleVal = computed(() =>
Array.isArray(props.data[key.value]) ? props.data[key.value][0] : props.data[key.value],
);
const unit = computed(() => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit || ""));

function getValue() {
if (decorations.value[singleVal.value]) {
return decorations.value[singleVal.value];
if (valueMappings.value[singleVal.value]) {
return valueMappings.value[singleVal.value];
}
const regex = /-?\d+(\.\d+)?/g;
const list = Object.keys(decorations.value);
const list = Object.keys(valueMappings.value);
for (const i of list) {
const k = i.replace(/\s+/g, "");
let withinRange = false;
Expand All @@ -81,9 +81,8 @@ limitations under the License. -->
} else {
withinRange = withinRange && (k.endsWith("+∞)") || Number(singleVal.value) < (ranges[1] || ranges[0]));
}
console.log(withinRange);
if (withinRange) {
return decorations.value[i] || singleVal.value;
return valueMappings.value[i] || singleVal.value;
}
}
return singleVal.value;
Expand Down
12 changes: 6 additions & 6 deletions src/views/dashboard/graphs/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ limitations under the License. -->
showTableValues: boolean;
tableHeaderCol2: string;
typesOfMQE: string[];
decorations: {};
valueMappings: {};
}>,
default: () => ({ showTableValues: true }),
},
});

const { t } = useI18n();
const decorations = computed<{ [key: string]: string }>(() => props.config.decorations || {});
const valueMappings = computed<{ [key: string]: string }>(() => props.config.valueMappings || {});
const nameWidth = computed(() => (props.config.showTableValues ? 80 : 100));
const dataKeys = computed(() => {
const keys = Object.keys(props.data || {}).filter(
Expand All @@ -78,11 +78,11 @@ limitations under the License. -->

function getColValue(keys: string[]) {
const source = props.data[(keys as string[]).join(",")][props.data[(keys as string[]).join(",")].length - 1 || 0];
if (decorations.value[source]) {
return decorations.value[source];
if (valueMappings.value[source]) {
return valueMappings.value[source];
}
const regex = /-?\d+(\.\d+)?/g;
const list = Object.keys(decorations.value);
const list = Object.keys(valueMappings.value);
for (const i of list) {
const k = i.replace(/\s+/g, "");
let withinRange = false;
Expand All @@ -98,7 +98,7 @@ limitations under the License. -->
withinRange = withinRange && (k.endsWith("+∞)") || Number(source) < (ranges[1] || ranges[0]));
}
if (withinRange) {
return decorations.value[i];
return valueMappings.value[i];
}
}
return source;
Expand Down

0 comments on commit 18fdd63

Please sign in to comment.