diff --git a/src/pages/Logs/providers/LogsProvider.tsx b/src/pages/Logs/providers/LogsProvider.tsx index eb538e01..165314c8 100644 --- a/src/pages/Logs/providers/LogsProvider.tsx +++ b/src/pages/Logs/providers/LogsProvider.tsx @@ -464,7 +464,7 @@ const setData = (store: LogsStore, data: Log[]) => { // only if pageoffset is 1 const newHeaders = filteredData && existingData.schema && custQuerySearchState.isQuerySearchActive - ? makeHeadersfromData(existingData.schema, custQuerySearchState.custSearchQuery) + ? makeHeadersfromData(filteredData) : makeHeadersFromSchema(existingData.schema); return { diff --git a/src/pages/Logs/utils.ts b/src/pages/Logs/utils.ts index d2c102fa..025935c7 100644 --- a/src/pages/Logs/utils.ts +++ b/src/pages/Logs/utils.ts @@ -16,13 +16,19 @@ export const makeHeadersFromSchema = (schema: LogStreamSchemaData | null): strin } }; -export const makeHeadersfromData = (schema: LogStreamSchemaData, custSearchQuery: string | null): string[] => { - const allColumns = makeHeadersFromSchema(schema); - if (custSearchQuery === null) return allColumns; +export const makeHeadersfromData = (data: Log[]): string[] => { + const allKeys: string[] = []; - const selectClause = custSearchQuery.match(/SELECT(.*?)FROM/i)?.[1]; - if (!selectClause || selectClause.includes('*')) return allColumns; + // cannot parse cust search query and get the possible keys. + // and also its not necessary that each record will have all the specified columns + // so go through all the records and get the keys + data.forEach((obj) => { + Object.keys(obj).forEach((key) => { + if (!allKeys.includes(key)) { + allKeys.push(key); + } + }); + }); - const commonColumns = allColumns.filter((column) => selectClause.includes(column)); - return commonColumns; -}; \ No newline at end of file + return allKeys; +};