Skip to content
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

Rename header action to playground #180183

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const ConnectorDetail: React.FC = () => {
}>();

const {
productAccess: { hasAppSearchAccess },
productFeatures: { hasDefaultIngestPipeline },
} = useValues(KibanaLogic);

Expand Down Expand Up @@ -239,7 +238,7 @@ export const ConnectorDetail: React.FC = () => {
responsive: false,
wrap: false,
},
rightSideItems: getHeaderActions(index, hasAppSearchAccess, connector),
rightSideItems: getHeaderActions(index, connector),
tabs,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import React from 'react';

import { useSearchParams } from 'react-router-dom-v5-compat';

import { useValues } from 'kea';

import { i18n } from '@kbn/i18n';
Expand All @@ -15,10 +17,18 @@ import { KibanaLogic } from '../../../shared/kibana';
import { EnterpriseSearchContentPageTemplate } from '../layout/page_template';

export const Playground: React.FC = () => {
const [searchParams] = useSearchParams();
const index: string | null = searchParams.has('default-index')
? searchParams.get('default-index')
: null;
const { searchPlayground } = useValues(KibanaLogic);

return (
<searchPlayground.PlaygroundProvider>
<searchPlayground.PlaygroundProvider
defaultValues={{
indices: index ? [index] : [],
}}
>
<EnterpriseSearchContentPageTemplate
pageChrome={[
i18n.translate('xpack.enterpriseSearch.content.playground.breadcrumb', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,25 @@ import React from 'react';
import { CrawlerStatusIndicator } from '../../../shared/crawler_status_indicator/crawler_status_indicator';

import { getHeaderActions } from './header_actions';
import { SearchEnginesPopover } from './search_engines_popover';
import { SearchPlaygroundPopover } from './search_playground_popover';
import { SyncsContextMenu } from './syncs_context_menu';

describe('Header Actions', () => {
it('renders api index', () => {
expect(getHeaderActions(apiIndex, true)).toEqual([
<SearchEnginesPopover indexName="api" ingestionMethod="api" isHiddenIndex={false} />,
expect(getHeaderActions(apiIndex)).toEqual([
<SearchPlaygroundPopover indexName="api" ingestionMethod="api" />,
]);
expect(getHeaderActions(apiIndex, false)).toEqual([]);
});
it('renders connector index', () => {
expect(getHeaderActions(connectorIndex, true)).toEqual([
expect(getHeaderActions(connectorIndex)).toEqual([
<SyncsContextMenu />,
<SearchEnginesPopover
indexName="connector"
ingestionMethod="connector"
isHiddenIndex={false}
/>,
<SearchPlaygroundPopover indexName="connector" ingestionMethod="connector" />,
]);
expect(getHeaderActions(connectorIndex, false)).toEqual([<SyncsContextMenu />]);
});
it('renders crawler index', () => {
expect(getHeaderActions(crawlerIndex, true)).toEqual([
expect(getHeaderActions(crawlerIndex)).toEqual([
<CrawlerStatusIndicator />,
<SearchEnginesPopover indexName="crawler" ingestionMethod="crawler" isHiddenIndex={false} />,
<SearchPlaygroundPopover indexName="crawler" ingestionMethod="crawler" />,
]);
expect(getHeaderActions(crawlerIndex, false)).toEqual([<CrawlerStatusIndicator />]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,20 @@ import { ElasticsearchIndexWithIngestion } from '../../../../../../../common/typ
import { isCrawlerIndex, isConnectorIndex, getIngestionMethod } from '../../../../utils/indices';
import { CrawlerStatusIndicator } from '../../../shared/crawler_status_indicator/crawler_status_indicator';

import { SearchEnginesPopover } from './search_engines_popover';
import { SearchPlaygroundPopover } from './search_playground_popover';
import { SyncsContextMenu } from './syncs_context_menu';

// Used to populate rightSideItems of an EuiPageTemplate, which is rendered right-to-left
export const getHeaderActions = (
indexData: ElasticsearchIndexWithIngestion | undefined,
hasAppSearchAccess: boolean,
connector?: Connector
) => {
const ingestionMethod = getIngestionMethod(indexData);
return [
...(isCrawlerIndex(indexData) && indexData.connector ? [<CrawlerStatusIndicator />] : []),
...(isConnectorIndex(indexData) || connector ? [<SyncsContextMenu />] : []),
...(hasAppSearchAccess && indexData
? [
<SearchEnginesPopover
indexName={indexData?.name}
ingestionMethod={ingestionMethod}
isHiddenIndex={indexData?.hidden}
/>,
]
...(indexData
? [<SearchPlaygroundPopover indexName={indexData?.name} ingestionMethod={ingestionMethod} />]
: []),
];
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 React from 'react';

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

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

import { KibanaLogic } from '../../../../../shared/kibana';

import { PLAYGROUND_PATH } from '../../../../routes';

export interface SearchPlaygroundPopoverProps {
indexName: string;
ingestionMethod: string;
}

export const SearchPlaygroundPopover: React.FC<SearchPlaygroundPopoverProps> = ({
indexName,
ingestionMethod,
}) => {
const playgroundUrl = PLAYGROUND_PATH + `?default-index=${indexName}`;

return (
<EuiButton
data-telemetry-id={`entSearchContent-${ingestionMethod}-header-viewPlayground`}
iconType="eye"
onClick={() => {
KibanaLogic.values.navigateToUrl(playgroundUrl, {
shouldNotCreateHref: false,
});
}}
>
{i18n.translate('xpack.enterpriseSearch.content.index.viewPlayground', {
defaultMessage: 'View in Playground',
})}
</EuiButton>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const SearchIndex: React.FC = () => {
const {
config,
guidedOnboarding,
productAccess: { hasAppSearchAccess },
productFeatures: { hasDefaultIngestPipeline },
} = useValues(KibanaLogic);

Expand Down Expand Up @@ -232,7 +231,7 @@ export const SearchIndex: React.FC = () => {
rightSideGroupProps: {
responsive: false,
},
rightSideItems: getHeaderActions(index, hasAppSearchAccess),
rightSideItems: getHeaderActions(index),
}}
>
{isCrawlerIndex(index) && !index.connector ? (
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/search_playground/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export const renderApp = (
<I18nProvider>
<Router basename={appBasePath}>
<navigation.ui.TopNavMenu appName={PLUGIN_ID} />
<PlaygroundProvider>
<PlaygroundProvider
defaultValues={{
indices: [],
}}
>
<KibanaPageTemplate
pageChrome={[
i18n.translate('xpack.searchPlayground.breadcrumb', {
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/search_playground/public/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { ComponentType, lazy, LazyExoticComponent, Suspense } from 'react';
import type { App } from './components/app';
import type { PlaygroundProvider as PlaygroundProviderComponent } from './providers/playground_provider';
import { PlaygroundProviderProps } from './providers/playground_provider';
import type { Toolbar } from './components/toolbar';

const lazyRender =
Expand All @@ -33,9 +33,7 @@ export const PlaygroundToolbar = lazyRender<React.ComponentProps<typeof Toolbar>
}))
);

export const PlaygroundProvider = lazyRender<
React.ComponentProps<typeof PlaygroundProviderComponent>
>(
export const PlaygroundProvider = lazyRender<PlaygroundProviderProps>(
lazy(async () => ({
default: (await import('./providers/playground_provider')).PlaygroundProvider,
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ import { ChatForm, SummarizationModelName } from '../types';

const queryClient = new QueryClient({});

export const PlaygroundProvider: React.FC = ({ children }) => {
export interface PlaygroundProviderProps {
children: React.ReactNode;
defaultValues: {
indices: string[];
};
}

export const PlaygroundProvider: React.FC<PlaygroundProviderProps> = ({
children,
defaultValues,
}) => {
const form = useForm<ChatForm>({
defaultValues: {
prompt: 'You are an assistant for question-answering tasks.',
docSize: 5,
source_fields: [],
summarization_model: SummarizationModelName.gpt3_5_turbo,
indices: defaultValues.indices,
},
});

Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -15335,9 +15335,6 @@
"xpack.enterpriseSearch.content.index.pipelines.textExpansionCallOut.title": "Améliorer vos résultats avec ELSER",
"xpack.enterpriseSearch.content.index.pipelines.textExpansionCallOut.titleBadge": "Nouveauté",
"xpack.enterpriseSearch.content.index.searchApplication.createSearchApplication": "Créer une application de recherche",
"xpack.enterpriseSearch.content.index.searchEngines.createEngineDisabledTooltip": "Vous ne pouvez pas créer d'applications de recherche à partir d'index masqués.",
"xpack.enterpriseSearch.content.index.searchEngines.label": "Applications de recherche",
"xpack.enterpriseSearch.content.index.searchEngines.viewEngines": "Afficher les applications de recherche",
"xpack.enterpriseSearch.content.index.syncButton.label": "Sync",
"xpack.enterpriseSearch.content.index.syncButton.syncing.label": "Synchronisation en cours",
"xpack.enterpriseSearch.content.index.syncButton.waitingForSync.label": "En attente de la synchronisation",
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -15313,9 +15313,6 @@
"xpack.enterpriseSearch.content.index.pipelines.textExpansionCallOut.title": "ELSERで結果を改善",
"xpack.enterpriseSearch.content.index.pipelines.textExpansionCallOut.titleBadge": "新規",
"xpack.enterpriseSearch.content.index.searchApplication.createSearchApplication": "検索アプリケーションを作成",
"xpack.enterpriseSearch.content.index.searchEngines.createEngineDisabledTooltip": "非表示のインデックスからは検索アプリケーションを作成できません。",
"xpack.enterpriseSearch.content.index.searchEngines.label": "検索アプリケーション",
"xpack.enterpriseSearch.content.index.searchEngines.viewEngines": "検索アプリケーションを表示",
"xpack.enterpriseSearch.content.index.syncButton.label": "同期",
"xpack.enterpriseSearch.content.index.syncButton.syncing.label": "同期中",
"xpack.enterpriseSearch.content.index.syncButton.waitingForSync.label": "同期を待機しています",
Expand Down
Loading