-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Search] Credentials: add FlashMessages, stub out credentials fly…
…out (#81391) * Added an empty Flyout * Refactor CredentialsFlyout to its own component folder + split out child sub components for easier testing/reading * Add initial FlashMessages setup - mostly just DELETE_MESSAGE currently, since that's what's already wired up - CREATE_MESSAGE and UPDATE_MESSAGE will be used in an upcoming commit + adds FlashMessages in flyout, which will show returned form errors from the API * Fix flash messages appearing on flyout open e.g. deletion success messages + incidental linting/cleanup Co-authored-by: Jason Stoltzfus <jastoltz24@gmail.com>
- Loading branch information
1 parent
7d93024
commit c9d4dc3
Showing
13 changed files
with
373 additions
and
13 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
18 changes: 18 additions & 0 deletions
18
...ch/public/applications/app_search/components/credentials/credentials_flyout/body.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,18 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiFlyoutBody } from '@elastic/eui'; | ||
|
||
import { CredentialsFlyoutBody } from './body'; | ||
|
||
describe('CredentialsFlyoutBody', () => { | ||
it('renders', () => { | ||
const wrapper = shallow(<CredentialsFlyoutBody />); | ||
expect(wrapper.find(EuiFlyoutBody)).toHaveLength(1); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
..._search/public/applications/app_search/components/credentials/credentials_flyout/body.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,19 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { EuiFlyoutBody } from '@elastic/eui'; | ||
|
||
import { FlashMessages } from '../../../../shared/flash_messages'; | ||
|
||
export const CredentialsFlyoutBody: React.FC = () => { | ||
return ( | ||
<EuiFlyoutBody> | ||
<FlashMessages /> | ||
Details go here | ||
</EuiFlyoutBody> | ||
); | ||
}; |
64 changes: 64 additions & 0 deletions
64
.../public/applications/app_search/components/credentials/credentials_flyout/footer.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,64 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiFlyoutFooter, EuiButtonEmpty } from '@elastic/eui'; | ||
|
||
import { CredentialsFlyoutFooter } from './footer'; | ||
|
||
describe('CredentialsFlyoutFooter', () => { | ||
const values = { | ||
activeApiTokenExists: false, | ||
}; | ||
const actions = { | ||
hideCredentialsForm: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<CredentialsFlyoutFooter />); | ||
expect(wrapper.find(EuiFlyoutFooter)).toHaveLength(1); | ||
}); | ||
|
||
it('closes the flyout', () => { | ||
const wrapper = shallow(<CredentialsFlyoutFooter />); | ||
const button = wrapper.find(EuiButtonEmpty); | ||
button.simulate('click'); | ||
expect(button.prop('children')).toEqual('Close'); | ||
expect(actions.hideCredentialsForm).toHaveBeenCalled(); | ||
}); | ||
|
||
it('renders action button text for new tokens', () => { | ||
const wrapper = shallow(<CredentialsFlyoutFooter />); | ||
const button = wrapper.find('[data-test-subj="APIKeyActionButton"]'); | ||
|
||
expect(button.prop('children')).toEqual('Save'); | ||
}); | ||
|
||
it('renders action button text for existing tokens', () => { | ||
setMockValues({ activeApiTokenExists: true }); | ||
const wrapper = shallow(<CredentialsFlyoutFooter />); | ||
const button = wrapper.find('[data-test-subj="APIKeyActionButton"]'); | ||
|
||
expect(button.prop('children')).toEqual('Update'); | ||
}); | ||
|
||
it('calls onApiTokenChange on action button press', () => { | ||
const wrapper = shallow(<CredentialsFlyoutFooter />); | ||
const button = wrapper.find('[data-test-subj="APIKeyActionButton"]'); | ||
button.simulate('click'); | ||
|
||
// TODO: Expect onApiTokenChange to have been called | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
...earch/public/applications/app_search/components/credentials/credentials_flyout/footer.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,54 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { useValues, useActions } from 'kea'; | ||
import { | ||
EuiFlyoutFooter, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiButtonEmpty, | ||
EuiButton, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { CredentialsLogic } from '../credentials_logic'; | ||
|
||
export const CredentialsFlyoutFooter: React.FC = () => { | ||
const { hideCredentialsForm } = useActions(CredentialsLogic); | ||
const { activeApiTokenExists } = useValues(CredentialsLogic); | ||
|
||
return ( | ||
<EuiFlyoutFooter> | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty iconType="cross" onClick={hideCredentialsForm}> | ||
{i18n.translate('xpack.enterpriseSearch.appSearch.credentials.flyout.closeText', { | ||
defaultMessage: 'Close', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
onClick={() => window.alert('submit')} | ||
fill={true} | ||
color="secondary" | ||
iconType="check" | ||
data-test-subj="APIKeyActionButton" | ||
> | ||
{activeApiTokenExists | ||
? i18n.translate('xpack.enterpriseSearch.appSearch.credentials.flyout.updateText', { | ||
defaultMessage: 'Update', | ||
}) | ||
: i18n.translate('xpack.enterpriseSearch.appSearch.credentials.flyout.saveText', { | ||
defaultMessage: 'Save', | ||
})} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlyoutFooter> | ||
); | ||
}; |
55 changes: 55 additions & 0 deletions
55
.../public/applications/app_search/components/credentials/credentials_flyout/header.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,55 @@ | ||
/* | ||
* 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 } from '../../../../__mocks__/kea.mock'; | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiFlyoutHeader } from '@elastic/eui'; | ||
|
||
import { ApiTokenTypes } from '../constants'; | ||
import { IApiToken } from '../types'; | ||
|
||
import { CredentialsFlyoutHeader } from './header'; | ||
|
||
describe('CredentialsFlyoutHeader', () => { | ||
const apiToken: IApiToken = { | ||
name: '', | ||
type: ApiTokenTypes.Private, | ||
read: true, | ||
write: true, | ||
access_all_engines: true, | ||
}; | ||
const values = { | ||
activeApiToken: apiToken, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<CredentialsFlyoutHeader />); | ||
|
||
expect(wrapper.find(EuiFlyoutHeader)).toHaveLength(1); | ||
expect(wrapper.find('h2').prop('id')).toEqual('credentialsFlyoutTitle'); | ||
expect(wrapper.find('h2').prop('children')).toEqual('Create a new key'); | ||
}); | ||
|
||
it('changes the title text if editing an existing token', () => { | ||
setMockValues({ | ||
activeApiToken: { | ||
...apiToken, | ||
id: 'some-id', | ||
name: 'search-key', | ||
}, | ||
}); | ||
const wrapper = shallow(<CredentialsFlyoutHeader />); | ||
|
||
expect(wrapper.find('h2').prop('children')).toEqual('Update search-key'); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...earch/public/applications/app_search/components/credentials/credentials_flyout/header.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,34 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { useValues } from 'kea'; | ||
import { EuiFlyoutHeader, EuiTitle } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { CredentialsLogic } from '../credentials_logic'; | ||
import { FLYOUT_ARIA_LABEL_ID } from '../constants'; | ||
|
||
export const CredentialsFlyoutHeader: React.FC = () => { | ||
const { activeApiToken } = useValues(CredentialsLogic); | ||
|
||
return ( | ||
<EuiFlyoutHeader hasBorder={true}> | ||
<EuiTitle size="m"> | ||
<h2 id={FLYOUT_ARIA_LABEL_ID}> | ||
{activeApiToken.id | ||
? i18n.translate('xpack.enterpriseSearch.appSearch.credentials.flyout.updateTitle', { | ||
defaultMessage: 'Update {tokenName}', | ||
values: { tokenName: activeApiToken.name }, | ||
}) | ||
: i18n.translate('xpack.enterpriseSearch.appSearch.credentials.flyout.createTitle', { | ||
defaultMessage: 'Create a new key', | ||
})} | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
); | ||
}; |
33 changes: 33 additions & 0 deletions
33
...h/public/applications/app_search/components/credentials/credentials_flyout/index.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,33 @@ | ||
/* | ||
* 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 { setMockActions } from '../../../../__mocks__/kea.mock'; | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiFlyout } from '@elastic/eui'; | ||
|
||
import { CredentialsFlyout } from './'; | ||
|
||
describe('CredentialsFlyout', () => { | ||
const actions = { | ||
hideCredentialsForm: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<CredentialsFlyout />); | ||
const flyout = wrapper.find(EuiFlyout); | ||
|
||
expect(flyout).toHaveLength(1); | ||
expect(flyout.prop('aria-labelledby')).toEqual('credentialsFlyoutTitle'); | ||
expect(flyout.prop('onClose')).toEqual(actions.hideCredentialsForm); | ||
}); | ||
}); |
Oops, something went wrong.