fix minor lookup bugs

This commit is contained in:
Keith Grant 2019-11-26 15:01:13 -08:00
parent cb07e9c757
commit f8153393b1
7 changed files with 24 additions and 25 deletions

View File

@ -1,5 +1,5 @@
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 { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
@ -18,7 +18,15 @@ const QS_CONFIG = getQSConfig('instance_groups', {
});
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 [count, setCount] = useState(0);
const [error, setError] = useState(null);
@ -50,6 +58,7 @@ function InstanceGroupsLookup(props) {
onChange={onChange}
qsConfig={QS_CONFIG}
multiple
required={required}
renderOptionsList={({ state, dispatch, canDelete }) => (
<OptionsList
value={state.selectedItems}
@ -95,11 +104,13 @@ InstanceGroupsLookup.propTypes = {
tooltip: string,
onChange: func.isRequired,
className: string,
required: bool,
};
InstanceGroupsLookup.defaultProps = {
tooltip: '',
className: '',
required: false,
};
export default withI18n()(withRouter(InstanceGroupsLookup));

View File

@ -61,6 +61,7 @@ function InventoryLookup({
value={value}
onChange={onChange}
onBlur={onBlur}
required={required}
qsConfig={QS_CONFIG}
renderOptionsList={({ state, dispatch, canDelete }) => (
<OptionsList

View File

@ -98,7 +98,7 @@ describe('<Lookup multiple/>', () => {
wrapper = mountWithContexts(
<Lookup
multiple
lookupHeader="Foo Bar"
header="Foo Bar"
name="foobar"
value={mockSelected}
onLookupSave={onChange}
@ -240,7 +240,7 @@ describe('<Lookup />', () => {
document.body.innerHTML = '';
wrapper = mountWithContexts(
<Lookup
lookupHeader="Foo Bar"
header="Foo Bar"
name="foobar"
value={mockSelected}
onLookupSave={onChange}
@ -340,7 +340,7 @@ describe('<Lookup />', () => {
<_Lookup
multiple
name="foo"
lookupHeader="Foo Bar"
header="Foo Bar"
onLookupSave={() => {}}
value={mockData}
columns={mockColumns}
@ -369,7 +369,7 @@ describe('<Lookup />', () => {
<_Lookup
multiple
name="foo"
lookupHeader="Foo Bar"
header="Foo Bar"
onLookupSave={() => {}}
value={mockData}
columns={mockColumns}

View File

@ -86,7 +86,7 @@ function MultiCredentialsLookup(props) {
{tooltip && <FieldTooltip content={tooltip} />}
<Lookup
id="multiCredential"
lookupHeader={i18n._(t`Credentials`)}
header={i18n._(t`Credentials`)}
value={value}
multiple
onChange={onChange}

View File

@ -57,7 +57,7 @@ function ProjectLookup({
{tooltip && <FieldTooltip content={tooltip} />}
<Lookup
id="project"
lookupHeader={i18n._(t`Project`)}
header={i18n._(t`Project`)}
name="project"
value={value}
onBlur={onBlur}

View File

@ -29,6 +29,7 @@ function OptionsList({
selectItem,
deselectItem,
renderItemChip,
isLoading,
i18n,
}) {
return (
@ -49,6 +50,7 @@ function OptionsList({
pluralizedItemName={header}
qsConfig={qsConfig}
toolbarColumns={columns}
hasContentLoading={isLoading}
renderItem={item => (
<CheckboxListItem
key={item.id}
@ -75,7 +77,7 @@ OptionsList.propTypes = {
value: arrayOf(Item).isRequired,
options: arrayOf(Item).isRequired,
optionCount: number.isRequired,
columns: arrayOf(shape({})).isRequired,
columns: arrayOf(shape({})),
multiple: bool,
qsConfig: QSConfig.isRequired,
selectItem: func.isRequired,
@ -85,6 +87,7 @@ OptionsList.propTypes = {
OptionsList.defaultProps = {
multiple: false,
renderItemChip: null,
columns: [],
};
export default withI18n()(OptionsList);

View File

@ -1,7 +1,6 @@
// import { useReducer, useEffect } from 'react';
export default function reducer(state, action) {
// console.log(action, state);
switch (action.type) {
case 'SELECT_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');
}
}
//
// 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];
// }