Skip to content

Commit

Permalink
Merge pull request #204 from kbase/heatmapFilters
Browse files Browse the repository at this point in the history
RE2022-310 Implement Heatmap filters
  • Loading branch information
codytodonnell authored May 16, 2024
2 parents e407210 + ddd8674 commit dd6feda
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 26 deletions.
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
1 change: 1 addition & 0 deletions 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 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

0 comments on commit dd6feda

Please sign in to comment.