-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
handling references for kibana_context and get_index_pattern expression functions #95224
handling references for kibana_context and get_index_pattern expression functions #95224
Conversation
Pinging @elastic/kibana-app-services (Team:AppServices) |
3e2d11f
to
b7b86cb
Compare
id: state.id[0] as string, | ||
}, | ||
]; | ||
state.id[0] = refName; |
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.
Is that okay that the state object is mutable? Wouldn't it cause any side effects?
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.
i'll update it to not mutate
src/plugins/data/common/index_patterns/expressions/load_index_pattern.ts
Outdated
Show resolved
Hide resolved
|
||
extract(state) { | ||
const references: SavedObjectReference[] = []; | ||
if (state.savedSearchId.length && typeof state.savedeSearchId[0] === 'string') { |
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.
The first clause is redundant because the typeof
will return undefined for an unexisting item.
if (state.savedSearchId.length && typeof state.savedeSearchId[0] === 'string') { | |
if (typeof state.savedeSearchId[0] === 'string') { |
getStartServices: StartServicesAccessor<DataPluginStartDependencies, DataPluginStart>; | ||
}) { | ||
return getKibanaContextFn(async (getKibanaRequest) => { | ||
if (!getKibanaRequest || !getKibanaRequest()) { |
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 (!getKibanaRequest || !getKibanaRequest()) { | |
if (!getKibanaRequest?.()) { |
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.
I just left a few minor suggestions, but the code looks good to me.
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.
Checked on Chrome/Mac, LGTM, except the savedSearchId
property check, see below.
const timeRange = args.timeRange || input?.timeRange; | ||
let queries = mergeQueries(input?.query, args?.q || []); | ||
let filters = [...(input?.filters || []), ...(args?.filters?.map(unboxExpressionValue) || [])]; | ||
async fn(input, args, { getKibanaRequest }) { |
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.
I'm a bit confused about what does getKibanaRequest
resolve to, as KibanaRequest
is the server-side type and makes sense only on the server.
Not specific to this PR:
Also, I'm skeptical about using KibanaRequest
type in expressions
plugin. Maybe there is a way to create our own wrapper around it, call it ExpressionUserContext
.
The problem I see with it is that it assumes that you can authenticate only using KibanaRequest
. Also, it exports KibanaRequest
in ExecutionContext
interface from expressions
plugin, making it our public API, but when Core will want to change something in KibanaRequest
, they might need to do changes to expressions
plugin and it might be breaking change in expressions
plugin. Just some thoughts.
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.
getKibanaRequest on the client will be undefined, but the getStartServices function on the client doesn't expect it. this is just so we can keep the same code in common.
i agree the whole kibana request thing is a bit weird and we should probably do somethin about it in the future
return getKibanaContextFn(async (getKibanaRequest) => { | ||
if (!getKibanaRequest || !getKibanaRequest()) { | ||
throw new Error( | ||
i18n.translate('data.search.kibana_context.error.kibanaRequest', { |
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 seems like an error message for Kibana developers, and this error should never happen, it looks like a check just in case a developer made a mistake. In that case, shall we skip translation here, especially considering that this code executes on the server.
If we still want to translate it, maybe better throw an error code, like
throw new Error('KIBANA_REQUEST_MISSING');
and then translate the error on the client-side.
Co-authored-by: Vadim Dalecky <streamich@gmail.com>
Co-authored-by: Michael Dokolin <dokmic@gmail.com>
# Conflicts: # src/plugins/data/server/search/search_service.ts
💚 Build SucceededMetrics [docs]Module Count
Page load bundle
History
To update your PR or re-run it, just comment with: |
…on functions (elastic#95224) # Conflicts: # src/plugins/data/server/search/search_service.ts
Summary
Handling reference injection and extraction for
kibana_context
andgetIndexPattern
expression functionskibana_context
function was refactored so it no longer depends ongetSavedObject
handlergetSavedObject
handler was removed from expression handlerskibana_context
function now extracts and injects reference to the saved search from itssavedSearchId
parametergetIndexPattern
function now extracts and injects reference to the saved index pattern from itsid
parameterresolves #59960
Checklist
Delete any items that are not applicable to this PR.