-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Query api #289
Query api #289
Conversation
src/utils/URLParamsParser.ts
Outdated
@@ -0,0 +1,6 @@ | |||
export function paramsParser(queryParams: Record<string, string>) { | |||
for (let i in queryParams) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try sending multiple items in the queryParams object and verify whether you get the expected result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current implemention will take a singe param which will append to the url with "?" in front of the param. For multiple params we can chain them using '&'
@@ -0,0 +1,14 @@ | |||
export function paramsParser(queryParams: Record<string, string>) { | |||
let parsedParams = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use reduce then we do not have to append an extra '&' and rmv it
- This function should accept null | undefined and return an empty string for invalid params so that we don't have to write conditional operators on each endpoint where we need a query string. Like this: https://github.com/parseablehq/console/pull/289/files#diff-dc3796761041251e6580415307413937f036d7143b52eb0a254085147ac758bcR8
- The '?' itself should be emitted from this function.
- If we make all these changes, the fn name is inappropriate. It should mention what it receives and what it returns.
@@ -7,6 +8,11 @@ export type LogStreamSchemaData = { | |||
metadata: Record<string, string>; | |||
}; | |||
|
|||
export type LogStreamQueryWithFields = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a query. Rename the type.
// to optimize performace, it has been decided to round off the time at the given level | ||
// so making the end-time inclusive | ||
const optimizeEndTime = (endTime: Date) => { | ||
return dayjs(endTime).add(1, 'minute').toDate(); | ||
}; | ||
|
||
export const getQueryLogs = (logsQuery: QueryLogs) => { | ||
export const getQueryLogs = (logsQuery: QueryLogs, queryParams?: QueryParams) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should always receive an object. Empty {} if no params.
@@ -33,11 +33,11 @@ export const getQueryLogs = (logsQuery: QueryLogs) => { | |||
); | |||
}; | |||
|
|||
export const getQueryResult = (logsQuery: LogsQuery, query = '') => { | |||
export const getQueryResult = (logsQuery: LogsQuery, query = '', queryParams?: QueryParams) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should always receive an object. Empty {} if no params.
|
||
const data = logsQueryRes.data; | ||
const data = logsQueryRes.data.records; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a possibility where server could just send you {} or null.
Verify you always get a result that contains a records array even if there is no data.
export const makeHeadersFromQueryFields = (queryResponse: LogStreamQueryWithFields | null): string[] => { | ||
if (queryResponse) { | ||
const { fields } = queryResponse; | ||
return fields; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If its straight forward, why'd you need a separate function ?
setData: ( | ||
store: LogsStore, | ||
data: Log[], | ||
queryResponse: LogStreamQueryWithFields | null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data: Log[],
queryResponse: LogStreamQueryWithFields | null
With logs provider context, both deal with almost the same values. Rmv one with less significant.
@@ -272,7 +277,7 @@ type LogsStoreReducers = { | |||
getUniqueValues: (data: Log[], key: string) => string[]; | |||
makeExportData: (data: Log[], headers: string[], type: string) => Log[]; | |||
setRetention: (store: LogsStore, retention: { description: string; duration: string }) => ReducerOutput; | |||
setTableHeaders: (store: LogsStore, schema: LogStreamSchemaData) => ReducerOutput; | |||
setTableHeaders: (store: LogsStore, queryResponse: LogStreamQueryWithFields) => ReducerOutput; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for setting table headers, why'd you need entire LogStreamQueryWithFields
const { data: existingData, custQuerySearchState, tableOpts } = store; | ||
const { filteredData } = existingData; | ||
const newHeaders = | ||
filteredData && custQuerySearchState.isQuerySearchActive | ||
? makeHeadersfromData(filteredData) | ||
: makeHeadersFromSchema(schema); | ||
: makeHeadersFromQueryFields(queryResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's straight forward. You do not need a function here.
@@ -563,7 +573,7 @@ const setData = (store: LogsStore, data: Log[], schema: LogStreamSchemaData | nu | |||
: filterAndSortData(tableOpts, data); | |||
const newPageSlice = filteredData && getPageSlice(currentPage, tableOpts.perPage, filteredData); | |||
const newHeaders = | |||
isQuerySearchActive && activeMode === 'sql' ? makeHeadersfromData(data) : makeHeadersFromSchema(schema); | |||
isQuerySearchActive && activeMode === 'sql' ? makeHeadersfromData(data) : makeHeadersFromQueryFields(queryResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why'd you want to make headers from data when
isQuerySearchActive && activeMode === 'sql'
@Koustavd18 |
@Koustavd18 Stating the above, it's better to have a common query function, that will always return an object {fields: string[], records: Log[] }. Just to prevent when we expect an array where its going to be an object response. |
This will be addressed in a separate pr. |
Update: Use of enhanced query API
using enhanced query api which will fetch the table headers along with data