Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make table headers from data #240

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pages/Logs/providers/LogsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 14 additions & 8 deletions src/pages/Logs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Loading