File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
ui-services/history-ui-service/src/api Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,15 @@ const mapToHistoryEntry = (payload: HistoryEntryPayload): HistoryEntry => {
102102 } ;
103103} ;
104104
105+ function getEntryTimestamp ( entry : HistoryEntry ) : number {
106+ return (
107+ entry . sessionEndedAt ?. getTime ( ) ??
108+ entry . updatedAt ?. getTime ( ) ??
109+ entry . createdAt ?. getTime ( ) ??
110+ 0
111+ ) ;
112+ }
113+
105114export async function fetchHistoryEntries (
106115 options : {
107116 userId ?: string ;
@@ -139,7 +148,22 @@ export async function fetchHistoryEntries(
139148 }
140149
141150 const items = Array . isArray ( data . items ) ? data . items : [ ] ;
142- return items . map ( mapToHistoryEntry ) ;
151+ const entries = items . map ( mapToHistoryEntry ) ;
152+
153+ const latestByQuestionId = new Map < string , HistoryEntry > ( ) ;
154+ for ( const entry of entries ) {
155+ if ( ! entry . questionId ) {
156+ continue ;
157+ }
158+ const existing = latestByQuestionId . get ( entry . questionId ) ;
159+ if ( ! existing || getEntryTimestamp ( entry ) > getEntryTimestamp ( existing ) ) {
160+ latestByQuestionId . set ( entry . questionId , entry ) ;
161+ }
162+ }
163+
164+ return Array . from ( latestByQuestionId . values ( ) ) . sort (
165+ ( a , b ) => getEntryTimestamp ( b ) - getEntryTimestamp ( a ) ,
166+ ) ;
143167}
144168
145169export { HISTORY_SERVICE_BASE_URL } ;
You can’t perform that action at this time.
0 commit comments