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

[Search] [Playground] Hide create index button when plugin not available #209165

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,43 @@
* 2.0.
*/

import React, { useCallback } from 'react';
import { EuiButton, EuiCallOut } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import React, { useCallback, useMemo } from 'react';
import { SEARCH_INDICES, SEARCH_INDICES_CREATE_INDEX } from '@kbn/deeplinks-search/constants';
import { i18n } from '@kbn/i18n';
import { useKibana } from '../../hooks/use_kibana';

export const CreateIndexButton: React.FC = () => {
const {
services: { application, share },
services: { application, chrome },
} = useKibana();

const createIndexLocator = useMemo(
() => share.url.locators.get('SEARCH_CREATE_INDEX'),
[share.url.locators]
);
const createIndexUrl = chrome.navLinks.get(
`${SEARCH_INDICES}:${SEARCH_INDICES_CREATE_INDEX}`
)?.url;

const handleCreateIndexClick = useCallback(
async (event: React.MouseEvent<HTMLAnchorElement>) => {
(event: React.MouseEvent<HTMLAnchorElement>) => {
event.preventDefault();

if (!createIndexLocator) {
if (!createIndexUrl) {
return;
}

const url = await createIndexLocator.getUrl({});
application?.navigateToUrl(url);
application?.navigateToUrl(createIndexUrl);
},
[application, createIndexLocator]
[application, createIndexUrl]
);

return createIndexLocator ? (
return createIndexUrl ? (
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiButton
color="primary"
iconType="plusInCircle"
fill
data-test-subj="createIndexButton"
href={createIndexLocator.getRedirectUrl({})}
href={createIndexUrl}
onClick={handleCreateIndexClick}
>
<FormattedMessage
Expand Down