Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

555-sighting-encounter-search #559

Merged
merged 4 commits into from
Sep 20, 2023
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
4 changes: 3 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,5 +1260,7 @@
"CHANGE_LOG" : "Change Log",
"TIME_CHANGE_OCCURRED" : "Time Change occurred",
"MANAGE_REQUESTS" : "Manage Requests",
"NO_SEARCH_RESULT" : "Your search did not match any records."
"NO_SEARCH_RESULT" : "Your search did not match any records.",
"ENCOUNTER_SEX" : "Encounter sex",
"ENCOUNTER_SPECIES" : "Encounter species"
}
24 changes: 12 additions & 12 deletions src/components/dataDisplays/ElasticsearchSightingsDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ export default function ElasticsearchSightingsDisplay({
...rest
}) {
const title = `${dataCount || sightings.length} matching sightings`;

const tableData = sightings.map(sighting => {
const encounters = sighting?.encounters || [];
const photoCount = encounters.reduce((memo, e) => {
memo += e.images.length;
return memo;
}, 0);
// const encounters = sighting?.encounters || [];
// const photoCount = encounters.reduce((memo, e) => {
// memo += e.images.length;
// return memo;
// }, 0);

const individuals = encounters.reduce((memo, e) => {
const individual = get(e, 'individual.id', null);
return individual ? [...memo, individual] : null;
}, []);
// const individuals = encounters.reduce((memo, e) => {
// const individual = get(e, 'individual.id', null);
// return individual ? [...memo, individual] : null;
// }, []);

return {
...sighting,
photoCount,
individuals,
// photoCount,
// individuals,
};
});

Expand Down
10 changes: 3 additions & 7 deletions src/components/filterFields/OptionTermFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const OptionTermFilter = function (props) {

const [value, setValue] = useState('');

const [values, setValues] = useState([]);

function getLabel(object) {
if (object?.labelId)
return intl.formatMessage({ id: object.labelId });
Expand All @@ -45,10 +43,8 @@ const OptionTermFilter = function (props) {
!minimalLabels && (description || descriptionId);

const translatedLabel = labelId
? (intl.messages[labelId]
? intl.formatMessage({ id: labelId })
: labelId )
: label;
? intl.formatMessage({ id: labelId, defaultMessage: labelId })
: label;

const safeChoices = choices || [];

Expand Down Expand Up @@ -87,7 +83,7 @@ const OptionTermFilter = function (props) {
}}
value={value}
renderValue={currentValue => {
if(!currentValue) {
if (!currentValue) {
return '';
}
const selectedChoice = safeChoices.find(
Expand Down
81 changes: 81 additions & 0 deletions src/components/filterFields/useBuildFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import OptionTermFilter from './OptionTermFilter';
import SubstringFilter from './SubstringFilter';
import IntegerFilter from './IntegerFilter';
import FloatFilter from './FloatFilter';
import MultiSelectFilter from './MultiSelectFilter';
import DateRangeFilter from './DateRangeFilter';
import PointDistanceFilter from './PointDistanceFilter';
import useOptions from '../../hooks/useOptions';

const excludedFieldTypes = [
'individual',
'feetmeters',
'date',
'daterange',
];

export default function useBuildFilter(fields, component) {
const { booleanChoices } = useOptions();
let queryTerm;
let queryTerms;
if (component === 'sightings' || component === 'individuals') {
queryTerm = 'customFields';
queryTerms = 'customFields';
} else if (component === 'encounters') {
queryTerm = 'encounters.customFields';
queryTerms = 'encounters.customFields';
}

return fields
.filter(
data => !excludedFieldTypes.includes(data.schema.displayType),
)
.map(data => {
let customFilter;
switch (data.schema.displayType) {
case 'select':
customFilter = OptionTermFilter;
break;
case 'string':
customFilter = SubstringFilter;
break;
case 'integer':
customFilter = IntegerFilter;
break;
case 'float':
customFilter = FloatFilter;
break;
case 'multiselect':
customFilter = MultiSelectFilter;
break;
case 'daterange':
customFilter = DateRangeFilter;
break;
case 'boolean':
customFilter = OptionTermFilter;
break;
case 'latlong':
customFilter = PointDistanceFilter;
break;
case 'longstring':
customFilter = SubstringFilter;
break;
default:
customFilter = SubstringFilter;
break;
}
return {
id: data.name,
labelId: data.schema.label,
FilterComponent: customFilter,
filterComponentProps: {
filterId: data.name,
queryTerm: `${queryTerm}.${data.id}`,
queryTerms: [`${queryTerms}.${data.id}`],
choices: data.schema.choices
? data.schema.choices
: booleanChoices,
},
};
});
}
97 changes: 29 additions & 68 deletions src/models/individual/useIndividualSearchSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import useOptions from '../../hooks/useOptions';
import OptionTermFilter from '../../components/filterFields/OptionTermFilter';
import SubstringFilter from '../../components/filterFields/SubstringFilter';
import DateRangeFilter from '../../components/filterFields/DateRangeFilter';
import PointDistanceFilter from '../../components/filterFields/PointDistanceFilter';
import IntegerFilter from '../../components/filterFields/IntegerFilter';
import FloatFilter from '../../components/filterFields/FloatFilter';
import MultiSelectFilter from '../../components/filterFields/MultiSelectFilter';
import autogenNameFilter from '../../components/filterFields/autogenNameFilter';
import sexOptions from '../../constants/sexOptions';
import useSocialGroups from '../../models/socialGroups/useSocialGroups';
import useSiteSettings from '../../models/site/useSiteSettings';
import useSocialGroups from '../socialGroups/useSocialGroups';
import useSiteSettings from '../site/useSiteSettings';
import useBuildFilter from '../../components/filterFields/useBuildFilter';

const labeledSexOptions = sexOptions.map(o => ({
labelId: o?.filterLabelId || o.labelId,
Expand All @@ -35,62 +33,25 @@ const hasAnnotationOptions = [
];

export default function useIndividualSearchSchemas() {
const { speciesOptions, socialGroupRolesOptions, relationshipOptions, booleanChoices } = useOptions();
const {
speciesOptions,
socialGroupRolesOptions,
relationshipOptions,
} = useOptions();
const { data: socialGroups } = useSocialGroups();
const { data: siteSettings } = useSiteSettings();
const customIndividualFields = siteSettings['site.custom.customFields.Individual'].value.definitions || [];
const socialGroupOptions = socialGroups?.map(data => {
return {
label: data.name,
value: data.guid
}
});
let filterComponent1 = null;
const customFields = customIndividualFields.map(data => {
switch (data.schema.displayType) {
case "select":
filterComponent1 = OptionTermFilter;
break;
case "string":
filterComponent1 = SubstringFilter;
break;
case "integer":
filterComponent1 = IntegerFilter;
break;
case "float":
filterComponent1 = FloatFilter;
break;
case "multiselect":
filterComponent1 = MultiSelectFilter;
break;
case "daterange":
filterComponent1 = DateRangeFilter;
break;
case "boolean":
filterComponent1 = OptionTermFilter;
break;
case "latlong":
filterComponent1 = PointDistanceFilter;
break;
case "longstring":
filterComponent1 = SubstringFilter;
break;
default:
filterComponent1 = SubstringFilter;
break;
}
return {
id: data.name,
labelId: data.schema.label,
FilterComponent: filterComponent1,
filterComponentProps: {
filterId: data.name,
queryTerm: `customFields.${data.id}`,
queryTerms: [`customFields.${data.id}`],
choices: data.schema.choices? data.schema.choices : booleanChoices,
},
};
})
const customIndividualFields =
siteSettings['site.custom.customFields.Individual'].value
.definitions || [];
const socialGroupOptions = socialGroups?.map(data => ({
label: data.name,
value: data.guid,
}));

const customFields = useBuildFilter(
customIndividualFields,
'individuals',
);

return [
{
Expand Down Expand Up @@ -189,8 +150,8 @@ export default function useIndividualSearchSchemas() {
filterComponentProps: {
queryTerm: 'relationships.type_guid',
filterId: 'relationship',
choices: relationshipOptions,
}
choices: relationshipOptions,
},
},
{
id: 'relationshipRoles',
Expand All @@ -205,25 +166,25 @@ export default function useIndividualSearchSchemas() {
},
{
id: 'socialGroups',
labelId: 'SOCIAL_GROUPS',
labelId: 'SOCIAL_GROUPS',
FilterComponent: OptionTermFilter,
filterComponentProps: {
queryTerm: 'social_groups.guid',
filterId: 'socialGroups',
choices: socialGroupOptions
choices: socialGroupOptions,
},
},
{
id: 'socialGroupsRoles',
labelId: 'SOCIAL_GROUP_ROLES',
labelId: 'SOCIAL_GROUP_ROLES',
FilterComponent: OptionTermFilter,
filterComponentProps: {
customField: "social_group_roles",
customField: 'social_group_roles',
queryTerm: 'social_groups.role_guids',
filterId: 'socialGroupsRoles',
choices: socialGroupRolesOptions
choices: socialGroupRolesOptions,
},
},
...customFields
...customFields,
];
}
}
Loading
Loading