diff --git a/awx/ui_next/src/components/Lookup/CredentialLookup.jsx b/awx/ui_next/src/components/Lookup/CredentialLookup.jsx index bea32e63de..6b61b3c486 100644 --- a/awx/ui_next/src/components/Lookup/CredentialLookup.jsx +++ b/awx/ui_next/src/components/Lookup/CredentialLookup.jsx @@ -71,7 +71,7 @@ function CredentialLookup({ optionCount={count} header={label} qsConfig={QS_CONFIG} - readOnly={canDelete} + readOnly={!canDelete} selectItem={item => dispatch({ type: 'SELECT_ITEM', item })} deselectItem={item => dispatch({ type: 'DESELECT_ITEM', item })} /> diff --git a/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx b/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx index 2d1eff8965..1a020cab26 100644 --- a/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx +++ b/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx @@ -43,9 +43,7 @@ function MultiCredentialsLookup(props) { try { const types = await loadCredentialTypes(); setCredentialTypes(types); - setSelectedType( - types.find(type => type.name === 'Machine') || types[0] - ); + setSelectedType(types.find(type => type.kind === 'ssh') || types[0]); } catch (err) { onError(err); } @@ -71,7 +69,7 @@ function MultiCredentialsLookup(props) { })(); }, [selectedType, history.location.search, onError]); - const isMultiple = selectedType && selectedType.name === 'Vault'; + const isMultiple = selectedType && selectedType.kind === 'vault'; const renderChip = ({ item, removeItem, canDelete }) => ( - {error.message || 'An error occured'} + {error.message || i18n._(t`An error occured`)} ); } -export default LookupErrorMessage; +export default withI18n()(LookupErrorMessage); diff --git a/awx/ui_next/src/components/Lookup/shared/reducer.js b/awx/ui_next/src/components/Lookup/shared/reducer.js index bf97284f88..315f652846 100644 --- a/awx/ui_next/src/components/Lookup/shared/reducer.js +++ b/awx/ui_next/src/components/Lookup/shared/reducer.js @@ -1,5 +1,3 @@ -// import { useReducer, useEffect } from 'react'; - export default function reducer(state, action) { switch (action.type) { case 'SELECT_ITEM': @@ -51,10 +49,16 @@ function toggleModal(state) { if (isModalOpen) { return closeModal(state); } + let selectedItems = []; + if (multiple) { + selectedItems = [...value]; + } else if (value) { + selectedItems.push(value); + } return { ...state, isModalOpen: !isModalOpen, - selectedItems: multiple ? [...value] : [value], + selectedItems, }; } diff --git a/awx/ui_next/src/components/Lookup/shared/reducer.test.js b/awx/ui_next/src/components/Lookup/shared/reducer.test.js index 22bf9da106..62c963cbfb 100644 --- a/awx/ui_next/src/components/Lookup/shared/reducer.test.js +++ b/awx/ui_next/src/components/Lookup/shared/reducer.test.js @@ -129,6 +129,24 @@ describe('Lookup reducer', () => { }); }); + it('should set null value to empty array', () => { + const state = { + isModalOpen: false, + selectedItems: [{ id: 1 }], + value: null, + multiple: false, + }; + const result = reducer(state, { + type: 'TOGGLE_MODAL', + }); + expect(result).toEqual({ + isModalOpen: true, + selectedItems: [], + value: null, + multiple: false, + }); + }); + it('should open the modal (multiple)', () => { const state = { isModalOpen: false,