11import React from "react" ;
22import tw , { styled } from "twin.macro" ;
3- import { NumberField } from "react-admin" ;
3+ import { FunctionField } from "react-admin" ;
44import TextField from "./TextField" ;
55import { getFieldColor } from "../../themes/field-colors" ;
66import { STUDENT_COURSE } from "../../constants/apiObjects" ;
7+ import { formatDecimal } from '../../services/Utility'
78
89const StyledTextField = styled ( TextField ) `
910 ${ tw `fontStyle-6 text-gray-700 font-medium` }
@@ -12,23 +13,24 @@ const StyledTextField = styled(TextField)`
1213 font-size: 1.4em;
1314` ;
1415
15- const StyledNumberField = styled ( NumberField ) `
16+ const StyledFunctionField = styled ( FunctionField ) `
1617 ${ tw `fontStyle-6 text-gray-700 font-medium` }
1718
1819 color: ${ props => props . color } ;
1920 font-size: 1.4em;
2021` ;
2122
2223const GradeField = props => {
23- return props . source === STUDENT_COURSE . LETTER_GRADE ? (
24- < StyledTextField color = { getFieldColor ( props ) } { ...props } />
25- ) : (
26- < StyledNumberField
27- color = { getFieldColor ( props ) }
28- { ...props }
29- options = { { maximumFractionDigits : 2 } }
30- />
31- ) ;
24+ return props . source === STUDENT_COURSE . LETTER_GRADE ?
25+ (
26+ < StyledTextField color = { getFieldColor ( props ) } { ...props } />
27+ ) : (
28+ < StyledFunctionField
29+ render = { record => `${ formatDecimal ( record [ props . source ] ) } ` }
30+ color = { getFieldColor ( props ) }
31+ { ...props }
32+ />
33+ ) ;
3234} ;
3335
3436export default GradeField ;
0 commit comments