Skip to content

Commit

Permalink
fix(search): use locator to navigate to playground
Browse files Browse the repository at this point in the history
  • Loading branch information
TattdCodeMonkey committed Dec 2, 2024
1 parent 5871e2d commit 732cb8c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 64 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/enterprise_search/common/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import {
type CreateIndexLocatorParams,
} from './create_index_locator';
import { SearchInferenceEndpointLocatorDefinition } from './inference_locator';
import { PlaygroundLocatorDefinition, type PlaygroundLocatorParams } from './playground_locator';

export function registerLocators(share: SharePluginSetup) {
share.url.locators.create<CreateIndexLocatorParams>(new CreateIndexLocatorDefinition());
share.url.locators.create<PlaygroundLocatorParams>(new PlaygroundLocatorDefinition());
share.url.locators.create<SerializableRecord>(new SearchInferenceEndpointLocatorDefinition());
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useCallback } from 'react';

import { useValues } from 'kea';

Expand All @@ -25,9 +25,6 @@ import { FormattedMessage } from '@kbn/i18n-react';

import { ConnectorStatus } from '@kbn/search-connectors';

import { APPLICATIONS_PLUGIN } from '../../../../../../common/constants';

import { PLAYGROUND_PATH } from '../../../../applications/routes';
import { generateEncodedPath } from '../../../../shared/encode_path_params';
import { KibanaLogic } from '../../../../shared/kibana';
import { EuiButtonTo } from '../../../../shared/react_router_helpers';
Expand All @@ -53,7 +50,14 @@ export const WhatsNextBox: React.FC<WhatsNextBoxProps> = ({
isSyncing = false,
isWaitingForConnector = false,
}) => {
const { navigateToUrl } = useValues(KibanaLogic);
const { share } = useValues(KibanaLogic);
const onStartPlaygroundClick = useCallback(() => {
if (!share) return;
const playgroundLocator = share.url.locators.get('PLAYGROUND_LOCATOR_ID');
if (playgroundLocator) {
playgroundLocator.navigate({ 'default-index': connectorIndex });
}
}, [connectorIndex, share]);
const isConfigured = !(
connectorStatus === ConnectorStatus.NEEDS_CONFIGURATION ||
connectorStatus === ConnectorStatus.CREATED
Expand Down Expand Up @@ -84,14 +88,7 @@ export const WhatsNextBox: React.FC<WhatsNextBoxProps> = ({
data-test-subj="enterpriseSearchWhatsNextBoxSearchPlaygroundButton"
iconType="sparkles"
disabled={!connectorIndex || disabled}
onClick={() => {
navigateToUrl(
`${APPLICATIONS_PLUGIN.URL}${PLAYGROUND_PATH}?default-index=${connectorIndex}`,
{
shouldNotCreateHref: true,
}
);
}}
onClick={onStartPlaygroundClick}
>
<FormattedMessage
id="xpack.enterpriseSearch.whatsNextBox.searchPlaygroundButtonLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import { css } from '@emotion/react';

Expand All @@ -30,11 +30,10 @@ import { i18n } from '@kbn/i18n';

import { useKibana } from '@kbn/kibana-react-plugin/public';

import { APPLICATIONS_PLUGIN, ELASTICSEARCH_PLUGIN } from '../../../../../../common/constants';
import { ELASTICSEARCH_PLUGIN } from '../../../../../../common/constants';

import { KibanaDeps } from '../../../../../../common/types';

import { PLAYGROUND_PATH } from '../../../../applications/routes';
import { generateEncodedPath } from '../../../../shared/encode_path_params';
import { HttpLogic } from '../../../../shared/http';
import { KibanaLogic } from '../../../../shared/kibana';
Expand Down Expand Up @@ -66,7 +65,14 @@ export const FinishUpStep: React.FC<FinishUpStepProps> = ({ title }) => {
const isSyncing = isWaitingForSync || isSyncingProp;

const { http } = useValues(HttpLogic);
const { application } = useValues(KibanaLogic);
const { application, share } = useValues(KibanaLogic);
const onStartPlaygroundClick = useCallback(() => {
if (!share) return;
const playgroundLocator = share.url.locators.get('PLAYGROUND_LOCATOR_ID');
if (playgroundLocator) {
playgroundLocator.navigate({ 'default-index': connector?.index_name });
}
}, [connector, share]);
useEffect(() => {
setTimeout(() => {
window.scrollTo({
Expand Down Expand Up @@ -134,14 +140,7 @@ export const FinishUpStep: React.FC<FinishUpStepProps> = ({ title }) => {
'xpack.enterpriseSearch.createConnector.finishUpStep.euiButton.startSearchPlaygroundLabel',
{ defaultMessage: 'Start Search Playground' }
)}
onClick={() => {
if (connector) {
KibanaLogic.values.navigateToUrl(
`${APPLICATIONS_PLUGIN.URL}${PLAYGROUND_PATH}?default-index=${connector.index_name}`,
{ shouldNotCreateHref: true }
);
}
}}
onClick={onStartPlaygroundClick}
>
{i18n.translate(
'xpack.enterpriseSearch.createConnector.finishUpStep.startSearchPlaygroundButtonLabel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

import React from 'react';
import React, { useCallback } from 'react';

import { useValues } from 'kea';

import { EuiButton } from '@elastic/eui';

import { i18n } from '@kbn/i18n';

import { APPLICATIONS_PLUGIN } from '../../../../../../../common/constants';
import { PLAYGROUND_PATH } from '../../../../../applications/routes';
import { KibanaLogic } from '../../../../../shared/kibana';

export interface SearchPlaygroundPopoverProps {
Expand All @@ -24,18 +24,21 @@ export const SearchPlaygroundPopover: React.FC<SearchPlaygroundPopoverProps> = (
indexName,
ingestionMethod,
}) => {
const playgroundUrl = `${APPLICATIONS_PLUGIN.URL}${PLAYGROUND_PATH}?default-index=${indexName}`;
const { share } = useValues(KibanaLogic);
const onStartPlaygroundClick = useCallback(() => {
if (!share) return;
const playgroundLocator = share.url.locators.get('PLAYGROUND_LOCATOR_ID');
if (playgroundLocator) {
playgroundLocator.navigate({ 'default-index': indexName });
}
}, [indexName, share]);

return (
<EuiButton
data-test-subj="enterpriseSearchSearchPlaygroundPopoverViewInPlaygroundButton"
data-telemetry-id={`entSearchContent-${ingestionMethod}-header-viewPlayground`}
iconType="eye"
onClick={() => {
KibanaLogic.values.navigateToUrl(playgroundUrl, {
shouldNotCreateHref: true,
});
}}
onClick={onStartPlaygroundClick}
>
{i18n.translate('xpack.enterpriseSearch.content.index.viewPlayground', {
defaultMessage: 'View in Playground',
Expand Down

0 comments on commit 732cb8c

Please sign in to comment.