Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library-authoring/LibraryAuthoringPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe('<LibraryAuthoringPage />', () => {
fireEvent.change(searchBox, { target: { value: 'words to find' } });

// Default sort option changes to "Most Relevant"
expect(screen.getAllByText('Most Relevant').length).toEqual(2);
expect((await screen.findAllByText('Most Relevant')).length).toEqual(2);
await waitFor(() => {
expect(fetchMock).toHaveBeenLastCalledWith(searchEndpoint, {
body: expect.stringContaining('"sort":[]'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ describe('<LibraryCollectionPage />', () => {
fireEvent.change(searchBox, { target: { value: 'words to find' } });

// Default sort option changes to "Most Relevant"
expect(screen.getAllByText('Most Relevant').length).toEqual(2);
expect((await screen.findAllByText('Most Relevant')).length).toEqual(2);
await waitFor(() => {
expect(fetchMock).toHaveBeenLastCalledWith(searchEndpoint, {
body: expect.stringContaining('"sort":[]'),
Expand Down
8 changes: 7 additions & 1 deletion src/search-manager/SearchKeywordsField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useIntl } from '@edx/frontend-platform/i18n';
import { SearchField } from '@openedx/paragon';
import { debounce } from 'lodash';
import messages from './messages';
import { useSearchContext } from './SearchManager';

Expand All @@ -17,10 +18,15 @@ const SearchKeywordsField: React.FC<{
const defaultPlaceholder = usageKey ? messages.clearUsageKeyToSearch : messages.inputPlaceholder;
const { placeholder = intl.formatMessage(defaultPlaceholder) } = props;

const handleSearch = React.useCallback(
debounce((term) => setSearchKeywords(term.trim()), 400),
[searchKeywords],
);// Perform search after 500ms

return (
<SearchField.Advanced
onSubmit={setSearchKeywords}
onChange={setSearchKeywords}
onChange={handleSearch}
onClear={() => setSearchKeywords('')}
value={searchKeywords}
className={props.className}
Expand Down