@@ -14,13 +14,14 @@ import {
14
14
modifyLocalStorageValue ,
15
15
setLocalStorageValue ,
16
16
} from '../../localStorage/liveFeedbackChat/operations' ;
17
- import { suggestionsTranslations } from '../../suggestionTranslations' ;
17
+ import {
18
+ suggestionFixesTranslations ,
19
+ suggestionsTranslations ,
20
+ } from '../../suggestionTranslations' ;
18
21
import {
19
22
AnswerFile ,
20
23
ChatSender ,
21
24
ChatShape ,
22
- FeedbackLine ,
23
- FeedbackShape ,
24
25
LiveFeedbackChatData ,
25
26
Suggestion ,
26
27
} from '../../types' ;
@@ -38,9 +39,17 @@ const initialState: LiveFeedbackChatState = {
38
39
liveFeedbackChatUrl : '' ,
39
40
} ;
40
41
41
- const sampleSuggestions = ( ) : Suggestion [ ] => {
42
+ const sampleSuggestions = (
43
+ isIncludingSuggestionFixes : boolean ,
44
+ ) : Suggestion [ ] => {
42
45
const suggestions = Object . values ( suggestionsTranslations ) ;
43
- const chosenSuggestions = shuffle ( suggestions ) . slice ( 0 , 3 ) ;
46
+ const suggestionFixes = Object . values ( suggestionFixesTranslations ) ;
47
+
48
+ const chosenSuggestions = isIncludingSuggestionFixes
49
+ ? shuffle ( suggestions )
50
+ . slice ( 0 , 2 )
51
+ . concat ( shuffle ( suggestionFixes ) . slice ( 0 , 1 ) )
52
+ : shuffle ( suggestions ) . slice ( 0 , 3 ) ;
44
53
45
54
return chosenSuggestions . map ( ( suggestion ) => {
46
55
return {
@@ -50,46 +59,6 @@ const sampleSuggestions = (): Suggestion[] => {
50
59
} ) ;
51
60
} ;
52
61
53
- const sortAndCombineFeedbacks = (
54
- feedbackLines : {
55
- path : string ;
56
- annotation : FeedbackLine ;
57
- } [ ] ,
58
- ) : {
59
- path : string ;
60
- line : number ;
61
- content : string [ ] ;
62
- } [ ] => {
63
- const processedFeedbackLines : {
64
- path : string ;
65
- line : number ;
66
- content : string [ ] ;
67
- } [ ] = Object . values (
68
- feedbackLines . reduce ( ( acc , current ) => {
69
- if ( ! acc [ ( current . path , current . annotation . line ) ] ) {
70
- acc [ ( current . path , current . annotation . line ) ] = {
71
- path : current . path ,
72
- line : current . annotation . line ,
73
- content : [ current . annotation . content ] ,
74
- } ;
75
- } else {
76
- acc [ ( current . path , current . annotation . line ) ] . content = [
77
- ...acc [ ( current . path , current . annotation . line ) ] . content ,
78
- current . annotation . content ,
79
- ] ;
80
- }
81
-
82
- return acc ;
83
- } , { } ) ,
84
- ) ;
85
-
86
- processedFeedbackLines
87
- . sort ( ( f1 , f2 ) => f1 . line - f2 . line )
88
- . sort ( ( f1 , f2 ) => f1 . path . localeCompare ( f2 . path ) ) ;
89
-
90
- return processedFeedbackLines ;
91
- } ;
92
-
93
62
const defaultValue = ( answerId : number ) : LiveFeedbackChatData => {
94
63
return {
95
64
id : answerId ,
@@ -101,7 +70,7 @@ const defaultValue = (answerId: number): LiveFeedbackChatData => {
101
70
isCurrentThreadExpired : false ,
102
71
chats : [ ] ,
103
72
answerFiles : [ ] ,
104
- suggestions : sampleSuggestions ( ) ,
73
+ suggestions : sampleSuggestions ( false ) ,
105
74
} ;
106
75
} ;
107
76
@@ -230,9 +199,7 @@ export const liveFeedbackChatSlice = createSlice({
230
199
...liveFeedbackChats . chats ,
231
200
{
232
201
sender : ChatSender . student ,
233
- lineNumber : null ,
234
- lineContent : null ,
235
- message : [ message ] ,
202
+ message,
236
203
createdAt : currentTime ,
237
204
isError : false ,
238
205
} ,
@@ -276,53 +243,18 @@ export const liveFeedbackChatSlice = createSlice({
276
243
action : PayloadAction < {
277
244
answerId : number ;
278
245
overallContent : string | null ;
279
- feedbackFiles : FeedbackShape [ ] ;
280
246
} > ,
281
247
) => {
282
- const { answerId, overallContent, feedbackFiles } = action . payload ;
248
+ const { answerId, overallContent } = action . payload ;
283
249
const liveFeedbackChats =
284
250
state . liveFeedbackChatPerAnswer . entities [ answerId ] ;
285
251
286
252
if ( liveFeedbackChats ) {
287
- const feedbackLines = feedbackFiles . flatMap ( ( file ) =>
288
- file . annotations . map ( ( annotation ) => ( {
289
- path : file . path ,
290
- annotation,
291
- } ) ) ,
292
- ) ;
293
-
294
- const sortedAndCombinedFeedbacks =
295
- sortAndCombineFeedbacks ( feedbackLines ) ;
296
-
297
- const answerLines = liveFeedbackChats . answerFiles . reduce (
298
- ( acc , current ) => {
299
- if ( ! acc [ current . filename ] ) {
300
- acc [ current . filename ] = current . content . split ( '\n' ) ;
301
- }
302
- return acc ;
303
- } ,
304
- { } ,
305
- ) ;
306
-
307
- const newChats : ChatShape [ ] = sortedAndCombinedFeedbacks . map ( ( line ) => {
308
- return {
309
- sender : ChatSender . codaveri ,
310
- filename : line . path ,
311
- lineNumber : line . line ,
312
- lineContent : answerLines [ line . path ] [ line . line - 1 ] . trim ( ) ?? null ,
313
- message : line . content ,
314
- createdAt : moment ( new Date ( ) ) . format ( SHORT_TIME_FORMAT ) ,
315
- isError : false ,
316
- } ;
317
- } ) ;
318
-
319
253
const summaryChat : ChatShape [ ] = overallContent
320
254
? [
321
255
{
322
256
sender : ChatSender . codaveri ,
323
- lineNumber : null ,
324
- lineContent : null ,
325
- message : [ overallContent ] ,
257
+ message : overallContent ,
326
258
createdAt : moment ( new Date ( ) ) . format ( SHORT_TIME_FORMAT ) ,
327
259
isError : false ,
328
260
} ,
@@ -332,8 +264,8 @@ export const liveFeedbackChatSlice = createSlice({
332
264
const changes : Partial < LiveFeedbackChatData > = {
333
265
isRequestingLiveFeedback : false ,
334
266
pendingFeedbackToken : null ,
335
- chats : [ ...liveFeedbackChats . chats , ...summaryChat , ... newChats ] ,
336
- suggestions : sampleSuggestions ( ) ,
267
+ chats : [ ...liveFeedbackChats . chats , ...summaryChat ] ,
268
+ suggestions : sampleSuggestions ( true ) ,
337
269
} ;
338
270
339
271
liveFeedbackChatAdapter . updateOne ( state . liveFeedbackChatPerAnswer , {
@@ -358,9 +290,7 @@ export const liveFeedbackChatSlice = createSlice({
358
290
if ( liveFeedbackChats ) {
359
291
const newChat : ChatShape = {
360
292
sender : ChatSender . codaveri ,
361
- lineNumber : null ,
362
- lineContent : null ,
363
- message : [ errorMessage ] ,
293
+ message : errorMessage ,
364
294
createdAt : moment ( new Date ( ) ) . format ( SHORT_TIME_FORMAT ) ,
365
295
isError : true ,
366
296
} ;
@@ -369,7 +299,7 @@ export const liveFeedbackChatSlice = createSlice({
369
299
isRequestingLiveFeedback : false ,
370
300
pendingFeedbackToken : null ,
371
301
chats : [ ...liveFeedbackChats . chats , newChat ] ,
372
- suggestions : sampleSuggestions ( ) ,
302
+ suggestions : sampleSuggestions ( true ) ,
373
303
} ;
374
304
375
305
liveFeedbackChatAdapter . updateOne ( state . liveFeedbackChatPerAnswer , {
0 commit comments