mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 09:57:35 -02:30
Lookup tweaks/bug fixes
This commit is contained in:
@@ -71,7 +71,7 @@ function CredentialLookup({
|
|||||||
optionCount={count}
|
optionCount={count}
|
||||||
header={label}
|
header={label}
|
||||||
qsConfig={QS_CONFIG}
|
qsConfig={QS_CONFIG}
|
||||||
readOnly={canDelete}
|
readOnly={!canDelete}
|
||||||
selectItem={item => dispatch({ type: 'SELECT_ITEM', item })}
|
selectItem={item => dispatch({ type: 'SELECT_ITEM', item })}
|
||||||
deselectItem={item => dispatch({ type: 'DESELECT_ITEM', item })}
|
deselectItem={item => dispatch({ type: 'DESELECT_ITEM', item })}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ function MultiCredentialsLookup(props) {
|
|||||||
try {
|
try {
|
||||||
const types = await loadCredentialTypes();
|
const types = await loadCredentialTypes();
|
||||||
setCredentialTypes(types);
|
setCredentialTypes(types);
|
||||||
setSelectedType(
|
setSelectedType(types.find(type => type.kind === 'ssh') || types[0]);
|
||||||
types.find(type => type.name === 'Machine') || types[0]
|
|
||||||
);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
onError(err);
|
onError(err);
|
||||||
}
|
}
|
||||||
@@ -71,7 +69,7 @@ function MultiCredentialsLookup(props) {
|
|||||||
})();
|
})();
|
||||||
}, [selectedType, history.location.search, onError]);
|
}, [selectedType, history.location.search, onError]);
|
||||||
|
|
||||||
const isMultiple = selectedType && selectedType.name === 'Vault';
|
const isMultiple = selectedType && selectedType.kind === 'vault';
|
||||||
const renderChip = ({ item, removeItem, canDelete }) => (
|
const renderChip = ({ item, removeItem, canDelete }) => (
|
||||||
<CredentialChip
|
<CredentialChip
|
||||||
key={item.id}
|
key={item.id}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { withI18n } from '@lingui/react';
|
||||||
|
import { t } from '@lingui/macro';
|
||||||
|
|
||||||
function LookupErrorMessage({ error }) {
|
function LookupErrorMessage({ error, i18n }) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pf-c-form__helper-text pf-m-error" aria-live="polite">
|
<div className="pf-c-form__helper-text pf-m-error" aria-live="polite">
|
||||||
{error.message || 'An error occured'}
|
{error.message || i18n._(t`An error occured`)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LookupErrorMessage;
|
export default withI18n()(LookupErrorMessage);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// import { useReducer, useEffect } from 'react';
|
|
||||||
|
|
||||||
export default function reducer(state, action) {
|
export default function reducer(state, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SELECT_ITEM':
|
case 'SELECT_ITEM':
|
||||||
@@ -51,10 +49,16 @@ function toggleModal(state) {
|
|||||||
if (isModalOpen) {
|
if (isModalOpen) {
|
||||||
return closeModal(state);
|
return closeModal(state);
|
||||||
}
|
}
|
||||||
|
let selectedItems = [];
|
||||||
|
if (multiple) {
|
||||||
|
selectedItems = [...value];
|
||||||
|
} else if (value) {
|
||||||
|
selectedItems.push(value);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isModalOpen: !isModalOpen,
|
isModalOpen: !isModalOpen,
|
||||||
selectedItems: multiple ? [...value] : [value],
|
selectedItems,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)', () => {
|
it('should open the modal (multiple)', () => {
|
||||||
const state = {
|
const state = {
|
||||||
isModalOpen: false,
|
isModalOpen: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user