[Search][Dashboard] Restore searchSessionId from URL#81489
[Search][Dashboard] Restore searchSessionId from URL#81489Dosant merged 2 commits intoelastic:masterfrom
Conversation
lukasolson
left a comment
There was a problem hiding this comment.
Can we merge with master to avoid the noise of the previous PR? Thanks!
There was a problem hiding this comment.
Looks very similar to the utility in src/plugins/es_ui_shared/public/url/extract_query_params.ts. Not sure the best approach here but it would be nice if we could combine these.
There was a problem hiding this comment.
Thanks for point me to it!
I extracted my function from existing history helper (in kibana_utils) so technically I didn't introduce new code.
I decided to leave as is keeping dashboard -> kibana_utils dep and not introducing dashboard -> es_ui dep.
Probably ideally es_ui_shared/public/url/extract_query_params.ts should be removed and utility from kibana_utils should be used instead, but es_ui_shared is not dependent on kibana_utils today, so doesn't worth introducing dependency to maintain for these couple lines.
There was a problem hiding this comment.
If we make this generic, can we avoid the cast as string above?
| export function getQueryParams(location: Location): ParsedQuery { | |
| export function getQueryParams<T>(location: Location): ParsedQuery<T> { |
There was a problem hiding this comment.
Looked into it,
ParsedQuery<T> is a weird loose type:
export interface ParsedQuery<T = string> {
[key: string]: T | T[] | null;
}
that attempt to cover all the query cases and doesn't cover undefined.
T in that case is just type of value in query object.
So I guess possible way to improve with typecasting for us is something like:
export function getQueryParams<T>(location: Location): T {
return query as unknown as T
}
But I think this is worth then current downcasting on consumer level, because this involves unknown
|
Pinging @elastic/kibana-app-arch (Team:AppArch) |
There was a problem hiding this comment.
LGTM. Added a nit below and just wanted to confirm: Is this the first place we're using actual query parameters instead of stuffing things in the _a or _g (app/global state)? Are there any ramifications of this we need to be aware of?
Also wanted to note that I tested this and things seemed to function as expected (sessionId was properly set and displayed in the inspector and properly cleared when making a change that resulted in a re-fetch, which generated a new sessionId).
| [UrlParams.HIDE_FILTER_BAR]: boolean; | ||
| } | ||
|
|
||
| const getSearchSessionIdFromURL = (history: History): string | undefined => |
There was a problem hiding this comment.
Nit: This would probably make more sense inside src/plugins/dashboard/public/url_generator.ts. We could add a test for it there too.
There was a problem hiding this comment.
I am keeping it separate because it depends on client side history and url_generator stuff shouldn't depend on it and should be moved to common eventually.
No, this is not the first place. Dashboard has bunch of other query params options. Reasons I thought we are better of with separate query param:
|
ThomThomson
left a comment
There was a problem hiding this comment.
Tested locally in chrome. Restoring a search session works well, and everything else still works as expected. Tests and code LGTM!
| ); | ||
|
|
||
| if (state.searchSessionId) { | ||
| url = `${url}&${DashboardConstants.SEARCH_SESSION_ID}=${state.searchSessionId}`; |
There was a problem hiding this comment.
//nit
We don't have any function in our code base to serialize url params?
There was a problem hiding this comment.
I think that would be
import { stringify } from 'query-string'; but I guess in this particular case using it would add more code then not using it
(can't benefit from it for _a & _g params here because their helpers already handling everything)
|
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]@kbn/optimizer bundle module count
async chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
Build on top of #81297
Part of #61738
Summary
searchSessionIdfrom URLsearchSessionIdsupport to dashboard's URL generatorAdditional info
How to test
You can build a dashboard URL with fake session id:
Open it.
And you should see
__fake__as session id in inspector.^^ this is what a functional test does
Checklist
Delete any items that are not applicable to this PR.