@@ -101,6 +101,44 @@ const execute = () => {
101101execute ()
102102
103103const hasResults = computed (() => tree .value !== null )
104+
105+ const expandToResults = () => {
106+ if (! tree .value ) return
107+
108+ // Helper function to check if a node has a primitive match
109+ const hasPrimitiveValue = (node : TreeNodeType ): boolean => {
110+ if (
111+ node .type === ' Identifier' &&
112+ node .astNode .type === ' Identifier' &&
113+ ' name' in node .astNode
114+ ) {
115+ return primitiveResults .value .includes ((node .astNode as { name: string }).name )
116+ } else if (node .type === ' Literal' && ' value' in node .astNode ) {
117+ const value = (node .astNode as { value: unknown }).value
118+ if (typeof value === ' string' || typeof value === ' number' || typeof value === ' boolean' ) {
119+ return primitiveResults .value .includes (value )
120+ }
121+ }
122+ return false
123+ }
124+
125+ // Deep clone the tree with updated expansion states
126+ const cloneWithExpansion = (node : TreeNodeType ): TreeNodeType => {
127+ const shouldExpand = node .isAncestorOfMatch || node .isMatched || hasPrimitiveValue (node )
128+
129+ return {
130+ ... node ,
131+ isExpanded: shouldExpand ,
132+ children: node .children .map ((child ) => cloneWithExpansion (child )),
133+ }
134+ }
135+
136+ if (Array .isArray (tree .value )) {
137+ tree .value = tree .value .map ((node ) => cloneWithExpansion (node ))
138+ } else {
139+ tree .value = cloneWithExpansion (tree .value )
140+ }
141+ }
104142 </script >
105143
106144<template >
@@ -131,7 +169,12 @@ const hasResults = computed(() => tree.value !== null)
131169 ></textarea >
132170 </div >
133171
134- <button @click =" execute" class =" execute-btn" >Execute Query</button >
172+ <div class =" button-group" >
173+ <button @click =" execute" class =" execute-btn" >Execute Query</button >
174+ <button @click =" expandToResults" class =" expand-btn" :disabled =" matchCount === 0" >
175+ Expand to Results
176+ </button >
177+ </div >
135178 </div >
136179
137180 <div v-if =" errorMessage" class =" error-message" >
@@ -238,7 +281,13 @@ const hasResults = computed(() => tree.value !== null)
238281 box-shadow : 0 0 0 2px rgba (76 , 175 , 80 , 0.1 );
239282}
240283
241- .execute-btn {
284+ .button-group {
285+ display : flex ;
286+ gap : 10px ;
287+ }
288+
289+ .execute-btn ,
290+ .expand-btn {
242291 background : #4caf50 ;
243292 color : white ;
244293 border : none ;
@@ -250,10 +299,24 @@ const hasResults = computed(() => tree.value !== null)
250299 transition : background-color 0.2s ;
251300}
252301
302+ .expand-btn {
303+ background : #2196f3 ;
304+ }
305+
253306.execute-btn :hover {
254307 background : #45a049 ;
255308}
256309
310+ .expand-btn :hover:not (:disabled ) {
311+ background : #1976d2 ;
312+ }
313+
314+ .expand-btn :disabled {
315+ background : #ccc ;
316+ cursor : not-allowed ;
317+ opacity : 0.6 ;
318+ }
319+
257320.execute-btn :active {
258321 background : #3d8b40 ;
259322}
0 commit comments