Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RE2022-310 Implement Heatmap filters #204

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/common/api/collectionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/common/components/FilterChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const FilterChip = ({
})
.map((val) => val.toLocaleString());
filterString = `${minString} to ${maxString}`;
} else if (filter.type === 'bool') {
filterString = Boolean(filter.value).toString();
} else {
const val = filter.value;
if (typeof val === 'string') {
Expand Down
15 changes: 12 additions & 3 deletions src/features/collections/CollectionDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 <></>;
Expand All @@ -416,7 +417,7 @@ const FilterChips = ({ collectionId }: { collectionId: string }) => {
<FilterChip
filter={filter}
key={`${column}-${context}-${filter.type}`}
name={column}
name={columnMeta?.[column]?.display_name || column}
onDelete={() => clearFilterState(column)}
/>
);
Expand Down Expand Up @@ -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 (
<div className={styles['filters_panel']}>
<Stack direction="row" className={styles['filters-panel-header']}>
<h3>Genome Filters</h3>
<h3>{menuLabel}</h3>
<Stack direction="row" spacing={1}>
<Button
size="small"
Expand Down
3 changes: 2 additions & 1 deletion src/features/collections/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export const useContextFilterQueryManagement = (
])
);
} else {
// column.type === 'count'
const filterMeta: ColumnMeta = {
type: 'int',
key: column.col_id,
Expand All @@ -280,7 +281,7 @@ export const useContextFilterQueryManagement = (
context,
column.col_id,
{
type: filterMeta.type,
type: 'int',
min_value: filterMeta.min_value,
max_value: filterMeta.max_value,
value:
Expand Down
5 changes: 5 additions & 0 deletions src/features/collections/collectionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ export const useFilters = (
filterState.type === 'ngram'
) {
if (filterState.value !== undefined) filterValue = filterState.value;
} else if (
filterState.type === 'bool' &&
filterState.value !== undefined
) {
filterValue = Boolean(filterState.value).toString();
} else if (
(filterState.type === 'date' ||
filterState.type === 'int' ||
Expand Down
40 changes: 30 additions & 10 deletions src/features/collections/data_products/Biolog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useAppParam } from '../../params/hooks';
import classes from '../Collections.module.scss';
import {
useFilterContextState,
useFilters,
useGenerateSelectionId,
} from '../collectionsSlice';
import { useFilterContexts } from '../Filters';
Expand Down Expand Up @@ -128,6 +129,10 @@ const useBiolog = (collection_id: string | undefined) => {
pageSize: 56,
});
const context = useFilterContextState(collection_id);
const { filterParams } = useFilters(collection_id, context);
const allFilters = useFilters(collection_id, 'biolog.all').filterParams;
const matchFilters = useFilters(collection_id, 'biolog.matched').filterParams;
const selFilters = useFilters(collection_id, 'biolog.selected').filterParams;

const pageLastIdCache: Record<string, string> = useMemo(
() => ({}),
Expand Down Expand Up @@ -157,7 +162,8 @@ const useBiolog = (collection_id: string | undefined) => {
context,
]
);
const allCountParams = useMemo(

const countParams = useMemo(
() => ({
...heatMapParams,
count: true,
Expand All @@ -171,7 +177,15 @@ const useBiolog = (collection_id: string | undefined) => {
[collection_id]
);

const biologQuery = getBiolog.useQuery(heatMapParams, {
const filteredParams = useMemo(
() => ({
...heatMapParams,
...filterParams,
}),
[heatMapParams, filterParams]
);

const biologQuery = getBiolog.useQuery(filteredParams, {
skip: !collection_id,
});
const biolog = biologQuery.data;
Expand Down Expand Up @@ -204,24 +218,30 @@ const useBiolog = (collection_id: string | undefined) => {
skip: !collection_id,
});

const { data: count, ...countQuery } = getBiolog.useQuery(allCountParams, {
skip: !collection_id,
});

const [matchCountParams, selCountParams] = useMemo(
const [allCountParams, matchCountParams, selCountParams] = useMemo(
() => [
{
...allCountParams,
...countParams,
...allFilters,
},
{
...countParams,
match_mark: false,
...matchFilters,
},
{
...allCountParams,
...countParams,
selection_mark: false,
...selFilters,
},
],
[allCountParams]
[allFilters, countParams, matchFilters, selFilters]
);

const { data: count, ...countQuery } = getBiolog.useQuery(allCountParams, {
skip: !collection_id,
});

const matchCount = getBiolog.useQuery(matchCountParams, {
skip: !collection_id || !matchId,
});
Expand Down
44 changes: 31 additions & 13 deletions src/features/collections/data_products/Microtrait.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
useMatchId,
useGenerateSelectionId,
useFilterContextState,
useFilters,
} from '../collectionsSlice';
import { useFilterContexts } from '../Filters';
import { useProcessStatePolling } from '../hooks';
Expand Down Expand Up @@ -148,6 +149,10 @@ const useMicrotrait = (collection_id: string | undefined) => {
skip: !collection_id,
});
const context = useFilterContextState(collection_id);
const { filterParams } = useFilters(collection_id, context);
const allFilters = useFilters(collection_id, 'biolog.all').filterParams;
const matchFilters = useFilters(collection_id, 'biolog.matched').filterParams;
const selFilters = useFilters(collection_id, 'biolog.selected').filterParams;

const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 0,
Expand Down Expand Up @@ -182,7 +187,7 @@ const useMicrotrait = (collection_id: string | undefined) => {
context,
]
);
const allCountParams = useMemo(
const countParams = useMemo(
() => ({
...heatMapParams,
count: true,
Expand All @@ -197,7 +202,14 @@ const useMicrotrait = (collection_id: string | undefined) => {
);

// HeatMap cell query
const microtraitQuery = getMicroTrait.useQuery(heatMapParams, {
const filteredParams = useMemo(
() => ({
...heatMapParams,
...filterParams,
}),
[heatMapParams, filterParams]
);
const microtraitQuery = getMicroTrait.useQuery(filteredParams, {
skip: !collection_id,
});
const microtrait = microtraitQuery.data;
Expand Down Expand Up @@ -230,25 +242,31 @@ const useMicrotrait = (collection_id: string | undefined) => {
skip: !collection_id,
});

const { data: count, ...countQuery } = getMicroTrait.useQuery(
allCountParams,
{
skip: !collection_id,
}
);

const [matchCountParams, selCountParams] = useMemo(
const [allCountParams, matchCountParams, selCountParams] = useMemo(
() => [
{
...allCountParams,
...countParams,
...allFilters,
},
{
...countParams,
match_mark: false,
...matchFilters,
},
{
...allCountParams,
...countParams,
selection_mark: false,
...selFilters,
},
],
[allCountParams]
[allFilters, countParams, matchFilters, selFilters]
);

const { data: count, ...countQuery } = getMicroTrait.useQuery(
allCountParams,
{
skip: !collection_id,
}
);

const matchCount = getMicroTrait.useQuery(matchCountParams, {
Expand Down