@@ -46,6 +46,9 @@ export default class HistoryPopup extends React.Component {
46
46
payload : {
47
47
...props . payload ,
48
48
} ,
49
+ payloadCopy : {
50
+ ...props . payload , // Here first made copy of data for later comparison
51
+ } ,
49
52
...state ,
50
53
} ;
51
54
}
@@ -59,8 +62,32 @@ export default class HistoryPopup extends React.Component {
59
62
}
60
63
61
64
handleSubmit ( e ) {
65
+ // 1. Whenever user changes any parameter,it is stored into payload.So we get changed data into payload.
66
+ // 2. We have copy of original data without any parameter change in payloadCopy object on line no 49.
67
+ // 3. Here we are first identifying key name of secret parameter, payloadKey is key variable name for
68
+ // payload object and payloadCopyKey is variable name for payloadCopy object.
69
+ // 4. Once we get both key, we are checking value of that key in both object.
70
+ // 5. So if user change secret parameter data, it will get in payload.
71
+ // 6. When user does not change secret parameter,in payload secret parameter value is *** and in
72
+ // payloadCopyKey object it is always *** because we are getting changed value in payload object only.
73
+ // 7. If data in both key same, then there is no any change and if data is not same in both key
74
+ // i.e payloadKey and payloadCopyKey, data is changed and we will send changed data to API.
62
75
e . preventDefault ( ) ;
63
-
76
+ const hasValue = Object . values ( this . state . payload ) . includes ( '********' ) ;
77
+ let payLoadKey ;
78
+ if ( hasValue === true ) {
79
+ payLoadKey = Object . keys ( this . state . payload ) . find ( key => this . state . payload [ key ] === '********' ) ;
80
+ }
81
+
82
+ const isValue = Object . values ( this . state . payloadCopy ) . includes ( '********' ) ;
83
+ let payloadCopyKey ;
84
+ if ( isValue === true ) {
85
+ payloadCopyKey = Object . keys ( this . state . payloadCopy ) . find ( key => this . state . payloadCopy [ key ] === '********' ) ;
86
+ }
87
+
88
+ if ( this . state . payload [ payLoadKey ] === this . state . payloadCopy [ payloadCopyKey ] ) {
89
+ delete this . state . payload [ payLoadKey ] ;
90
+ }
64
91
this . props . onSubmit ( this . state . payload ) ;
65
92
}
66
93
0 commit comments