Skip to content

Commit

Permalink
Merge pull request #992 from WildMeOrg/all_filters_encounter_search
Browse files Browse the repository at this point in the history
All filters encounter search
  • Loading branch information
naknomum authored Feb 3, 2025
2 parents aae82a2 + 1bd2631 commit de024d5
Show file tree
Hide file tree
Showing 25 changed files with 876 additions and 182 deletions.
7 changes: 7 additions & 0 deletions frontend/src/components/Chip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ function Chip({ children }) {
}
}

if (query?.geo_distance) {
const { occurrenceLocationGeoPoint, distance } = query.geo_distance;
entries.push(
`Location within ${distance} km of latitude: ${occurrenceLocationGeoPoint.lat}, longitude: ${occurrenceLocationGeoPoint.lon}`,
);
}

return entries.length > 0 ? `${entries.join(", ")}` : `No filters set`;
}

Expand Down
102 changes: 59 additions & 43 deletions frontend/src/components/FilterPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,40 +146,48 @@ export default function FilterPanel({
}}
>
{safeSchemas.map((schema, index) => {
return (
<div
key={index}
className={`d-flex justify-content-between align-items-center rounded-3 p-2 mt-2 ${clicked === schema.id ? "bg-white" : "text-white"} cursor-pointer`}
style={{
color:
clicked === schema.id
? theme.primaryColors.primary700
: "white",
minHeight: "50px",
cursor: "pointer",
}}
onClick={() => {
setClicked(schema.id);
handleClick(schema.id);
}}
>
<Text
id={schema.labelId}
className="m-3"
if (schema.FilterComponent) {
return (
<div
key={index}
className={`d-flex justify-content-between ms-4 align-items-center rounded-3 p-2 ${clicked === schema.id ? "bg-white" : "text-white"} cursor-pointer`}
style={{
fontWeight: "500",
marginRight: "20px",
color:
clicked === schema.id
? theme.primaryColors.primary700
: "white",
minHeight: "50px",
cursor: "pointer",
}}
></Text>
<span>
{" "}
<i
className="bi bi-chevron-right"
style={{ fontSize: "14px" }}
></i>{" "}
</span>
</div>
);
onClick={() => {
setClicked(schema.id);
handleClick(schema.id);
}}
>
<Text
id={schema.labelId}
className="m-3"
style={{
fontWeight: "500",
marginRight: "20px",
}}
></Text>
<span>
{" "}
<i
className="bi bi-chevron-right"
style={{ fontSize: "14px" }}
></i>{" "}
</span>
</div>
);
} else {
return (
<div className="mt-2 mb-2" key={index}>
{schema.id}
</div>
);
}
})}
<div className="mt-2 d-flex flex-wrap justify-content-center align-items-center w-100 gap-3">
<BrutalismButton
Expand Down Expand Up @@ -259,17 +267,25 @@ export default function FilterPanel({
key={index}
ref={schemaRefs.current[index]}
>
<schema.FilterComponent
key={schema.id}
labelId={schema.labelId}
onChange={handleFilterChange}
onClearFilter={clearFilter}
{...schema.filterComponentProps}
data={data}
tempFormFilters={tempFormFilters}
setFormFilters={setFormFilters}
formFilters={formFilters}
/>
{schema.FilterComponent ? (
<schema.FilterComponent
key={schema.id}
labelId={schema.labelId}
onChange={handleFilterChange}
onClearFilter={clearFilter}
{...schema.filterComponentProps}
data={data}
tempFormFilters={tempFormFilters}
setFormFilters={setFormFilters}
formFilters={formFilters}
/>
) : (
<div>
<h2>
<FormattedMessage id={schema.labelId} />
</h2>
</div>
)}
</div>
);
})}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/filterFields/ApplyQueryFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function ApplyQueryFilter() {
const [queryId, setQueryId] = React.useState("");
return (
<div>
<h3>
<h4>
<FormattedMessage id="APPLY_SEARCH_ID" />
</h3>
</h4>
{/* <Description>
<FormattedMessage id="FILTER_METADATA_DESC" />
</Description> */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export default function BiologicalSamplesAndAnalysesFilter({ onChange, data }) {

return (
<div>
<h3>
<h4>
<FormattedMessage id="FILTER_BIOLOGICAL_SAMPLE" />
</h3>
</h4>
<Description>
<FormattedMessage id="FILTER_BIOLOGICAL_SAMPLE_DESC" />
</Description>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/filterFields/DateFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ export default function DateFilter({ onChange, data }) {

return (
<div>
<h3>
<h4>
<FormattedMessage id="FILTER_DATE" />
</h3>
</h4>
<Description>
<FormattedMessage id="FILTER_DATE_DESC" />
</Description>
<>
<FormLabel>
<FormattedMessage id="FILTER_SIGHTING_DATE" />
<FormattedMessage id="FILTER_ENCOUNTER_DATE" />
</FormLabel>
<div className="d-flex flex-row w-100 mb-2">
<FormGroup className="w-50" style={{ marginRight: "10px" }}>
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/components/filterFields/IdentityFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default function IdentityFilter({ onChange }) {

return (
<div>
<h3>
<h4>
<FormattedMessage id="FILTER_IDENTITY" />
</h3>
</h4>
<Description>
<FormattedMessage id="FILTER_IDENTITY_DESC" />
</Description>
Expand Down Expand Up @@ -100,6 +100,15 @@ export default function IdentityFilter({ onChange }) {
}}
/>
</Form>
<FormGroupText
label="FILTER_NUMBER_REPORTED_MARKED_INDIVIDUALS"
noDesc={true}
field={"occurrenceIndividualCount"}
term={"match"}
filterId={"occurrenceIndividualCount"}
onChange={onChange}
filterKey={"Number of Reported Marked Individuals"}
/>
<FormGroupText
label="FILTER_ALTERNATIVE_ID"
noDesc={true}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/filterFields/ImageLabelFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export default function ImageLabelFilter({ data, onChange }) {

return (
<div>
<h3>
<h4>
<FormattedMessage id="FILTER_IMAGE_LABEL" />
</h3>
</h4>
<Description>
<FormattedMessage id="FILTER_IMAGE_LABEL_DESC" />
</Description>
Expand Down
72 changes: 72 additions & 0 deletions frontend/src/components/filterFields/IndividualDateFilter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { useState } from "react";
import { FormattedMessage } from "react-intl";
import Description from "../Form/Description";
import { FormGroup, FormControl } from "react-bootstrap";

export default function IndividualDateFilter({ onChange }) {
const [birthDate, setBirthDate] = useState("");
const [deathDate, setDeathDate] = useState("");

return (
<div>
<h4>
<FormattedMessage id="FILTER_DATE" />
</h4>
<Description>
<FormattedMessage id="FILTER_DATE_DESC" />
</Description>
<>
<FormGroup className="w-100" style={{ marginRight: "10px" }}>
<p>
<FormattedMessage id="FILTER_BIRTH" defaultMessage="Birth" />
</p>
<FormControl
type="date"
value={birthDate}
onChange={(e) => {
setBirthDate(e.target.value);
onChange({
filterId: "individualTimeOfBirth",
filterKey: "Birth Date",
clause: "filter",
query: {
range: {
individualTimeOfBirth: {
gte: `${e.target.value}T00:00:00.000Z`,
lte: `${e.target.value}T23:59:59.000Z`,
},
},
},
});
}}
/>
</FormGroup>
<FormGroup className="w-100" style={{ marginRight: "10px" }}>
<p>
<FormattedMessage id="FILTER_DEATH" defaultMessage="Death" />
</p>
<FormControl
type="date"
value={deathDate}
onChange={(e) => {
setDeathDate(e.target.value);
onChange({
filterId: "individualTimeOfDeath",
filterKey: "Death Date",
clause: "filter",
query: {
range: {
individualTimeOfDeath: {
gte: `${e.target.value}T00:00:00.000Z`,
lte: `${e.target.value}T23:59:59.000Z`,
},
},
},
});
}}
/>
</FormGroup>
</>
</div>
);
}
45 changes: 45 additions & 0 deletions frontend/src/components/filterFields/IndividualEstimateFilter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react";
import { FormattedMessage } from "react-intl";
import Description from "../Form/Description";
import FormGroupText from "../Form/FormGroupText";

export default function IndividualEstimateFilter({ onChange }) {
return (
<div>
<h4>
<FormattedMessage id="FILTER_INDIVIDUAL_ESTIMATE" />
</h4>
<Description>
<FormattedMessage id="FILTER_INDIVIDUAL_ESTIMATE_DESC" />
</Description>

<FormGroupText
label="FILTER_BEST_ESTIMATE_INDIVIDUALS"
noDesc={true}
field={"occurrenceBestGroupSizeEstimate"}
term={"match"}
filterId={"occurrenceBestGroupSizeEstimate"}
onChange={onChange}
filterKey={"Best Estimate Individuals"}
/>
<FormGroupText
label="FILTER_MINIMUM_ESTIMATE_INDIVIDUALS"
noDesc={true}
field={"occurrenceMinGroupSizeEstimate"}
term={"match"}
filterId={"occurrenceMinGroupSizeEstimate"}
onChange={onChange}
filterKey={"Minimum Estimate Individuals"}
/>
<FormGroupText
label="FILTER_MAXIMUM_ESTIMATE_INDIVIDUALS"
noDesc={true}
field={"occurrenceMaxGroupSizeEstimate"}
term={"match"}
filterId={"occurrenceMaxGroupSizeEstimate"}
onChange={onChange}
filterKey={"Maximum Estimate Individuals"}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from "react";
import Description from "../Form/Description";
import { FormattedMessage } from "react-intl";
import FormGroupMultiSelect from "../Form/FormGroupMultiSelect";

export default function ObservationAttributeFilter({ onChange, data }) {
const sexOptions =
data?.sex?.map((item) => {
return {
value: item,
label: item,
};
}) || [];

const genusAndSpeciesOptions =
data?.siteTaxonomies?.map((item) => {
return {
value: item?.scientificName,
label: item?.scientificName,
};
}) || [];

return (
<div
style={{
overflow: "visible",
}}
>
<h4>
<FormattedMessage id="FILTER_OBSERVATION_ATTRIBUTE" />
</h4>
<Description>
<FormattedMessage id="FILTER_OBSERVATION_ATTRIBUTE_DESC" />
</Description>
<FormGroupMultiSelect
isMulti={true}
noDesc={true}
label="FILTER_INDIVIDUAL_SEX"
options={sexOptions}
onChange={onChange}
field="individualSex"
term="terms"
filterKey="individualSex"
/>
<FormGroupMultiSelect
isMulti={true}
label="FILTER_INDIVIDUAL_TAXONOMY"
noDesc={true}
options={genusAndSpeciesOptions}
onChange={onChange}
field="individualTaxonomy"
term="terms"
filterId={"individualTaxonomy"}
filterKey={"Individual Taxonomy"}
/>
</div>
);
}
Loading

0 comments on commit de024d5

Please sign in to comment.