-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
568 additions
and
731 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
apps/hcdc-web-app/src/features/test-element/components/NormalRuleEditor/columns.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { PatientCategory, PatientCategoryValues } from '@diut/hcdc' | ||
import { GridColDef } from '@mui/x-data-grid' | ||
|
||
import { TestElementNormalRuleDto } from 'src/infra/api/access-service/test-element' | ||
|
||
const patientCategoryDisplayText = { | ||
[PatientCategory.Any]: 'Tất cả', | ||
[PatientCategory.YoungMale]: 'Bé trai', | ||
[PatientCategory.YoungFemale]: 'Bé gái', | ||
[PatientCategory.MatureMale]: 'Nam', | ||
[PatientCategory.MatureFemale]: 'Nữ', | ||
[PatientCategory.Pregnant]: 'Thai phụ', | ||
} | ||
|
||
export type TestElementNormalRuleDtoWithId = TestElementNormalRuleDto & { | ||
id: string | ||
} | ||
|
||
export const normalRuleColumns: GridColDef<TestElementNormalRuleDtoWithId>[] = [ | ||
{ | ||
field: 'category', | ||
headerName: 'Phân loại', | ||
type: 'singleSelect', | ||
minWidth: 150, | ||
sortable: false, | ||
editable: true, | ||
valueOptions: PatientCategoryValues.map((category) => ({ | ||
value: category, | ||
label: patientCategoryDisplayText[category], | ||
})), | ||
// valueFormatter: ({ value }) => patientCategoryDisplayText[value as PatientCategory], | ||
}, | ||
{ | ||
field: 'normalLowerBound', | ||
headerName: 'Min', | ||
type: 'number', | ||
width: 100, | ||
sortable: false, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'normalUpperBound', | ||
headerName: 'Max', | ||
type: 'number', | ||
width: 100, | ||
sortable: false, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'normalValue', | ||
headerName: 'So sánh', | ||
minWidth: 100, | ||
flex: 1, | ||
sortable: false, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'description', | ||
headerName: 'Mô tả', | ||
minWidth: 100, | ||
flex: 1, | ||
sortable: false, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'note', | ||
headerName: 'Tham khảo', | ||
minWidth: 100, | ||
flex: 1, | ||
sortable: false, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'defaultChecked', | ||
type: 'boolean', | ||
headerName: 'Mặc định', | ||
minWidth: 80, | ||
sortable: false, | ||
editable: true, | ||
valueGetter: ({ value }) => { | ||
return value ?? false | ||
}, | ||
}, | ||
] |
93 changes: 93 additions & 0 deletions
93
apps/hcdc-web-app/src/features/test-element/components/NormalRuleEditor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useEffect, useState } from 'react' | ||
import { Box, Button } from '@mui/material' | ||
|
||
import { | ||
TestElementNormalRuleDto, | ||
TestElementResponseDto, | ||
} from 'src/infra/api/access-service/test-element' | ||
import { CrudTable } from 'src/components/table' | ||
import { SideAction } from 'src/components/ui/SideAction' | ||
import { TestElementNormalRuleDtoWithId, normalRuleColumns } from './columns' | ||
|
||
type NormalRuleEditorProps = { | ||
element: TestElementResponseDto | null | ||
onClose: Function | ||
onSubmit: (normalRules: TestElementNormalRuleDto[]) => void | ||
isSubmitting: boolean | ||
} | ||
|
||
export function NormalRuleEditor(props: NormalRuleEditorProps) { | ||
const [items, setItems] = useState<TestElementNormalRuleDtoWithId[]>([]) | ||
|
||
useEffect(() => { | ||
if (props.element?.normalRules) { | ||
setItems( | ||
props.element?.normalRules.map((rule) => ({ | ||
id: JSON.stringify(rule), | ||
...rule, | ||
})), | ||
) | ||
} | ||
}, [props.element?.normalRules]) | ||
|
||
const handleSubmit = () => { | ||
props.onSubmit( | ||
items.map((rule) => ({ | ||
...rule, | ||
id: undefined, | ||
defaultChecked: rule.defaultChecked ?? false, | ||
})), | ||
) | ||
props.onClose() | ||
} | ||
|
||
const handleCancel = () => { | ||
props.onClose() | ||
} | ||
|
||
return ( | ||
<SideAction | ||
fullWidth | ||
open={props.element != null} | ||
onClose={props.onClose} | ||
title={props.element?.name ?? ''} | ||
disableClickOutside={props.isSubmitting} | ||
> | ||
<Box sx={{ height: '100%' }}> | ||
<CrudTable | ||
items={items} | ||
itemIdField="id" | ||
fieldColumns={normalRuleColumns} | ||
onItemCreate={(item) => { | ||
setItems((items) => [ | ||
...items, | ||
{ ...item, id: JSON.stringify(item) }, | ||
]) | ||
}} | ||
onItemUpdate={(item) => { | ||
setItems((items) => [ | ||
{ ...item, id: JSON.stringify(item) }, | ||
...items.filter((rule) => rule.id !== item.id), | ||
]) | ||
}} | ||
onItemDelete={(item) => { | ||
setItems((items) => items.filter((rule) => rule.id !== item.id)) | ||
}} | ||
/> | ||
<Box> | ||
<Button | ||
sx={{ mt: 2 }} | ||
variant="contained" | ||
color="primary" | ||
onClick={handleSubmit} | ||
> | ||
Lưu | ||
</Button> | ||
<Button sx={{ mt: 2, mx: 1 }} color="primary" onClick={handleCancel}> | ||
Huỷ | ||
</Button> | ||
</Box> | ||
</Box> | ||
</SideAction> | ||
) | ||
} |
Oops, something went wrong.