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

Fix/skfp 483 #3776

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 19 additions & 26 deletions src/components/uiKit/FilterList/CustomFilterContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,52 @@ import { useEffect, useState } from 'react';
import FilterContainer from '@ferlab/ui/core/components/filters/FilterContainer';
import { IFilter, IFilterGroup, TExtendedMapping } from '@ferlab/ui/core/components/filters/types';
import { updateActiveQueryFilters } from '@ferlab/ui/core/components/QueryBuilder/utils/useQueryBuilderState';
import { underscoreToDot } from '@ferlab/ui/core/data/arranger/formatting';
import { getFilterGroup } from '@ferlab/ui/core/data/filters/utils';
import { getSelectedFilters } from '@ferlab/ui/core/data/sqon/utils';
import { IExtendedMappingResults, IGqlResults } from '@ferlab/ui/core/graphql/types';
import { getFilters } from 'graphql/utils/Filters';
import { isUndefined } from 'lodash';

import { getFilterGroup } from '@ferlab/ui/core/data/filters/utils';
import { getSelectedFilters } from '@ferlab/ui/core/data/sqon/utils';
import { getFacetsDictionary, getFiltersDictionary } from 'utils/translation';

import { underscoreToDot } from '@ferlab/ui/core/data/arranger/formatting';
import CustomFilterSelector from './CustomFilterSelector';
import { TCustomFilterMapper } from '.';

type OwnProps = {
classname: string;
index: string;
queryBuilderId: string;
filterKey: string;
filter: string;
defaultOpen?: boolean;
extendedMappingResults: IExtendedMappingResults;
filtersOpen?: boolean;
filterMapper?: TCustomFilterMapper;
headerTooltip?: boolean;
noDataInputOption?: boolean;
results: IGqlResults<any>;
};

const CustomFilterContainer = ({
classname,
index,
queryBuilderId,
filterKey,
filtersOpen,
defaultOpen,
extendedMappingResults,
filterMapper,
filter,
headerTooltip,
noDataInputOption,
results,
}: OwnProps) => {
const [isSearchVisible, setIsSearchVisible] = useState(false);
const [isOpen, setIsOpen] = useState(defaultOpen);
const [results, setResults] = useState<IGqlResults<any>>();
const found = (extendedMappingResults?.data || []).find(
(f: TExtendedMapping) => f.field === underscoreToDot(filterKey),
);


useEffect(() => {
if (!isUndefined(filtersOpen) && isOpen !== filtersOpen) {
setIsOpen(filtersOpen);
}
// eslint-disable-next-line
}, [filtersOpen]);

const onChange = (fg: IFilterGroup, f: IFilter[]) => {
const onFilterSelectorChange = (fg: IFilterGroup, f: IFilter[]) => {
updateActiveQueryFilters({
queryBuilderId,
filterGroup: fg,
Expand All @@ -62,18 +56,23 @@ const CustomFilterContainer = ({
});
};

const aggregations = results?.aggregations ? results?.aggregations[filterKey] : {};
const found = (extendedMappingResults?.data || []).find(
(f: TExtendedMapping) => f.field === underscoreToDot(filter),
);

const aggregations = results?.aggregations ? results?.aggregations[filter] : null;

const filterGroup = getFilterGroup({
extendedMapping: found,
aggregation: aggregations,
aggregation: aggregations || {},
rangeTypes: [],
filterFooter: true,
headerTooltip,
dictionary: getFacetsDictionary(),
noDataInputOption,
});

const filters = results?.aggregations ? getFilters(results?.aggregations, filterKey) : [];
const filters = results?.aggregations ? getFilters(results?.aggregations, filter) : [];
const selectedFilters = results?.data
? getSelectedFilters({
queryBuilderId,
Expand All @@ -83,7 +82,7 @@ const CustomFilterContainer = ({
: [];

return (
<div className={classname} key={filterKey}>
<div className={classname} key={filter}>
<FilterContainer
maxShowing={5}
isOpen={isOpen}
Expand All @@ -97,19 +96,13 @@ const CustomFilterContainer = ({
}}
customContent={
<CustomFilterSelector
index={index}
queryBuilderId={queryBuilderId}
filterKey={filterKey}
dictionary={getFiltersDictionary()}
filters={filters}
filterGroup={filterGroup}
maxShowing={5}
onChange={onChange}
onChange={onFilterSelectorChange}
selectedFilters={selectedFilters}
searchInputVisible={isSearchVisible}
onDataLoaded={setResults}
extendedMappingResults={extendedMappingResults}
filterMapper={filterMapper}
/>
}
/>
Expand Down
70 changes: 11 additions & 59 deletions src/components/uiKit/FilterList/CustomFilterSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,25 @@ import { useEffect } from 'react';
import FilterSelector, {
FilterSelectorProps,
} from '@ferlab/ui/core/components/filters/FilterSelector';
import useQueryBuilderState from '@ferlab/ui/core/components/QueryBuilder/utils/useQueryBuilderState';
import { resolveSyntheticSqon } from '@ferlab/ui/core/data/sqon/utils';
import { IExtendedMappingResults } from '@ferlab/ui/core/graphql/types';
import { Spin } from 'antd';
import { AGGREGATION_QUERY } from 'graphql/queries';

import useGetAggregations from 'hooks/graphql/useGetAggregations';

import { TCustomFilterMapper } from '.';

type OwnProps = FilterSelectorProps & {
index: string;
queryBuilderId: string;
filterKey: string;
onDataLoaded: Function;
extendedMappingResults: IExtendedMappingResults;
filterMapper?: TCustomFilterMapper;
};

const CustomFilterSelector = ({
index,
queryBuilderId,
filterKey,
AltefrohneGaelle marked this conversation as resolved.
Show resolved Hide resolved
dictionary,
filters,
filterGroup,
maxShowing,
selectedFilters,
onChange,
onDataLoaded,
searchInputVisible,
extendedMappingResults,
filterMapper,
}: OwnProps) => {
const { queryList, activeQuery } = useQueryBuilderState(queryBuilderId);

const resolvedSqon = filterMapper
? filterMapper(resolveSyntheticSqon(queryList, activeQuery))
: resolveSyntheticSqon(queryList, activeQuery);
const results = useGetAggregations(
{
sqon: resolvedSqon,
},
AGGREGATION_QUERY(index, [filterKey], extendedMappingResults),
index,
);

useEffect(() => {
if (results.data) {
onDataLoaded(results);
}
// eslint-disable-next-line
}, [results.aggregations]);

return (
<Spin spinning={results.loading}>
<FilterSelector
dictionary={dictionary}
filterGroup={filterGroup}
filters={filters}
maxShowing={maxShowing}
onChange={onChange}
searchInputVisible={searchInputVisible}
selectedFilters={selectedFilters}
/>
</Spin>
);
};
}: FilterSelectorProps) => (
<FilterSelector
dictionary={dictionary}
filterGroup={filterGroup}
filters={filters}
maxShowing={maxShowing}
onChange={onChange}
searchInputVisible={searchInputVisible}
selectedFilters={selectedFilters}
/>
);

export default CustomFilterSelector;
36 changes: 28 additions & 8 deletions src/components/uiKit/FilterList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useState } from 'react';
import { Button, Layout, Space, Typography } from 'antd';
import intl from 'react-intl-universal';
import { ISqonGroupFilter, ISyntheticSqon } from '@ferlab/ui/core/data/sqon/types';
import { IExtendedMappingResults } from '@ferlab/ui/core/graphql/types';
import { Button, Layout, Space, Spin, Typography } from 'antd';
import cx from 'classnames';
import { isEmpty } from 'lodash';

import styles from 'components/uiKit/FilterList/Filters.module.scss';
import { IExtendedMappingResults } from '@ferlab/ui/core/graphql/types';
import useQueryBuilderState from '@ferlab/ui/core/components/QueryBuilder/utils/useQueryBuilderState';
import { resolveSyntheticSqon } from '@ferlab/ui/core/data/sqon/utils';
import useGetAggregations from 'hooks/graphql/useGetAggregations';
import { AGGREGATION_QUERY } from 'graphql/queries';
import { ISqonGroupFilter, ISyntheticSqon } from '@ferlab/ui/core/data/sqon/types';

import CustomFilterContainer from './CustomFilterContainer';
import { FilterGroup, FilterInfo } from './types';

import styles from 'components/uiKit/FilterList/Filters.module.scss';

export type TCustomFilterMapper = (filters: ISqonGroupFilter) => ISyntheticSqon;

type OwnProps = {
Expand Down Expand Up @@ -45,9 +50,24 @@ const FilterList = ({
filterMapper,
}: OwnProps) => {
const [filtersOpen, setFiltersOpen] = useState<boolean | undefined>(isAllFacetOpen(filterInfo));
const { queryList, activeQuery } = useQueryBuilderState(queryBuilderId);

const filters = filterInfo.groups.flatMap(g => g.facets) as string[];
const resolvedSqon = filterMapper
? filterMapper(resolveSyntheticSqon(queryList, activeQuery))
: resolveSyntheticSqon(queryList, activeQuery);

const aggQuery = AGGREGATION_QUERY(index, filters, extendedMappingResults);
const aggResults = useGetAggregations(
{
sqon: resolvedSqon,
},
aggQuery,
index,
);

if (extendedMappingResults.loading) {
return <Spin className={styles.filterLoader} spinning />;
if (aggResults.loading) {
return <></>;
}

return (
Expand Down Expand Up @@ -78,15 +98,15 @@ const FilterList = ({
typeof facet === 'string' ? (
<CustomFilterContainer
key={facet}
filter={facet}
index={index}
queryBuilderId={queryBuilderId}
classname={cx(styles.customFilterContainer, styles.filter)}
filterKey={facet}
extendedMappingResults={extendedMappingResults}
filtersOpen={filtersOpen}
defaultOpen={filterInfo.defaultOpenFacets?.includes(facet) ? true : undefined}
filterMapper={filterMapper}
headerTooltip={group.tooltips?.includes(facet)}
results={aggResults}
/>
) : (
<div key={i + ii} className={cx(styles.customFilterWrapper, styles.filter)}>
Expand Down
6 changes: 5 additions & 1 deletion src/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const AGGREGATION_QUERY = (
) => {
if (!mappingResults || mappingResults.loading) return gql``;

const aggListDotNotation = aggList.map((i) => underscoreToDot(i));
const aggListDotNotation = aggList.map((i) => {
if (typeof i === 'string') {
return underscoreToDot(i);
}
});

const extendedMappingsFields = aggListDotNotation.flatMap((i) =>
(mappingResults?.data || []).filter((e) => e.field === i),
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/studies/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface IStudyResultTree {

export interface IStudyEntity {
id: string;
domain: string;
study_id: string;
study_code: string;
study_name: string;
Expand All @@ -17,3 +18,4 @@ export interface IStudyEntity {
data_category: string[];
website: string;
}

1 change: 1 addition & 0 deletions src/graphql/studies/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const SEARCH_STUDIES_QUERY = gql`
edges {
node {
id
domain
study_id
study_code
study_name
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/utils/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const generateFilters = ({
);
});

const translateWhenNeeded = (group: string, key: string) =>
const translateWhenNeeded = (group: string, key: string) =>
intl.get(`facets.options.${group}.${keyEnhance(key)}`).defaultMessage(keyEnhance(key));

export const getFilters = (aggregations: TAggregations | null, key: string): IFilter[] => {
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"facets.options.zygosity.HOM": "Homozygote",
"facets.options.zygosity.UNK": "Unknown",
"facets.observed_phenotype.name": "Observed Phenotype (HPO)",
"facets.options.domain.CANCERANDBIRTHDEFECT": "Cancer and Birth Defect",
"facets.options.domain.CANCER": "Cancer",
"facets.options.domain.BIRTHDEFECT": "Birth Defect",
"family": "family",
"father": "father",
"female": "Female",
Expand Down
1 change: 0 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,6 @@ const en = {
af: '1000 Genomes',
},
},

// Studies
domain: 'Study Domain',
population: 'Population',
Expand Down
8 changes: 5 additions & 3 deletions src/views/Studies/components/SideBarFacet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { STUDIES_REPO_QB_ID } from '../../utils/constant';
import FilterList from 'components/uiKit/FilterList';
import { INDEXES } from 'graphql/constants';
import { FilterInfo } from 'components/uiKit/FilterList/types';
import { Button } from 'antd';
import { Button, Spin } from 'antd';
import { IExtendedMappingResults } from '@ferlab/ui/core/graphql/types';

type OwnProps = {
Expand Down Expand Up @@ -39,14 +39,16 @@ const SideBarFacet = ({ className, extendedMappingResults, filterInfo }: OwnProp
<ScrollContent>
{!collapsed && (
<div className={styles.content}>
<FilterList
{ extendedMappingResults.loading
? <Spin className={styles.filterLoader} spinning />
: <FilterList
loading={loading}
key={INDEXES.STUDIES}
index={INDEXES.STUDIES}
queryBuilderId={STUDIES_REPO_QB_ID}
extendedMappingResults={extendedMappingResults}
filterInfo={filterInfo}
/>
/>}
</div>
)}
</ScrollContent>
Expand Down
Loading
Loading