Skip to content

Commit f1938f0

Browse files
committed
update table-selector
1 parent 592dd46 commit f1938f0

File tree

3 files changed

+79
-55
lines changed

3 files changed

+79
-55
lines changed

apps/docs/components/ui/icon-mapping.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ import {
118118
StagehandIcon,
119119
StripeIcon,
120120
SupabaseIcon,
121-
TableIcon,
122121
TavilyIcon,
123122
TelegramIcon,
124123
TextractIcon,
@@ -258,7 +257,6 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
258257
stripe: StripeIcon,
259258
stt_v2: STTIcon,
260259
supabase: SupabaseIcon,
261-
table: TableIcon,
262260
tavily: TavilyIcon,
263261
telegram: TelegramIcon,
264262
textract_v2: TextractIcon,
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use client'
22

33
import { useCallback, useMemo } from 'react'
4-
import { ExternalLink } from 'lucide-react'
54
import { useParams } from 'next/navigation'
6-
import { Combobox, type ComboboxOption, Tooltip } from '@/components/emcn'
7-
import { Button } from '@/components/ui/button'
5+
import { Combobox, type ComboboxOption } from '@/components/emcn'
86
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
97
import type { SubBlockConfig } from '@/blocks/types'
108
import { useTablesList } from '@/hooks/queries/tables'
@@ -18,12 +16,12 @@ interface TableSelectorProps {
1816
}
1917

2018
/**
21-
* Table selector component with dropdown and link to view table
19+
* Table selector component with dropdown for selecting workspace tables
2220
*
2321
* @remarks
24-
* Provides a dropdown to select workspace tables and an external link
25-
* to navigate directly to the table page view when a table is selected.
22+
* Provides a dropdown to select workspace tables.
2623
* Uses React Query for efficient data fetching and caching.
24+
* The external link to view the table is rendered in the label row by the parent SubBlock.
2725
*/
2826
export function TableSelector({
2927
blockId,
@@ -37,7 +35,6 @@ export function TableSelector({
3735

3836
const [storeValue, setStoreValue] = useSubBlockValue<string>(blockId, subBlock.id)
3937

40-
// Use React Query hook for table data - it handles caching, loading, and error states
4138
const {
4239
data: tables = [],
4340
isLoading,
@@ -62,50 +59,20 @@ export function TableSelector({
6259
[isPreview, disabled, setStoreValue]
6360
)
6461

65-
const handleNavigateToTable = useCallback(() => {
66-
if (tableId && workspaceId) {
67-
window.open(`/workspace/${workspaceId}/tables/${tableId}`, '_blank')
68-
}
69-
}, [workspaceId, tableId])
70-
71-
const hasSelectedTable = tableId && !tableId.startsWith('<')
72-
73-
// Convert error object to string if needed
7462
const errorMessage = error instanceof Error ? error.message : error ? String(error) : undefined
7563

7664
return (
77-
<div className='flex items-center gap-[6px]'>
78-
<div className='flex-1'>
79-
<Combobox
80-
options={options}
81-
value={tableId ?? undefined}
82-
onChange={handleChange}
83-
placeholder={subBlock.placeholder || 'Select a table'}
84-
disabled={disabled || isPreview}
85-
editable={false}
86-
isLoading={isLoading}
87-
error={errorMessage}
88-
searchable={options.length > 5}
89-
searchPlaceholder='Search...'
90-
/>
91-
</div>
92-
{hasSelectedTable && !isPreview && (
93-
<Tooltip.Root>
94-
<Tooltip.Trigger asChild>
95-
<Button
96-
variant='ghost'
97-
size='sm'
98-
className='h-[30px] w-[30px] flex-shrink-0 p-0'
99-
onClick={handleNavigateToTable}
100-
>
101-
<ExternalLink className='h-[14px] w-[14px] text-[var(--text-secondary)]' />
102-
</Button>
103-
</Tooltip.Trigger>
104-
<Tooltip.Content side='top'>
105-
<p>View table</p>
106-
</Tooltip.Content>
107-
</Tooltip.Root>
108-
)}
109-
</div>
65+
<Combobox
66+
options={options}
67+
value={tableId ?? undefined}
68+
onChange={handleChange}
69+
placeholder={subBlock.placeholder || 'Select a table'}
70+
disabled={disabled || isPreview}
71+
editable={false}
72+
isLoading={isLoading}
73+
error={errorMessage}
74+
searchable={options.length > 5}
75+
searchPlaceholder='Search...'
76+
/>
11077
)
11178
}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/sub-block.tsx

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
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'
22
import 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'
412
import { Button, Input, Label, Tooltip } from '@/components/emcn/components'
513
import { cn } from '@/lib/core/utils/cn'
614
import 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

Comments
 (0)