@@ -10,6 +10,8 @@ import ActionPreviewHeader from './ActionPreviewHeader';
10
10
import DiffTab from './tabs/DiffTab' ;
11
11
import StateTab from './tabs/StateTab' ;
12
12
import ActionTab from './tabs/ActionTab' ;
13
+ import { getValueByPath } from './utils/getValueByPath' ;
14
+ import { copyToClipboard } from './utils/copyToClipboard' ;
13
15
14
16
export interface TabComponentProps < S , A extends Action < string > > {
15
17
labelRenderer : LabelRenderer ;
@@ -184,7 +186,7 @@ class ActionPreview<S, A extends Action<string>> extends Component<
184
186
185
187
labelRenderer : LabelRenderer = ( [ key , ...rest ] , nodeType , expanded ) => {
186
188
const { onInspectPath, inspectedPath } = this . props ;
187
-
189
+ const reversedPath = [ key , ... rest ] . reverse ( ) ;
188
190
return (
189
191
< span >
190
192
< span > { key } </ span >
@@ -202,14 +204,41 @@ class ActionPreview<S, A extends Action<string>> extends Component<
202
204
onClick = { ( ) =>
203
205
onInspectPath ( [
204
206
...inspectedPath . slice ( 0 , inspectedPath . length - 1 ) ,
205
- ...[ key , ... rest ] . reverse ( ) ,
207
+ ...reversedPath ,
206
208
] )
207
209
}
208
210
>
209
- { '(pin)' }
210
- </ span >
211
- { ! expanded && ': ' }
211
+ { '(pin)' }
212
212
</ span >
213
+ < span
214
+ css = { ( theme ) => ( {
215
+ fontSize : '0.7em' ,
216
+ paddingLeft : '5px' ,
217
+ cursor : 'pointer' ,
218
+ '&:hover' : {
219
+ textDecoration : 'underline' ,
220
+ } ,
221
+ color : theme . PIN_COLOR ,
222
+ } ) }
223
+ onClick = { event => {
224
+ event . stopPropagation ( ) ;
225
+ let objectForCopying ;
226
+ if ( this . props . tabName === 'Action' ) {
227
+ objectForCopying = getValueByPath ( this . props . action , reversedPath ) ;
228
+ } else if ( this . props . tabName === 'State' ) {
229
+ objectForCopying = getValueByPath ( this . props . nextState , reversedPath ) ;
230
+ }
231
+ if ( objectForCopying !== undefined ) {
232
+ copyToClipboard ( objectForCopying ) ;
233
+ } else {
234
+ console . error ( 'Unable to find the object to copy' ) ;
235
+ }
236
+ } }
237
+ >
238
+ { '(copy)' }
239
+ </ span >
240
+ { ! expanded && ': ' }
241
+ </ span >
213
242
) ;
214
243
} ;
215
244
}
0 commit comments