Skip to content

Commit

Permalink
update search
Browse files Browse the repository at this point in the history
  • Loading branch information
abeglova committed Feb 14, 2024
1 parent 2999c21 commit 26ab8d1
Show file tree
Hide file tree
Showing 26 changed files with 726 additions and 1,676 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:
test-e2e:
env:
OCW_STUDIO_BASE_URL: ${{ secrets.OCW_STUDIO_BASE_URL }}
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
COURSE_SEARCH_API_URL: ${{ secrets.COURSE_SEARCH_API_URL }}
CONTENT_FILE_SEARCH_API_URL: ${{ secrets.CONTENT_FILE_SEARCH_API_URL }}
STATIC_API_BASE_URL: ${{ secrets.STATIC_API_BASE_URL }}
RESOURCE_BASE_URL: ${{ secrets.RESOURCE_BASE_URL }}
COURSE_HUGO_CONFIG_PATH: "$GITHUB_WORKSPACE/ocw-hugo-projects/ocw-course-v2/config.yaml"
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ jobs:
run: (cd ../ocw-www; hugo --config $GITHUB_WORKSPACE/ocw-hugo-projects/ocw-www/config.yaml --themesDir ../ocw-hugo-themes)
env:
OCW_STUDIO_BASE_URL: ${{ secrets.OCW_STUDIO_BASE_URL }}
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
COURSE_SEARCH_API_URL: ${{ secrets.COURSE_SEARCH_API_URL }}
CONTENT_FILE_SEARCH_API_URL: ${{ secrets.CONTENT_FILE_SEARCH_API_URL }}
OCW_COURSE_STARTER_SLUG: ${{ secrets.OCW_COURSE_STARTER_SLUG }}
STATIC_API_BASE_URL: ${{ secrets.STATIC_API_BASE_URL }}
RESOURCE_BASE_URL: ${{ secrets.RESOURCE_BASE_URL }}
Expand All @@ -63,7 +64,8 @@ jobs:
run: (cd ../ocw-course; hugo --config $GITHUB_WORKSPACE/ocw-hugo-projects/ocw-course-v2/config.yaml --destination public-v2 --themesDir ../ocw-hugo-themes)
env:
OCW_STUDIO_BASE_URL: ${{ secrets.OCW_STUDIO_BASE_URL }}
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
COURSE_SEARCH_API_URL: ${{ secrets.COURSE_SEARCH_API_URL }}
CONTENT_FILE_SEARCH_API_URL: ${{ secrets.CONTENT_FILE_SEARCH_API_URL }}
OCW_COURSE_STARTER_SLUG: ${{ secrets.OCW_COURSE_STARTER_SLUG }}
STATIC_API_BASE_URL: ${{ secrets.STATIC_API_BASE_URL }}
RESOURCE_BASE_URL: ${{ secrets.RESOURCE_BASE_URL }}
Expand Down
3 changes: 2 additions & 1 deletion base-theme/assets/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ declare global {
declare let RELEASE_VERSION: string
namespace NodeJS {
interface ProcessEnv {
SEARCH_API_URL: string
COURSE_SEARCH_API_URL: string
CONTENT_FILE_SEARCH_API_URL: string
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ const envSchema = {
desc: "Base URL with which to prefix resource paths in Hugo's output.",
devDefault: "https://live-qa.ocw.mit.edu/"
}),
SEARCH_API_URL: envalid.url({
desc: "The URL of the search API.",
devDefault: "https://discussions-rc.odl.mit.edu/api/v0/search/"
COURSE_SEARCH_API_URL: envalid.url({
desc: "The URL of the learning resource search API.",
devDefault:
"https://mit-open-rc.odl.mit.edu/api/v1/learning_resources_search/"
}),
CONTENT_FILE_SEARCH_API_URL: envalid.url({
desc: "The URL of the contentfile search API.",
devDefault: "https://mit-open-rc.odl.mit.edu/api/v1/content_file_search/"
}),
SENTRY_ENV: envalid.str({
desc: "The environment for Sentry",
Expand Down
5 changes: 4 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const config: Config.InitialOptions = {
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: ["/node_modules/", "tests-e2e/"],
preset: "ts-jest",
testEnvironment: "jsdom"
testEnvironment: "jsdom",
moduleNameMapper: {
axios: "axios/dist/node/axios.cjs"
}
}

export default config
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"browserslist": "> 0.25%, not dead",
"dependencies": {
"@mitodl/course-search-utils": "^2.3.0",
"@mitodl/course-search-utils": "^3.0.0",
"@sentry/browser": "^5.19.0",
"array-flat-polyfill": "^1.0.1",
"bootstrap": "^4.3.1",
Expand Down Expand Up @@ -70,7 +70,6 @@
"videojs-youtube": "^2.6.1"
},
"devDependencies": {
"@mitodl/ocw-to-hugo": "1.36.0",
"@playwright/test": "^1.40.0",
"@swc/core": "^1.3.14",
"@swc/helpers": "^0.4.12",
Expand Down
167 changes: 20 additions & 147 deletions www/assets/js/LearningResources.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable camelcase */
import { LearningResourceType, Facets } from "@mitodl/course-search-utils"
import { Facets } from "@mitodl/course-search-utils"
import {
OCW_PLATFORM,
COURSE_ARCHIVED,
COURSE_CURRENT,
PROFESSIONAL,
Expand All @@ -19,30 +18,6 @@ type Audience =

type Certification = [] | [typeof CERTIFICATE]

export interface CourseResult {
id: number
course_id: string
coursenum: string
title: string
url: string
image_src: string
short_description: string
department: string
platform: typeof OCW_PLATFORM
offered_by: [typeof OCW_PLATFORM]
topics: string[]
object_type: LearningResourceType.Course
runs: CourseRun[]
audience: Audience
certification: Certification
course_feature_tags: string[]
content_title: undefined
run_title: undefined
run_slug: undefined
content_type: undefined
short_url: undefined
}

interface Instructor {
first_name: string
last_name: string
Expand Down Expand Up @@ -144,135 +119,33 @@ export interface CourseRun {
short_url: undefined
}

export interface VideoResult {
id: number
video_id: string
title: string
url: string
image_src: string
short_description: string
topics: string[]
object_type: LearningResourceType.Video
offered_by: [typeof OCW_PLATFORM]
runs: any[]
audience: Audience
certification: Certification
department: undefined
content_title: undefined
run_title: undefined
run_slug: undefined
coursenum: undefined
content_type: undefined
short_url: undefined
course_id: undefined
course_feature_tags: undefined
}

export interface PodcastResult {
id: number
podcast_id: string
title: string
url: string
image_src: string
short_description: string
topics: string[]
object_type: LearningResourceType.Podcast
offered_by: [typeof OCW_PLATFORM]
runs: any[]
audience: Audience
certification: Certification
department: undefined
content_title: undefined
run_title: undefined
run_slug: undefined
coursenum: undefined
content_type: undefined
short_url: undefined
course_id: undefined
course_feature_tags: undefined
}

export interface PodcastEpisodeResult {
id: number
podcast_id: string
title: string
url: string
image_src: string
short_description: string
topics: string[]
object_type: LearningResourceType.PodcastEpisode
offered_by: [typeof OCW_PLATFORM]
runs: any[]
series_title: string
audience: Audience
certification: Certification
department: undefined
content_title: undefined
run_title: undefined
run_slug: undefined
coursenum: undefined
content_type: undefined
short_url: undefined
course_id: undefined
course_feature_tags: undefined
}

export interface ResourceFileResult {
id: number
course_id: string
coursenum: string
title: string
url: string
image_src: string
topics: string[]
object_type: LearningResourceType.ResourceFile
content_title: string
run_title: string
run_slug: string
content_type: ContentType
short_url: string
runs: undefined
audience: undefined
certification: undefined
department: undefined
short_description: string
course_feature_tags: undefined
}

export type LearningResourceResult =
| CourseResult
| VideoResult
| PodcastResult
| PodcastEpisodeResult
| ResourceFileResult

interface Topic {
name: string
}

export interface LearningResource {
id: number | string
title: string
id?: number | string
title: string | null
image_src: string
object_type: LearningResourceType
platform: string | null
object_type?: string
platform?: string | null
topics: Topic[]
runs: CourseRun[]
level: Level[] | null
runs?: CourseRun[]
level?: Level[] | null
instructors: string[]
department: string | undefined
audience: Audience | undefined
certification: Certification | undefined
content_title: string | undefined
run_title: string | null
run_slug: string | null
content_type: ContentType | null
url: string | null
short_url: string | null
course_id: string | null
coursenum: string | null
description: string | null
course_feature_tags: string[]
department?: string | undefined
audience?: Audience | undefined
certification?: Certification | undefined
content_title?: string | undefined | null
run_title?: string | null
run_slug?: string | null
content_type?: ContentType | null
url?: string | null
short_url?: string | null
course_id?: string | null
coursenum?: string | null
description?: string | null
course_feature_tags?: string[]
}

export type FacetKey = keyof Facets
Expand Down
9 changes: 3 additions & 6 deletions www/assets/js/components/CourseListRow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { mount } from "enzyme"
import React from "react"
import { LearningResourceType } from "@mitodl/course-search-utils"

import { makeLearningResourceResult } from "../factories/search"
import { searchResultToLearningResource } from "../lib/search"
import { makeCourseSearchResult } from "../factories/search"
import { courseSearchResultToLearningResource } from "../lib/search"
import CourseListRow from "./CourseListRow"

function setup() {
const course = searchResultToLearningResource(
makeLearningResourceResult(LearningResourceType.Course)
)
const course = courseSearchResultToLearningResource(makeCourseSearchResult())

const wrapper = mount(<CourseListRow course={course} />)

Expand Down
35 changes: 19 additions & 16 deletions www/assets/js/components/Facet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState } from "react"
import { contains } from "ramda"
import has from "lodash.has"

import SearchFacetItem from "./SearchFacetItem"
import { Aggregation } from "@mitodl/course-search-utils"
Expand All @@ -15,18 +14,26 @@ interface Props {
currentlySelected: string[]
onUpdate: React.ChangeEventHandler<HTMLInputElement>
expandedOnLoad: boolean
labelFunction?: ((value: string) => string | null) | null
}

function SearchFacet(props: Props) {
const { name, title, results, currentlySelected, onUpdate, expandedOnLoad } =
props
const {
name,
title,
results,
currentlySelected,
onUpdate,
expandedOnLoad,
labelFunction
} = props

const [showFacetList, setShowFacetList] = useState(expandedOnLoad)
const [showAllFacets, setShowAllFacets] = useState(false)

const titleLineIcon = showFacetList ? "arrow_drop_down" : "arrow_right"

return results && results.buckets && results.buckets.length === 0 ? null : (
return results && results.length === 0 ? null : (
<div className="facets mb-3">
<button
className="filter-section-button pl-3 py-2 pr-0"
Expand All @@ -41,22 +48,25 @@ function SearchFacet(props: Props) {
</button>
{showFacetList ? (
<React.Fragment>
{results && results.buckets ?
results.buckets.map((facet, i) =>
{results ?
results.map((facet, i) =>
showAllFacets ||
i < MAX_DISPLAY_COUNT ||
results.buckets.length < FACET_COLLAPSE_THRESHOLD ? (
results.length < FACET_COLLAPSE_THRESHOLD ? (
<SearchFacetItem
key={i}
facet={facet}
isChecked={contains(facet.key, currentlySelected || [])}
onUpdate={onUpdate}
name={name}
displayKey={
labelFunction ? labelFunction(facet.key) : facet.key
}
/>
) : null
) :
null}
{results && results.buckets.length >= FACET_COLLAPSE_THRESHOLD ? (
{results && results.length >= FACET_COLLAPSE_THRESHOLD ? (
<button
className="facet-more-less-button"
onClick={() => setShowAllFacets(!showAllFacets)}
Expand All @@ -71,11 +81,4 @@ function SearchFacet(props: Props) {
)
}

const propsAreEqual = (_prevProps: Props, nextProps: Props) => {
// results.buckets is null while the search request is in-flight
// we want to defer rendering in that case because it will cause
// all the facets to briefly disappear before reappearing
return !has(nextProps.results, "buckets")
}

export default React.memo(SearchFacet, propsAreEqual)
export default SearchFacet
Loading

0 comments on commit 26ab8d1

Please sign in to comment.