Skip to content

Commit 3197419

Browse files
authored
Revert "Server render search results (search and channel pages) (#1833)"
This reverts commit c92adf0.
1 parent c92adf0 commit 3197419

File tree

16 files changed

+245
-517
lines changed

16 files changed

+245
-517
lines changed

frontends/api/src/ssr/prefetch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export const prefetch = async (
1212
queryClient = queryClient || new QueryClient()
1313

1414
await Promise.all(
15-
queries
16-
.filter(Boolean)
17-
.map((query) => queryClient.prefetchQuery(query as Query)),
15+
queries.map((query) => queryClient.prefetchQuery(query as Query)),
1816
)
1917

2018
return { dehydratedState: dehydrate(queryClient), queryClient }

frontends/main/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": {
1313
"@ebay/nice-modal-react": "^1.2.13",
1414
"@emotion/cache": "^11.13.1",
15-
"@mitodl/course-search-utils": "git://github.com/mitodl/course-search-utils.git#jk/6035-export-validation",
15+
"@mitodl/course-search-utils": "^3.3.1",
1616
"@next/bundle-analyzer": "^14.2.15",
1717
"@remixicon/react": "^4.2.0",
1818
"@sentry/nextjs": "^8.36.0",

frontends/main/src/app-pages/ChannelPage/ChannelPage.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import { useParams } from "next/navigation"
66
import { ChannelPageTemplate } from "./ChannelPageTemplate"
77
import { useChannelDetail } from "api/hooks/channels"
88
import ChannelSearch from "./ChannelSearch"
9+
import type {
10+
Facets,
11+
FacetKey,
12+
BooleanFacets,
13+
} from "@mitodl/course-search-utils"
914
import { ChannelTypeEnum } from "api/v0"
1015
import { Typography } from "ol-components"
11-
import { getConstantSearchParams } from "./searchRequests"
1216

1317
type RouteParams = {
1418
channelType: ChannelTypeEnum
@@ -18,11 +22,20 @@ type RouteParams = {
1822
const ChannelPage: React.FC = () => {
1923
const { channelType, name } = useParams<RouteParams>()
2024
const channelQuery = useChannelDetail(String(channelType), String(name))
25+
const searchParams: Facets & BooleanFacets = {}
2126
const publicDescription = channelQuery.data?.public_description
2227

23-
const channelSearchFilter = channelQuery.data?.search_filter
24-
25-
const searchParams = getConstantSearchParams(channelSearchFilter)
28+
if (channelQuery.data?.search_filter) {
29+
const urlParams = new URLSearchParams(channelQuery.data.search_filter)
30+
for (const [key, value] of urlParams.entries()) {
31+
const paramEntry = searchParams[key as FacetKey]
32+
if (paramEntry !== undefined) {
33+
paramEntry.push(value)
34+
} else {
35+
searchParams[key as FacetKey] = [value]
36+
}
37+
}
38+
}
2639

2740
return (
2841
name &&
@@ -33,9 +46,9 @@ const ChannelPage: React.FC = () => {
3346
{publicDescription && (
3447
<Typography variant="body1">{publicDescription}</Typography>
3548
)}
36-
{channelSearchFilter && (
49+
{channelQuery.data?.search_filter && (
3750
<ChannelSearch
38-
channelTitle={channelQuery.data!.title}
51+
channelTitle={channelQuery.data.title}
3952
constantSearchParams={searchParams}
4053
channelType={channelType}
4154
/>

frontends/main/src/app-pages/ChannelPage/ChannelSearch.tsx

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import React, { useCallback, useMemo } from "react"
2+
import { LearningResourceOfferor } from "api"
23
import { ChannelTypeEnum } from "api/v0"
34
import { useOfferorsList } from "api/hooks/learningResources"
4-
import { useResourceSearchParams } from "@mitodl/course-search-utils"
5-
import type { Facets, BooleanFacets } from "@mitodl/course-search-utils"
5+
6+
import {
7+
useResourceSearchParams,
8+
UseResourceSearchParamsProps,
9+
} from "@mitodl/course-search-utils"
10+
import type {
11+
Facets,
12+
BooleanFacets,
13+
FacetManifest,
14+
} from "@mitodl/course-search-utils"
615
import { useSearchParams } from "@mitodl/course-search-utils/next"
716
import SearchDisplay from "@/page-components/SearchDisplay/SearchDisplay"
817
import { Container, styled, VisuallyHidden } from "ol-components"
918
import { SearchField } from "@/page-components/SearchField/SearchField"
10-
import { getFacets } from "./searchRequests"
19+
20+
import { getFacetManifest } from "@/app-pages/SearchPage/SearchPage"
1121

1222
import _ from "lodash"
1323

@@ -25,6 +35,34 @@ const StyledSearchField = styled(SearchField)({
2535
width: "624px",
2636
})
2737

38+
const FACETS_BY_CHANNEL_TYPE: Record<ChannelTypeEnum, string[]> = {
39+
[ChannelTypeEnum.Topic]: [
40+
"free",
41+
"resource_type",
42+
"certification_type",
43+
"delivery",
44+
"offered_by",
45+
"department",
46+
],
47+
[ChannelTypeEnum.Department]: [
48+
"free",
49+
"resource_type",
50+
"certification_type",
51+
"topic",
52+
"delivery",
53+
"offered_by",
54+
],
55+
[ChannelTypeEnum.Unit]: [
56+
"free",
57+
"resource_type",
58+
"topic",
59+
"certification_type",
60+
"delivery",
61+
"department",
62+
],
63+
[ChannelTypeEnum.Pathway]: [],
64+
}
65+
2866
const SHOW_PROFESSIONAL_TOGGLE_BY_CHANNEL_TYPE: Record<
2967
ChannelTypeEnum,
3068
boolean
@@ -35,6 +73,24 @@ const SHOW_PROFESSIONAL_TOGGLE_BY_CHANNEL_TYPE: Record<
3573
[ChannelTypeEnum.Pathway]: false,
3674
}
3775

76+
const getFacetManifestForChannelType = (
77+
channelType: ChannelTypeEnum,
78+
offerors: Record<string, LearningResourceOfferor>,
79+
constantSearchParams: Facets,
80+
resourceCategory: string | null,
81+
): FacetManifest => {
82+
const facets = FACETS_BY_CHANNEL_TYPE[channelType] || []
83+
return getFacetManifest(offerors, resourceCategory)
84+
.filter(
85+
(facetSetting) =>
86+
!Object.keys(constantSearchParams).includes(facetSetting.name) &&
87+
facets.includes(facetSetting.name),
88+
)
89+
.sort(
90+
(a, b) => facets.indexOf(a.name) - facets.indexOf(b.name),
91+
) as FacetManifest
92+
}
93+
3894
interface ChannelSearchProps {
3995
constantSearchParams: Facets & BooleanFacets
4096
channelType: ChannelTypeEnum
@@ -54,9 +110,14 @@ const ChannelSearch: React.FC<ChannelSearchProps> = ({
54110
const [searchParams, setSearchParams] = useSearchParams()
55111
const resourceCategory = searchParams.get("resource_category")
56112

57-
const { facetNames, facetManifest } = useMemo(
113+
const facetManifest = useMemo(
58114
() =>
59-
getFacets(channelType, offerors, constantSearchParams, resourceCategory),
115+
getFacetManifestForChannelType(
116+
channelType,
117+
offerors,
118+
constantSearchParams,
119+
resourceCategory,
120+
),
60121
[offerors, channelType, constantSearchParams, resourceCategory],
61122
)
62123

@@ -79,6 +140,18 @@ const ChannelSearch: React.FC<ChannelSearchProps> = ({
79140
setPage(1)
80141
}, [setPage])
81142

143+
const facetNames = Array.from(
144+
new Set(
145+
facetManifest.flatMap((facet) => {
146+
if (facet.type === "group") {
147+
return facet.facets.map((subfacet) => subfacet.name)
148+
} else {
149+
return [facet.name]
150+
}
151+
}),
152+
),
153+
) as UseResourceSearchParamsProps["facets"]
154+
82155
const {
83156
hasFacets,
84157
params,

frontends/main/src/app-pages/ChannelPage/searchRequests.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)