1- import { type JSX , type MouseEvent , memo , useCallback , useRef , useState } from 'react'
1+ import { type JSX , type MouseEvent , memo , useCallback , useMemo , useRef , useState } from 'react'
22import isEqual from 'lodash/isEqual'
3- import { AlertTriangle , ArrowLeftRight , ArrowUp , Check , Clipboard } from 'lucide-react'
3+ import {
4+ AlertTriangle ,
5+ ArrowLeftRight ,
6+ ArrowUp ,
7+ Check ,
8+ Clipboard ,
9+ ExternalLink ,
10+ } from 'lucide-react'
11+ import { useParams } from 'next/navigation'
412import { Button , Input , Label , Tooltip } from '@/components/emcn/components'
513import { cn } from '@/lib/core/utils/cn'
614import type { FilterRule , SortRule } from '@/lib/table/query-builder/constants'
@@ -206,7 +214,12 @@ const renderLabel = (
206214 copied : boolean
207215 onCopy : ( ) => void
208216 } ,
209- labelSuffix ?: React . ReactNode
217+ labelSuffix ?: React . ReactNode ,
218+ externalLink ?: {
219+ show : boolean
220+ onClick : ( ) => void
221+ tooltip : string
222+ }
210223) : JSX . Element | null => {
211224 if ( config . type === 'switch' ) return null
212225 if ( ! config . title ) return null
@@ -215,6 +228,7 @@ const renderLabel = (
215228 const showWand = wandState ?. isWandEnabled && ! wandState . isPreview && ! wandState . disabled
216229 const showCanonicalToggle = ! ! canonicalToggle && ! wandState ?. isPreview
217230 const showCopy = copyState ?. showCopyButton && ! wandState ?. isPreview
231+ const showExternalLink = externalLink ?. show && ! wandState ?. isPreview
218232 const canonicalToggleDisabledResolved = canonicalToggleIsDisabled ?? canonicalToggle ?. disabled
219233
220234 return (
@@ -355,6 +369,23 @@ const renderLabel = (
355369 </ Tooltip . Content >
356370 </ Tooltip . Root >
357371 ) }
372+ { showExternalLink && (
373+ < Tooltip . Root >
374+ < Tooltip . Trigger asChild >
375+ < button
376+ type = 'button'
377+ className = 'flex h-[12px] w-[12px] flex-shrink-0 items-center justify-center bg-transparent p-0'
378+ onClick = { externalLink ?. onClick }
379+ aria-label = { externalLink ?. tooltip }
380+ >
381+ < ExternalLink className = '!h-[12px] !w-[12px] text-[var(--text-secondary)]' />
382+ </ button >
383+ </ Tooltip . Trigger >
384+ < Tooltip . Content side = 'top' >
385+ < p > { externalLink ?. tooltip } </ p >
386+ </ Tooltip . Content >
387+ </ Tooltip . Root >
388+ ) }
358389 </ div >
359390 </ div >
360391 )
@@ -419,6 +450,9 @@ function SubBlockComponent({
419450 labelSuffix,
420451 dependencyContext,
421452} : SubBlockProps ) : JSX . Element {
453+ const params = useParams ( )
454+ const workspaceId = params . workspaceId as string
455+
422456 const [ isValidJson , setIsValidJson ] = useState ( true )
423457 const [ isSearchActive , setIsSearchActive ] = useState ( false )
424458 const [ searchQuery , setSearchQuery ] = useState ( '' )
@@ -455,6 +489,30 @@ function SubBlockComponent({
455489 }
456490 } , [ webhookManagement ?. webhookUrl ] )
457491
492+ const tableId =
493+ config . type === 'table-selector' && subBlockValues
494+ ? ( subBlockValues [ config . id ] ?. value as string | null )
495+ : null
496+ const hasSelectedTable = tableId && ! tableId . startsWith ( '<' )
497+
498+ const handleNavigateToTable = useCallback ( ( ) => {
499+ if ( tableId && workspaceId ) {
500+ window . open ( `/workspace/${ workspaceId } /tables/${ tableId } ` , '_blank' )
501+ }
502+ } , [ workspaceId , tableId ] )
503+
504+ const externalLink = useMemo (
505+ ( ) =>
506+ config . type === 'table-selector' && hasSelectedTable
507+ ? {
508+ show : true ,
509+ onClick : handleNavigateToTable ,
510+ tooltip : 'View table' ,
511+ }
512+ : undefined ,
513+ [ config . type , hasSelectedTable , handleNavigateToTable ]
514+ )
515+
458516 /**
459517 * Handles wand icon click to activate inline prompt mode.
460518 * Focuses the input after a brief delay to ensure DOM is ready.
@@ -1099,7 +1157,8 @@ function SubBlockComponent({
10991157 copied,
11001158 onCopy : handleCopy ,
11011159 } ,
1102- labelSuffix
1160+ labelSuffix ,
1161+ externalLink
11031162 ) }
11041163 { renderInput ( ) }
11051164 </ div >
0 commit comments