Skip to content

Commit

Permalink
Boolean Facets (#106)
Browse files Browse the repository at this point in the history
* Add BooleanFacetGroup + simplify facetOptions

* Fix tests, rename SearchFilter -> FilterIndicator

* add tests; update swc, add coverage

* add a tests for filterable facet

* rename facetMap -> facetManifest

* do not render MultiFacetGroup when empty
  • Loading branch information
ChristopherChudzicki authored May 20, 2024
1 parent 8d816ff commit 0737ab3
Show file tree
Hide file tree
Showing 15 changed files with 707 additions and 493 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
coverage
dist/*
*.tgz

Expand Down
32 changes: 7 additions & 25 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import { Config } from "@jest/types"
import { Config } from "@jest/types";

const common = {
const config: Config.InitialOptions = {
testEnvironment: "jsdom",
transform: {
collectCoverage: true,
transform: {
"^.+\\.(t)sx?$": "@swc/jest",
},
setupFilesAfterEnv: ["<rootDir>src/test_setup.ts"],
testMatch: ["<rootDir>/src/**/*.(spec|test).ts?(x)"],
}

const config: Config.InitialOptions = {
projects: [
{
displayName: "history-v4",
moduleNameMapper: {
history$: "history-v4",
},
...common,
},
{
displayName: "history-v5",
moduleNameMapper: {
history$: "history",
},
...common,
},
],
}
testMatch: ["<rootDir>/src/**/*.(spec|test).ts?(x)"],
};

export default config
export default config;
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@
"homepage": "https://github.com/mitodl/course-search-utils#readme",
"dependencies": {
"@mitodl/open-api-axios": "^2024.5.6",
"@testing-library/react": "12",
"@testing-library/user-event": "^14.5.2",
"axios": "^1.6.7",
"fuse.js": "^7.0.0",
"query-string": "^6.13.1",
"ramda": "^0.27.1"
},
"devDependencies": {
"@swc/core": "^1.3.0",
"@swc/jest": "^0.2.22",
"@swc/core": "^1.5.7",
"@swc/jest": "^0.2.36",
"@testing-library/react": "12",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/enzyme": "^3.10.7",
"@types/jest": "^29.0.1",
"@types/lodash": "^4.14.162",
Expand Down Expand Up @@ -80,7 +80,8 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router": "^6.22.2",
"ts-node": "^10.9.1",
"tiny-invariant": "^1.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"peerDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions src/facet_display/Facet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react"
import { contains } from "ramda"

import { SearchFacetItem } from "./SearchFacetItem"
import { BucketWithLabel } from "./FacetDisplay"
import { BucketWithLabel } from "./types"

const MAX_DISPLAY_COUNT = 5
const FACET_COLLAPSE_THRESHOLD = 15
Expand Down Expand Up @@ -40,17 +40,17 @@ function SearchFacet(props: Props) {
{showFacetList ? (
<>
{results ?
results.map((facet, i) =>
results.map((bucket, i) =>
showAllFacets ||
i < MAX_DISPLAY_COUNT ||
results.length < FACET_COLLAPSE_THRESHOLD ? (
<SearchFacetItem
key={`${name}-${facet.key}`}
facet={facet}
isChecked={contains(facet.key, selected || [])}
key={`${name}-${bucket.key}`}
bucket={bucket}
isChecked={contains(bucket.key, selected || [])}
onUpdate={onUpdate}
name={name}
displayKey={facet.label}
displayKey={bucket.label}
/>
) : null
) :
Expand Down
Loading

0 comments on commit 0737ab3

Please sign in to comment.