-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Added a Credentials page to App Search (#79749)
- Loading branch information
1 parent
8bea172
commit 44b48a2
Showing
20 changed files
with
952 additions
and
63 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
73 changes: 73 additions & 0 deletions
73
...erprise_search/public/applications/app_search/components/credentials/credentials.test.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,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { setMockValues, setMockActions } from '../../../__mocks__/kea.mock'; | ||
import { unmountHandler } from '../../../__mocks__/shallow_useeffect.mock'; | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { Credentials } from './credentials'; | ||
import { EuiCopy, EuiPageContentBody } from '@elastic/eui'; | ||
|
||
import { externalUrl } from '../../../shared/enterprise_search_url'; | ||
|
||
describe('Credentials', () => { | ||
// Kea mocks | ||
const values = { | ||
dataLoading: false, | ||
}; | ||
const actions = { | ||
initializeCredentialsData: jest.fn(), | ||
resetCredentials: jest.fn(), | ||
showCredentialsForm: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<Credentials />); | ||
expect(wrapper.find(EuiPageContentBody)).toHaveLength(1); | ||
}); | ||
|
||
it('initializes data on mount', () => { | ||
shallow(<Credentials />); | ||
expect(actions.initializeCredentialsData).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('calls resetCredentials on unmount', () => { | ||
shallow(<Credentials />); | ||
unmountHandler(); | ||
expect(actions.resetCredentials).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('renders nothing if data is still loading', () => { | ||
setMockValues({ dataLoading: true }); | ||
const wrapper = shallow(<Credentials />); | ||
expect(wrapper.find(EuiPageContentBody)).toHaveLength(0); | ||
}); | ||
|
||
it('renders the API endpoint and a button to copy it', () => { | ||
externalUrl.enterpriseSearchUrl = 'http://localhost:3002'; | ||
const copyMock = jest.fn(); | ||
const wrapper = shallow(<Credentials />); | ||
// We wrap children in a div so that `shallow` can render it. | ||
const copyEl = shallow(<div>{wrapper.find(EuiCopy).props().children(copyMock)}</div>); | ||
expect(copyEl.find('EuiButtonIcon').props().onClick).toEqual(copyMock); | ||
expect(copyEl.text().replace('<EuiButtonIcon />', '')).toEqual('http://localhost:3002'); | ||
}); | ||
|
||
it('will show the Crendentials Flyout when the Create API Key button is pressed', () => { | ||
const wrapper = shallow(<Credentials />); | ||
const button: any = wrapper.find('[data-test-subj="CreateAPIKeyButton"]'); | ||
button.props().onClick(); | ||
expect(actions.showCredentialsForm).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
132 changes: 132 additions & 0 deletions
132
...s/enterprise_search/public/applications/app_search/components/credentials/credentials.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,132 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useActions, useValues } from 'kea'; | ||
|
||
import { | ||
EuiPageHeader, | ||
EuiPageHeaderSection, | ||
EuiTitle, | ||
EuiPageContentBody, | ||
EuiPanel, | ||
EuiCopy, | ||
EuiButtonIcon, | ||
EuiSpacer, | ||
EuiButton, | ||
EuiPageContentHeader, | ||
EuiPageContentHeaderSection, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; | ||
import { CredentialsLogic } from './credentials_logic'; | ||
import { externalUrl } from '../../../shared/enterprise_search_url/external_url'; | ||
import { CredentialsList } from './credentials_list'; | ||
|
||
export const Credentials: React.FC = () => { | ||
const { initializeCredentialsData, resetCredentials, showCredentialsForm } = useActions( | ||
CredentialsLogic | ||
); | ||
|
||
const { dataLoading } = useValues(CredentialsLogic); | ||
|
||
useEffect(() => { | ||
initializeCredentialsData(); | ||
return () => { | ||
resetCredentials(); | ||
}; | ||
}, []); | ||
|
||
// TODO | ||
// if (dataLoading) { return <Loading /> } | ||
if (dataLoading) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
<SetPageChrome | ||
trail={[ | ||
i18n.translate('xpack.enterpriseSearch.appSearch.credentials.title', { | ||
defaultMessage: 'Credentials', | ||
}), | ||
]} | ||
/> | ||
<EuiPageHeader> | ||
<EuiPageHeaderSection> | ||
<EuiTitle size="l"> | ||
<h1> | ||
{i18n.translate('xpack.enterpriseSearch.appSearch.credentials.title', { | ||
defaultMessage: 'Credentials', | ||
})} | ||
</h1> | ||
</EuiTitle> | ||
</EuiPageHeaderSection> | ||
</EuiPageHeader> | ||
<EuiPageContentBody> | ||
<EuiPanel className="eui-textCenter"> | ||
<EuiTitle size="s"> | ||
<h2> | ||
{i18n.translate('xpack.enterpriseSearch.appSearch.credentials.apiEndpoint', { | ||
defaultMessage: 'Endpoint', | ||
})} | ||
</h2> | ||
</EuiTitle> | ||
<EuiCopy | ||
textToCopy={externalUrl.enterpriseSearchUrl} | ||
afterMessage={i18n.translate('xpack.enterpriseSearch.appSearch.credentials.copied', { | ||
defaultMessage: 'Copied', | ||
})} | ||
> | ||
{(copy) => ( | ||
<> | ||
<EuiButtonIcon | ||
onClick={copy} | ||
iconType="copyClipboard" | ||
aria-label={i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.credentials.copyApiEndpoint', | ||
{ | ||
defaultMessage: 'Copy API Endpoint to clipboard.', | ||
} | ||
)} | ||
/> | ||
{externalUrl.enterpriseSearchUrl} | ||
</> | ||
)} | ||
</EuiCopy> | ||
</EuiPanel> | ||
<EuiSpacer size="xxl" /> | ||
<EuiPageContentHeader responsive={false}> | ||
<EuiPageContentHeaderSection> | ||
<EuiTitle size="m"> | ||
<h2> | ||
{i18n.translate('xpack.enterpriseSearch.appSearch.credentials.apiKeys', { | ||
defaultMessage: 'API Keys', | ||
})} | ||
</h2> | ||
</EuiTitle> | ||
</EuiPageContentHeaderSection> | ||
<EuiPageContentHeaderSection> | ||
<EuiButton | ||
color="primary" | ||
data-test-subj="CreateAPIKeyButton" | ||
fill={true} | ||
onClick={() => showCredentialsForm()} | ||
> | ||
{i18n.translate('xpack.enterpriseSearch.appSearch.credentials.createKey', { | ||
defaultMessage: 'Create a key', | ||
})} | ||
</EuiButton> | ||
</EuiPageContentHeaderSection> | ||
</EuiPageContentHeader> | ||
<EuiSpacer size="s" /> | ||
<EuiPanel> | ||
<CredentialsList /> | ||
</EuiPanel> | ||
</EuiPageContentBody> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.