diff --git a/packages/kbn-search-api-panels/components/code_box.tsx b/packages/kbn-search-api-panels/components/code_box.tsx index 55b8915328285..3e265e83837cd 100644 --- a/packages/kbn-search-api-panels/components/code_box.tsx +++ b/packages/kbn-search-api-panels/components/code_box.tsx @@ -41,7 +41,7 @@ interface CodeBoxProps { pluginId: string; application?: ApplicationStart; sharePlugin: SharePluginStart; - showTryInConsole: boolean; + consoleRequest?: string; } export const CodeBox: React.FC = ({ @@ -54,7 +54,7 @@ export const CodeBox: React.FC = ({ selectedLanguage, setSelectedLanguage, sharePlugin, - showTryInConsole, + consoleRequest, }) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); @@ -115,10 +115,10 @@ export const CodeBox: React.FC = ({ )} - {showTryInConsole && ( + {consoleRequest !== undefined && ( diff --git a/packages/kbn-search-api-panels/components/ingest_data.tsx b/packages/kbn-search-api-panels/components/ingest_data.tsx index 9f82b91e76159..7af36b92fe59b 100644 --- a/packages/kbn-search-api-panels/components/ingest_data.tsx +++ b/packages/kbn-search-api-panels/components/ingest_data.tsx @@ -28,7 +28,7 @@ interface IngestDataProps { application?: ApplicationStart; sharePlugin: SharePluginStart; languages: LanguageDefinition[]; - showTryInConsole: boolean; + consoleRequest?: string; } export const IngestData: React.FC = ({ @@ -41,7 +41,7 @@ export const IngestData: React.FC = ({ application, sharePlugin, languages, - showTryInConsole, + consoleRequest, }) => { const [selectedIngestMethod, setSelectedIngestMethod] = useState< 'ingestViaApi' | 'ingestViaIntegration' @@ -55,7 +55,7 @@ export const IngestData: React.FC = ({ leftPanelContent={ selectedIngestMethod === 'ingestViaApi' ? ( void; http: HttpStart; @@ -52,7 +52,7 @@ const Link: React.FC<{ language: LanguageDefinition; http: HttpStart; pluginId: export const InstallClientPanel: React.FC = ({ codeSnippet, - showTryInConsole, + consoleRequest, language, languages, setSelectedLanguage, @@ -66,7 +66,7 @@ export const InstallClientPanel: React.FC = ({ const panelContent = ( <> = { buildSearchQuery: `POST /books/_search?pretty diff --git a/packages/kbn-search-api-panels/utils.ts b/packages/kbn-search-api-panels/utils.ts index d6c8ba1341515..ffd81257c5a30 100644 --- a/packages/kbn-search-api-panels/utils.ts +++ b/packages/kbn-search-api-panels/utils.ts @@ -7,6 +7,7 @@ */ import { LanguageDefinition, LanguageDefinitionSnippetArguments } from './types'; +import { consoleDefinition } from './languages/console'; export const getLanguageDefinitionCodeSnippet = ( language: Partial, @@ -24,3 +25,8 @@ export const getLanguageDefinitionCodeSnippet = ( return ''; } }; + +export const getConsoleRequest = (code: keyof LanguageDefinition): string | undefined => + code in consoleDefinition && typeof consoleDefinition[code] === 'string' + ? (consoleDefinition[code] as string) + : undefined; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/getting_started.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/getting_started.tsx index 4c4aa595af8a9..a0d8552e15843 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/getting_started.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/getting_started.tsx @@ -32,6 +32,7 @@ import { OverviewPanel, CodeBox, getLanguageDefinitionCodeSnippet, + getConsoleRequest, } from '@kbn/search-api-panels'; import { LanguageDefinition } from '@kbn/search-api-panels'; @@ -50,7 +51,6 @@ import { GenerateApiKeyModal } from '../generate_api_key_modal/modal'; import { javascriptDefinition } from './languages/javascript'; import { languageDefinitions } from './languages/languages'; -import { showTryInConsole } from './languages/utils'; const DEFAULT_URL = 'https://localhost:9200'; @@ -106,7 +106,7 @@ export const APIGettingStarted = () => { { 'configureClient', codeArgs )} - showTryInConsole={showTryInConsole('configureClient')} + consoleRequest={getConsoleRequest('configureClient')} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} http={http} @@ -336,7 +336,7 @@ export const APIGettingStarted = () => { 'testConnection', codeArgs )} - showTryInConsole={showTryInConsole('testConnection')} + consoleRequest={getConsoleRequest('testConnection')} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} http={http} @@ -365,7 +365,7 @@ export const APIGettingStarted = () => { { 'buildSearchQuery', codeArgs )} - showTryInConsole={showTryInConsole('buildSearchQuery')} + consoleRequest={getConsoleRequest('buildSearchQuery')} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} http={http} diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/languages/utils.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/languages/utils.ts deleted file mode 100644 index dcaa78cc450e9..0000000000000 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/components/getting_started/languages/utils.ts +++ /dev/null @@ -1,12 +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 { LanguageDefinition } from '@kbn/search-api-panels'; - -import { consoleDefinition } from './console'; - -export const showTryInConsole = (code: keyof LanguageDefinition) => code in consoleDefinition; diff --git a/x-pack/plugins/serverless_search/public/application/components/indexing_api.tsx b/x-pack/plugins/serverless_search/public/application/components/indexing_api.tsx index 5fb8380f936ff..87f964c7e7fb8 100644 --- a/x-pack/plugins/serverless_search/public/application/components/indexing_api.tsx +++ b/x-pack/plugins/serverless_search/public/application/components/indexing_api.tsx @@ -28,6 +28,7 @@ import { LanguageClientPanel, CodeBox, getLanguageDefinitionCodeSnippet, + getConsoleRequest, } from '@kbn/search-api-panels'; import type { LanguageDefinition, @@ -42,7 +43,6 @@ import { API_KEY_PLACEHOLDER, ELASTICSEARCH_URL_PLACEHOLDER } from '../constants import { useKibanaServices } from '../hooks/use_kibana'; import { javascriptDefinition } from './languages/javascript'; import { languageDefinitions } from './languages/languages'; -import { showTryInConsole } from './languages/utils'; const NoIndicesContent = () => ( <> @@ -232,7 +232,7 @@ export const ElasticsearchIndexingApi = () => { http={http} pluginId={PLUGIN_ID} sharePlugin={share} - showTryInConsole={showTryInConsole('ingestDataIndex')} + consoleRequest={getConsoleRequest('ingestDataIndex')} /> } diff --git a/x-pack/plugins/serverless_search/public/application/components/languages/console.ts b/x-pack/plugins/serverless_search/public/application/components/languages/console.ts deleted file mode 100644 index d234262d93f13..0000000000000 --- a/x-pack/plugins/serverless_search/public/application/components/languages/console.ts +++ /dev/null @@ -1,37 +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 { LanguageDefinition } from '@kbn/search-api-panels'; -import { INDEX_NAME_PLACEHOLDER } from '../../constants'; - -export const consoleDefinition: Partial = { - buildSearchQuery: `POST /books/_search?pretty -{ - "query": { - "query_string": { - "query": "snow" - } - } -}`, - ingestData: `POST _bulk?pretty -{ "index" : { "_index" : "books" } } -{"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470} -{ "index" : { "_index" : "books" } } -{"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585} -{ "index" : { "_index" : "books" } } -{"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328} -{ "index" : { "_index" : "books" } } -{"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227} -{ "index" : { "_index" : "books" } } -{"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268} -{ "index" : { "_index" : "books" } } -{"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}`, - ingestDataIndex: ({ indexName }) => `POST _bulk?pretty - { "index" : { "_index" : "${indexName ?? INDEX_NAME_PLACEHOLDER}" } } - {"name": "foo", "title": "bar"} -`, -}; diff --git a/x-pack/plugins/serverless_search/public/application/components/languages/utils.ts b/x-pack/plugins/serverless_search/public/application/components/languages/utils.ts deleted file mode 100644 index f814c32537ebc..0000000000000 --- a/x-pack/plugins/serverless_search/public/application/components/languages/utils.ts +++ /dev/null @@ -1,11 +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 { LanguageDefinition } from '@kbn/search-api-panels'; -import { consoleDefinition } from './console'; - -export const showTryInConsole = (code: keyof LanguageDefinition) => code in consoleDefinition; diff --git a/x-pack/plugins/serverless_search/public/application/components/overview.tsx b/x-pack/plugins/serverless_search/public/application/components/overview.tsx index c9dcc2fd447c3..f78d4f871836c 100644 --- a/x-pack/plugins/serverless_search/public/application/components/overview.tsx +++ b/x-pack/plugins/serverless_search/public/application/components/overview.tsx @@ -28,6 +28,7 @@ import { LanguageClientPanel, InstallClientPanel, getLanguageDefinitionCodeSnippet, + getConsoleRequest, } from '@kbn/search-api-panels'; import React, { useMemo, useState } from 'react'; @@ -45,7 +46,6 @@ import { javascriptDefinition } from './languages/javascript'; import { languageDefinitions } from './languages/languages'; import './overview.scss'; import { ApiKeyPanel } from './api_key/api_key'; -import { showTryInConsole } from './languages/utils'; export const ElasticsearchOverview = () => { const [selectedLanguage, setSelectedLanguage] = @@ -99,7 +99,7 @@ export const ElasticsearchOverview = () => { 'installClient', codeSnippetArguments )} - showTryInConsole={showTryInConsole('installClient')} + consoleRequest={getConsoleRequest('installClient')} languages={languageDefinitions} language={selectedLanguage} setSelectedLanguage={setSelectedLanguage} @@ -142,7 +142,7 @@ export const ElasticsearchOverview = () => { 'configureClient', codeSnippetArguments )} - showTryInConsole={showTryInConsole('configureClient')} + consoleRequest={getConsoleRequest('configureClient')} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} http={http} @@ -185,7 +185,7 @@ export const ElasticsearchOverview = () => { 'testConnection', codeSnippetArguments )} - showTryInConsole={showTryInConsole('testConnection')} + consoleRequest={getConsoleRequest('testConnection')} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} http={http} @@ -207,7 +207,7 @@ export const ElasticsearchOverview = () => { 'ingestData', codeSnippetArguments )} - showTryInConsole={showTryInConsole('ingestData')} + showTryInConsole={getConsoleRequest('ingestData')} languages={languageDefinitions} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} @@ -232,7 +232,7 @@ export const ElasticsearchOverview = () => { 'buildSearchQuery', codeSnippetArguments )} - showTryInConsole={showTryInConsole('buildSearchQuery')} + consoleRequest={getConsoleRequest('buildSearchQuery')} selectedLanguage={selectedLanguage} setSelectedLanguage={setSelectedLanguage} http={http}