Skip to content

Commit

Permalink
Fix types for ResourceListPageContent
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Feb 26, 2025
1 parent e7415ce commit 8d6d002
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/uberComponents/ResourceListPageContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { Trans } from '@lingui/macro';
import { Empty } from 'antd';
import { ColumnsType, TablePaginationConfig } from 'antd/lib/table';
import { Bundle, Resource } from 'fhir/r4b';
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';

import { formatError } from '@beda.software/fhir-react';
import { isFailure, isLoading, isSuccess } from '@beda.software/remote-data';

import { PageContainerContent } from 'src/components/BaseLayout/PageContainer/PageContainerContent';
import { SearchBar } from 'src/components/SearchBar';
import { useSearchBar } from 'src/components/SearchBar/hooks';
import { isTableFilter } from 'src/components/SearchBar/utils';
import { SpinIndicator } from 'src/components/Spinner';
import { Table } from 'src/components/Table';
import { populateTableColumnsWithFiltersAndSorts } from 'src/components/Table/utils';

import { S } from './styles';
import { getRecordActionsColumn, ResourcesListPageReport } from '../ResourceListPage';
import { HeaderQuestionnaireAction } from '../ResourceListPage/actions';
import { useResourceListPage } from '../ResourceListPage/hooks';
import { BatchActions } from '../ResourceListPage/BatchActions';
import { getRecordActionsColumn, ResourceListPageProps, ResourcesListPageReport } from '../ResourceListPage';
import { PageContainerContent } from 'src/components/BaseLayout/PageContainer/PageContainerContent';
import { S } from './styles';
import { useResourceListPage } from '../ResourceListPage/hooks';
import { ResourceListProps, TableManager } from '../ResourceListPage/types';

type RecordType<R extends Resource> = { resource: R; bundle: Bundle };

type ResourceListPageContentProps<R extends Resource> = Omit<ResourceListPageProps<R>, 'headerTitle' | 'maxWidth'> & {};
type ResourceListPageContentProps<R extends Resource> = Omit<ResourceListProps<R>, 'headerTitle' | 'maxWidth'> & {
getTableColumns: (manager: TableManager) => ColumnsType<RecordType<R>>;
};

export function ResourceListPageContent<R extends Resource>({
resourceType,
Expand All @@ -46,15 +50,26 @@ export function ResourceListPageContent<R extends Resource>({
[JSON.stringify(columnsFilterValues)],
);

const {
recordResponse,
reload,
pagination,
handleTableChange,
selectedRowKeys,
setSelectedRowKeys,
selectedResourcesBundle,
} = useResourceListPage(resourceType, extractPrimaryResources, columnsFilterValues, searchParams ?? {});
const { recordResponse, reload, pagination, selectedRowKeys, setSelectedRowKeys, selectedResourcesBundle } =
useResourceListPage(resourceType, extractPrimaryResources, columnsFilterValues, searchParams ?? {});

const handleTableChange = useCallback(
(event: TablePaginationConfig) => {
if (typeof event.current !== 'number') {
return;
}
if (event.pageSize && event.pageSize !== pagination.pageSize) {
pagination.reload();
pagination.updatePageSize(event.pageSize);
} else {
pagination.loadPage(event.current, {
_page: event.current,
});
}
setSelectedRowKeys([]);
},
[pagination],
);

// TODO: move to hooks
const initialTableColumns = getTableColumns({ reload });
Expand Down

0 comments on commit 8d6d002

Please sign in to comment.