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

feat: #3353 remove pagination form study page table #3354

Merged
merged 2 commits into from
Jun 29, 2021
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
9 changes: 1 addition & 8 deletions src/pages/studies/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ import SidebarFilters from './SidebarFilters';
import styles from './Sidebar.module.scss';

type StudiesProps = {
onChange: () => void;
filters: ISqonGroupFilter;
};
type OwnProps = SidebarData & StudiesProps;

const StudiesFiltersSider = ({
studiesResults,
studiesMappingResults,
onChange,
filters,
}: OwnProps) => {
const StudiesFiltersSider = ({ studiesResults, studiesMappingResults, filters }: OwnProps) => {
const [collapsed, setCollapsed] = useState<boolean>(false);
return (
<div className={styles.sider} data-collapsed={collapsed}>
Expand All @@ -35,7 +29,6 @@ const StudiesFiltersSider = ({
<ScrollView className={styles.scrollView}>
{!collapsed && (
<SidebarFilters
onChange={onChange}
studiesResults={studiesResults}
studiesMappingResults={studiesMappingResults}
filters={filters}
Expand Down
4 changes: 1 addition & 3 deletions src/pages/studies/SidebarFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const keyEnhanceBooleanOnly = (key: string) => {
};

type StudiesProps = {
onChange: () => void;
filters: ISqonGroupFilter;
};
type OwnProps = SidebarData & StudiesProps;
Expand All @@ -55,7 +54,7 @@ const sqon = {
op: 'and',
};

const SidebarFilters = ({ studiesResults, studiesMappingResults, onChange, filters }: OwnProps) => {
const SidebarFilters = ({ studiesResults, studiesMappingResults, filters }: OwnProps) => {
const data = studiesResults;
const options: ItemProps[] = [];

Expand Down Expand Up @@ -126,7 +125,6 @@ const SidebarFilters = ({ studiesResults, studiesMappingResults, onChange, filte
filterGroup={filterGroup}
filters={filters}
onChange={(fg, f) => {
onChange();
updateFilters(history, fg, f);
}}
selectedFilters={selectedFilters}
Expand Down
7 changes: 3 additions & 4 deletions src/pages/studies/StudyPageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import StudyIcon from 'icons/StudyIconSvg';
import history from 'services/history';
import { StudiesPageContainerData } from 'store/graphql/studies/actions';

import StudyTableContainer, { PaginationType } from './StudyTableContainer';
import StudyTableContainer from './StudyTableContainer';
import {
getQueryBuilderCache,
setQueryBuilderCache,
Expand All @@ -17,13 +17,12 @@ import {

import styles from './StudiesPageContainer.module.scss';

type StudyPageContainerProps = StudiesPageContainerData & PaginationType;
type StudyPageContainerProps = StudiesPageContainerData;

const StudyPageContainer = ({
studiesResults,
studiesMappingResults,
filters,
pagination,
}: StudyPageContainerProps) => {
const total = studiesResults?.data?.hits?.total || 0;

Expand Down Expand Up @@ -53,7 +52,7 @@ const StudyPageContainer = ({
<StudyTableContainer
data={studiesResults.data}
loading={studiesResults.loading}
pagination={pagination}
total={total}
/>
</StackLayout>
</StackLayout>
Expand Down
18 changes: 5 additions & 13 deletions src/pages/studies/StudyTableContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { Table, Typography } from 'antd';
import { TablePaginationConfig } from 'antd/lib/table';

import { createQueryInCohortBuilder, DispatchStoryPage } from 'store/actionCreators/studyPage';
import { StudiesResults } from 'store/graphql/studies/actions';
Expand All @@ -28,30 +27,23 @@ const mapState = (state: RootState): StudyTableContainerState => ({
const connector = connect(mapState, mapDispatch);

type PropsFromRedux = ConnectedProps<typeof connector>;
export type PaginationType = {
pagination: TablePaginationConfig;
};

type Props = StudiesResults & PropsFromRedux & PaginationType;
type Props = StudiesResults & PropsFromRedux & { total: number };

const StudyTable = (props: Props) => {
const { pagination } = props;
const { current: currentPage, total: itemTotal = 0, pageSize: itemPerPage = 10 } = pagination;

const tableData = generateTableData(props);
const pageRange = `${currentPage}-${itemTotal > itemPerPage ? itemPerPage : itemTotal}`;
const { total } = props;

return (
<div>
<div className={styles.tableHeader}>
Showing <Text strong>{pageRange}</Text>
<span> out of </span>
<Text strong>{itemTotal}</Text>
Showing <Text strong>{total}</Text>
adipaul1981 marked this conversation as resolved.
Show resolved Hide resolved
<span> studies </span>
</div>
<Table
columns={studiesColumns(props.currentVirtualStudy, props.onClickStudyLink)}
dataSource={tableData || []}
pagination={pagination}
pagination={false}
/>
</div>
);
Expand Down
19 changes: 4 additions & 15 deletions src/pages/studies/studies.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import ScrollView from '@ferlab/ui/core/layout/ScrollView';
import { Layout } from 'antd';

Expand All @@ -11,16 +11,15 @@ import { useFilters } from './utils';

import styles from './studies.module.scss';

const studiesPerPage = 10;
const MAX_NUMBER_STUDIES = 1000;

const Studies = () => {
const { filters } = useFilters();
const [currentPage, setCurrentPage] = useState(1);

let studiesResults = useGetStudiesPageData({
sqon: filters,
first: studiesPerPage,
offset: (currentPage - 1) * studiesPerPage,
first: MAX_NUMBER_STUDIES,
adipaul1981 marked this conversation as resolved.
Show resolved Hide resolved
offset: 0,
});

let studiesMappingResults = useGetExtendedMappings('studies');
Expand All @@ -30,7 +29,6 @@ const Studies = () => {
<Sidebar
studiesMappingResults={studiesMappingResults}
studiesResults={studiesResults}
onChange={() => setCurrentPage(1)}
filters={filters}
/>
<ScrollView className={styles.scrollContent}>
Expand All @@ -39,15 +37,6 @@ const Studies = () => {
studiesResults={studiesResults}
studiesMappingResults={studiesMappingResults}
filters={filters}
pagination={{
current: currentPage,
pageSize: studiesPerPage,
total: studiesResults.data?.hits.total || 0,
onChange: (page: number) => {
setCurrentPage(page);
},
size: 'small',
}}
/>
</PageContent>
</ScrollView>
Expand Down