Skip to content

Commit

Permalink
fixed react warning, updated validation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Jul 1, 2020
1 parent 58b2ceb commit 3026957
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const AutocompleteFieldMatchComponent: React.FC<AutocompleteFieldMatchPro
onChange(newValue ?? '');
};

const onSearchChange = (searchVal: string) => {
const onSearchChange = (searchVal: string): void => {
const signal = new AbortController().signal;

updateSuggestions({
Expand All @@ -77,6 +77,11 @@ export const AutocompleteFieldMatchComponent: React.FC<AutocompleteFieldMatchPro
});
};

const isValid = useMemo(
(): boolean => validateParams(selectedValue, selectedField ? selectedField.type : ''),
[selectedField, selectedValue]
);

return (
<EuiComboBox
placeholder={isLoading || isLoadingSuggestions ? i18n.LOADING : placeholder}
Expand All @@ -89,7 +94,7 @@ export const AutocompleteFieldMatchComponent: React.FC<AutocompleteFieldMatchPro
singleSelection={{ asPlainText: true }}
onSearchChange={onSearchChange}
onCreateOption={onChange}
isInvalid={!validateParams(selectedValue, selectedField ? selectedField.type : '')}
isInvalid={!isValid}
sortMatchesBy="startsWith"
data-test-subj="valuesAutocompleteComboBox matchComboxBox"
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const AutocompleteFieldMatchAnyComponent: React.FC<AutocompleteFieldMatch
onSearchChange={onSearchChange}
onCreateOption={onCreateOption}
isInvalid={!isValid}
sortMatchesBy="startsWith"
delimiter=", "
data-test-subj="valuesAutocompleteComboBox matchAnyComboxBox"
fullWidth
async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ describe('helpers', () => {
});

describe('#validateParams', () => {
test('returns true if value is undefined', () => {
const isValid = validateParams(undefined, 'date');

expect(isValid).toBeTruthy();
});

test('returns true if value is empty string', () => {
const isValid = validateParams('', 'date');

expect(isValid).toBeTruthy();
});

test('returns true if type is "date" and value is valid', () => {
const isValid = validateParams('1994-11-05T08:15:30-05:00', 'date');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,7 @@ describe('useFieldValueAutocomplete', () => {
result.current[2],
];

expect(getValueSuggestionsMock).toHaveBeenNthCalledWith(1, {
field: getField('@tags'),
indexPattern: stubIndexPatternWithFields,
query: '',
signal: new AbortController().signal,
});
expect(getValueSuggestionsMock).toHaveBeenNthCalledWith(2, {
field: getField('@tags'),
indexPattern: stubIndexPatternWithFields,
query: 'hello',
signal: new AbortController().signal,
});
expect(getValueSuggestionsMock).toHaveBeenCalledTimes(2);
expect(result.current).toEqual(expectedResult);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const useFieldValueAutocomplete = ({
const newSuggestions = await services.data.autocomplete.getValueSuggestions({
indexPattern: patterns,
field: fieldSelected,
query: `${value ?? ''}`,
query: '',
signal,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ export const ExceptionListItemComponent = React.memo<ExceptionListItemProps>(
<EuiFlexItem grow={6}>
<EuiFlexGroup gutterSize="s" direction="column">
{entries.map((item, index) => (
<EuiFlexItem
key={`${exceptionId}_${item.field ? item.field.name : ''}_${index}`}
grow={1}
>
<EuiFlexItem key={`${exceptionId}-${index}`} grow={1}>
<EuiFlexGroup gutterSize="xs" alignItems="center" direction="row">
<EuiFlexItem grow={1}>
<EntryItemComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,17 @@ export const getFormattedBuilderEntries = (
({ name }) => item.field != null && item.field === name
);
return {
field: selectedField,
field: {
name: 'nestedField.child',
type: 'nested',
esTypes: ['text'],
count: 0,
scripted: false,
searchable: true,
aggregatable: false,
readFromDocValues: false,
subType: { nested: { path: 'nestedField' } },
},
operator: getExceptionOperatorSelect(item),
value: getEntryValue(item),
};
Expand Down

0 comments on commit 3026957

Please sign in to comment.