Skip to content

Commit

Permalink
certification type (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeglova authored Jun 6, 2024
1 parent 20b592b commit e1eb695
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://github.com/mitodl/course-search-utils#readme",
"dependencies": {
"@mitodl/open-api-axios": "^2024.5.6",
"@mitodl/open-api-axios": "^2024.6.4",
"axios": "^1.6.7",
"fuse.js": "^7.0.0",
"query-string": "^6.13.1",
Expand Down
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ export const LEVELS = {
introductory: "Introductory"
}

export const CERTIFICATION_TYPES = {
none: "No Certificate",
completion: "Certificate of Completion",
micromasters: "MicroMasters Credential",
professional: "Professional Certificate"
}

export const BOOLEAN_FACET_NAMES = ["certification", "professional"]
12 changes: 11 additions & 1 deletion src/facet_display/FacetDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
BooleanFacets,
BucketWithLabel
} from "./types"
import { LEVELS, DEPARTMENTS } from "../constants"
import { LEVELS, DEPARTMENTS, CERTIFICATION_TYPES } from "../constants"
import MultiFacetGroup from "./MultiFacetGroup"

interface FacetDisplayProps {
Expand All @@ -27,6 +27,16 @@ interface FacetDisplayProps {
onFacetChange: (name: string, value: string, isEnabled: boolean) => void
}

export const getCertificationTypeName = (certificationType: string): string => {
if (certificationType in CERTIFICATION_TYPES) {
return CERTIFICATION_TYPES[
certificationType as keyof typeof CERTIFICATION_TYPES
]
} else {
return certificationType
}
}

export const getDepartmentName = (departmentId: string): string => {
if (departmentId in DEPARTMENTS) {
return DEPARTMENTS[departmentId as keyof typeof DEPARTMENTS]
Expand Down
1 change: 1 addition & 0 deletions src/facet_display/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface Facets {
resource_type?: string[]
content_feature_type?: string[]
learning_format?: string[]
certification_type?: string[]
}

export interface BooleanFacets {
Expand Down
36 changes: 19 additions & 17 deletions src/hooks/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
LearningResourcesSearchRetrieveSortbyEnum: SortByEnum,
LearningResourcesSearchRetrieveAggregationsEnum: AggregationsEnum,
LearningResourcesSearchRetrieveLearningFormatEnum: LearningFormatEnum,
CertificationTypeEnum,
ContentFileSearchRetrieveSortbyEnum,
ContentFileSearchRetrieveAggregationsEnum
} = v1
Expand Down Expand Up @@ -39,23 +40,24 @@ type QueryParamValidators<ReqParams> = {
}

const resourceSearchValidators: QueryParamValidators<ResourceSearchRequest> = {
resource_type: withinEnum(Object.values(ResourceTypeEnum)),
department: withinEnum(Object.values(DepartmentEnum)),
level: withinEnum(Object.values(LevelEnum)),
platform: withinEnum(Object.values(PlatformEnum)),
offered_by: withinEnum(Object.values(OfferedByEnum)),
sortby: values => withinEnum(Object.values(SortByEnum))(values)[0],
q: first,
topic: identity,
certification: firstBoolean,
professional: firstBoolean,
aggregations: withinEnum(Object.values(AggregationsEnum)),
course_feature: identity,
limit: firstNumber,
offset: firstNumber,
id: numbers,
free: firstBoolean,
learning_format: withinEnum(Object.values(LearningFormatEnum))
resource_type: withinEnum(Object.values(ResourceTypeEnum)),
department: withinEnum(Object.values(DepartmentEnum)),
level: withinEnum(Object.values(LevelEnum)),
platform: withinEnum(Object.values(PlatformEnum)),
offered_by: withinEnum(Object.values(OfferedByEnum)),
sortby: values => withinEnum(Object.values(SortByEnum))(values)[0],
q: first,
topic: identity,
certification: firstBoolean,
professional: firstBoolean,
aggregations: withinEnum(Object.values(AggregationsEnum)),
course_feature: identity,
limit: firstNumber,
offset: firstNumber,
id: numbers,
free: firstBoolean,
learning_format: withinEnum(Object.values(LearningFormatEnum)),
certification_type: withinEnum(Object.values(CertificationTypeEnum))
}

const contentSearchValidators: QueryParamValidators<ContentFileSearchRequest> =
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export {
default as FacetDisplay,
AvailableFacets,
getDepartmentName,
getLevelName
getLevelName,
getCertificationTypeName
} from "./facet_display/FacetDisplay"
export { default as FilterableFacet } from "./facet_display/FilterableFacet"
export { sanitizeFacets } from "./facet_display/SanitizeFacets"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,10 @@
dependencies:
make-plural "^7.0.0"

"@mitodl/open-api-axios@^2024.5.6":
version "2024.5.6"
resolved "https://registry.yarnpkg.com/@mitodl/open-api-axios/-/open-api-axios-2024.5.6.tgz#81a0777198da6de54cfbb0968c6fd1f620b11686"
integrity sha512-Z3mmohEeWHI4csKJQlqp5G5szE+6uzE16rX9bSovSfCSui8svpGNyiwlcfsZL7VHMr/6CKT7LYl9I0ydlxvgcw==
"@mitodl/open-api-axios@^2024.6.4":
version "2024.6.4"
resolved "https://registry.yarnpkg.com/@mitodl/open-api-axios/-/open-api-axios-2024.6.4.tgz#e906b764b115665858570f4bbf04bc065a2eeb4f"
integrity sha512-oJ3AwyDTrHOQXairhtqHyBHb9CzIf7En2gV7y6BANDKXhYGXKOVvxqWtvV+1jsCzgGWT6A2nBXYsKuVIGoAP6w==
dependencies:
"@types/node" "^20.11.19"
axios "^1.6.5"
Expand Down

0 comments on commit e1eb695

Please sign in to comment.