|
1 | | -import React, { useCallback, useEffect, useState } from 'react' |
2 | | -import { AlertCircle, PlusIcon, Server, WrenchIcon, XIcon } from 'lucide-react' |
| 1 | +import type React from 'react' |
| 2 | +import { useCallback, useEffect, useState } from 'react' |
| 3 | +import { PlusIcon, Server, WrenchIcon, XIcon } from 'lucide-react' |
3 | 4 | import { useParams } from 'next/navigation' |
4 | 5 | import { Button } from '@/components/ui/button' |
5 | 6 | import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' |
@@ -374,42 +375,40 @@ function FileUploadSyncWrapper({ |
374 | 375 | ) |
375 | 376 | } |
376 | 377 |
|
377 | | -// Error boundary component for tool input |
378 | | -class ToolInputErrorBoundary extends React.Component< |
379 | | - { children: React.ReactNode; blockName?: string }, |
380 | | - { hasError: boolean; error?: Error } |
381 | | -> { |
382 | | - constructor(props: any) { |
383 | | - super(props) |
384 | | - this.state = { hasError: false } |
385 | | - } |
386 | | - |
387 | | - static getDerivedStateFromError(error: Error) { |
388 | | - return { hasError: true, error } |
389 | | - } |
390 | | - |
391 | | - componentDidCatch(error: Error, info: React.ErrorInfo) { |
392 | | - console.error('ToolInput error:', error, info) |
393 | | - } |
394 | | - |
395 | | - render() { |
396 | | - if (this.state.hasError) { |
397 | | - return ( |
398 | | - <div className='rounded-md bg-red-50 p-4 text-red-800 text-sm dark:bg-red-900/20 dark:text-red-200'> |
399 | | - <div className='flex items-center gap-2'> |
400 | | - <AlertCircle className='h-4 w-4' /> |
401 | | - <span className='font-medium'>Tool Configuration Error</span> |
402 | | - </div> |
403 | | - <p className='mt-1 text-xs opacity-80'> |
404 | | - {this.props.blockName ? `Block "${this.props.blockName}": ` : ''} |
405 | | - Invalid tool reference. Please check the workflow configuration. |
406 | | - </p> |
407 | | - </div> |
408 | | - ) |
409 | | - } |
410 | | - |
411 | | - return this.props.children |
412 | | - } |
| 378 | +function ChannelSelectorSyncWrapper({ |
| 379 | + blockId, |
| 380 | + paramId, |
| 381 | + value, |
| 382 | + onChange, |
| 383 | + uiComponent, |
| 384 | + disabled, |
| 385 | + previewContextValues, |
| 386 | +}: { |
| 387 | + blockId: string |
| 388 | + paramId: string |
| 389 | + value: string |
| 390 | + onChange: (value: string) => void |
| 391 | + uiComponent: any |
| 392 | + disabled: boolean |
| 393 | + previewContextValues?: Record<string, any> |
| 394 | +}) { |
| 395 | + return ( |
| 396 | + <GenericSyncWrapper blockId={blockId} paramId={paramId} value={value} onChange={onChange}> |
| 397 | + <ChannelSelectorInput |
| 398 | + blockId={blockId} |
| 399 | + subBlock={{ |
| 400 | + id: paramId, |
| 401 | + type: 'channel-selector' as const, |
| 402 | + title: paramId, |
| 403 | + provider: uiComponent.provider || 'slack', |
| 404 | + placeholder: uiComponent.placeholder, |
| 405 | + }} |
| 406 | + onChannelSelect={onChange} |
| 407 | + disabled={disabled} |
| 408 | + previewContextValues={previewContextValues} |
| 409 | + /> |
| 410 | + </GenericSyncWrapper> |
| 411 | + ) |
413 | 412 | } |
414 | 413 |
|
415 | 414 | export function ToolInput({ |
@@ -1060,19 +1059,14 @@ export function ToolInput({ |
1060 | 1059 |
|
1061 | 1060 | case 'channel-selector': |
1062 | 1061 | return ( |
1063 | | - <ChannelSelectorInput |
| 1062 | + <ChannelSelectorSyncWrapper |
1064 | 1063 | blockId={blockId} |
1065 | | - subBlock={{ |
1066 | | - id: `tool-${toolIndex || 0}-${param.id}`, |
1067 | | - type: 'channel-selector' as const, |
1068 | | - title: param.id, |
1069 | | - provider: uiComponent.provider || 'slack', |
1070 | | - placeholder: uiComponent.placeholder, |
1071 | | - }} |
1072 | | - onChannelSelect={onChange} |
| 1064 | + paramId={param.id} |
| 1065 | + value={value} |
| 1066 | + onChange={onChange} |
| 1067 | + uiComponent={uiComponent} |
1073 | 1068 | disabled={disabled} |
1074 | | - isPreview={true} |
1075 | | - previewValue={value} |
| 1069 | + previewContextValues={currentToolParams as any} |
1076 | 1070 | /> |
1077 | 1071 | ) |
1078 | 1072 |
|
|
0 commit comments