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: [Search:SearchApplications:Connect page]Button behind modal dialog is announced (#199668) #199869

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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 @@ -9,14 +9,16 @@ import { setMockValues, setMockActions } from '../../../../../__mocks__/kea_logi

import React from 'react';

import { shallow, mount } from 'enzyme';
import { shallow } from 'enzyme';

import { EuiModal, EuiFieldText, EuiCodeBlock } from '@elastic/eui';

const mockActions = { makeRequest: jest.fn(), setKeyName: jest.fn() };

const mockValues = { apiKey: '', isLoading: false, isSuccess: false, keyName: '' };

import { mountWithIntl } from '@kbn/test-jest-helpers';

import { GenerateSearchApplicationApiKeyModal } from './generate_search_application_api_key_modal';

const onCloseMock = jest.fn();
Expand Down Expand Up @@ -50,7 +52,7 @@ describe('GenerateSearchApplicationApiKeyModal', () => {
});

it('pre-set the key name with search application name', () => {
mount(
mountWithIntl(
<GenerateSearchApplicationApiKeyModal
searchApplicationName="puggles"
onClose={onCloseMock}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

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

import { useValues, useActions } from 'kea';

Expand All @@ -24,12 +24,12 @@ import {
EuiFieldText,
EuiFormRow,
EuiText,
EuiSpacer,
EuiFormLabel,
EuiCallOut,
EuiCodeBlock,
} from '@elastic/eui';

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

import { GenerateSearchApplicationApiKeyLogic } from '../../../../api/search_applications/generate_search_application_api_key_logic';

Expand All @@ -46,11 +46,18 @@ export const GenerateSearchApplicationApiKeyModal: React.FC<
const { keyName, apiKey, isLoading, isSuccess } = useValues(GenerateApiKeyModalLogic);
const { setKeyName } = useActions(GenerateApiKeyModalLogic);
const { makeRequest } = useActions(GenerateSearchApplicationApiKeyLogic);
const copyApiKeyRef = useRef<HTMLAnchorElement>(null);

useEffect(() => {
setKeyName(`${searchApplicationName} read-only API key`);
}, [searchApplicationName]);

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

return (
<EuiModal onClose={onClose}>
<EuiModalHeader>
Expand All @@ -65,15 +72,24 @@ export const GenerateSearchApplicationApiKeyModal: React.FC<
</EuiModalHeader>
<EuiModalBody>
<>
<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.generateSearchApplicationApiKeyModal.euiFormRow.nameYourAPIKeyLabel"
defaultMessage="Name your API key"
/>
}
fullWidth
>
<EuiFieldText
data-test-subj="enterpriseSearchGenerateSearchApplicationApiKeyModalFieldText"
data-telemetry-id="entSearchApplications-api-generateSearchApplicationApiKeyModal-editName"
fullWidth
placeholder="Type a name for your API key"
Expand Down Expand Up @@ -110,8 +126,20 @@ export const GenerateSearchApplicationApiKeyModal: React.FC<
</>
) : (
<EuiFlexItem>
<EuiFormLabel>{keyName}</EuiFormLabel>
<EuiSpacer size="xs" />
<EuiCallOut
title={
<FormattedMessage
id="xpack.enterpriseSearch.searchApplication.searchApplication.api.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 @@ -126,6 +154,8 @@ export const GenerateSearchApplicationApiKeyModal: React.FC<
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonIcon
buttonRef={copyApiKeyRef}
data-test-subj="enterpriseSearchGenerateSearchApplicationApiKeyModalButton"
data-telemetry-id="entSearchApplications-api-generateSearchApplicationApiKeyModal-csvDownloadButton"
aria-label={i18n.translate(
'xpack.enterpriseSearch.searchApplication.searchApplication.api.generateApiKeyModal.csvDownloadButton',
Expand Down Expand Up @@ -165,6 +195,7 @@ export const GenerateSearchApplicationApiKeyModal: React.FC<
<EuiModalFooter>
{apiKey ? (
<EuiButton
data-test-subj="enterpriseSearchGenerateSearchApplicationApiKeyModalDoneButton"
data-telemetry-id="entSearchApplications-api-generateSearchApplicationApiKeyModal-done"
fill
onClick={onClose}
Expand All @@ -178,6 +209,7 @@ export const GenerateSearchApplicationApiKeyModal: React.FC<
</EuiButton>
) : (
<EuiButtonEmpty
data-test-subj="enterpriseSearchGenerateSearchApplicationApiKeyModalCancelButton"
data-telemetry-id="entSearchApplications-api-generateSearchApplicationApiKeyModal-cancel"
onClick={onClose}
>
Expand Down