diff --git a/specifyweb/frontend/js_src/lib/components/DataModel/collection.ts b/specifyweb/frontend/js_src/lib/components/DataModel/collection.ts index 9aa75af2d83..de889b2695d 100644 --- a/specifyweb/frontend/js_src/lib/components/DataModel/collection.ts +++ b/specifyweb/frontend/js_src/lib/components/DataModel/collection.ts @@ -193,6 +193,7 @@ export const fetchRows = async < readonly fields: FIELDS; readonly distinct?: boolean; readonly limit?: number; + readonly filterChronostrat?: boolean; }, /** * Advanced filters, not type-safe. diff --git a/specifyweb/frontend/js_src/lib/components/PickLists/__tests__/fetch.test.ts b/specifyweb/frontend/js_src/lib/components/PickLists/__tests__/fetch.test.ts index 04cc8ced4c1..14ba1ab0c5a 100644 --- a/specifyweb/frontend/js_src/lib/components/PickLists/__tests__/fetch.test.ts +++ b/specifyweb/frontend/js_src/lib/components/PickLists/__tests__/fetch.test.ts @@ -182,7 +182,7 @@ describe('fetchPickListItems', () => { }); overrideAjax( - '/api/specify_rows/locality/?limit=0&domainfilter=true&distinct=true&fields=localityname', + '/api/specify_rows/locality/?limit=0&domainfilter=true&filterchronostrat=false&distinct=true&fields=localityname', [['abc']] ); test('entire column', async () => { diff --git a/specifyweb/frontend/js_src/lib/components/PickLists/fetch.ts b/specifyweb/frontend/js_src/lib/components/PickLists/fetch.ts index a5ce74f680a..f4fb195f439 100644 --- a/specifyweb/frontend/js_src/lib/components/PickLists/fetch.ts +++ b/specifyweb/frontend/js_src/lib/components/PickLists/fetch.ts @@ -14,7 +14,7 @@ import { deserializeResource, serializeResource, } from '../DataModel/serializers'; -import { strictGetTable } from '../DataModel/tables'; +import { strictGetTable, tables } from '../DataModel/tables'; import type { PickList, PickListItem, Tables } from '../DataModel/types'; import { softFail } from '../Errors/Crash'; import { format } from '../Formatters/formatters'; @@ -159,6 +159,7 @@ async function fetchFromField( fields: { [fieldName]: ['string', 'number', 'boolean', 'null'] }, distinct: true, domainFilter: true, + filterChronostrat: tableName === tables.GeologicTimePeriod.name.toLowerCase() && fieldName === "name", // Prop for age filter in QueryBuilder }).then((rows) => rows .map((row) => row[fieldName] ?? '') diff --git a/specifyweb/specify/api.py b/specifyweb/specify/api.py index e1dfbfd9319..22dd396a305 100644 --- a/specifyweb/specify/api.py +++ b/specifyweb/specify/api.py @@ -216,11 +216,14 @@ class GetCollectionForm(forms.Form): orderby = forms.CharField(required=False) + filterchronostrat = forms.BooleanField(required=False) + defaults = dict( domainfilter=None, limit=0, offset=0, orderby=None, + filterchronostrat=False, ) def clean_limit(self): @@ -1010,7 +1013,7 @@ def apply_filters(logged_in_collection, params, model, control_params=GetCollect filters.update({param: val}) - if model.__name__ == 'Geologictimeperiod': + if control_params['filterchronostrat'] == True: # Filter out invalid chronostrats filters.update({ 'startperiod__isnull': False, @@ -1081,6 +1084,7 @@ class RowsForm(GetCollectionForm): orderby=None, distinct=False, fields=None, + filterchronostrat=False, ) def rows(request, model_name: str) -> HttpResponse: