Skip to content

Commit

Permalink
fix(stage-wizard): ux fixes for $search wizard (#5037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabaasit authored Oct 31, 2023
1 parent 121c6d4 commit e30f24b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('TextSearch', function () {

context('calls onChange', function () {
it('for text search with fields', () => {
setSelectValue(/select search type/i, 'text-search');
setSelectValue(/select search type/i, 'text search');
setSelectValue(/select search path/i, 'field names');
setMultiSelectComboboxValues(new RegExp(MULTI_SELECT_LABEL, 'i'), [
'a',
Expand All @@ -81,10 +81,9 @@ describe('TextSearch', function () {
expect(onChangeSpy.lastCall.lastArg).to.be.null;
});

it('for text search with wildcard', () => {
setSelectValue(/select search type/i, 'text-search');
setSelectValue(/select search path/i, 'wildcard');
setInputElementValue(/Wildcard/i, 'path.*');
it('for text search with any fields', () => {
setSelectValue(/select search type/i, 'text search');
setSelectValue(/select search path/i, 'any fields');

setInputElementValue(/text/i, 'abc');
setComboboxValue(/select or type a search index/i, 'index1');
Expand All @@ -95,7 +94,7 @@ describe('TextSearch', function () {
text: {
query: 'abc',
path: {
wildcard: 'path.*',
wildcard: '*',
},
},
})
Expand All @@ -104,7 +103,7 @@ describe('TextSearch', function () {
});

it('for fuzzy search with fields', () => {
setSelectValue(/select search type/i, 'fuzzy-search');
setSelectValue(/select search type/i, 'fuzzy search');
setInputElementValue(/maxEdits/i, '1');

setSelectValue(/select search path/i, 'field names');
Expand All @@ -131,12 +130,11 @@ describe('TextSearch', function () {
expect(onChangeSpy.lastCall.lastArg).to.be.null;
});

it('for fuzzy search with wildcard', () => {
setSelectValue(/select search type/i, 'fuzzy-search');
it('for fuzzy search with any fields', () => {
setSelectValue(/select search type/i, 'fuzzy search');
setInputElementValue(/maxEdits/i, '2');

setSelectValue(/select search path/i, 'wildcard');
setInputElementValue(/wildcard/i, 'path.*');
setSelectValue(/select search path/i, 'any fields');

setInputElementValue(/text/i, 'xyz');
setComboboxValue(/select or type a search index/i, 'index2');
Expand All @@ -147,7 +145,7 @@ describe('TextSearch', function () {
text: {
query: 'xyz',
path: {
wildcard: 'path.*',
wildcard: '*',
},
fuzzy: {
maxEdits: 2,
Expand All @@ -161,7 +159,7 @@ describe('TextSearch', function () {

context('validation', function () {
it('should validate maxEdits', function () {
setSelectValue(/select search type/i, 'fuzzy-search');
setSelectValue(/select search type/i, 'fuzzy search');
{
setInputElementValue(/maxEdits/i, '0');
expect(onChangeSpy.lastCall.lastArg).to.be.an.instanceOf(Error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type TextSearchState = {
path: SearchPath;
maxEdits?: number;
fields?: string[];
wildcard?: string;
text: string;
indexName: string;
};
Expand Down Expand Up @@ -64,10 +63,7 @@ const mapTextSearchDataToStageValue = (formData: TextSearchState): Document => {
index: formData.indexName || 'default',
text: {
query: formData.text,
path:
formData.path === 'wildcard'
? { wildcard: formData.wildcard || '*' }
: formData.fields,
path: formData.path === 'wildcard' ? { wildcard: '*' } : formData.fields,
...(formData.type === 'fuzzy'
? { fuzzy: { maxEdits: formData.maxEdits } }
: {}),
Expand Down Expand Up @@ -111,14 +107,13 @@ export const TextSearch = ({
type: 'text',
path: 'fields',
maxEdits: 2,
wildcard: '*',
text: '',
indexName: '',
});

useEffect(() => {
onFetchIndexes();
}, []);
}, [onFetchIndexes]);

const onSetFormData = (data: TextSearchState) => {
const stageValue = mapTextSearchDataToStageValue(data);
Expand Down Expand Up @@ -149,8 +144,8 @@ export const TextSearch = ({
value={formData.type}
onChange={(value) => onChangeProperty('type', value as SearchType)}
>
<Option value="text">text-search</Option>
<Option value="fuzzy">fuzzy-search</Option>
<Option value="text">text search</Option>
<Option value="fuzzy">fuzzy search</Option>
</Select>
<div className={inputWithLabelStyles}>
<Body>with maxEdits</Body>
Expand Down Expand Up @@ -180,26 +175,16 @@ export const TextSearch = ({
onChange={(value) => onChangeProperty('path', value as SearchPath)}
>
<Option value="fields">field names</Option>
<Option value="wildcard">wildcard</Option>
<Option value="wildcard">any fields</Option>
</Select>
{formData.path === 'fields' && (
<FieldCombobox
className={inputStyles}
value={formData.fields}
onChange={(val: string[]) => onChangeProperty('fields', val)}
fields={fields}
multiselect={true}
/>
)}
{formData.path === 'wildcard' && (
<TextInput
placeholder={'*'}
aria-label={'Wildcard'}
value={formData.wildcard}
className={inputStyles}
onChange={(e) => onChangeProperty('wildcard', e.target.value)}
/>
)}
<FieldCombobox
className={inputStyles}
value={formData.fields}
onChange={(val: string[]) => onChangeProperty('fields', val)}
fields={fields}
multiselect={true}
disabled={formData.path === 'wildcard'}
/>
</div>
<div className={rowStyles}>
<Body className={labelStyles}>contains</Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
KeylineCard,
Link,
spacing,
Disclaimer,
Badge,
WarningSummary,
} from '@mongodb-js/compass-components';

Expand Down Expand Up @@ -212,7 +212,7 @@ export const StageWizard = ({
{useCase.stageOperator}
</Link>
</div>
{useCase.isAtlasOnly && <Disclaimer>Atlas-only</Disclaimer>}
{useCase.isAtlasOnly && <Badge>Atlas only</Badge>}
</div>
</div>
<div ref={focusContainerRef}>
Expand Down
4 changes: 3 additions & 1 deletion packages/compass-aggregations/test/form-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ export const setInputElementValue = (
selector: 'input',
});
userEvent.clear(input);
userEvent.type(input, value);
if (value !== '') {
userEvent.type(input, value);
}
};

0 comments on commit e30f24b

Please sign in to comment.