From 55466ce53933865172cb6fb5801af057f9787b99 Mon Sep 17 00:00:00 2001 From: balaji-jr Date: Tue, 7 May 2024 16:41:00 +0530 Subject: [PATCH 1/2] make table headers from data --- src/pages/Logs/providers/LogsProvider.tsx | 2 +- src/pages/Logs/utils.ts | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) 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..b3af01ff 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; + return allKeys; }; \ No newline at end of file From f228138621275adbc309e5a3c5f12e84afa059ab Mon Sep 17 00:00:00 2001 From: balaji-jr Date: Tue, 7 May 2024 16:44:02 +0530 Subject: [PATCH 2/2] add new line --- src/pages/Logs/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Logs/utils.ts b/src/pages/Logs/utils.ts index b3af01ff..025935c7 100644 --- a/src/pages/Logs/utils.ts +++ b/src/pages/Logs/utils.ts @@ -31,4 +31,4 @@ export const makeHeadersfromData = (data: Log[]): string[] => { }); return allKeys; -}; \ No newline at end of file +};