From c4109a470290843b39023e656db68845930174d0 Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Tue, 28 Apr 2020 22:28:26 +0530 Subject: [PATCH] feat: add Sort request in ViewPatients feat #1969 --- .../patients/list/ViewPatients.test.tsx | 7 ++++--- src/patients/list/ViewPatients.tsx | 21 +++++++++++++------ src/patients/patients-slice.ts | 7 +------ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/__tests__/patients/list/ViewPatients.test.tsx b/src/__tests__/patients/list/ViewPatients.test.tsx index 1ef7fa6834..4d44f7dcb3 100644 --- a/src/__tests__/patients/list/ViewPatients.test.tsx +++ b/src/__tests__/patients/list/ViewPatients.test.tsx @@ -11,7 +11,6 @@ import { act } from 'react-dom/test-utils' import * as ButtonBarProvider from 'page-header/ButtonBarProvider' import format from 'date-fns/format' import Page from 'clients/Page' -import { Unsorted } from 'clients/db/SortRequest' import ViewPatients from '../../../patients/list/ViewPatients' import PatientRepository from '../../../clients/db/PatientRepository' import * as patientSlice from '../../../patients/patients-slice' @@ -147,8 +146,10 @@ describe('Patients', () => { expect(searchPatientsSpy).toHaveBeenCalledTimes(1) expect(searchPatientsSpy).toHaveBeenLastCalledWith( expectedSearchText, - Unsorted, - UnpagedRequest, + { + sorts: [{ field: 'code', direction: 'desc' }], + }, + { limit: 1, skip: 0 }, ) }) }) diff --git a/src/patients/list/ViewPatients.tsx b/src/patients/list/ViewPatients.tsx index 60a70e06a7..437f76b7cb 100644 --- a/src/patients/list/ViewPatients.tsx +++ b/src/patients/list/ViewPatients.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next' import { Spinner, Button, Container, Row, TextInput, Column } from '@hospitalrun/components' import { useButtonToolbarSetter } from 'page-header/ButtonBarProvider' import format from 'date-fns/format' -import { Unsorted } from 'clients/db/SortRequest' +import SortRequest from 'clients/db/SortRequest' import PageRequest from 'clients/db/PageRequest' import PageComponent from 'components/PageComponent' import { RootState } from '../../store' @@ -22,10 +22,13 @@ const ViewPatients = () => { useTitle(t('patients.label')) useAddBreadcrumbs(breadcrumbs, true) const dispatch = useDispatch() - const { patients, isLoading, pageRequest } = useSelector((state: RootState) => state.patients) + const { patients, isLoading } = useSelector((state: RootState) => state.patients) const setButtonToolBar = useButtonToolbarSetter() - const [userPageRequest, setUserPageRequest] = useState(pageRequest) + const [userPageRequest, setUserPageRequest] = useState({ + skip: 0, + limit: 1, + }) const setNextPageRequest = () => { setUserPageRequest((p) => { @@ -56,11 +59,17 @@ const ViewPatients = () => { const debouncedSearchText = useDebounce(searchText, 500) useEffect(() => { - dispatch(searchPatients(debouncedSearchText, Unsorted, userPageRequest)) + const sortRequest: SortRequest = { + sorts: [{ field: 'code', direction: 'desc' }], + } + dispatch(searchPatients(debouncedSearchText, sortRequest, userPageRequest)) }, [dispatch, debouncedSearchText, userPageRequest]) useEffect(() => { - dispatch(fetchPatients(Unsorted, userPageRequest)) + const sortRequest: SortRequest = { + sorts: [{ field: 'code', direction: 'desc' }], + } + dispatch(fetchPatients(sortRequest, userPageRequest)) setButtonToolBar([