From 7c2f5352d29980fed6514b06509545d4c15e68b4 Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Fri, 29 Mar 2024 14:41:16 +0530 Subject: [PATCH] [Refactor]: Table Grid Formula issue. (#4758) * refactor: change the logic to match data from another query * refactor: updated logic * refactor: clean up * refactor: updated case to handle formula * chore: nit * refactor: isEqual instead of nested loops * chore: added comments * refactor: updated logic * refactor: clean up * refactor: updated case to handle formula * chore: nit * refactor: isEqual instead of nested loops --- .../src/lib/query/createTableColumnsFromQuery.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/query/createTableColumnsFromQuery.ts b/frontend/src/lib/query/createTableColumnsFromQuery.ts index d62e0a763f..1a7afbbc22 100644 --- a/frontend/src/lib/query/createTableColumnsFromQuery.ts +++ b/frontend/src/lib/query/createTableColumnsFromQuery.ts @@ -7,7 +7,7 @@ import { import { FORMULA_REGEXP } from 'constants/regExp'; import { QUERY_TABLE_CONFIG } from 'container/QueryTable/config'; import { QueryTableProps } from 'container/QueryTable/QueryTable.intefaces'; -import { isObject } from 'lodash-es'; +import { isEqual, isObject } from 'lodash-es'; import { ReactNode } from 'react'; import { IBuilderFormula, @@ -258,12 +258,7 @@ const findSeriaValueFromAnotherQuery = ( const localLabelEntries = Object.entries(seria.labels); if (localLabelEntries.length !== labelEntries.length) return; - const isExistLabels = localLabelEntries.find(([key, value]) => - labelEntries.find( - ([currentKey, currentValue]) => - currentKey === key && currentValue === value, - ), - ); + const isExistLabels = isEqual(localLabelEntries, labelEntries); if (isExistLabels) { value = seria; @@ -304,10 +299,9 @@ const fillRestAggregationData = ( if (targetSeria) { const isEqual = isEqualQueriesByLabel(equalQueriesByLabels, column.field); if (!isEqual) { + // This line is crucial. It ensures that no additional rows are added to the table for similar labels across all formulas here is how this check is applied: signoz/frontend/src/lib/query/createTableColumnsFromQuery.ts line number 370 equalQueriesByLabels.push(column.field); } - - column.data.push(parseFloat(targetSeria.values[0].value).toFixed(2)); } else { column.data.push('N/A'); } @@ -357,6 +351,7 @@ const fillDataFromSeries = ( } if (column.type !== 'field' && column.field !== queryName) { + // This code is executed only when there are multiple formulas. It checks if there are similar labels present in other formulas and, if found, adds them to the corresponding column data in the table. fillRestAggregationData( column, queryTableData,