mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 18:07:36 -02:30
fix minor lookup bugs
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { arrayOf, string, func, object } from 'prop-types';
|
import { arrayOf, string, func, object, bool } from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
@@ -18,7 +18,15 @@ const QS_CONFIG = getQSConfig('instance_groups', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function InstanceGroupsLookup(props) {
|
function InstanceGroupsLookup(props) {
|
||||||
const { value, onChange, tooltip, className, history, i18n } = props;
|
const {
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
tooltip,
|
||||||
|
className,
|
||||||
|
required,
|
||||||
|
history,
|
||||||
|
i18n,
|
||||||
|
} = props;
|
||||||
const [instanceGroups, setInstanceGroups] = useState([]);
|
const [instanceGroups, setInstanceGroups] = useState([]);
|
||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
@@ -50,6 +58,7 @@ function InstanceGroupsLookup(props) {
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
qsConfig={QS_CONFIG}
|
qsConfig={QS_CONFIG}
|
||||||
multiple
|
multiple
|
||||||
|
required={required}
|
||||||
renderOptionsList={({ state, dispatch, canDelete }) => (
|
renderOptionsList={({ state, dispatch, canDelete }) => (
|
||||||
<OptionsList
|
<OptionsList
|
||||||
value={state.selectedItems}
|
value={state.selectedItems}
|
||||||
@@ -95,11 +104,13 @@ InstanceGroupsLookup.propTypes = {
|
|||||||
tooltip: string,
|
tooltip: string,
|
||||||
onChange: func.isRequired,
|
onChange: func.isRequired,
|
||||||
className: string,
|
className: string,
|
||||||
|
required: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
InstanceGroupsLookup.defaultProps = {
|
InstanceGroupsLookup.defaultProps = {
|
||||||
tooltip: '',
|
tooltip: '',
|
||||||
className: '',
|
className: '',
|
||||||
|
required: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(withRouter(InstanceGroupsLookup));
|
export default withI18n()(withRouter(InstanceGroupsLookup));
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function InventoryLookup({
|
|||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
|
required={required}
|
||||||
qsConfig={QS_CONFIG}
|
qsConfig={QS_CONFIG}
|
||||||
renderOptionsList={({ state, dispatch, canDelete }) => (
|
renderOptionsList={({ state, dispatch, canDelete }) => (
|
||||||
<OptionsList
|
<OptionsList
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ describe('<Lookup multiple/>', () => {
|
|||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Lookup
|
<Lookup
|
||||||
multiple
|
multiple
|
||||||
lookupHeader="Foo Bar"
|
header="Foo Bar"
|
||||||
name="foobar"
|
name="foobar"
|
||||||
value={mockSelected}
|
value={mockSelected}
|
||||||
onLookupSave={onChange}
|
onLookupSave={onChange}
|
||||||
@@ -240,7 +240,7 @@ describe('<Lookup />', () => {
|
|||||||
document.body.innerHTML = '';
|
document.body.innerHTML = '';
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Lookup
|
<Lookup
|
||||||
lookupHeader="Foo Bar"
|
header="Foo Bar"
|
||||||
name="foobar"
|
name="foobar"
|
||||||
value={mockSelected}
|
value={mockSelected}
|
||||||
onLookupSave={onChange}
|
onLookupSave={onChange}
|
||||||
@@ -340,7 +340,7 @@ describe('<Lookup />', () => {
|
|||||||
<_Lookup
|
<_Lookup
|
||||||
multiple
|
multiple
|
||||||
name="foo"
|
name="foo"
|
||||||
lookupHeader="Foo Bar"
|
header="Foo Bar"
|
||||||
onLookupSave={() => {}}
|
onLookupSave={() => {}}
|
||||||
value={mockData}
|
value={mockData}
|
||||||
columns={mockColumns}
|
columns={mockColumns}
|
||||||
@@ -369,7 +369,7 @@ describe('<Lookup />', () => {
|
|||||||
<_Lookup
|
<_Lookup
|
||||||
multiple
|
multiple
|
||||||
name="foo"
|
name="foo"
|
||||||
lookupHeader="Foo Bar"
|
header="Foo Bar"
|
||||||
onLookupSave={() => {}}
|
onLookupSave={() => {}}
|
||||||
value={mockData}
|
value={mockData}
|
||||||
columns={mockColumns}
|
columns={mockColumns}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ function MultiCredentialsLookup(props) {
|
|||||||
{tooltip && <FieldTooltip content={tooltip} />}
|
{tooltip && <FieldTooltip content={tooltip} />}
|
||||||
<Lookup
|
<Lookup
|
||||||
id="multiCredential"
|
id="multiCredential"
|
||||||
lookupHeader={i18n._(t`Credentials`)}
|
header={i18n._(t`Credentials`)}
|
||||||
value={value}
|
value={value}
|
||||||
multiple
|
multiple
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function ProjectLookup({
|
|||||||
{tooltip && <FieldTooltip content={tooltip} />}
|
{tooltip && <FieldTooltip content={tooltip} />}
|
||||||
<Lookup
|
<Lookup
|
||||||
id="project"
|
id="project"
|
||||||
lookupHeader={i18n._(t`Project`)}
|
header={i18n._(t`Project`)}
|
||||||
name="project"
|
name="project"
|
||||||
value={value}
|
value={value}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ function OptionsList({
|
|||||||
selectItem,
|
selectItem,
|
||||||
deselectItem,
|
deselectItem,
|
||||||
renderItemChip,
|
renderItemChip,
|
||||||
|
isLoading,
|
||||||
i18n,
|
i18n,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
@@ -49,6 +50,7 @@ function OptionsList({
|
|||||||
pluralizedItemName={header}
|
pluralizedItemName={header}
|
||||||
qsConfig={qsConfig}
|
qsConfig={qsConfig}
|
||||||
toolbarColumns={columns}
|
toolbarColumns={columns}
|
||||||
|
hasContentLoading={isLoading}
|
||||||
renderItem={item => (
|
renderItem={item => (
|
||||||
<CheckboxListItem
|
<CheckboxListItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
@@ -75,7 +77,7 @@ OptionsList.propTypes = {
|
|||||||
value: arrayOf(Item).isRequired,
|
value: arrayOf(Item).isRequired,
|
||||||
options: arrayOf(Item).isRequired,
|
options: arrayOf(Item).isRequired,
|
||||||
optionCount: number.isRequired,
|
optionCount: number.isRequired,
|
||||||
columns: arrayOf(shape({})).isRequired,
|
columns: arrayOf(shape({})),
|
||||||
multiple: bool,
|
multiple: bool,
|
||||||
qsConfig: QSConfig.isRequired,
|
qsConfig: QSConfig.isRequired,
|
||||||
selectItem: func.isRequired,
|
selectItem: func.isRequired,
|
||||||
@@ -85,6 +87,7 @@ OptionsList.propTypes = {
|
|||||||
OptionsList.defaultProps = {
|
OptionsList.defaultProps = {
|
||||||
multiple: false,
|
multiple: false,
|
||||||
renderItemChip: null,
|
renderItemChip: null,
|
||||||
|
columns: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(OptionsList);
|
export default withI18n()(OptionsList);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// import { useReducer, useEffect } from 'react';
|
// import { useReducer, useEffect } from 'react';
|
||||||
|
|
||||||
export default function reducer(state, action) {
|
export default function reducer(state, action) {
|
||||||
// console.log(action, state);
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SELECT_ITEM':
|
case 'SELECT_ITEM':
|
||||||
return selectItem(state, action.item);
|
return selectItem(state, action.item);
|
||||||
@@ -91,18 +90,3 @@ function assertCorrectValueType(value, multiple) {
|
|||||||
throw new Error('Lookup value must be an array if `multiple` is set');
|
throw new Error('Lookup value must be an array if `multiple` is set');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// export function useLookup(config) {
|
|
||||||
// const { value, multiple, required, onChange, history } = config;
|
|
||||||
// const [state, dispatch] = useReducer(
|
|
||||||
// config.reducer || reducer,
|
|
||||||
// {
|
|
||||||
// value,
|
|
||||||
// multiple,
|
|
||||||
// required,
|
|
||||||
// },
|
|
||||||
// config.initReducer || initReducer
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// return [state, dispatch];
|
|
||||||
// }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user