forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES3][Search] Create Index Page (elastic#199402)
## Summary This PR introduces a Create Index page for the serverless search solution. This page is almost identical to the new Global Empty State, but is navigated to via the Create Index button in Index Management. The index details redirect logic is also slightly different on the Create Index page, it will only redirect when the "code" view is open and a new index is created. instead of redirecting from both UI and Code view like the Global Empty State page does. With the addition of this page we are also removing the "Home" link from the serverless search side nav to reduce confusion when the global empty start redirects to index management when indices exist. There is also some minor clean-up to ensure both the global empty state and the new create index pages have proper document titles and breadcrumbs. ### Screenshots Updates to Global Empty State: ![image](https://github.com/user-attachments/assets/bb60734e-543d-4481-b121-d52633d462a8) Create Index Page: <img width="1320" alt="image" src="https://github.com/user-attachments/assets/0d095eb6-fda3-4783-83ab-20449b5b31f1"> ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
Showing
51 changed files
with
1,420 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
x-pack/plugins/search_indices/public/components/create_index/create_index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* 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, { useCallback, useState } from 'react'; | ||
|
||
import type { IndicesStatusResponse, UserStartPrivilegesResponse } from '../../../common'; | ||
|
||
import { AnalyticsEvents } from '../../analytics/constants'; | ||
import { AvailableLanguages } from '../../code_examples'; | ||
import { useKibana } from '../../hooks/use_kibana'; | ||
import { useUsageTracker } from '../../hooks/use_usage_tracker'; | ||
import { CreateIndexFormState } from '../../types'; | ||
import { generateRandomIndexName } from '../../utils/indices'; | ||
import { getDefaultCodingLanguage } from '../../utils/language'; | ||
|
||
import { CreateIndexPanel } from '../shared/create_index_panel'; | ||
|
||
import { CreateIndexCodeView } from './create_index_code_view'; | ||
import { CreateIndexUIView } from './create_index_ui_view'; | ||
|
||
function initCreateIndexState() { | ||
const defaultIndexName = generateRandomIndexName(); | ||
return { | ||
indexName: defaultIndexName, | ||
defaultIndexName, | ||
codingLanguage: getDefaultCodingLanguage(), | ||
}; | ||
} | ||
|
||
export interface CreateIndexProps { | ||
indicesData?: IndicesStatusResponse; | ||
userPrivileges?: UserStartPrivilegesResponse; | ||
} | ||
|
||
enum CreateIndexViewMode { | ||
UI = 'ui', | ||
Code = 'code', | ||
} | ||
|
||
export const CreateIndex = ({ indicesData, userPrivileges }: CreateIndexProps) => { | ||
const { application } = useKibana().services; | ||
const [createIndexView, setCreateIndexView] = useState<CreateIndexViewMode>( | ||
userPrivileges?.privileges.canCreateIndex === false | ||
? CreateIndexViewMode.Code | ||
: CreateIndexViewMode.UI | ||
); | ||
const [formState, setFormState] = useState<CreateIndexFormState>(initCreateIndexState); | ||
const usageTracker = useUsageTracker(); | ||
const onChangeView = useCallback( | ||
(id: string) => { | ||
switch (id) { | ||
case CreateIndexViewMode.UI: | ||
usageTracker.click(AnalyticsEvents.createIndexShowUIClick); | ||
setCreateIndexView(CreateIndexViewMode.UI); | ||
return; | ||
case CreateIndexViewMode.Code: | ||
usageTracker.click(AnalyticsEvents.createIndexShowCodeClick); | ||
setCreateIndexView(CreateIndexViewMode.Code); | ||
return; | ||
} | ||
}, | ||
[usageTracker] | ||
); | ||
const onChangeCodingLanguage = useCallback( | ||
(language: AvailableLanguages) => { | ||
setFormState({ | ||
...formState, | ||
codingLanguage: language, | ||
}); | ||
usageTracker.count([ | ||
AnalyticsEvents.createIndexLanguageSelect, | ||
`${AnalyticsEvents.createIndexLanguageSelect}_${language}`, | ||
]); | ||
}, | ||
[usageTracker, formState, setFormState] | ||
); | ||
const onClose = useCallback(() => { | ||
application.navigateToApp('management', { deepLinkId: 'index_management' }); | ||
}, [application]); | ||
|
||
return ( | ||
<CreateIndexPanel | ||
createIndexView={createIndexView} | ||
onChangeView={onChangeView} | ||
onClose={onClose} | ||
> | ||
{createIndexView === CreateIndexViewMode.UI && ( | ||
<CreateIndexUIView | ||
formState={formState} | ||
setFormState={setFormState} | ||
userPrivileges={userPrivileges} | ||
/> | ||
)} | ||
{createIndexView === CreateIndexViewMode.Code && ( | ||
<CreateIndexCodeView | ||
indicesData={indicesData} | ||
selectedLanguage={formState.codingLanguage} | ||
indexName={formState.indexName} | ||
changeCodingLanguage={onChangeCodingLanguage} | ||
canCreateApiKey={userPrivileges?.privileges.canCreateApiKeys} | ||
analyticsEvents={{ | ||
runInConsole: AnalyticsEvents.createIndexRunInConsole, | ||
installCommands: AnalyticsEvents.createIndexCodeCopyInstall, | ||
createIndex: AnalyticsEvents.createIndexCodeCopy, | ||
}} | ||
/> | ||
)} | ||
</CreateIndexPanel> | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/search_indices/public/components/create_index/create_index_code_view.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 type { IndicesStatusResponse } from '../../../common'; | ||
import { | ||
CreateIndexCodeView as SharedCreateIndexCodeView, | ||
CreateIndexCodeViewProps as SharedCreateIndexCodeViewProps, | ||
} from '../shared/create_index_code_view'; | ||
|
||
import { useIndicesRedirect } from './hooks/use_indices_redirect'; | ||
|
||
export interface CreateIndexCodeViewProps extends SharedCreateIndexCodeViewProps { | ||
indicesData?: IndicesStatusResponse; | ||
} | ||
|
||
export const CreateIndexCodeView = ({ indicesData, ...props }: CreateIndexCodeViewProps) => { | ||
useIndicesRedirect(indicesData); | ||
|
||
return <SharedCreateIndexCodeView {...props} />; | ||
}; |
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/search_indices/public/components/create_index/create_index_page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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, { useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { EuiLoadingLogo, EuiPageTemplate } from '@elastic/eui'; | ||
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template'; | ||
|
||
import { useKibana } from '../../hooks/use_kibana'; | ||
import { useIndicesStatusQuery } from '../../hooks/api/use_indices_status'; | ||
import { useUserPrivilegesQuery } from '../../hooks/api/use_user_permissions'; | ||
import { LoadIndicesStatusError } from '../shared/load_indices_status_error'; | ||
|
||
import { CreateIndex } from './create_index'; | ||
import { usePageChrome } from '../../hooks/use_page_chrome'; | ||
import { IndexManagementBreadcrumbs } from '../shared/breadcrumbs'; | ||
|
||
const CreateIndexLabel = i18n.translate('xpack.searchIndices.createIndex.docTitle', { | ||
defaultMessage: 'Create Index', | ||
}); | ||
|
||
export const CreateIndexPage = () => { | ||
const { console: consolePlugin } = useKibana().services; | ||
const { | ||
data: indicesData, | ||
isInitialLoading, | ||
isError: hasIndicesStatusFetchError, | ||
error: indicesFetchError, | ||
} = useIndicesStatusQuery(); | ||
const { data: userPrivileges } = useUserPrivilegesQuery(); | ||
|
||
const embeddableConsole = useMemo( | ||
() => (consolePlugin?.EmbeddableConsole ? <consolePlugin.EmbeddableConsole /> : null), | ||
[consolePlugin] | ||
); | ||
usePageChrome(CreateIndexLabel, [...IndexManagementBreadcrumbs, { text: CreateIndexLabel }]); | ||
|
||
return ( | ||
<EuiPageTemplate | ||
offset={0} | ||
restrictWidth={false} | ||
data-test-subj="elasticsearchCreateIndexPage" | ||
grow={false} | ||
> | ||
<KibanaPageTemplate.Section alignment="center" restrictWidth={false} grow> | ||
{isInitialLoading && <EuiLoadingLogo />} | ||
{hasIndicesStatusFetchError && <LoadIndicesStatusError error={indicesFetchError} />} | ||
{!isInitialLoading && !hasIndicesStatusFetchError && ( | ||
<CreateIndex indicesData={indicesData} userPrivileges={userPrivileges} /> | ||
)} | ||
</KibanaPageTemplate.Section> | ||
{embeddableConsole} | ||
</EuiPageTemplate> | ||
); | ||
}; |
Oops, something went wrong.