Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removing prequery optimizely code #413

Merged
merged 1 commit into from
Sep 16, 2024
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
4 changes: 1 addition & 3 deletions packages/catalog-search/src/PrequerySearchSuggestionItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';

const PrequerySearchSuggestionItem = ({
url, hit, optimizelySuggestionClickHandler,
url, hit,
}) => (
<Link
to={url}
key={hit.title}
className="prequery-item pr-4 d-flex flex-column"
onClick={() => optimizelySuggestionClickHandler(hit.key)}
>
<div className="d-flex align-items-center justify-content-start">
<Image className="prequery-image mr-2" src={hit.card_image_url} />
Expand Down Expand Up @@ -43,7 +42,6 @@ PrequerySearchSuggestionItem.propTypes = {
),
learning_type: PropTypes.string,
}).isRequired,
optimizelySuggestionClickHandler: PropTypes.func.isRequired,
};

export default PrequerySearchSuggestionItem;
11 changes: 2 additions & 9 deletions packages/catalog-search/src/SearchBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export const SearchBoxBase = ({
enterpriseSlug,
suggestionSubmitOverride,
disableSuggestionRedirect,
isPreQueryEnabled,
optimizelySuggestionClickHandler,
}) => {
const { dispatch, trackingName } = useContext(SearchContext);

Expand Down Expand Up @@ -122,8 +120,8 @@ export const SearchBoxBase = ({
// If there are no results of the suggested search, hide the empty suggestion component
setShowSuggestions(false);
}
// If isPreQueryEnabled is true display the prequery results when user clicks on search box but has not began typing
} else if (query === '' && isPreQueryEnabled) {
// Display the prequery results when user clicks on search box but has not began typing
} else if (query === '') {
const { hits } = await index.search(query, {
filters,
attributesToHighlight: ['title'],
Expand Down Expand Up @@ -200,7 +198,6 @@ export const SearchBoxBase = ({
handleSubmit={() => handleSubmit(searchQuery)}
handleSuggestionClickSubmit={hit => handleSuggestionSubmit(hit)}
disableSuggestionRedirect={disableSuggestionRedirect}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>
)}
</div>
Expand All @@ -218,8 +215,6 @@ SearchBoxBase.propTypes = {
enterpriseSlug: PropTypes.string,
suggestionSubmitOverride: PropTypes.func,
disableSuggestionRedirect: PropTypes.bool,
isPreQueryEnabled: PropTypes.bool,
optimizelySuggestionClickHandler: PropTypes.func,
};

SearchBoxBase.defaultProps = {
Expand All @@ -233,8 +228,6 @@ SearchBoxBase.defaultProps = {
index: undefined,
suggestionSubmitOverride: undefined,
disableSuggestionRedirect: false,
isPreQueryEnabled: false,
optimizelySuggestionClickHandler: undefined,
};

export default connectSearchBox(SearchBoxBase);
11 changes: 0 additions & 11 deletions packages/catalog-search/src/SearchHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const SearchHeader = ({
suggestionSubmitOverride,
enterpriseConfig: { slug, enablePathways },
disableSuggestionRedirect,
optimizelySuggestionClickHandler,
isPreQueryEnabled,
hideSearchBox,
}) => {
const { refinements } = useContext(SearchContext);
Expand Down Expand Up @@ -61,8 +59,6 @@ const SearchHeader = ({
enterpriseSlug={slug}
suggestionSubmitOverride={suggestionSubmitOverride}
disableSuggestionRedirect={disableSuggestionRedirect}
isPreQueryEnabled={isPreQueryEnabled}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>
)}
</Col>
Expand All @@ -89,8 +85,6 @@ SearchHeader.defaultProps = {
suggestionSubmitOverride: undefined,
disableSuggestionRedirect: false,
index: undefined,
optimizelySuggestionClickHandler: undefined,
isPreQueryEnabled: false,
hideSearchBox: false,
};

Expand All @@ -105,15 +99,10 @@ SearchHeader.propTypes = {
{
slug: PropTypes.string,
enablePathways: PropTypes.bool,
enterpriseFeatures: PropTypes.shape({
featurePrequerySearchSuggestions: PropTypes.bool,
}),
},
),
suggestionSubmitOverride: PropTypes.func,
disableSuggestionRedirect: PropTypes.bool,
optimizelySuggestionClickHandler: PropTypes.func,
isPreQueryEnabled: PropTypes.bool,
hideSearchBox: PropTypes.bool,
};

Expand Down
5 changes: 1 addition & 4 deletions packages/catalog-search/src/SearchSuggestionItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';

const SearchSuggestionItem = ({
url, suggestionItemHandler, hit, disableSuggestionRedirect, optimizelySuggestionClickHandler,
url, suggestionItemHandler, hit, disableSuggestionRedirect,
}) => {
const authoringOrganization = hit.key && hit.key.split('+')[0];
// If the disable redirect bool is provided, prevent the redirect from happening and instead call the provided submit
Expand All @@ -13,7 +13,6 @@ const SearchSuggestionItem = ({
e.preventDefault();
suggestionItemHandler(hit);
}
optimizelySuggestionClickHandler(hit.key || hit.course_keys);
};
return (
<Link to={url} key={hit.title} className="suggestion-item" onClick={handleLinkDisable}>
Expand Down Expand Up @@ -57,12 +56,10 @@ SearchSuggestionItem.propTypes = {
learning_type: PropTypes.string,
}).isRequired,
disableSuggestionRedirect: PropTypes.bool.isRequired,
optimizelySuggestionClickHandler: PropTypes.func,
};

SearchSuggestionItem.defaultProps = {
suggestionItemHandler: undefined,
optimizelySuggestionClickHandler: undefined,
};

export default SearchSuggestionItem;
7 changes: 0 additions & 7 deletions packages/catalog-search/src/SearchSuggestions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const SearchSuggestions = ({
handleSubmit,
handleSuggestionClickSubmit,
disableSuggestionRedirect,
optimizelySuggestionClickHandler,
}) => {
const getLinkToCourse = (course) => {
const { learning_type: learningType } = course;
Expand Down Expand Up @@ -71,7 +70,6 @@ const SearchSuggestions = ({
key={hit.title}
url={getUrl(hit)}
hit={hit}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>
);
})
Expand All @@ -96,7 +94,6 @@ const SearchSuggestions = ({
hit={hit}
disableSuggestionRedirect={disableSuggestionRedirect}
suggestionItemHandler={handleSuggestionClickSubmit}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>
))
}
Expand All @@ -120,7 +117,6 @@ const SearchSuggestions = ({
hit={hit}
disableSuggestionRedirect={disableSuggestionRedirect}
suggestionItemHandler={handleSuggestionClickSubmit}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>
))
}
Expand All @@ -144,7 +140,6 @@ const SearchSuggestions = ({
hit={hit}
disableSuggestionRedirect={disableSuggestionRedirect}
suggestionItemHandler={handleSuggestionClickSubmit}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>
))
}
Expand Down Expand Up @@ -172,7 +167,6 @@ SearchSuggestions.propTypes = {
handleSuggestionClickSubmit: PropTypes.func,
disableSuggestionRedirect: PropTypes.bool,
preQueryHits: PropTypes.arrayOf(PropTypes.shape()),
optimizelySuggestionClickHandler: PropTypes.func,
};

SearchSuggestions.defaultProps = {
Expand All @@ -181,7 +175,6 @@ SearchSuggestions.defaultProps = {
handleSuggestionClickSubmit: undefined,
disableSuggestionRedirect: false,
preQueryHits: undefined,
optimizelySuggestionClickHandler: undefined,
};

export default SearchSuggestions;

This file was deleted.

3 changes: 0 additions & 3 deletions packages/catalog-search/src/tests/SearchBox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ describe('<SearchBox />', () => {
});
test('search box renders search suggestion and can override redirect', async () => {
const suggestionSubmitOverride = jest.fn();
const optimizelySuggestionClickHandler = jest.fn();
SearchBoxBase.handleSuggestionSubmit = jest.fn();
const hits = [
{ learning_type: 'course', _highlightResult: { title: { value: 'test-title' } } },
Expand All @@ -150,7 +149,6 @@ describe('<SearchBox />', () => {
index={index}
suggestionSubmitOverride={suggestionSubmitOverride}
disableSuggestionRedirect
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
/>,
);

Expand All @@ -163,7 +161,6 @@ describe('<SearchBox />', () => {
await act(async () => {
userEvent.click(screen.getByText('test-title'));
});
expect(optimizelySuggestionClickHandler).toHaveBeenCalled();
expect(suggestionSubmitOverride).toHaveBeenCalledWith(
{ learning_type: 'course', _highlightResult: { title: { value: 'test-title' } } },
);
Expand Down
3 changes: 0 additions & 3 deletions packages/catalog-search/src/tests/SearchHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jest.mock('../SearchFilters', () => ({
}));
const enterpriseConfig = {
slug: 'test-enterprise',
enterpriseFeatures: {
featurePrequerySearchSuggestions: true,
},
};
describe('SearchHeader', () => {
test('displays a SearchBox', () => {
Expand Down
10 changes: 0 additions & 10 deletions packages/catalog-search/src/tests/SearchSuggestionItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('<SeachSuggestionItem />', () => {
title: 'test-course',
_highlightResult: { title: { value: '<em>course</em> <em>catalog</em>' } },
},
optimizelySuggestionClickHandler: jest.fn(),
},
};

Expand All @@ -26,7 +25,6 @@ describe('<SeachSuggestionItem />', () => {
suggestionItemHandler={mockData.course.suggestionItemHandler}
hit={mockData.course.hit}
disableSuggestionRedirect={mockData.course.disableSuggestionRedirect}
optimizelySuggestionClickHandler={mockData.optimizelySuggestionClickHandler}
/>);
expect(screen.getByRole('link', { name: 'course catalog edX' })).not.toBeNull();
expect(screen.getByText('course')).not.toBeNull();
Expand All @@ -48,15 +46,13 @@ describe('<SeachSuggestionItem />', () => {
_highlightResult: { title: { value: '<em>program</em> <em>catalog</em>' } },
},
},
optimizelySuggestionClickHandler: jest.fn(),
};

renderWithRouter(<SearchSuggestionItem
url={mockData.program.url}
suggestionItemHandler={mockData.program.suggestionItemHandler}
hit={mockData.program.hit}
disableSuggestionRedirect={mockData.program.disableSuggestionRedirect}
optimizelySuggestionClickHandler={mockData.optimizelySuggestionClickHandler}
/>);
expect(screen.getByRole('link', { name: 'program catalog edX Professional Program' })).not.toBeNull();
expect(screen.getByText('program')).not.toBeNull();
Expand All @@ -79,19 +75,16 @@ describe('<SeachSuggestionItem />', () => {
_highlightResult: { title: { value: '<em>program</em> <em>catalog</em>' } },
},
},
optimizelySuggestionClickHandler: jest.fn(),
};

const { container } = renderWithRouter(<SearchSuggestionItem
url={mockData.program.url}
suggestionItemHandler={mockData.program.suggestionItemHandler}
hit={mockData.program.hit}
disableSuggestionRedirect={mockData.program.disableSuggestionRedirect}
optimizelySuggestionClickHandler={mockData.optimizelySuggestionClickHandler}
/>);
userEvent.click(container.getElementsByClassName('suggestion-item')[0]);
expect(window.location.pathname).toBe(mockData.program.url);
expect(mockData.optimizelySuggestionClickHandler.mock.calls.length).toBe(1);
});

test('fires callback on click if disableSuggestionRedirect is true', () => {
Expand All @@ -108,18 +101,15 @@ describe('<SeachSuggestionItem />', () => {
_highlightResult: { title: { value: '<em>program</em> <em>catalog</em>' } },
},
},
optimizelySuggestionClickHandler: jest.fn(),
};

const { container } = renderWithRouter(<SearchSuggestionItem
url={mockData.program.url}
suggestionItemHandler={mockData.program.suggestionItemHandler}
hit={mockData.program.hit}
disableSuggestionRedirect={mockData.program.disableSuggestionRedirect}
optimizelySuggestionClickHandler={mockData.optimizelySuggestionClickHandler}
/>);
userEvent.click(container.getElementsByClassName('suggestion-item')[0]);
expect(mockData.program.suggestionItemHandler).toHaveBeenCalledWith(mockData.program.hit);
expect(mockData.optimizelySuggestionClickHandler.mock.calls.length).toBe(1);
});
});
Loading
Loading