Skip to content

Commit

Permalink
add filters to Biolog and Microtrait
Browse files Browse the repository at this point in the history
  • Loading branch information
dauglyon committed Apr 26, 2024
1 parent 03adbf0 commit 1996044
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/features/collections/CollectionDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const pageConfig: Record<
}
> = {
samples: { features: ['filter'] },
biolog: { features: [] },
microtrait: { features: [] },
biolog: { features: ['filter'] },
microtrait: { features: ['filter'] },
genome_attribs: {
features: ['filter', 'match', 'search'],
},
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 @@ -113,6 +114,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 @@ -142,7 +147,8 @@ const useBiolog = (collection_id: string | undefined) => {
context,
]
);
const allCountParams = useMemo(

const countParams = useMemo(
() => ({
...heatMapParams,
count: true,
Expand All @@ -156,7 +162,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 @@ -189,24 +203,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 @@ -110,6 +111,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 @@ -144,7 +149,7 @@ const useMicrotrait = (collection_id: string | undefined) => {
context,
]
);
const allCountParams = useMemo(
const countParams = useMemo(
() => ({
...heatMapParams,
count: true,
Expand All @@ -159,7 +164,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 @@ -192,25 +204,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

0 comments on commit 1996044

Please sign in to comment.