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

feat(app): Implement search facets for DatasetType field #3036

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export interface SearchParams {
tracerRadionuclides: string[]
sortBy_available
sortBy_selected
bidsDatasetType_available: string[]
bidsDatasetType_selected: string | null
}

// TODO: move to this initial state
Expand Down Expand Up @@ -237,6 +239,8 @@ const TEMPORARY_initialSearchParams: SearchParams = {
tracerRadionuclides: [],
sortBy_available: sortBy,
sortBy_selected: sortBy[0],
bidsDatasetType_available: ["raw", "derivative"],
bidsDatasetType_selected: null,
}

export default TEMPORARY_initialSearchParams
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { FC, useContext } from "react"
import { SearchParamsCtx } from "../search-params-ctx"
import { FacetSelect } from "@openneuro/components/facets"
import { AccordionTab, AccordionWrap } from "@openneuro/components/accordion"

const DatasetTypeSelect: FC = () => {
const { searchParams, setSearchParams } = useContext(SearchParamsCtx)

const { bidsDatasetType_selected, bidsDatasetType_available } = searchParams
const setDatasetType = (bidsDatasetType_selected) =>
setSearchParams((prevState) => ({
...prevState,
bidsDatasetType_selected,
}))

return (
<AccordionWrap className="facet-accordion">
<AccordionTab
accordionStyle="plain"
label="Dataset Type"
startOpen={false}
>
<FacetSelect
selected={bidsDatasetType_selected}
setSelected={setDatasetType}
items={bidsDatasetType_available}
/>
</AccordionTab>
</AccordionWrap>
)
}

Check warning on line 31 in packages/openneuro-app/src/scripts/search/inputs/dataset-type-select.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/search/inputs/dataset-type-select.tsx#L7-L31

Added lines #L7 - L31 were not covered by tests

export default DatasetTypeSelect
2 changes: 2 additions & 0 deletions packages/openneuro-app/src/scripts/search/inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ModalitySelect from "./modality-select"
import ShowDatasetRadios from "./show-datasets-radios"
import AgeRangeInput from "./age-range-input"
import SubjectCountRangeInput from "./subject-count-range-input"
import DatasetTypeSelect from "./dataset-type-select"
import DiagnosisSelect from "./diagnosis-select"
import TaskInput from "./task-input"
import AuthorInput from "./author-input"
Expand All @@ -24,6 +25,7 @@ export {
AllDatasetsToggle,
AuthorInput,
BodyPartsInput,
DatasetTypeSelect,
DateRadios,
DiagnosisSelect,
KeywordInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AllDatasetsToggle,
AuthorInput,
BodyPartsInput,
DatasetTypeSelect,
DateRadios,
DiagnosisSelect,
KeywordInput,
Expand Down Expand Up @@ -166,6 +167,7 @@
{!portalContent
? <ModalitySelect portalStyles={true} label="Modalities" />
: <ModalitySelect portalStyles={false} label="Choose Modality" />}
<DatasetTypeSelect />

Check warning on line 170 in packages/openneuro-app/src/scripts/search/search-container.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/search/search-container.tsx#L170

Added line #L170 was not covered by tests
<AgeRangeInput />
<SubjectCountRangeInput />
<DiagnosisSelect />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
scannerManufacturersModelNames,
tracerNames,
tracerRadionuclides,
bidsDatasetType_selected,

Check warning on line 126 in packages/openneuro-app/src/scripts/search/search-params-ctx.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/search/search-params-ctx.tsx#L126

Added line #L126 was not covered by tests
}) => ({
keywords,
modality_selected,
Expand All @@ -144,6 +145,7 @@
scannerManufacturersModelNames,
tracerNames,
tracerRadionuclides,
bidsDatasetType_selected,

Check warning on line 148 in packages/openneuro-app/src/scripts/search/search-params-ctx.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/search/search-params-ctx.tsx#L148

Added line #L148 was not covered by tests
})

/**
Expand Down
13 changes: 12 additions & 1 deletion packages/openneuro-components/src/search-page/FiltersBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { FacetSelectValueType } from "../facets/FacetSelect"
import { NeurobagelSearch } from "./NeurobagelSearch"


export interface FiltersBlockProps {
keywords: string[]
modality_selected?: FacetSelectValueType
Expand All @@ -33,6 +32,7 @@
removeAllFilters?(): void
numTotalResults: number
loading: boolean
bidsDatasetType_selected?: FacetSelectValueType
}

export const FiltersBlock = ({
Expand Down Expand Up @@ -61,6 +61,7 @@
removeFilterItem,
removeAllFilters,
numTotalResults,
bidsDatasetType_selected,

Check warning on line 64 in packages/openneuro-components/src/search-page/FiltersBlock.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-components/src/search-page/FiltersBlock.tsx#L64

Added line #L64 was not covered by tests
}: FiltersBlockProps) => {
const ageRangeIsNull =
JSON.stringify(ageRange) === JSON.stringify([null, null])
Expand Down Expand Up @@ -114,6 +115,16 @@
removeFilterItem={removeFilterItem(true)}
/>
)}
{bidsDatasetType_selected && (
<FilterListItem
type="Dataset Type"
item={{
param: "bidsDatasetType_selected",
value: bidsDatasetType_selected,
}}
removeFilterItem={removeFilterItem(true)}
/>
)}

Check warning on line 127 in packages/openneuro-components/src/search-page/FiltersBlock.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-components/src/search-page/FiltersBlock.tsx#L118-L127

Added lines #L118 - L127 were not covered by tests
{!searchAllDatasets && (
<>
{datasetType_selected && (
Expand Down
Loading