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

Search page cleanup #675

Merged
merged 11 commits into from
Mar 27, 2024
4 changes: 4 additions & 0 deletions frontends/api/src/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
LearningResourcesApi,
LearningpathsApi,
UserlistsApi,
OfferorsApi,
TopicsApi,
ArticlesApi,
ProgramLettersApi,
Expand Down Expand Up @@ -33,6 +34,8 @@ const learningpathsApi = new LearningpathsApi(

const userListsApi = new UserlistsApi(undefined, BASE_PATH, axiosInstance)

const offerorsApi = new OfferorsApi(undefined, BASE_PATH, axiosInstance)

const topicsApi = new TopicsApi(undefined, BASE_PATH, axiosInstance)

const articlesApi = new ArticlesApi(undefined, BASE_PATH, axiosInstance)
Expand All @@ -52,6 +55,7 @@ export {
userListsApi,
topicsApi,
articlesApi,
offerorsApi,
programLettersApi,
learningResourcesSearchApi,
fieldsApi,
Expand Down
12 changes: 12 additions & 0 deletions frontends/api/src/hooks/learningResources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
LearningResourcesSearchApiLearningResourcesSearchRetrieveRequest as LRSearchRequest,
UserlistsApiUserlistsListRequest as ULListRequest,
UserlistsApiUserlistsItemsListRequest as ULItemsListRequest,
OfferorsApiOfferorsListRequest,
} from "../../generated/v1"
import learningResources, { invalidateResourceQueries } from "./keyFactory"

Expand Down Expand Up @@ -229,6 +230,16 @@ const useInfiniteUserListItems = (
})
}

const useOfferorsList = (
params: OfferorsApiOfferorsListRequest = {},
opts: Pick<UseQueryOptions, "enabled"> = {},
) => {
return useQuery({
...learningResources.offerors(params),
...opts,
})
}

export {
useLearningResourcesList,
useLearningResourcesDetail,
Expand All @@ -245,4 +256,5 @@ export {
useLearningResourcesSearch,
useUserListList,
useInfiniteUserListItems,
useOfferorsList,
}
8 changes: 8 additions & 0 deletions frontends/api/src/hooks/learningResources/keyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
learningResourcesSearchApi,
topicsApi,
userListsApi,
offerorsApi,
} from "../../clients"
import axiosInstance from "../../axios"
import type {
Expand All @@ -20,6 +21,7 @@ import type {
UserlistsApiUserlistsListRequest as ULListRequest,
PaginatedUserListRelationshipList,
UserList,
OfferorsApiOfferorsListRequest,
} from "../../generated/v1"
import { createQueryKeys } from "@lukemorales/query-key-factory"

Expand Down Expand Up @@ -113,6 +115,12 @@ const learningResources = createQueryKeys("learningResources", {
}),
},
},
offerors: (params: OfferorsApiOfferorsListRequest) => {
return {
queryKey: [params],
queryFn: () => offerorsApi.offerorsList(params).then((res) => res.data),
}
},
})

const learningPathHasResource =
Expand Down
2 changes: 2 additions & 0 deletions frontends/api/src/test-utils/factories/learningResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const learningResourceOfferor: Factory<LearningResourceOfferor> = (
...overrides,
}
}
const learningResourceOfferors = makePaginatedFactory(learningResourceOfferor)

const learningResourceRun: Factory<LearningResourceRun> = (overrides = {}) => {
const start = overrides.start_date
Expand Down Expand Up @@ -404,6 +405,7 @@ export {
learningResourceImage as image,
learningResourceDepartment as department,
learningResourceTopics as topics,
learningResourceOfferors as offerors,
learningPath,
learningPaths,
microRelationship,
Expand Down
7 changes: 7 additions & 0 deletions frontends/api/src/test-utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
LearningpathsApi,
ArticlesApi,
UserlistsApi,
OfferorsApi,
} from "../generated/v1"
import type { BaseAPI } from "../generated/v1/base"

Expand All @@ -36,6 +37,11 @@ const learningResources = {
`/api/v1/learning_resources/${params.id}/`,
}

const offerors = {
list: (params?: Params<OfferorsApi, "offerorsList">) =>
`/api/v1/offerors/${query(params)}`,
}

const topics = {
list: (params?: Params<TopicsApi, "topicsList">) =>
`/api/v1/topics/${query(params)}`,
Expand Down Expand Up @@ -107,4 +113,5 @@ export {
programLetters,
fields,
widgetLists,
offerors,
}
2 changes: 1 addition & 1 deletion frontends/mit-open/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@ebay/nice-modal-react": "^1.2.13",
"@mitodl/course-search-utils": "^3.0.3",
"@mitodl/course-search-utils": "https://github.com/mitodl/course-search-utils.git#baafa5995878c4c889799d86ec490674b522c405",
"@mui/icons-material": "^5.14.19",
"@sentry/react": "^7.57.0",
"@tanstack/react-query": "^4.36.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { styled } from "ol-components"

const SPACER = "1.5em"

const CardRowList = styled.ul<{ disabled?: boolean }>`
const CardRowList = styled.ul<{ disabled?: boolean; marginTop?: boolean }>`
padding-left: 0;
margin-left: 0;
margin-right: 0;
${({ marginTop }) => (marginTop ? "" : "margin-top: 0;")}

> li {
list-style: none;
Expand Down

This file was deleted.

16 changes: 7 additions & 9 deletions frontends/mit-open/src/pages/SearchPage/ResourceTypeTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react"
import { Tab, TabContext, TabList, TabPanel } from "ol-components"
import type { ResourceTypeEnum, LearningResourceSearchResponse } from "api"
import type { UseSearchQueryParamsResult } from "@mitodl/course-search-utils"

type TabConfig = {
resource_type: ResourceTypeEnum
Expand Down Expand Up @@ -42,15 +41,17 @@ const ResourceTypesTabContext: React.FC<{
type ResourceTypeTabsProps = {
aggregations?: Aggregations
tabs: TabConfig[]
setFacetActive: UseSearchQueryParamsResult["setFacetActive"]
clearFacet: UseSearchQueryParamsResult["clearFacet"]
patchParams: ({
resource_type,
}: {
resource_type: ResourceTypeEnum[]
}) => void
onTabChange?: (tab: ResourceTypeEnum | "all") => void
}
const ResourceTypeTabList: React.FC<ResourceTypeTabsProps> = ({
tabs,
aggregations,
setFacetActive,
clearFacet,
patchParams,
onTabChange,
}) => {
const counts = resourceTypeCounts(aggregations)
Expand All @@ -60,10 +61,7 @@ const ResourceTypeTabList: React.FC<ResourceTypeTabsProps> = ({
return (
<TabList
onChange={(_e, value) => {
clearFacet("resource_type")
if (value !== "all") {
setFacetActive("resource_type", value, true)
}
patchParams({ resource_type: value === "all" ? [] : [value] })
onTabChange?.(value)
}}
>
Expand Down
Loading
Loading