@@ -3,6 +3,7 @@ import React, {
3
3
} from 'react' ;
4
4
import orderBy from 'lodash/orderBy' ;
5
5
import { Typography } from '@mui/material' ;
6
+ import { cloneDeep } from 'lodash' ;
6
7
7
8
import DataTable from '@/components/DataTable' ;
8
9
import useReport from '@/hooks/useReport' ;
@@ -64,7 +65,26 @@ const Therapeutic = ({
64
65
] = useState < TherapeuticType [ ] | Partial < TherapeuticType > [ ] > ( [ ] ) ;
65
66
66
67
const [ showDialog , setShowDialog ] = useState < boolean > ( false ) ;
67
- const [ editData , setEditData ] = useState ( ) ;
68
+ const [ editData , setEditData ] = useState < TherapeuticType > ( {
69
+ ident : null ,
70
+ createdAt : null ,
71
+ updatedAt : null ,
72
+ type : null ,
73
+ rank : null ,
74
+ gene : null ,
75
+ geneGraphkbId : null ,
76
+ variant : null ,
77
+ variantGraphkbId : null ,
78
+ therapy : null ,
79
+ therapyGraphkbId : null ,
80
+ context : null ,
81
+ contextGraphkbId : null ,
82
+ evidenceLevel : null ,
83
+ iprEvidenceLevel : null ,
84
+ evidenceLevelGraphkbId : null ,
85
+ kbStatementIds : null ,
86
+ notes : null ,
87
+ } ) ;
68
88
69
89
const { canEdit } = useReport ( ) ;
70
90
const { report } = useContext ( ReportContext ) ;
@@ -108,7 +128,7 @@ const Therapeutic = ({
108
128
try {
109
129
setShowDialog ( false ) ;
110
130
let tableData : TherapeuticType [ ] | Partial < TherapeuticType > [ ] ;
111
- let setter : React . Dispatch < React . SetStateAction < TherapeuticType [ ] > > ;
131
+ let setter : React . Dispatch < React . SetStateAction < TherapeuticType [ ] | Partial < TherapeuticType > [ ] > > ;
112
132
113
133
if ( newData ) {
114
134
if ( newData . type === 'therapeutic' ) {
@@ -142,12 +162,19 @@ const Therapeutic = ({
142
162
143
163
if ( tableType === 'therapeutic' ) {
144
164
setter = setTherapeuticData ;
145
- data = therapeuticData ;
165
+ data = cloneDeep ( therapeuticData ) ;
146
166
} else {
147
167
setter = setChemoresistanceData ;
148
- data = chemoresistanceData ;
168
+ data = cloneDeep ( chemoresistanceData ) ;
149
169
}
150
170
171
+ // For datafixes on the front-end, bugs introduced due to data inconsistencies between indexed by 0 or 1
172
+ // This forces indexed by 0
173
+ data = data . sort ( ( a , b ) => a . rank - b . rank ) . map ( ( row , idx ) => {
174
+ row . rank = idx ;
175
+ return row ;
176
+ } ) ;
177
+
151
178
const newData = data . map ( ( row ) => {
152
179
if ( row . rank === oldRank ) {
153
180
row . rank = newRank ;
@@ -162,6 +189,7 @@ const Therapeutic = ({
162
189
return row ;
163
190
} ) ;
164
191
192
+ // @ts -expect-error - specialized data object vs a general API call
165
193
await api . put ( `/reports/${ report . ident } /therapeutic-targets` , newData ) . request ( ) ;
166
194
setter ( newData ) ;
167
195
snackbar . success ( 'Row updated' ) ;
0 commit comments