mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-22 13:11:06 +08:00

* added more changes to query builder * added types for composite queries * (feat): added edit rules and create rules forms * (feat): added chart preview for alert metric ui * (feat): added threshold in chart, translations in alert form and a few fixes * feat: added a link for alert name in list alerts page and source for each rule update Co-authored-by: Pranshu Chittora <pranshu@signoz.io>
55 lines
1.0 KiB
TypeScript
55 lines
1.0 KiB
TypeScript
import { Labels } from 'types/api/alerts/def';
|
|
|
|
import { ILabelRecord } from './types';
|
|
|
|
const hiddenLabels = ['severity', 'description'];
|
|
|
|
export const createQuery = (
|
|
selectedItems: Array<string | string[]> = [],
|
|
): ILabelRecord | null => {
|
|
if (selectedItems.length === 2) {
|
|
return {
|
|
key: selectedItems[0] as string,
|
|
value: selectedItems[1] as string,
|
|
};
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const flattenLabels = (labels: Labels): ILabelRecord[] => {
|
|
const recs: ILabelRecord[] = [];
|
|
|
|
Object.keys(labels).forEach((key) => {
|
|
if (!hiddenLabels.includes(key)) {
|
|
recs.push({
|
|
key,
|
|
value: labels[key],
|
|
});
|
|
}
|
|
});
|
|
|
|
return recs;
|
|
};
|
|
|
|
export const prepareLabels = (
|
|
recs: ILabelRecord[],
|
|
alertLabels: Labels | undefined,
|
|
): Labels => {
|
|
const labels: Labels = {};
|
|
|
|
recs.forEach((rec) => {
|
|
if (!hiddenLabels.includes(rec.key)) {
|
|
labels[rec.key] = rec.value;
|
|
}
|
|
});
|
|
if (alertLabels) {
|
|
Object.keys(alertLabels).forEach((key) => {
|
|
if (hiddenLabels.includes(key)) {
|
|
labels[key] = alertLabels[key];
|
|
}
|
|
});
|
|
}
|
|
|
|
return labels;
|
|
};
|