From 0f57c19cf709888a86c9cc5156b85df5829d2239 Mon Sep 17 00:00:00 2001 From: David Lyon Date: Fri, 26 Apr 2024 13:28:55 -0700 Subject: [PATCH 1/6] Add bool support (as range value, dedicated state will be implemented when we have a bool filter controller component) --- src/common/api/collectionsApi.ts | 2 +- src/common/components/FilterChip.tsx | 2 ++ src/features/collections/CollectionDetail.tsx | 8 ++++++-- src/features/collections/collectionsSlice.ts | 11 ++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/common/api/collectionsApi.ts b/src/common/api/collectionsApi.ts index b0ade21e..f7162c94 100644 --- a/src/common/api/collectionsApi.ts +++ b/src/common/api/collectionsApi.ts @@ -177,7 +177,7 @@ export type ColumnMeta = { display_name?: string; } & ( | { - type: 'date' | 'int' | 'float'; + type: 'date' | 'int' | 'float' | 'bool'; filter_strategy: undefined; min_value: number; max_value: number; diff --git a/src/common/components/FilterChip.tsx b/src/common/components/FilterChip.tsx index 521017e0..44b50c62 100644 --- a/src/common/components/FilterChip.tsx +++ b/src/common/components/FilterChip.tsx @@ -30,6 +30,8 @@ export const FilterChip = ({ }) .map((val) => val.toLocaleString()); filterString = `${minString} to ${maxString}`; + } else if (filter.type === 'bool') { + filterString = filter.value.range[1] === 1 ? 'true' : 'false'; } else { const val = filter.value; if (typeof val === 'string') { diff --git a/src/features/collections/CollectionDetail.tsx b/src/features/collections/CollectionDetail.tsx index 2d781a6c..6bd8ed32 100644 --- a/src/features/collections/CollectionDetail.tsx +++ b/src/features/collections/CollectionDetail.tsx @@ -583,7 +583,11 @@ const FilterControls = ({ collectionId={collectionId} /> ); - } else if (filter.type === 'int' || filter.type === 'float') { + } else if ( + filter.type === 'int' || + filter.type === 'float' || + filter.type === 'bool' + ) { return ( { // initial defaults const [defMin, defMax] = filter.value?.range ?? [ diff --git a/src/features/collections/collectionsSlice.ts b/src/features/collections/collectionsSlice.ts index 23d8f130..d97a1582 100644 --- a/src/features/collections/collectionsSlice.ts +++ b/src/features/collections/collectionsSlice.ts @@ -30,7 +30,7 @@ interface FilterRange { export type FilterState = | { type: 'fulltext' | 'prefix' | 'identity' | 'ngram'; value?: string } | { - type: 'int' | 'float'; + type: 'int' | 'float' | 'bool'; value?: FilterRange; min_value: number; max_value: number; @@ -435,6 +435,15 @@ export const useFilters = ( filterState.type === 'ngram' ) { if (filterState.value !== undefined) filterValue = filterState.value; + } else if ( + filterState.type === 'bool' && + filterState.value !== undefined + ) { + const fStart = filterState.value.range[0]; + const fEnd = filterState.value.range[1]; + if (fStart === fEnd) { + filterValue = fStart === 1 ? 'true' : 'false'; + } } else if ( (filterState.type === 'date' || filterState.type === 'int' || From 2af716332f87a4aeb2885cdf35d1e2d51499f0bb Mon Sep 17 00:00:00 2001 From: David Lyon Date: Fri, 26 Apr 2024 13:45:31 -0700 Subject: [PATCH 2/6] Use columnMeta for filter chip labels, use filter context for filter menu header --- src/features/collections/CollectionDetail.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/features/collections/CollectionDetail.tsx b/src/features/collections/CollectionDetail.tsx index 6bd8ed32..4cd93295 100644 --- a/src/features/collections/CollectionDetail.tsx +++ b/src/features/collections/CollectionDetail.tsx @@ -49,7 +49,7 @@ import { import { useForm } from 'react-hook-form'; import { CollectionOverview } from './CollectionOverview'; import { FilterChip } from '../../common/components/FilterChip'; -import { FilterContextTabs } from './Filters'; +import { filterContextScope, FilterContextTabs } from './Filters'; export const detailPath = ':id'; export const detailDataProductPath = ':id/:data_product'; @@ -406,6 +406,7 @@ const useFilterEntries = (collectionId: string) => { }; const FilterChips = ({ collectionId }: { collectionId: string }) => { + const { columnMeta } = useFilters(collectionId); const { filterEntries, clearFilterState, context } = useFilterEntries(collectionId); if (filterEntries.length === 0) return <>; @@ -416,7 +417,7 @@ const FilterChips = ({ collectionId }: { collectionId: string }) => { clearFilterState(column)} /> ); @@ -456,11 +457,19 @@ const FilterMenu = ({ setExpandedCategory(expanded ? category : ''); }; + const menuLabel = { + DEFAULT: 'Filters', + genomes: 'Genome Filters', + samples: 'Sample Filters', + biolog: 'Biolog Filters', + microtrait: 'Microtrait Filters', + }[filterContextScope(context) || 'DEFAULT']; + if (open) { return (
-

Genome Filters

+

{menuLabel}