mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-16 05:55:53 +08:00
refactor: create rows for table (#3235)
Divide different cased into separated functions Co-authored-by: Palash Gupta <palashgdev@gmail.com>
This commit is contained in:
parent
348fa0ba5e
commit
23e6902921
@ -305,36 +305,21 @@ const isEqualQueriesByLabel = (
|
|||||||
queryName: string,
|
queryName: string,
|
||||||
): boolean => equalQueries.includes(queryName);
|
): boolean => equalQueries.includes(queryName);
|
||||||
|
|
||||||
const fillDataFromSeries = (
|
const fillAggregationData = (
|
||||||
currentQuery: QueryDataV3,
|
column: DynamicColumn,
|
||||||
queryTableData: QueryDataV3[],
|
value: string,
|
||||||
columns: DynamicColumns,
|
unusedColumnsKeys: Set<keyof RowData>,
|
||||||
equalQueriesByLabels: string[],
|
|
||||||
// TODO: fix it
|
|
||||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
||||||
): void => {
|
): void => {
|
||||||
const { series, queryName } = currentQuery;
|
column.data.push(parseFloat(value).toFixed(2));
|
||||||
const isEqualQuery = isEqualQueriesByLabel(equalQueriesByLabels, queryName);
|
|
||||||
|
|
||||||
if (!series) return;
|
|
||||||
|
|
||||||
series.forEach((seria) => {
|
|
||||||
const labelEntries = Object.entries(seria.labels);
|
|
||||||
|
|
||||||
const unusedColumnsKeys = new Set<keyof RowData>(
|
|
||||||
columns.map((item) => item.field),
|
|
||||||
);
|
|
||||||
|
|
||||||
columns.forEach((column) => {
|
|
||||||
if (queryName === column.field) {
|
|
||||||
if (seria.values.length === 0) return;
|
|
||||||
|
|
||||||
column.data.push(parseFloat(seria.values[0].value).toFixed(2));
|
|
||||||
unusedColumnsKeys.delete(column.field);
|
unusedColumnsKeys.delete(column.field);
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if (column.type !== 'field' && column.field !== queryName) {
|
const fillRestAggregationData = (
|
||||||
|
column: DynamicColumn,
|
||||||
|
queryTableData: QueryDataV3[],
|
||||||
|
seria: SeriesItem,
|
||||||
|
equalQueriesByLabels: string[],
|
||||||
|
): void => {
|
||||||
const nextQueryData =
|
const nextQueryData =
|
||||||
queryTableData.find((q) => q.queryName === column.field) || null;
|
queryTableData.find((q) => q.queryName === column.field) || null;
|
||||||
|
|
||||||
@ -353,13 +338,14 @@ const fillDataFromSeries = (
|
|||||||
} else {
|
} else {
|
||||||
column.data.push('N/A');
|
column.data.push('N/A');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
unusedColumnsKeys.delete(column.field);
|
const fillLabelsData = (
|
||||||
|
column: DynamicColumn,
|
||||||
return;
|
seria: SeriesItem,
|
||||||
}
|
unusedColumnsKeys: Set<keyof RowData>,
|
||||||
|
): void => {
|
||||||
if (isEqualQuery) return;
|
const labelEntries = Object.entries(seria.labels);
|
||||||
|
|
||||||
labelEntries.forEach(([key, currentValue]) => {
|
labelEntries.forEach(([key, currentValue]) => {
|
||||||
if (column.field === key) {
|
if (column.field === key) {
|
||||||
@ -367,6 +353,50 @@ const fillDataFromSeries = (
|
|||||||
unusedColumnsKeys.delete(key);
|
unusedColumnsKeys.delete(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const fillDataFromSeries = (
|
||||||
|
currentQuery: QueryDataV3,
|
||||||
|
queryTableData: QueryDataV3[],
|
||||||
|
columns: DynamicColumns,
|
||||||
|
equalQueriesByLabels: string[],
|
||||||
|
): void => {
|
||||||
|
const { series, queryName } = currentQuery;
|
||||||
|
const isEqualQuery = isEqualQueriesByLabel(equalQueriesByLabels, queryName);
|
||||||
|
|
||||||
|
if (!series) return;
|
||||||
|
|
||||||
|
series.forEach((seria) => {
|
||||||
|
const unusedColumnsKeys = new Set<keyof RowData>(
|
||||||
|
columns.map((item) => item.field),
|
||||||
|
);
|
||||||
|
|
||||||
|
columns.forEach((column) => {
|
||||||
|
if (queryName === column.field) {
|
||||||
|
if (seria.values.length === 0) return;
|
||||||
|
|
||||||
|
fillAggregationData(
|
||||||
|
column,
|
||||||
|
parseFloat(seria.values[0].value).toFixed(2),
|
||||||
|
unusedColumnsKeys,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.type !== 'field' && column.field !== queryName) {
|
||||||
|
fillRestAggregationData(
|
||||||
|
column,
|
||||||
|
queryTableData,
|
||||||
|
seria,
|
||||||
|
equalQueriesByLabels,
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEqualQuery) return;
|
||||||
|
|
||||||
|
fillLabelsData(column, seria, unusedColumnsKeys);
|
||||||
|
|
||||||
fillEmptyRowCells(unusedColumnsKeys, columns, column);
|
fillEmptyRowCells(unusedColumnsKeys, columns, column);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user