@@ -4,6 +4,31 @@ import { isValidJson } from '../../overmind/utils'
44import * as styles from './styles'
55import { css } from 'emotion'
66import { colors } from '../../theme'
7+ import { FaEdit } from 'react-icons/fa'
8+
9+ type PathToolsProps = {
10+ path : string [ ]
11+ onClickPath : ( path : string [ ] ) => void
12+ }
13+
14+ const PathTools : FunctionComponent < PathToolsProps > = ( {
15+ path,
16+ onClickPath,
17+ children,
18+ } ) => {
19+ return (
20+ < div className = { styles . pathToolsWrapper } >
21+ { children } { ' ' }
22+ < FaEdit
23+ className = { styles . toolIcon }
24+ onClick = { ( event ) => {
25+ event . stopPropagation ( )
26+ onClickPath ( path )
27+ } }
28+ />
29+ </ div >
30+ )
31+ }
732
833type EditValueProps = {
934 value : any
@@ -79,15 +104,7 @@ const Nested: FunctionComponent<NestedProps> = ({
79104 } }
80105 >
81106 { path . length ? (
82- < span
83- className = { styles . key }
84- onClick = { ( event ) => {
85- event . stopPropagation ( )
86- onClickPath ( path )
87- } }
88- >
89- { path [ path . length - 1 ] } :
90- </ span >
107+ < span className = { styles . key } > { path [ path . length - 1 ] } :</ span >
91108 ) : null }
92109 < EditValue value = { value } onSubmit = { onSubmitState } />
93110 </ div >
@@ -103,24 +120,18 @@ const Nested: FunctionComponent<NestedProps> = ({
103120 onToggleExpand ( path )
104121 } }
105122 >
106- { path . length ? (
107- < span
108- className = { styles . key }
109- onClick = { ( event ) => {
110- event . stopPropagation ( )
111- onClickPath ( path )
112- } }
113- >
114- { path [ path . length - 1 ] } :
123+ < PathTools path = { path } onClickPath = { onClickPath } >
124+ { path . length ? (
125+ < span className = { styles . key } > { path [ path . length - 1 ] } : </ span >
126+ ) : null }
127+ { startBracket }
128+ < span className = { styles . keyCount } >
129+ { isArray
130+ ? keys . length + ' items'
131+ : keys . slice ( 0 , 3 ) . join ( ', ' ) + '...' }
115132 </ span >
116- ) : null }
117- { startBracket }
118- < span className = { styles . keyCount } >
119- { isArray
120- ? keys . length + ' items'
121- : keys . slice ( 0 , 3 ) . join ( ', ' ) + '...' }
122- </ span >
123- { endBracket }
133+ { endBracket }
134+ </ PathTools >
124135 </ div >
125136 )
126137 }
@@ -134,18 +145,12 @@ const Nested: FunctionComponent<NestedProps> = ({
134145 onToggleExpand ( path )
135146 } }
136147 >
137- { path . length ? (
138- < span
139- className = { styles . key }
140- onClick = { ( event ) => {
141- event . stopPropagation ( )
142- onClickPath ( path )
143- } }
144- >
145- { path [ path . length - 1 ] } :
146- </ span >
147- ) : null }
148- { startBracket }
148+ < PathTools path = { path } onClickPath = { onClickPath } >
149+ { path . length ? (
150+ < span className = { styles . key } > { path [ path . length - 1 ] } :</ span >
151+ ) : null }
152+ { startBracket }
153+ </ PathTools >
149154 </ div >
150155 < div className = { styles . nestedChildren } > { children ( ) } </ div >
151156 < div className = { styles . bracket ( false ) } > { endBracket } </ div >
@@ -172,15 +177,7 @@ const ValueComponent: FunctionComponent<ValueComponentProps> = ({
172177 return (
173178 < div className = { styles . genericValue } >
174179 { path . length ? (
175- < span
176- className = { styles . key }
177- onClick = { ( event ) => {
178- event . stopPropagation ( )
179- onClickPath ( path )
180- } }
181- >
182- { path [ path . length - 1 ] } :
183- </ span >
180+ < span className = { styles . key } > { path [ path . length - 1 ] } :</ span >
184181 ) : null }
185182 < EditValue value = { value } onSubmit = { onSubmitState } />
186183 </ div >
@@ -194,55 +191,37 @@ const ValueComponent: FunctionComponent<ValueComponentProps> = ({
194191 ) {
195192 return (
196193 < div className = { styles . otherValue } >
197- { path . length ? (
198- < span
199- className = { styles . key }
200- onClick = { ( event ) => {
201- event . stopPropagation ( )
202- onClickPath ( path )
203- } }
204- >
205- { path [ path . length - 1 ] } :
206- </ span >
207- ) : null }
208- { value . substr ( 1 , value . length - 2 ) }
194+ < PathTools path = { path } onClickPath = { onClickPath } >
195+ { path . length ? (
196+ < span className = { styles . key } > { path [ path . length - 1 ] } :</ span >
197+ ) : null }
198+ { value . substr ( 1 , value . length - 2 ) }
199+ </ PathTools >
209200 </ div >
210201 )
211202 }
212203
213204 if ( typeof value === 'string' ) {
214205 return (
215206 < div className = { styles . stringValue } >
216- { path . length ? (
217- < span
218- className = { styles . key }
219- onClick = { ( event ) => {
220- event . stopPropagation ( )
221- onClickPath ( path )
222- } }
223- >
224- { path [ path . length - 1 ] } :
225- </ span >
226- ) : null }
227- "{ value . length > 50 ? value . substr ( 0 , 50 ) + '...' : value } "
207+ < PathTools path = { path } onClickPath = { onClickPath } >
208+ { path . length ? (
209+ < span className = { styles . key } > { path [ path . length - 1 ] } :</ span >
210+ ) : null }
211+ "{ value . length > 50 ? value . substr ( 0 , 50 ) + '...' : value } "
212+ </ PathTools >
228213 </ div >
229214 )
230215 }
231216
232217 return (
233218 < div className = { styles . genericValue } >
234- { path . length ? (
235- < span
236- className = { styles . key }
237- onClick = { ( event ) => {
238- event . stopPropagation ( )
239- onClickPath ( path )
240- } }
241- >
242- { path [ path . length - 1 ] } :
243- </ span >
244- ) : null }
245- { String ( value ) }
219+ < PathTools path = { path } onClickPath = { onClickPath } >
220+ { path . length ? (
221+ < span className = { styles . key } > { path [ path . length - 1 ] } :</ span >
222+ ) : null }
223+ { String ( value ) }
224+ </ PathTools >
246225 </ div >
247226 )
248227}
0 commit comments