-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
d8edbbe
commit 712e061
Showing
6 changed files
with
392 additions
and
59 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
158 changes: 158 additions & 0 deletions
158
apps/modernization-ui/src/apps/dedup-config/DataElementsConfiguration/DataElementsTable.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,158 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useFormContext, Controller, useWatch } from 'react-hook-form'; | ||
import { DataElement } from '../const/init'; | ||
import { DataTable, Column } from 'design-system/table'; | ||
import { Checkbox } from '@trussworks/react-uswds'; | ||
import { Input } from 'components/FormInputs/Input'; | ||
import { useDataElementsContext } from '../context/DataElementsContext'; | ||
|
||
const columns = ( | ||
control: any, | ||
handleRowCheckboxChange: (index: number, checked: boolean) => void, | ||
checkedState: boolean[], | ||
watchedDataElements: DataElement[] | ||
): Column<DataElement>[] => [ | ||
{ | ||
id: 'active', | ||
name: 'Active', | ||
render: (dataElement, index) => ( | ||
<Controller | ||
control={control} | ||
name={`dataElements.${index}.active`} | ||
render={({ field: { value, onChange, name } }) => ( | ||
<Checkbox | ||
name={name} | ||
label="" | ||
id={`checkbox-${index}`} | ||
checked={value || false} | ||
onChange={(e) => { | ||
handleRowCheckboxChange(index, e.target.checked); | ||
onChange(e.target.checked); | ||
}} | ||
/> | ||
)} | ||
/> | ||
) | ||
}, | ||
{ | ||
id: 'name', | ||
name: 'Name', | ||
render: (dataElement) => dataElement.name | ||
}, | ||
{ | ||
id: 'm', | ||
name: 'M', | ||
render: (dataElement, index) => ( | ||
<Controller | ||
control={control} | ||
name={`dataElements.${index}.m`} | ||
render={({ field: { value, onChange, onBlur, name } }) => ( | ||
<Input | ||
type="number" | ||
defaultValue={value} | ||
value={value} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
name={name} | ||
disabled={!checkedState[index]} | ||
/> | ||
)} | ||
/> | ||
) | ||
}, | ||
{ | ||
id: 'u', | ||
name: 'U', | ||
render: (dataElement, index) => ( | ||
<Controller | ||
control={control} | ||
name={`dataElements.${index}.u`} | ||
render={({ field: { value, onChange, onBlur, name } }) => ( | ||
<Input | ||
type="number" | ||
defaultValue={value} | ||
value={value} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
name={name} | ||
disabled={!checkedState[index]} | ||
/> | ||
)} | ||
/> | ||
) | ||
}, | ||
{ | ||
id: 'oddsRatio', | ||
name: 'Odds ratio', | ||
render: (dataElement, index) => { | ||
const m = watchedDataElements[index]?.m; | ||
const u = watchedDataElements[index]?.u; | ||
const oddsRatio = m && u && u !== 0 ? (m / u).toFixed(2) : 'No Data'; | ||
return oddsRatio; | ||
} | ||
}, | ||
{ | ||
id: 'logOdds', | ||
name: 'Log odds', | ||
render: (dataElement, index) => { | ||
const m = watchedDataElements[index]?.m; | ||
const u = watchedDataElements[index]?.u; | ||
const logOdds = m && u && u !== 0 && m !== 0 ? Math.log(m / u).toFixed(2) : 'No Data'; | ||
return logOdds; | ||
} | ||
}, | ||
{ | ||
id: 'threshold', | ||
name: 'Threshold', | ||
render: (dataElement, index) => ( | ||
<Controller | ||
control={control} | ||
name={`dataElements.${index}.threshold`} | ||
render={({ field: { value, onChange, onBlur, name } }) => ( | ||
<Input | ||
type="number" | ||
defaultValue={value} | ||
value={value} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
name={name} | ||
disabled={!checkedState[index]} | ||
/> | ||
)} | ||
/> | ||
) | ||
} | ||
]; | ||
|
||
const DataElementsTable = () => { | ||
const { control, setValue } = useFormContext<{ dataElements: DataElement[] }>(); | ||
const { dataElements } = useDataElementsContext(); | ||
const [checkedState, setCheckedState] = useState<boolean[]>([]); | ||
|
||
const watchedDataElements = useWatch({ | ||
control, | ||
name: 'dataElements', | ||
defaultValue: dataElements | ||
}); | ||
|
||
useEffect(() => { | ||
setValue('dataElements', dataElements); | ||
setCheckedState(dataElements.map((de) => de.active)); | ||
}, [dataElements, setValue]); | ||
|
||
const handleRowCheckboxChange = (index: number, checked: boolean) => { | ||
const updatedCheckedState = [...checkedState]; | ||
updatedCheckedState[index] = checked; | ||
setCheckedState(updatedCheckedState); | ||
}; | ||
|
||
return ( | ||
<DataTable<DataElement> | ||
id="dataElementsTable" | ||
columns={columns(control, handleRowCheckboxChange, checkedState, watchedDataElements)} | ||
data={dataElements} | ||
/> | ||
); | ||
}; | ||
|
||
export { DataElementsTable }; |
29 changes: 29 additions & 0 deletions
29
...zation-ui/src/apps/dedup-config/DataElementsConfiguration/data-elements-table.module.scss
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,29 @@ | ||
@use 'styles/colors'; | ||
|
||
.table { | ||
width: 100%; | ||
tbody tr:nth-child(odd) { | ||
background-color: colors.$base-lightest; | ||
} | ||
th { | ||
label::before { | ||
margin-top: -0.5rem; | ||
content: ''; | ||
display: inline-block; | ||
width: 1rem; | ||
height: 1rem; | ||
margin-right: 0.5rem; | ||
} | ||
} | ||
td { | ||
height: 3rem; | ||
label::before { | ||
margin-top: -0.75rem; | ||
content: ''; | ||
display: inline-block; | ||
width: 1rem; | ||
height: 1rem; | ||
margin-right: 0.5rem; | ||
} | ||
} | ||
} |
106 changes: 87 additions & 19 deletions
106
apps/modernization-ui/src/apps/dedup-config/const/init.ts
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 |
---|---|---|
@@ -1,19 +1,87 @@ | ||
export const DataElements = { | ||
"lastName": "", | ||
"secondLastName": "", | ||
"firstName": "", | ||
"middleName": "", | ||
"secondMiddleName": "", | ||
"suffix": "", | ||
"currentSex": "", | ||
"dateOfBirth": "", | ||
"ssn": "", | ||
"idType": "", | ||
"idAssigningAuthority": "", | ||
"idValue": "", | ||
"streetAddress1": "", | ||
"city": "", | ||
"state": "", | ||
"zipCode": "", | ||
"telephone": "" | ||
}; | ||
export type DataElement = { | ||
name: string; | ||
active: boolean; | ||
m: number; | ||
u: number; | ||
threshold: number; | ||
}; | ||
|
||
export const DataElements: DataElement[] = [ | ||
{ name: "lastName", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ name: "secondLastName", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ name: "firstName", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ name: "middleName", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ name: "secondMiddleName", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ name: "suffix", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ name: "currentSex", active: true, m: 0.5, u: 0.5, threshold: 0.5 }, | ||
{ | ||
name: "dateOfBirth", | ||
active: true, | ||
m: 0.5, | ||
u: 0.5, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "ssn", | ||
active: true, | ||
m: 0.5, | ||
u: 0.5, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "idType", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "idAssigningAuthority", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "idValue", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "streetAddress1", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "city", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "state", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "zip", | ||
active: true, | ||
m: 0.5, | ||
u: 0.25, | ||
threshold: 0.5, | ||
}, | ||
{ | ||
name: "telephone", | ||
active: true, | ||
m: 0.5, | ||
u: 0.1, | ||
threshold: 0.5, | ||
} | ||
]; |
Oops, something went wrong.