feat: update expression result

This commit is contained in:
Fine 2024-04-10 23:18:09 +08:00
parent fd2c7ca716
commit 5d26eaff93
2 changed files with 9 additions and 5 deletions

View File

@ -126,7 +126,15 @@ export async function useExpressionsQueryProcessor(config: Indexable) {
} }
} }
if (type === ExpressionResultType.SINGLE_VALUE) { if (type === ExpressionResultType.SINGLE_VALUE) {
source[c.label || name] = (results[0].values[0] || {}).value; for (const item of results) {
const label = item.metric.labels.map((d: any) => `${d.key}=${d.value}`).join(",");
const values = item.values.map((d: { value: unknown }) => d.value) || [];
if (results.length === 1) {
source[label || c.label || name] = values;
} else {
source[label] = values;
}
}
} }
if (([ExpressionResultType.RECORD_LIST, ExpressionResultType.SORTED_LIST] as string[]).includes(type)) { if (([ExpressionResultType.RECORD_LIST, ExpressionResultType.SORTED_LIST] as string[]).includes(type)) {
source[name] = results[0].values; source[name] = results[0].values;

View File

@ -76,10 +76,6 @@ limitations under the License. -->
const keys = Object.keys(props.data || {}); const keys = Object.keys(props.data || {});
return keys; return keys;
} }
if (props.config.typesOfMQE && props.config.typesOfMQE[0] === ExpressionResultType.SINGLE_VALUE) {
const keys = Object.keys(props.data || {});
return keys;
}
const keys = Object.keys(props.data || {}).filter( const keys = Object.keys(props.data || {}).filter(
(i: string) => Array.isArray(props.data[i]) && props.data[i].length, (i: string) => Array.isArray(props.data[i]) && props.data[i].length,
); );