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

Jmpi 775 fix review link undefined uid bug #151

Open
wants to merge 1 commit into
base: dev-api-link-interaction
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
GridCellParams,
GridColDef,
GridRenderCellParams,
GridValidRowModel,
GridValueFormatterParams,
DataGrid as MuiDataGrid
} from '@mui/x-data-grid'
Expand All @@ -15,7 +16,7 @@ import { useMemo } from 'react'
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>

interface CustomDataGridProps extends PartialBy<DataGridProps, 'columns'> {
interface CustomDataGridProps<R extends GridValidRowModel> extends PartialBy<DataGridProps<R>, 'columns'> {
action?: (uid: string) => void
}

Expand All @@ -35,12 +36,12 @@ const getCellClassName = (
} else return ''
}

const CustomDataGrid: React.FC<CustomDataGridProps> = ({
const CustomDataGrid = <R extends GridValidRowModel>({
sx,
rows,
action,
...props
}) => {
}: CustomDataGridProps<R>) => {
const { availableFields } = useAppConfig()

const fieldColumns: GridColDef[] = availableFields.map(
Expand All @@ -59,7 +60,7 @@ const CustomDataGrid: React.FC<CustomDataGridProps> = ({
cellClassName: (params: GridCellParams) =>
fieldName === 'recordType'
? getRecordTypeClassName(params)
: getCellClassName(params, groups, rows[0]),
: getCellClassName(params, groups, rows[0] as any as AnyRecord),
renderCell: (params: GridRenderCellParams) =>
getCellComponent(fieldName, params)
})
Expand Down
21 changes: 14 additions & 7 deletions JeMPI_Apps/JeMPI_UI/src/components/reviewLink/ReviewLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { useSnackbar } from 'notistack'
import { useState } from 'react'
import { CustomSearchQuery, SearchQuery } from 'types/SimpleSearch'
import { NotificationState } from '../../types/Notification'
import { AnyRecord } from '../../types/PatientRecord'
import {
AnyRecord,
GoldenRecord,
PatientRecord
} from '../../types/PatientRecord'
import Loading from '../common/Loading'
import ApiErrorMessage from '../error/ApiErrorMessage'
import NotFound from '../error/NotFound'
Expand All @@ -30,7 +34,7 @@ import { useLocation, useNavigate } from 'react-router-dom'
import { useConfig } from 'hooks/useConfig'
import { NotificationRequest } from 'types/BackendResponse'

const getRowClassName = (type: string) => {
const getRowClassName = (type?: string) => {
switch (type) {
case 'Current':
return 'super-app-theme--Current'
Expand Down Expand Up @@ -72,7 +76,8 @@ const ReviewLink = () => {
const { linkRecords, createNewGoldenRecord } = useRelink()

const mutateNotification = useMutation({
mutationFn: (request: NotificationRequest) => apiClient.updateNotification(request),
mutationFn: (request: NotificationRequest) =>
apiClient.updateNotification(request),
onError: (error: AxiosError) => {
enqueueSnackbar(`Error updating notification: ${error.message}`, {
variant: 'error'
Expand Down Expand Up @@ -182,7 +187,7 @@ const ReviewLink = () => {
...goldenRecord.linkRecords.filter(
record => record.uid !== patientRecord?.uid
),
patientRecord,
...(patientRecord ? [patientRecord] : []),
goldenRecord
]
: []
Expand Down Expand Up @@ -231,15 +236,17 @@ const ReviewLink = () => {
<Typography pl={1} variant="dgSubTitle">
PATIENT LINKED TO GOLDEN RECORD
</Typography>
<CustomDataGrid
<CustomDataGrid<GoldenRecord | PatientRecord>
rows={matches}
sx={{
borderRadius: '0px'
}}
getRowClassName={params =>
params.row.uid === payload?.patient_id
? 'super-app-theme--SelectedPatient'
: getRowClassName(params.row.type)
: 'type' in params.row
? getRowClassName(params.row.type)
: ''
}
/>
</Paper>
Expand Down Expand Up @@ -284,7 +291,7 @@ const ReviewLink = () => {
)}
</Stack>
<Paper>
<CustomDataGrid
<CustomDataGrid<AnyRecord>
rows={
payload?.notificationId
? candidateGoldenRecords || []
Expand Down
2 changes: 1 addition & 1 deletion JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ApiClient {
const { method } = request
if (['post', 'patch', 'put', 'delete'].indexOf(method || '') !== -1) {
const csrfToken = getCookie('XSRF-TOKEN')
if (csrfToken) {
if (csrfToken && request.headers) {
request.headers['X-XSRF-TOKEN'] = csrfToken
}
}
Expand Down