Skip to content

Commit

Permalink
add comments from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Nov 2, 2023
1 parent 875be15 commit 64cf726
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ const aggs = [
},
]

export default aggs
export default aggs
4 changes: 2 additions & 2 deletions pages/search/advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import type {
import { getQueryString } from "../../src/utils/searchUtils"

import ItemFilterContainer from "../../src/components/ItemFilters/FiltersContainer"
import testItemAggs from "../../src/components/ItemFilters/testAggregations"
import testItemAggs from "../../__test__/fixtures/testAggregations"

/**
* The Advanced Search page is responsible for displaying the Advanced Search form fields and
Expand Down Expand Up @@ -125,7 +125,7 @@ export default function AdvancedSearch() {
}
/>
)}
<ItemFilterContainer itemAggs={testItemAggs} />
<ItemFilterContainer itemAggs={[testItemAggs[0]]} />
<Heading level="two">Advanced Search</Heading>
<Form
id="advancedSearchForm"
Expand Down
17 changes: 7 additions & 10 deletions src/components/ItemFilters/ItemFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import {
import type { Dispatch } from "react"

import type { ItemFilterData } from "../../models/itemFilterData"
import type {
option as optionType,
selectedFilters as selectedFiltersType,
} from "../../types/filterTypes"
import type { Option, SelectedFilters } from "../../types/filterTypes"

interface ItemFilterProps {
itemFilterData: ItemFilterData
setSelectedFilters: Dispatch<React.SetStateAction<selectedFiltersType>>
selectedFilters: selectedFiltersType
setSelectedFilters: Dispatch<React.SetStateAction<SelectedFilters>>
selectedFilters: SelectedFilters
// this type is temporary for dev use only. could end up being different.
submitFilters: Dispatch<React.SetStateAction<selectedFiltersType>>
submitFilters: Dispatch<React.SetStateAction<SelectedFilters>>
}

const ItemFilter = ({
Expand All @@ -28,13 +25,13 @@ const ItemFilter = ({
const field = itemFilterData.field()
const fieldFormatted = itemFilterData.field(true)
const clearFilter = () => {
setSelectedFilters((prevFilters: selectedFiltersType) => {
setSelectedFilters((prevFilters: SelectedFilters) => {
return { ...prevFilters, [field]: [] }
})
}

const handleCheck = (selectedOptions: string[]) => {
setSelectedFilters((prevFilters: selectedFiltersType) => {
setSelectedFilters((prevFilters: SelectedFilters) => {
const newFilterSelection = {
...prevFilters,
[field]: selectedOptions,
Expand All @@ -57,7 +54,7 @@ const ItemFilter = ({
// the CheckboxGroup value array are selected.
value={selectedFilters[field]}
>
{itemFilterData.displayOptions().map(({ value, label }: optionType) => {
{itemFilterData.displayOptions().map(({ value, label }: Option) => {
return (
<Checkbox id={value} key={value} value={value} labelText={label} />
)
Expand Down
5 changes: 5 additions & 0 deletions src/components/ItemFilters/ItemFilters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import userEvent from "@testing-library/user-event"
jest.mock("next/router", () => jest.requireActual("next-router-mock"))

describe("Filters container", () => {
it("renders a single filter", () => {
render(<FiltersContainer itemAggs={[aggs[0]]} />)
const filters = screen.getAllByTestId("item-filter")
expect(filters.length).toBe(1)
})
it("renders three filter boxes", () => {
render(<FiltersContainer itemAggs={aggs} />)
const filters = screen.getAllByTestId("item-filter")
Expand Down
8 changes: 4 additions & 4 deletions src/components/ItemFilters/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { selectedFilters as selectedFiltersType } from "../../types/filterTypes"
import type { SelectedFilters } from "../../types/filterTypes"

const isRecapLocation = (loc: string) => {
return loc.split(":")[1].startsWith("rc")
Expand All @@ -11,7 +11,7 @@ export const combineRecapLocations = (locations: string[]) => {
} else return locations
}

type bibPageQueryParams = {
type BibPageQueryParams = {
item_location?: string
item_format?: string
item_status?: string
Expand All @@ -21,7 +21,7 @@ export const parseQueryParams = ({
item_status,
item_format,
item_location,
}: bibPageQueryParams) => {
}: BibPageQueryParams) => {
return {
location: item_location
? combineRecapLocations(item_location.split(","))
Expand All @@ -32,7 +32,7 @@ export const parseQueryParams = ({
}

export const buildQueryParams = (
{ location, format, status }: selectedFiltersType,
{ location, format, status }: SelectedFilters,
recapLocations: string[]
) => {
const locs = location.map((loc) => {
Expand Down
10 changes: 5 additions & 5 deletions src/models/itemFilterData.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type {
ItemAggregation,
ItemAggregationOption,
option as optionType,
Option,
} from "../types/filterTypes"

export class ItemFilterData {
options: ItemAggregationOption[]
_field: string
agg: ItemAggregation
constructor(agg: ItemAggregation) {
this._field = agg.field
this.agg = agg
this.options = agg.values
}

displayOptions(): optionType[] {
displayOptions(): Option[] {
return this.options
}

field(formatted = false) {
const f = this._field
const f = this.agg.field
const upperCased = f[0].toUpperCase() + f.substring(1)
return formatted ? upperCased : f
}
Expand Down
6 changes: 3 additions & 3 deletions src/types/filterTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type locations = string[]
export type Locations = string[]

export type selectedFilters = {
export type SelectedFilters = {
location: string[]
format: string[]
status: string[]
Expand All @@ -21,7 +21,7 @@ export interface ItemAggregation {
values: ItemAggregationOption[]
}

export type option = { value: string; label: string }
export type Option = { value: string; label: string }

export type ReducedItemAggregation = {
field: string
Expand Down

0 comments on commit 64cf726

Please sign in to comment.