diff --git a/x-pack/plugins/enterprise_search/common/locators/index.ts b/x-pack/plugins/enterprise_search/common/locators/index.ts index 35c1d43b3b30a..3c3597fe4f161 100644 --- a/x-pack/plugins/enterprise_search/common/locators/index.ts +++ b/x-pack/plugins/enterprise_search/common/locators/index.ts @@ -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(new CreateIndexLocatorDefinition()); - share.url.locators.create(new PlaygroundLocatorDefinition()); share.url.locators.create(new SearchInferenceEndpointLocatorDefinition()); } diff --git a/x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx b/x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx deleted file mode 100644 index eca283c8c2b06..0000000000000 --- a/x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { LocatorDefinition } from '@kbn/share-plugin/common'; -import type { SerializableRecord } from '@kbn/utility-types'; - -import { APPLICATIONS_PLUGIN, PLAYGROUND_URL } from '../constants'; - -export type PlaygroundLocatorParams = { 'default-index': string } & SerializableRecord; - -export class PlaygroundLocatorDefinition implements LocatorDefinition { - public readonly getLocation = async (params: PlaygroundLocatorParams) => { - const defaultIndex = params['default-index']; - const path = `${PLAYGROUND_URL}${defaultIndex ? `?default-index=${defaultIndex}` : ''}`; - - return { - app: APPLICATIONS_PLUGIN.ID, - path, - state: {}, - }; - }; - - public readonly id = 'PLAYGROUND_LOCATOR_ID'; -} diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/whats_next_box.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/whats_next_box.tsx index 2e04c094e7d7e..7e65b4d3367b8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/whats_next_box.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/whats_next_box.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React from 'react'; +import React, { useCallback } from 'react'; import { useValues } from 'kea'; @@ -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'; @@ -53,7 +50,14 @@ export const WhatsNextBox: React.FC = ({ 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 @@ -84,14 +88,7 @@ export const WhatsNextBox: React.FC = ({ data-test-subj="enterpriseSearchWhatsNextBoxSearchPlaygroundButton" iconType="sparkles" disabled={!connectorIndex || disabled} - onClick={() => { - navigateToUrl( - `${APPLICATIONS_PLUGIN.URL}${PLAYGROUND_PATH}?default-index=${connectorIndex}`, - { - shouldNotCreateHref: true, - } - ); - }} + onClick={onStartPlaygroundClick} > = ({ 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({ @@ -134,14 +140,7 @@ export const FinishUpStep: React.FC = ({ 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', diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/header_actions/search_playground_popover.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/header_actions/search_playground_popover.tsx index 283d594e2891b..8b85ab9b97168 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/header_actions/search_playground_popover.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/header_actions/search_playground_popover.tsx @@ -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 { @@ -24,18 +24,21 @@ export const SearchPlaygroundPopover: React.FC = ( 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 ( { - KibanaLogic.values.navigateToUrl(playgroundUrl, { - shouldNotCreateHref: true, - }); - }} + onClick={onStartPlaygroundClick} > {i18n.translate('xpack.enterpriseSearch.content.index.viewPlayground', { defaultMessage: 'View in Playground',