feat: add content decorations to Table and Card widgets (#419)

This commit is contained in:
Fine0830
2024-10-15 16:25:21 +08:00
committed by GitHub
parent a92365efcf
commit 61449f4b17
11 changed files with 128 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ limitations under the License. -->
justifyContent: config.textAlign || 'center',
}"
>
{{ singleVal }}
{{ decorations[singleVal] || singleVal }}
<span class="unit" v-show="config.showUnit && unit">
{{ decodeURIComponent(unit) }}
</span>
@@ -48,11 +48,13 @@ limitations under the License. -->
showUnit: true,
textAlign: "center",
metricConfig: [],
decorations: {},
}),
},
});
const { t } = useI18n();
const metricConfig = computed(() => props.config.metricConfig || []);
const decorations = computed(() => props.config.decorations || {});
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],

View File

@@ -37,7 +37,7 @@ limitations under the License. -->
>{{ k.split("=")[1] }}</div
>
<div class="value-col" v-if="config.showTableValues">
{{ data[(keys as string[]).join(",")][data[(keys as string[]).join(",")].length - 1 || 0] }}
{{ getColValue(keys) }}
</div>
</div>
</div>
@@ -58,12 +58,14 @@ limitations under the License. -->
showTableValues: boolean;
tableHeaderCol2: string;
typesOfMQE: string[];
decorations: {};
}>,
default: () => ({ showTableValues: true }),
},
});
const { t } = useI18n();
const decorations = computed<{ [key: number]: string }>(() => props.config.decorations || {});
const nameWidth = computed(() => (props.config.showTableValues ? 80 : 100));
const dataKeys = computed(() => {
const keys = Object.keys(props.data || {}).filter(
@@ -73,6 +75,10 @@ limitations under the License. -->
return list;
});
function getColValue(keys: string[]) {
const val = props.data[(keys as string[]).join(",")][props.data[(keys as string[]).join(",")].length - 1 || 0];
return decorations.value[val] || val;
}
</script>
<style lang="scss" scoped>
.chart-table {