Skip to content

Commit

Permalink
chore: modifying edx course filter for course type (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sheehan-edx authored Oct 18, 2022
1 parent 5e2f61f commit 6dbdf00
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/components/catalogNoResultsDeck/CatalogNoResultsDeck.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PropTypes from 'prop-types';
import {
CONTENT_TYPE_COURSE,
CONTENT_TYPE_PROGRAM,
EDX_COURSES_COURSE_TYPES,
NO_RESULTS_DECK_ITEM_COUNT,
NO_RESULTS_PAGE_SIZE,
NO_RESULTS_PAGE_ITEM_COUNT,
Expand All @@ -23,6 +24,7 @@ function CatalogNoResultsDeck({
columns,
renderCardComponent,
contentType,
courseType,
}) {
const [defaultData, setDefaultData] = useState([]);
const [apiError, setApiError] = useState(false);
Expand All @@ -37,14 +39,18 @@ function CatalogNoResultsDeck({

useEffect(() => {
const defaultCoursesRefinements = { enterprise_catalog_query_titles: selectedCatalog, content_type: contentType };
if (contentType === CONTENT_TYPE_COURSE) {
// if a course type is not specified, default to edx course content
defaultCoursesRefinements.course_type = courseType !== null ? [courseType] : EDX_COURSES_COURSE_TYPES;
}
EnterpriseCatalogApiService.fetchDefaultCoursesInCatalogWithFacets(defaultCoursesRefinements).then(response => {
setDefaultData(response.default_content || []);
setApiError(false);
}).catch(err => {
setApiError(true);
logError(err);
});
}, [selectedCatalog, contentType]);
}, [selectedCatalog, contentType, courseType]);

let defaultDeckTitle;
let alertText;
Expand Down Expand Up @@ -100,10 +106,12 @@ CatalogNoResultsDeck.defaultProps = {
renderCardComponent: () => {},
columns: [],
contentType: '',
courseType: null,
};

CatalogNoResultsDeck.propTypes = {
contentType: PropTypes.string,
courseType: PropTypes.string,
intl: intlShape.isRequired,
setCardView: PropTypes.func,
renderCardComponent: PropTypes.func,
Expand Down
4 changes: 4 additions & 0 deletions src/components/catalogSearchResults/CatalogSearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function BaseCatalogSearchResults({
error,
paginationComponent: PaginationComponent,
contentType,
courseType,
setNoCourses,
setNoPrograms,
preview,
Expand Down Expand Up @@ -296,6 +297,7 @@ export function BaseCatalogSearchResults({
columns={contentType === CONTENT_TYPE_COURSE ? courseColumns : programColumns}
renderCardComponent={renderCardComponent}
contentType={contentType}
courseType={courseType}
/>
)}
{(searchResults?.nbHits !== 0) && (
Expand Down Expand Up @@ -344,6 +346,7 @@ BaseCatalogSearchResults.defaultProps = {
preview: false,
setNoCourses: () => {},
setNoPrograms: () => {},
courseType: null,
};

BaseCatalogSearchResults.propTypes = {
Expand Down Expand Up @@ -372,6 +375,7 @@ BaseCatalogSearchResults.propTypes = {
// eslint-disable-next-line react/no-unused-prop-types
row: PropTypes.string,
contentType: PropTypes.string.isRequired,
courseType: PropTypes.string,
preview: PropTypes.bool,
setNoCourses: PropTypes.func,
setNoPrograms: PropTypes.func,
Expand Down
41 changes: 27 additions & 14 deletions src/components/catalogs/CatalogSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { useAlgoliaIndex } from './data/hooks';
import PageWrapper from '../PageWrapper';

import {
CONTENT_TYPE_COURSE, CONTENT_TYPE_PROGRAM, NUM_RESULTS_COURSE, NUM_RESULTS_PROGRAM, NUM_RESULTS_PER_PAGE,
CONTENT_TYPE_COURSE,
CONTENT_TYPE_PROGRAM,
EXECUTIVE_EDUCATION_2U_COURSE_TYPE,
NUM_RESULTS_COURSE,
NUM_RESULTS_PROGRAM,
NUM_RESULTS_PER_PAGE,
} from '../../constants';
import CatalogSearchResults from '../catalogSearchResults/CatalogSearchResults';
import CatalogInfoModal from '../catalogInfoModal/CatalogInfoModal';
Expand All @@ -19,7 +24,7 @@ import messages from '../catalogSearchResults/CatalogSearchResults.messages';
function CatalogSearch(intl) {
const { refinements: { content_type: contentType } } = useContext(SearchContext);
const { algoliaIndexName, searchClient } = useAlgoliaIndex();
const courseFilter = `content_type:${CONTENT_TYPE_COURSE}`;
const courseFilter = `content_type:${CONTENT_TYPE_COURSE} AND NOT course_type:${EXECUTIVE_EDUCATION_2U_COURSE_TYPE}`;
const programFilter = `content_type:${CONTENT_TYPE_PROGRAM}`;
const combinedFilter = `content_type:${CONTENT_TYPE_COURSE} OR content_type:${CONTENT_TYPE_PROGRAM}`;
const [noCourseResults, setNoCourseResults] = useState(false);
Expand Down Expand Up @@ -110,7 +115,11 @@ function CatalogSearch(intl) {
filters={courseFilter}
facetingAfterDistinct
/>
<CatalogSearchResults preview contentType={CONTENT_TYPE_COURSE} setNoCourses={setNoCourseResults} />
<CatalogSearchResults
preview
contentType={CONTENT_TYPE_COURSE}
setNoCourses={setNoCourseResults}
/>
</Index>
<Index indexName={algoliaIndexName} indexId="search-program">
<Configure
Expand Down Expand Up @@ -146,7 +155,11 @@ function CatalogSearch(intl) {
filters={courseFilter}
facetingAfterDistinct
/>
<CatalogSearchResults preview contentType={CONTENT_TYPE_COURSE} setNoCourses={setNoCourseResults} />
<CatalogSearchResults
preview
contentType={CONTENT_TYPE_COURSE}
setNoCourses={setNoCourseResults}
/>
</Index>
</>
)}
Expand All @@ -160,17 +173,17 @@ function CatalogSearch(intl) {
<CatalogSearchResults preview={false} contentType={CONTENT_TYPE_PROGRAM} />
</Index>
)}
{(specifiedContentType === CONTENT_TYPE_COURSE) && (
<Index indexName={algoliaIndexName} indexId="search-courses">
<Configure
hitsPerPage={NUM_RESULTS_PER_PAGE}
filters={courseFilter}
facetingAfterDistinct
/>
<CatalogSearchResults preview={false} contentType={CONTENT_TYPE_COURSE} />
</Index>
)}
</>
{(specifiedContentType === CONTENT_TYPE_COURSE) && (
<Index indexName={algoliaIndexName} indexId="search-courses">
<Configure
hitsPerPage={NUM_RESULTS_PER_PAGE}
filters={courseFilter}
facetingAfterDistinct
/>
<CatalogSearchResults preview={false} contentType={CONTENT_TYPE_COURSE} />
</Index>
)}
</InstantSearch>
</section>
</PageWrapper>
Expand Down
9 changes: 9 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export const PROGRAM_TITLE = 'Programs';
export const NO_RESULTS_DECK_ITEM_COUNT = 4;
export const NO_RESULTS_PAGE_ITEM_COUNT = 1;
export const NO_RESULTS_PAGE_SIZE = 4;
const AUDIT_COURSE_TYPE = 'audit';
const VERIFIED_AUDIT_COURSE_TYPE = 'verified-audit';
const PROFESSIONAL_COURSE_TYPE = 'professional';
const CREDIT_VERIFIED_AUDIT_COURSE_TYPE = 'credit-verified-audit';
export const EXECUTIVE_EDUCATION_2U_COURSE_TYPE = 'executive-education-2u';
export const TWOU_COURSE_TYPES = [EXECUTIVE_EDUCATION_2U_COURSE_TYPE];
export const EDX_COURSES_COURSE_TYPES = [
AUDIT_COURSE_TYPE, VERIFIED_AUDIT_COURSE_TYPE, PROFESSIONAL_COURSE_TYPE, CREDIT_VERIFIED_AUDIT_COURSE_TYPE,
];

const OVERRIDE_FACET_FILTERS = [];
if (features.PROGRAM_TYPE_FACET) {
Expand Down
2 changes: 1 addition & 1 deletion src/data/services/EnterpriseCatalogAPIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EnterpriseCatalogApiService {
}

static fetchDefaultCoursesInCatalog(options) {
const enterpriseListUrl = `${EnterpriseCatalogApiService.enterpriseCatalogServiceApiUrl}/default_course_set/?${qs.stringify(options)}`;
const enterpriseListUrl = `${EnterpriseCatalogApiService.enterpriseCatalogServiceApiUrl}/default_course_set?${qs.stringify(options)}`;
return EnterpriseCatalogApiService.apiClient().get(enterpriseListUrl);
}

Expand Down

0 comments on commit 6dbdf00

Please sign in to comment.