Skip to content

Commit bb4ec6f

Browse files
committed
fix
1 parent 87d9c3f commit bb4ec6f

4 files changed

Lines changed: 47 additions & 14 deletions

File tree

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,26 @@ export function Code({
221221
// Derived state
222222
const effectiveLanguage = (languageValue as 'javascript' | 'python' | 'json') || language
223223

224+
const trimmedCode = code.trim()
225+
const containsReferencePlaceholders =
226+
trimmedCode.includes('{{') ||
227+
trimmedCode.includes('}}') ||
228+
trimmedCode.includes('<') ||
229+
trimmedCode.includes('>')
230+
231+
const shouldValidateJson = effectiveLanguage === 'json' && !containsReferencePlaceholders
232+
224233
const isValidJson = useMemo(() => {
225-
if (subBlockId !== 'responseFormat' || !code.trim()) {
234+
if (!shouldValidateJson || !trimmedCode) {
226235
return true
227236
}
228237
try {
229-
JSON.parse(code)
238+
JSON.parse(trimmedCode)
230239
return true
231240
} catch {
232241
return false
233242
}
234-
}, [subBlockId, code])
243+
}, [shouldValidateJson, trimmedCode])
235244

236245
const gutterWidthPx = useMemo(() => {
237246
const lineCount = code.split('\n').length
@@ -309,14 +318,29 @@ export function Code({
309318
: storeValue
310319

311320
// Effects: JSON validation
321+
const lastValidationStatus = useRef<boolean>(true)
322+
312323
useEffect(() => {
313-
if (onValidationChange && subBlockId === 'responseFormat') {
314-
const timeoutId = setTimeout(() => {
315-
onValidationChange(isValidJson)
316-
}, 150)
317-
return () => clearTimeout(timeoutId)
324+
if (!onValidationChange) return
325+
326+
const nextStatus = shouldValidateJson ? isValidJson : true
327+
if (lastValidationStatus.current === nextStatus) {
328+
return
318329
}
319-
}, [isValidJson, onValidationChange, subBlockId])
330+
331+
lastValidationStatus.current = nextStatus
332+
333+
if (!shouldValidateJson) {
334+
onValidationChange(nextStatus)
335+
return
336+
}
337+
338+
const timeoutId = setTimeout(() => {
339+
onValidationChange(nextStatus)
340+
}, 150)
341+
342+
return () => clearTimeout(timeoutId)
343+
}, [isValidJson, onValidationChange, shouldValidateJson])
320344

321345
// Effects: AI stream handlers setup
322346
useEffect(() => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const renderLabel = (
190190
<div className='flex items-center gap-[6px] whitespace-nowrap'>
191191
{config.title}
192192
{required && <span className='ml-0.5'>*</span>}
193-
{config.id === 'responseFormat' && (
193+
{config.type === 'code' && config.language === 'json' && (
194194
<Tooltip.Root>
195195
<Tooltip.Trigger asChild>
196196
<AlertTriangle

apps/sim/blocks/blocks/onedrive.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ export const OneDriveBlock: BlockConfig<OneDriveResponse> = {
7979
{
8080
id: 'values',
8181
title: 'Values',
82-
type: 'long-input',
82+
type: 'code',
83+
language: 'json',
84+
generationType: 'json-object',
8385
placeholder:
84-
'Enter values as JSON array of arrays (e.g., [["A1","B1"],["A2","B2"]]) or an array of objects',
86+
'Enter a JSON array of rows (e.g., [["A1","B1"],["A2","B2"]]) or use a reference like {{block_1.rows}}',
8587
condition: {
8688
field: 'operation',
8789
value: 'create_file',
@@ -90,6 +92,13 @@ export const OneDriveBlock: BlockConfig<OneDriveResponse> = {
9092
value: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
9193
},
9294
},
95+
wandConfig: {
96+
enabled: true,
97+
prompt:
98+
'Generate a JSON array of arrays that can be written directly into an Excel worksheet.',
99+
placeholder: 'Describe the table you want to generate...',
100+
generationType: 'json-object',
101+
},
93102
required: false,
94103
},
95104
// File upload (basic mode)
@@ -379,7 +388,7 @@ export const OneDriveBlock: BlockConfig<OneDriveResponse> = {
379388
fileReference: { type: 'json', description: 'File reference from previous block' },
380389
content: { type: 'string', description: 'Text content to upload' },
381390
mimeType: { type: 'string', description: 'MIME type of file to create' },
382-
values: { type: 'string', description: 'Cell values for new Excel as JSON' },
391+
values: { type: 'json', description: 'Cell values for new Excel as JSON' },
383392
fileId: { type: 'string', description: 'File ID to download' },
384393
downloadFileName: { type: 'string', description: 'File name override for download' },
385394
folderId: { type: 'string', description: 'Folder ID' },

apps/sim/blocks/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export interface SubBlockConfig {
210210
}
211211
})
212212
// Props specific to 'code' sub-block type
213-
language?: 'javascript' | 'json'
213+
language?: 'javascript' | 'json' | 'python'
214214
generationType?: GenerationType
215215
collapsible?: boolean // Whether the code block can be collapsed
216216
defaultCollapsed?: boolean // Whether the code block is collapsed by default

0 commit comments

Comments
 (0)