From ac9efc18d93d5298bf2cbd1c9637bbbcce2d71ba Mon Sep 17 00:00:00 2001 From: Joseph McElroy Date: Fri, 11 Oct 2024 11:16:43 +0100 Subject: [PATCH] update to get defaultIndexName via formState --- .../search_indices/public/components/start/create_index.tsx | 5 ++--- .../public/components/start/elasticsearch_start.tsx | 4 +++- .../plugins/search_indices/public/components/start/types.ts | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/search_indices/public/components/start/create_index.tsx b/x-pack/plugins/search_indices/public/components/start/create_index.tsx index 38b3281741605..788bd1e36f2ee 100644 --- a/x-pack/plugins/search_indices/public/components/start/create_index.tsx +++ b/x-pack/plugins/search_indices/public/components/start/create_index.tsx @@ -54,7 +54,6 @@ export const CreateIndexForm = ({ }: CreateIndexFormProps) => { const { application } = useKibana().services; const [indexNameHasError, setIndexNameHasError] = useState(false); - const [defaultIndexName] = useState(formState.indexName); const usageTracker = useUsageTracker(); const { createIndex, isLoading } = useCreateIndex(); const onCreateIndex = useCallback( @@ -65,13 +64,13 @@ export const CreateIndexForm = ({ } usageTracker.click(AnalyticsEvents.startCreateIndexClick); - if (defaultIndexName !== formState.indexName) { + if (formState.defaultIndexName !== formState.indexName) { usageTracker.click(AnalyticsEvents.startCreateIndexPageModifyIndexName); } createIndex({ indexName: formState.indexName }); }, - [usageTracker, createIndex, formState.indexName, defaultIndexName] + [usageTracker, createIndex, formState.indexName, formState.defaultIndexName] ); const onIndexNameChange = (e: React.ChangeEvent) => { const newIndexName = e.target.value; diff --git a/x-pack/plugins/search_indices/public/components/start/elasticsearch_start.tsx b/x-pack/plugins/search_indices/public/components/start/elasticsearch_start.tsx index 8bc8d5fcd7ea2..42b021043cb34 100644 --- a/x-pack/plugins/search_indices/public/components/start/elasticsearch_start.tsx +++ b/x-pack/plugins/search_indices/public/components/start/elasticsearch_start.tsx @@ -35,8 +35,10 @@ import { CreateIndexFormState } from './types'; import { useKibana } from '../../hooks/use_kibana'; function initCreateIndexState(): CreateIndexFormState { + const defaultIndexName = generateRandomIndexName(); return { - indexName: generateRandomIndexName(), + indexName: defaultIndexName, + defaultIndexName, codingLanguage: getDefaultCodingLanguage(), }; } diff --git a/x-pack/plugins/search_indices/public/components/start/types.ts b/x-pack/plugins/search_indices/public/components/start/types.ts index c0dbbeca88883..4c0235ec515f1 100644 --- a/x-pack/plugins/search_indices/public/components/start/types.ts +++ b/x-pack/plugins/search_indices/public/components/start/types.ts @@ -9,5 +9,6 @@ import type { AvailableLanguages } from '../../code_examples'; export interface CreateIndexFormState { indexName: string; + defaultIndexName: string; codingLanguage: AvailableLanguages; }