Skip to content

Commit 88d2e7b

Browse files
waleedlatif1waleed
authored andcommitted
fix(env-vars): remove regex parsing from table subblock, add formatDisplayText to various subblocks that didn't have it (#1582)
1 parent c04eb01 commit 88d2e7b

File tree

10 files changed

+106
-210
lines changed

10 files changed

+106
-210
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/document-tag-entry/document-tag-entry.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { checkTagTrigger, TagDropdown } from '@/components/ui/tag-dropdown'
99
import { MAX_TAG_SLOTS } from '@/lib/knowledge/consts'
1010
import { cn } from '@/lib/utils'
1111
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/hooks/use-sub-block-value'
12+
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
1213
import type { SubBlockConfig } from '@/blocks/types'
1314
import { useKnowledgeBaseTagDefinitions } from '@/hooks/use-knowledge-base-tag-definitions'
1415
import { useTagSelection } from '@/hooks/use-tag-selection'
@@ -40,6 +41,7 @@ export function DocumentTagEntry({
4041
isConnecting = false,
4142
}: DocumentTagEntryProps) {
4243
const [storeValue, setStoreValue] = useSubBlockValue<string>(blockId, subBlock.id)
44+
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
4345

4446
// Get the knowledge base ID from other sub-blocks
4547
const [knowledgeBaseIdValue] = useSubBlockValue(blockId, 'knowledgeBaseId')
@@ -301,7 +303,12 @@ export function DocumentTagEntry({
301303
)}
302304
/>
303305
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'>
304-
<div className='whitespace-pre'>{formatDisplayText(cellValue)}</div>
306+
<div className='whitespace-pre'>
307+
{formatDisplayText(cellValue, {
308+
accessiblePrefixes,
309+
highlightAll: !accessiblePrefixes,
310+
})}
311+
</div>
305312
</div>
306313
{showDropdown && availableTagDefinitions.length > 0 && (
307314
<div className='absolute top-full left-0 z-[100] mt-1 w-full'>
@@ -389,7 +396,10 @@ export function DocumentTagEntry({
389396
/>
390397
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'>
391398
<div className='whitespace-pre text-muted-foreground'>
392-
{formatDisplayText(cellValue)}
399+
{formatDisplayText(cellValue, {
400+
accessiblePrefixes,
401+
highlightAll: !accessiblePrefixes,
402+
})}
393403
</div>
394404
</div>
395405
{showTypeDropdown && !isReadOnly && (
@@ -469,7 +479,12 @@ export function DocumentTagEntry({
469479
className='w-full border-0 text-transparent caret-foreground placeholder:text-muted-foreground/50 focus-visible:ring-0 focus-visible:ring-offset-0'
470480
/>
471481
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'>
472-
<div className='whitespace-pre'>{formatDisplayText(cellValue)}</div>
482+
<div className='whitespace-pre'>
483+
{formatDisplayText(cellValue, {
484+
accessiblePrefixes,
485+
highlightAll: !accessiblePrefixes,
486+
})}
487+
</div>
473488
</div>
474489
</div>
475490
</td>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/knowledge-tag-filters/knowledge-tag-filters.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ export function KnowledgeTagFilters({
239239
onBlur={handleBlur}
240240
/>
241241
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'>
242-
<div className='whitespace-pre'>{formatDisplayText(cellValue || 'Select tag')}</div>
242+
<div className='whitespace-pre'>
243+
{formatDisplayText(cellValue || 'Select tag', {
244+
accessiblePrefixes,
245+
highlightAll: !accessiblePrefixes,
246+
})}
247+
</div>
243248
</div>
244249
{showDropdown && tagDefinitions.length > 0 && (
245250
<div className='absolute top-full left-0 z-[100] mt-1 w-full'>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/mcp-dynamic-args/mcp-dynamic-args.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback } from 'react'
22
import { useParams } from 'next/navigation'
3+
import { formatDisplayText } from '@/components/ui/formatted-text'
34
import { Input } from '@/components/ui/input'
45
import { Label } from '@/components/ui/label'
56
import {
@@ -14,6 +15,7 @@ import { Switch } from '@/components/ui/switch'
1415
import { Textarea } from '@/components/ui/textarea'
1516
import { cn } from '@/lib/utils'
1617
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/hooks/use-sub-block-value'
18+
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
1719
import { useMcpTools } from '@/hooks/use-mcp-tools'
1820
import { formatParameterLabel } from '@/tools/params'
1921

@@ -37,6 +39,7 @@ export function McpDynamicArgs({
3739
const { mcpTools } = useMcpTools(workspaceId)
3840
const [selectedTool] = useSubBlockValue(blockId, 'tool')
3941
const [toolArgs, setToolArgs] = useSubBlockValue(blockId, subBlockId)
42+
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
4043

4144
const selectedToolConfig = mcpTools.find((tool) => tool.id === selectedTool)
4245
const toolSchema = selectedToolConfig?.inputSchema
@@ -180,7 +183,7 @@ export function McpDynamicArgs({
180183

181184
case 'long-input':
182185
return (
183-
<div key={`${paramName}-long`}>
186+
<div key={`${paramName}-long`} className='relative'>
184187
<Textarea
185188
value={value || ''}
186189
onChange={(e) => updateParameter(paramName, e.target.value, paramSchema)}
@@ -192,8 +195,14 @@ export function McpDynamicArgs({
192195
}
193196
disabled={disabled}
194197
rows={4}
195-
className='min-h-[80px] resize-none'
198+
className='min-h-[80px] resize-none text-transparent caret-foreground'
196199
/>
200+
<div className='pointer-events-none absolute inset-0 overflow-auto whitespace-pre-wrap break-words p-3 text-sm'>
201+
{formatDisplayText(value || '', {
202+
accessiblePrefixes,
203+
highlightAll: !accessiblePrefixes,
204+
})}
205+
</div>
197206
</div>
198207
)
199208

@@ -203,9 +212,10 @@ export function McpDynamicArgs({
203212
paramName.toLowerCase().includes('password') ||
204213
paramName.toLowerCase().includes('token')
205214
const isNumeric = paramSchema.type === 'number' || paramSchema.type === 'integer'
215+
const isTextInput = !isPassword && !isNumeric
206216

207217
return (
208-
<div key={`${paramName}-short`}>
218+
<div key={`${paramName}-short`} className={isTextInput ? 'relative' : ''}>
209219
<Input
210220
type={isPassword ? 'password' : isNumeric ? 'number' : 'text'}
211221
value={value || ''}
@@ -231,7 +241,18 @@ export function McpDynamicArgs({
231241
`Enter ${formatParameterLabel(paramName).toLowerCase()}`
232242
}
233243
disabled={disabled}
244+
className={isTextInput ? 'text-transparent caret-foreground' : ''}
234245
/>
246+
{isTextInput && (
247+
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'>
248+
<div className='whitespace-pre'>
249+
{formatDisplayText(value?.toString() || '', {
250+
accessiblePrefixes,
251+
highlightAll: !accessiblePrefixes,
252+
})}
253+
</div>
254+
</div>
255+
)}
235256
</div>
236257
)
237258
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Input } from '@/components/ui/input'
88
import { checkTagTrigger, TagDropdown } from '@/components/ui/tag-dropdown'
99
import { cn } from '@/lib/utils'
1010
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/hooks/use-sub-block-value'
11+
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
1112

1213
interface TableProps {
1314
blockId: string
@@ -34,6 +35,7 @@ export function Table({
3435
const params = useParams()
3536
const workspaceId = params.workspaceId as string
3637
const [storeValue, setStoreValue] = useSubBlockValue<TableRow[]>(blockId, subBlockId)
38+
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
3739

3840
// Use preview value when in preview mode, otherwise use store value
3941
const value = isPreview ? previewValue : storeValue
@@ -240,7 +242,12 @@ export function Table({
240242
data-overlay={cellKey}
241243
className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'
242244
>
243-
<div className='whitespace-pre'>{formatDisplayText(cellValue)}</div>
245+
<div className='whitespace-pre'>
246+
{formatDisplayText(cellValue, {
247+
accessiblePrefixes,
248+
highlightAll: !accessiblePrefixes,
249+
})}
250+
</div>
244251
</div>
245252
</div>
246253
</td>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/trigger-config/components/trigger-config-section.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CommandItem,
1111
CommandList,
1212
} from '@/components/ui/command'
13+
import { formatDisplayText } from '@/components/ui/formatted-text'
1314
import { Input } from '@/components/ui/input'
1415
import { Label } from '@/components/ui/label'
1516
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
@@ -23,9 +24,11 @@ import {
2324
import { Switch } from '@/components/ui/switch'
2425
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
2526
import { cn } from '@/lib/utils'
27+
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
2628
import type { TriggerConfig } from '@/triggers/types'
2729

2830
interface TriggerConfigSectionProps {
31+
blockId: string
2932
triggerDef: TriggerConfig
3033
config: Record<string, any>
3134
onChange: (fieldId: string, value: any) => void
@@ -34,6 +37,7 @@ interface TriggerConfigSectionProps {
3437
}
3538

3639
export function TriggerConfigSection({
40+
blockId,
3741
triggerDef,
3842
config,
3943
onChange,
@@ -42,6 +46,7 @@ export function TriggerConfigSection({
4246
}: TriggerConfigSectionProps) {
4347
const [showSecrets, setShowSecrets] = useState<Record<string, boolean>>({})
4448
const [copied, setCopied] = useState<string | null>(null)
49+
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
4550

4651
const copyToClipboard = (text: string, type: string) => {
4752
navigator.clipboard.writeText(text)
@@ -258,9 +263,20 @@ export function TriggerConfigSection({
258263
className={cn(
259264
'h-9 rounded-[8px]',
260265
isSecret ? 'pr-32' : '',
261-
'focus-visible:ring-2 focus-visible:ring-primary/20'
266+
'focus-visible:ring-2 focus-visible:ring-primary/20',
267+
!isSecret && 'text-transparent caret-foreground'
262268
)}
263269
/>
270+
{!isSecret && (
271+
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden bg-transparent px-3 text-sm'>
272+
<div className='whitespace-pre'>
273+
{formatDisplayText(value?.toString() || '', {
274+
accessiblePrefixes,
275+
highlightAll: !accessiblePrefixes,
276+
})}
277+
</div>
278+
</div>
279+
)}
264280
{isSecret && (
265281
<div className='absolute top-0.5 right-0.5 flex h-8 items-center gap-1 pr-1'>
266282
<Button

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/trigger-config/components/trigger-modal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ export function TriggerModal({
467467
)}
468468

469469
<TriggerConfigSection
470+
blockId={blockId}
470471
triggerDef={triggerDef}
471472
config={config}
472473
onChange={handleConfigChange}

apps/sim/executor/handlers/condition/condition-handler.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('ConditionBlockHandler', () => {
165165
mockContext,
166166
mockBlock
167167
)
168-
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('context.value > 5', true)
168+
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('context.value > 5')
169169
expect(result).toEqual(expectedOutput)
170170
expect(mockContext.decisions.condition.get(mockBlock.id)).toBe('cond1')
171171
})
@@ -205,7 +205,7 @@ describe('ConditionBlockHandler', () => {
205205
mockContext,
206206
mockBlock
207207
)
208-
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('context.value < 0', true)
208+
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('context.value < 0')
209209
expect(result).toEqual(expectedOutput)
210210
expect(mockContext.decisions.condition.get(mockBlock.id)).toBe('else1')
211211
})
@@ -241,7 +241,7 @@ describe('ConditionBlockHandler', () => {
241241
mockContext,
242242
mockBlock
243243
)
244-
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('10 > 5', true)
244+
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('10 > 5')
245245
expect(mockContext.decisions.condition.get(mockBlock.id)).toBe('cond1')
246246
})
247247

@@ -268,7 +268,7 @@ describe('ConditionBlockHandler', () => {
268268
mockContext,
269269
mockBlock
270270
)
271-
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('"john" !== null', true)
271+
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('"john" !== null')
272272
expect(mockContext.decisions.condition.get(mockBlock.id)).toBe('cond1')
273273
})
274274

@@ -295,7 +295,7 @@ describe('ConditionBlockHandler', () => {
295295
mockContext,
296296
mockBlock
297297
)
298-
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('{{POOP}} === "hi"', true)
298+
expect(mockResolver.resolveEnvVariables).toHaveBeenCalledWith('{{POOP}} === "hi"')
299299
expect(mockContext.decisions.condition.get(mockBlock.id)).toBe('cond1')
300300
})
301301

apps/sim/executor/handlers/condition/condition-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class ConditionBlockHandler implements BlockHandler {
109109
// Use full resolution pipeline: variables -> block references -> env vars
110110
const resolvedVars = this.resolver.resolveVariableReferences(conditionValueString, block)
111111
const resolvedRefs = this.resolver.resolveBlockReferences(resolvedVars, context, block)
112-
resolvedConditionValue = this.resolver.resolveEnvVariables(resolvedRefs, true)
112+
resolvedConditionValue = this.resolver.resolveEnvVariables(resolvedRefs)
113113
logger.info(
114114
`Resolved condition "${condition.title}" (${condition.id}): from "${conditionValueString}" to "${resolvedConditionValue}"`
115115
)

apps/sim/executor/resolver/resolver.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ describe('InputResolver', () => {
432432

433433
expect(result.apiKey).toBe('test-api-key')
434434
expect(result.url).toBe('https://example.com?key=test-api-key')
435-
expect(result.regularParam).toBe('Base URL is: {{BASE_URL}}')
435+
expect(result.regularParam).toBe('Base URL is: https://api.example.com')
436436
})
437437

438438
it('should resolve explicit environment variables', () => {
@@ -458,7 +458,7 @@ describe('InputResolver', () => {
458458
expect(result.explicitEnv).toBe('https://api.example.com')
459459
})
460460

461-
it('should not resolve environment variables in regular contexts', () => {
461+
it('should resolve environment variables in all contexts', () => {
462462
const block: SerializedBlock = {
463463
id: 'test-block',
464464
metadata: { id: 'generic', name: 'Test Block' },
@@ -478,7 +478,7 @@ describe('InputResolver', () => {
478478

479479
const result = resolver.resolveInputs(block, mockContext)
480480

481-
expect(result.regularParam).toBe('Value with {{API_KEY}} embedded')
481+
expect(result.regularParam).toBe('Value with test-api-key embedded')
482482
})
483483
})
484484

0 commit comments

Comments
 (0)