@@ -14,7 +14,7 @@ import { VIOLATIONS_ASSOCIATIONS_FORM } from "../../../../../config";
14
14
import css from "../styles.css" ;
15
15
import { isFamilyDetailSubform , isFamilyMemberSubform , isViolationSubform } from "../../utils" ;
16
16
import { GuidingQuestions } from "../../components" ;
17
-
17
+ import orderBy from "lodash/orderBy" ;
18
18
import { isEmptyOrAllDestroyed , isTracesSubform } from "./utils" ;
19
19
import SubformSummary from "../../../../pages/admin/child-functioning/SubformSummary"
20
20
function Component ( {
@@ -76,14 +76,16 @@ function Component({
76
76
}
77
77
} , [ index ] ) ;
78
78
79
+ const sortedRecordsByDateDesc = orderBy ( orderedValues , [ ( v ) => new Date ( v [ "date_fa81c1a" ] ) ] , [ "desc" ] ) ;
80
+
79
81
const renderEmptyData = isEmptyOrAllDestroyed ( orderedValues ) ? (
80
82
< SubformEmptyData subformName = { title } />
81
83
) : (
82
84
< List dense = { renderAsAccordion } classes = { { root : css . list } } disablePadding >
83
85
< SubformFields
84
86
arrayHelpers = { arrayHelpers }
85
87
field = { field }
86
- values = { orderedValues }
88
+ values = { title === 'Child Functioning Subform' ? sortedRecordsByDateDesc : orderedValues }
87
89
locale = { i18n . locale }
88
90
mode = { mode }
89
91
setOpen = { setOpenDialog }
@@ -109,15 +111,16 @@ function Component({
109
111
< GuidingQuestions label = { i18n . t ( "buttons.guidance" ) } text = { guidingQuestions [ i18n . locale ] } />
110
112
</ div >
111
113
) ;
112
- const latestValue = orderedValues === undefined ? null : orderedValues [ orderedValues . length - 1 ]
114
+
115
+ const getlatestValue = ( arr ) => arr ?. [ 0 ] ?? null ;
116
+ const latestValue = getlatestValue ( sortedRecordsByDateDesc ) ;
113
117
return (
114
118
< div className = { css . fieldArray } data-testid = "subform-field-array" >
115
119
116
120
{ /* Conditionally Render Child Functioning Subform Summary */ }
117
121
{ title === 'Child Functioning Subform' && (
118
122
< SubformSummary latestValue = { latestValue } />
119
123
) }
120
-
121
124
< div className = { cssContainer } >
122
125
{ ! renderAsAccordion && (
123
126
< div data-testid = "subForm-header" >
@@ -162,7 +165,7 @@ function Component({
162
165
mode = { mode }
163
166
selectedValue = { selectedValue }
164
167
open = { open }
165
- orderedValues = { orderedValues }
168
+ orderedValues = { title === 'Child Functioning Subform' ? sortedRecordsByDateDesc : orderedValues }
166
169
recordModuleID = { recordModuleID }
167
170
recordType = { recordType }
168
171
setOpen = { setOpenDialog }
0 commit comments