Skip to content

Commit

Permalink
Add filters to instruments page
Browse files Browse the repository at this point in the history
  • Loading branch information
Tammo-Feldmann committed Jun 26, 2023
1 parent 6764dd9 commit 05b058d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/components/explore/explore-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ const ExploreTools = React.forwardRef(
label="Measurement Type"
options={getFilterOptionsById("type")}
/>
<FilterMenu
id="type"
selectedFilterIds={selectedFilterIds}
addFilter={addFilter}
removeFilter={removeFilter}
label="Measurement Style"
options={getFilterOptionsById("style")}
/>
<FilterMenu
id="vertical"
selectedFilterIds={selectedFilterIds}
Expand All @@ -298,6 +306,14 @@ const ExploreTools = React.forwardRef(
label="Vertical Measurement Region"
options={getFilterOptionsById("vertical")}
/>
<FilterMenu
id="type"
selectedFilterIds={selectedFilterIds}
addFilter={addFilter}
removeFilter={removeFilter}
label="Platforms"
options={getFilterOptionsById("platform")}
/>
</>
)}
</form>
Expand Down
32 changes: 32 additions & 0 deletions src/pages/explore/instruments.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function ExploreInstruments({ data, location }) {
const {
allInstrument,
allMeasurementType,
allMeasurementStyle,
allMeasurementRegion,
allCampaign,
allPlatform,
Expand Down Expand Up @@ -64,7 +65,9 @@ export default function ExploreInstruments({ data, location }) {

const { getFilterLabelById, getFilterOptionsById } = selector({
type: allMeasurementType,
style: allMeasurementStyle,
vertical: allMeasurementRegion,
platform: allPlatform,
})

return (
Expand Down Expand Up @@ -145,6 +148,20 @@ export const query = graphql`
longname: long_name
}
}
allMeasurementStyle {
options: nodes {
id
shortname: short_name
longname: long_name
}
}
allPlatform {
options: nodes {
id
shortname: short_name
longname: long_name
}
}
allMeasurementRegion {
options: nodes {
id
Expand All @@ -170,6 +187,12 @@ export const query = graphql`
measurementType: measurement_type {
id # required for filter
}
measurementStyle: measurement_style {
id # required for filter
}
platforms: platforms {
id
}
measurementRegions: measurement_regions {
id # required for filter
}
Expand All @@ -185,6 +208,14 @@ const instrumentShape = PropTypes.shape({
measurementType: PropTypes.shape({
id: PropTypes.string.isRequired,
}),
measurementStyle: PropTypes.shape({
id: PropTypes.string.isRequired,
}),
platforms: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
}).isRequired
),
measurementRegions: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
Expand Down Expand Up @@ -214,6 +245,7 @@ ExploreInstruments.propTypes = {
list: PropTypes.arrayOf(instrumentShape).isRequired,
}),
allMeasurementType: filterOptionShape,
allMeasurementStyle: filterOptionShape,
allMeasurementRegion: filterOptionShape,
allCampaign: PropTypes.shape({
totalCount: PropTypes.number.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/explore/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export default function ExploreProducts({ data, location }) {
},
{ values: [], set: new Set() }
).values
console.log({ allCampaignPlatformInstruments })

const { getFilterLabelById, getFilterOptionsById } = selector({
measurement: { options: allMeasurementTypes },
style: { options: allMeasurementStyles },
Expand Down
7 changes: 5 additions & 2 deletions src/utils/filter-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,18 @@ export function platformFilter(selectedFilterIds) {
}

export function instrumentFilter(selectedFilterIds) {
return instrument =>
selectedFilterIds.length === 0
return instrument => {
return selectedFilterIds.length === 0
? true
: selectedFilterIds.every(
filterId =>
(instrument.measurementType &&
instrument.measurementType.id === filterId) ||
(instrument.measurementStyle?.id ?? 0) === filterId ||
instrument.platforms.map(x => x.id).includes(filterId) ||
instrument.measurementRegions.map(x => x.id).includes(filterId)
)
}
}

export function doiFilter(selectedFilterIds) {
Expand Down

0 comments on commit 05b058d

Please sign in to comment.