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

[8.x] fix: [Stateful: Indices: Overview page] Wrong focus order after generating API key on the dialog (#197212) #198823

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
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,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useRef, useEffect } from 'react';

import { useValues, useActions } from 'kea';

Expand All @@ -26,11 +26,12 @@ import {
EuiText,
EuiSpacer,
EuiLink,
EuiFormLabel,
EuiCodeBlock,
EuiCallOut,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { docLinks } from '../../../../../shared/doc_links';

Expand All @@ -49,6 +50,13 @@ export const GenerateApiKeyModal: React.FC<GenerateApiKeyModalProps> = ({ indexN
const { ingestionMethod } = useValues(IndexViewLogic);
const { setKeyName } = useActions(GenerateApiKeyModalLogic);
const { makeRequest } = useActions(GenerateApiKeyLogic);
const copyApiKeyRef = useRef<HTMLAnchorElement>(null);

useEffect(() => {
if (isSuccess) {
copyApiKeyRef.current?.focus();
}
}, [isSuccess]);

return (
<EuiModal onClose={onClose}>
Expand All @@ -68,7 +76,11 @@ export const GenerateApiKeyModal: React.FC<GenerateApiKeyModalProps> = ({ indexN
"Before you can start posting documents to your Elasticsearch index you'll need to create at least one API key.",
})}
&nbsp;
<EuiLink href={docLinks.apiKeys} external>
<EuiLink
data-test-subj="enterpriseSearchGenerateApiKeyModalLearnMoreAboutApiKeysLink"
href={docLinks.apiKeys}
external
>
{i18n.translate(
'xpack.enterpriseSearch.content.overview.generateApiKeyModal.learnMore',
{ defaultMessage: 'Learn more about API keys' }
Expand All @@ -77,15 +89,25 @@ export const GenerateApiKeyModal: React.FC<GenerateApiKeyModalProps> = ({ indexN
</p>
</EuiText>
<EuiSpacer />
<EuiPanel hasShadow={false} color="primary">

<EuiPanel hasShadow={false} color={!isSuccess ? 'primary' : 'success'}>
<EuiFlexGroup direction="column">
<EuiFlexItem>
<EuiFlexGroup direction="row" alignItems="flexEnd">
{!isSuccess ? (
<>
<EuiFlexItem>
<EuiFormRow label="Name your API key" fullWidth>
<EuiFormRow
label={
<FormattedMessage
id="xpack.enterpriseSearch.generateApiKeyModal.euiFormRow.nameYourAPIKeyLabel"
defaultMessage="Name your API key"
/>
}
fullWidth
>
<EuiFieldText
data-test-subj="enterpriseSearchGenerateApiKeyModalFieldText"
data-telemetry-id={`entSearchContent-${ingestionMethod}-overview-generateApiKey-editName`}
fullWidth
placeholder="Type a name for your API key"
Expand Down Expand Up @@ -121,8 +143,20 @@ export const GenerateApiKeyModal: React.FC<GenerateApiKeyModalProps> = ({ indexN
</>
) : (
<EuiFlexItem>
<EuiFormLabel>{keyName}</EuiFormLabel>
<EuiSpacer size="xs" />
<EuiCallOut
title={
<FormattedMessage
id="xpack.enterpriseSearch.content.overview.generateApiKeyModal.callOutMessage"
defaultMessage="Done! The {name} API key was generated."
values={{
name: <strong>{keyName}</strong>,
}}
/>
}
color="success"
iconType="check"
role="alert"
/>
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
<EuiCodeBlock
Expand All @@ -137,6 +171,8 @@ export const GenerateApiKeyModal: React.FC<GenerateApiKeyModalProps> = ({ indexN
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonIcon
buttonRef={copyApiKeyRef}
data-test-subj="enterpriseSearchGenerateApiKeyModalButton"
data-telemetry-id={`entSearchContent-${ingestionMethod}-overview-generateApiKey-download`}
aria-label={i18n.translate(
'xpack.enterpriseSearch.content.overview.generateApiKeyModal.csvDownloadButton',
Expand Down Expand Up @@ -175,6 +211,7 @@ export const GenerateApiKeyModal: React.FC<GenerateApiKeyModalProps> = ({ indexN
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty
data-test-subj="enterpriseSearchGenerateApiKeyModalCancelButton"
data-telemetry-id={`entSearchContent-${ingestionMethod}-overview-generateApiKey-cancel`}
onClick={onClose}
>
Expand Down