-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ES|QL] Lookup join - Open in discover tab support #241317
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
Changes from 9 commits
a7356ab
75c93b0
ab555d5
30a4545
ba4125d
9785d3a
bbe4cc9
c35cbe6
3a8ba92
42d564b
368fb55
b30d141
198d6aa
b0dce8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,9 @@ | |
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import React, { useMemo, useState } from 'react'; | ||
| /* eslint-disable @elastic/eui/href-or-on-click */ | ||
stratoula marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import React, { useCallback, useMemo, useState } from 'react'; | ||
| import { | ||
| EuiButton, | ||
| EuiFlexGroup, | ||
|
|
@@ -20,11 +22,15 @@ import { useKibana } from '@kbn/kibana-react-plugin/public'; | |
| import useObservable from 'react-use/lib/useObservable'; | ||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import { FilePicker } from './file_picker'; | ||
| import type { KibanaContextExtra } from '../types'; | ||
| import type { EditLookupIndexContentContext, KibanaContextExtra } from '../types'; | ||
|
|
||
| export const QueryBar = () => { | ||
| export const QueryBar = ({ | ||
| onOpenIndexInDiscover, | ||
| }: { | ||
| onOpenIndexInDiscover?: EditLookupIndexContentContext['onOpenIndexInDiscover']; | ||
| }) => { | ||
| const { | ||
| services: { share, data, indexUpdateService, indexEditorTelemetryService }, | ||
| services: { share, data, indexUpdateService, indexEditorTelemetryService, featureFlags }, | ||
| } = useKibana<KibanaContextExtra>(); | ||
|
|
||
| const dataView = useObservable(indexUpdateService.dataView$); | ||
|
|
@@ -34,13 +40,20 @@ export const QueryBar = () => { | |
| indexUpdateService.indexCreated$, | ||
| indexUpdateService.isIndexCreated() | ||
| ); | ||
| const indexName = useObservable(indexUpdateService.indexName$, null); | ||
|
|
||
| const [queryError, setQueryError] = useState<string>(''); | ||
|
|
||
| const discoverLocator = useMemo(() => { | ||
| return share?.url.locators.get('DISCOVER_APP_LOCATOR'); | ||
| }, [share?.url.locators]); | ||
|
|
||
| const isOpeningInNewTabEnabled = useMemo( | ||
| () => featureFlags?.getBooleanValue('discover.tabsEnabled', true) ?? true, | ||
|
||
| [featureFlags] | ||
| ); | ||
|
|
||
| // Only used as fallback if onOpenIndexInDiscover is not provided or tabs are disabled | ||
| const discoverLink = | ||
| isIndexCreated && esqlDiscoverQuery | ||
| ? discoverLocator?.getRedirectUrl({ | ||
|
|
@@ -51,6 +64,29 @@ export const QueryBar = () => { | |
| }) | ||
| : null; | ||
|
|
||
| const openInDiscover = useCallback( | ||
| async (e: React.MouseEvent) => { | ||
stratoula marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| indexEditorTelemetryService.trackQueryThisIndexClicked(searchQuery); | ||
|
|
||
| // If onOpenIndexInDiscover is provided, we let that handler to manage the navigation to Discover | ||
| // If not, the button href will be executed | ||
| if (isOpeningInNewTabEnabled && onOpenIndexInDiscover && indexName && esqlDiscoverQuery) { | ||
| e.preventDefault(); | ||
| const onExitCallback = () => onOpenIndexInDiscover(indexName, esqlDiscoverQuery); | ||
| indexUpdateService.exit(onExitCallback); | ||
| } | ||
| }, | ||
| [ | ||
| indexEditorTelemetryService, | ||
| searchQuery, | ||
| isOpeningInNewTabEnabled, | ||
| onOpenIndexInDiscover, | ||
| indexName, | ||
| esqlDiscoverQuery, | ||
| indexUpdateService, | ||
| ] | ||
| ); | ||
|
|
||
| if (!dataView) { | ||
| return null; | ||
| } | ||
|
|
@@ -82,13 +118,13 @@ export const QueryBar = () => { | |
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButton | ||
| size={'s'} | ||
| color={'text'} | ||
| isDisabled={!discoverLink} | ||
| href={discoverLink ?? undefined} | ||
| onClick={() => indexEditorTelemetryService.trackQueryThisIndexClicked(searchQuery)} | ||
| size="s" | ||
| color="text" | ||
| isDisabled={!isIndexCreated || !esqlDiscoverQuery} | ||
| onClick={openInDiscover} | ||
| href={discoverLink || undefined} | ||
| target="_blank" | ||
| iconType={'discoverApp'} | ||
| iconType="discoverApp" | ||
| > | ||
| <EuiText size="xs"> | ||
| <FormattedMessage | ||
|
|
||
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 in one component is
onOpenQueryand on the other isonOpenIndex?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.
From the
index editorpoint of view, it wants to open a specific index in a new tab.From the
esql editorpoint of view, it provides a general purpose callback to open any kind of query in a new tab.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 see, makes sense