-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[App Search] Credentials: implement working flyout form #81541
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c2fbd47
Add key name field
cee-chen 2692d17
Add key type field
cee-chen 8672aff
Add key read/write fields
cee-chen 94db91a
Add key engine access / selection
cee-chen 6f81b63
Add key update warning callout
cee-chen 05b1625
Update flyout body with form components
cee-chen 947f9f5
[PR feedback] i18n - change appSearch.tokens to appSearch.credentials
cee-chen ee377e2
[PR feedback] Remove unnecessary conditional
cee-chen dab0456
Merge remote-tracking branch 'upstream/master' into credentials-flyout-3
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 additions & 0 deletions
11
...pplications/app_search/components/credentials/credentials_flyout/form_components/index.ts
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,11 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { FormKeyName } from './key_name'; | ||
export { FormKeyType } from './key_type'; | ||
export { FormKeyReadWriteAccess } from './key_read_write_access'; | ||
export { FormKeyEngineAccess } from './key_engine_access'; | ||
export { FormKeyUpdateWarning } from './key_update_warning'; | ||
135 changes: 135 additions & 0 deletions
135
...arch/components/credentials/credentials_flyout/form_components/key_engine_access.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,135 @@ | ||
/* | ||
* 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 { EuiRadio, EuiCheckbox } from '@elastic/eui'; | ||
|
||
import { FormKeyEngineAccess, EngineSelection } from './key_engine_access'; | ||
|
||
describe('FormKeyEngineAccess', () => { | ||
const values = { | ||
myRole: { canAccessAllEngines: true }, | ||
fullEngineAccessChecked: true, | ||
}; | ||
const actions = { | ||
setAccessAllEngines: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find(EuiRadio)).toHaveLength(2); | ||
expect(wrapper.find(EngineSelection)).toHaveLength(0); | ||
}); | ||
|
||
it('hides the full access radio option if the user does not have access to all engines', () => { | ||
setMockValues({ | ||
...values, | ||
myRole: { canAccessAllEngines: false }, | ||
}); | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find('#all_engines').prop('hidden')).toEqual(true); | ||
}); | ||
|
||
it('controls the checked values for access radios', () => { | ||
setMockValues({ | ||
...values, | ||
fullEngineAccessChecked: true, | ||
}); | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find('#all_engines').prop('checked')).toEqual(true); | ||
expect(wrapper.find('#all_engines').prop('value')).toEqual('true'); | ||
expect(wrapper.find('#specific_engines').prop('checked')).toEqual(false); | ||
expect(wrapper.find('#specific_engines').prop('value')).toEqual('false'); | ||
|
||
setMockValues({ | ||
...values, | ||
fullEngineAccessChecked: false, | ||
}); | ||
wrapper.setProps({}); // Re-render | ||
|
||
expect(wrapper.find('#all_engines').prop('checked')).toEqual(false); | ||
expect(wrapper.find('#all_engines').prop('value')).toEqual('false'); | ||
expect(wrapper.find('#specific_engines').prop('checked')).toEqual(true); | ||
expect(wrapper.find('#specific_engines').prop('value')).toEqual('true'); | ||
}); | ||
|
||
it('calls setAccessAllEngines when the radios are changed', () => { | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
wrapper.find('#all_engines').simulate('change'); | ||
expect(actions.setAccessAllEngines).toHaveBeenCalledWith(true); | ||
|
||
wrapper.find('#specific_engines').simulate('change'); | ||
expect(actions.setAccessAllEngines).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('displays the engine selection panel if the limited access radio is selected', () => { | ||
setMockValues({ | ||
...values, | ||
fullEngineAccessChecked: false, | ||
}); | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find(EngineSelection)).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('EngineSelection', () => { | ||
const values = { | ||
activeApiToken: { engines: [] }, | ||
engines: [{ name: 'engine1' }, { name: 'engine2' }, { name: 'engine3' }], | ||
}; | ||
const actions = { | ||
onEngineSelect: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<EngineSelection />); | ||
|
||
expect(wrapper.find('h4').text()).toEqual('Select Engines'); | ||
expect(wrapper.find(EuiCheckbox)).toHaveLength(3); | ||
expect(wrapper.find(EuiCheckbox).first().prop('label')).toEqual('engine1'); | ||
}); | ||
|
||
it('controls the engines checked state', () => { | ||
setMockValues({ | ||
...values, | ||
activeApiToken: { engines: ['engine3'] }, | ||
}); | ||
const wrapper = shallow(<EngineSelection />); | ||
|
||
expect(wrapper.find(EuiCheckbox).first().prop('checked')).toEqual(false); | ||
expect(wrapper.find(EuiCheckbox).last().prop('checked')).toEqual(true); | ||
}); | ||
|
||
it('calls onEngineSelect when the checkboxes are changed', () => { | ||
const wrapper = shallow(<EngineSelection />); | ||
|
||
wrapper.find(EuiCheckbox).first().simulate('change'); | ||
expect(actions.onEngineSelect).toHaveBeenCalledWith('engine1'); | ||
|
||
wrapper.find(EuiCheckbox).last().simulate('change'); | ||
expect(actions.onEngineSelect).toHaveBeenCalledWith('engine3'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super quick note about the naming schema I went with - I'm not in love with it or anything so definitely happy to take suggestions. One thing that drives me slightly nuts (but no idea how to fix lol) is the alternating terminology we use:
Anyway, don't mind me, I'm just dead inside over here