From f93a1bf837801ac246179c188c1bf76f59b8aeef Mon Sep 17 00:00:00 2001 From: Adam Gough Date: Sat, 31 May 2025 22:30:34 -0700 Subject: [PATCH] resolved comments --- .../components/deployed-workflow-card.tsx | 1 - .../control-bar/control-bar.test.ts | 8 ------ .../components/sub-block/components/code.tsx | 11 ++++---- .../sub-block/components/eval-input.tsx | 27 +++++++++---------- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/components/deployed-workflow-card.tsx b/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/components/deployed-workflow-card.tsx index 91e380d482..187c4fe10e 100644 --- a/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/components/deployed-workflow-card.tsx +++ b/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/components/deployed-workflow-card.tsx @@ -27,7 +27,6 @@ export function DeployedWorkflowCard({ const workflowToShow = showingDeployed ? deployedWorkflowState : currentWorkflowState const activeWorkflowId = useWorkflowRegistry((state) => state.activeWorkflowId) - // // Generate a unique key for the workflow preview const previewKey = useMemo(() => { return `${showingDeployed ? 'deployed' : 'current'}-preview-${activeWorkflowId}}` }, [showingDeployed, activeWorkflowId]) diff --git a/apps/sim/app/w/[id]/components/control-bar/control-bar.test.ts b/apps/sim/app/w/[id]/components/control-bar/control-bar.test.ts index 9159594aad..68d2c785c0 100644 --- a/apps/sim/app/w/[id]/components/control-bar/control-bar.test.ts +++ b/apps/sim/app/w/[id]/components/control-bar/control-bar.test.ts @@ -10,7 +10,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -// Mock the stores const mockWorkflowStore = { getState: vi.fn(), subscribe: vi.fn(), @@ -52,7 +51,6 @@ vi.mock('@/stores/workflows/utils', () => ({ mergeSubblockState: vi.fn((blocks) => blocks), })) -// Mock other dependencies vi.mock('@/lib/logs/console-logger', () => ({ createLogger: () => ({ error: vi.fn(), @@ -62,8 +60,6 @@ vi.mock('@/lib/logs/console-logger', () => ({ }), })) -// Import the function we want to test -// Since it's inside a component, we'll extract it for testing const normalizeBlocksForComparison = (blocks: Record) => { if (!blocks) return [] @@ -121,13 +117,11 @@ describe('normalizeBlocksForComparison', () => { expect(result).toHaveLength(2) - // Should only contain type, name, and subBlocks result.forEach((block) => { expect(block).toHaveProperty('type') expect(block).toHaveProperty('name') expect(block).toHaveProperty('subBlocks') - // Should NOT contain metadata properties expect(block).not.toHaveProperty('id') expect(block).not.toHaveProperty('position') expect(block).not.toHaveProperty('height') @@ -145,7 +139,6 @@ describe('normalizeBlocksForComparison', () => { const result = normalizeBlocksForComparison(blocks) - // Should be sorted: agent blocks first (by name), then api blocks (by name) expect(result[0]).toEqual({ type: 'agent', name: 'Agent 1', subBlocks: {} }) expect(result[1]).toEqual({ type: 'agent', name: 'Agent 2', subBlocks: {} }) expect(result[2]).toEqual({ type: 'api', name: 'API 1', subBlocks: {} }) @@ -164,7 +157,6 @@ describe('normalizeBlocksForComparison', () => { 'block-2': { type: 'agent', name: 'Agent 1', - // subBlocks missing }, } diff --git a/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx b/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx index d97d0c8b57..b04b805bcb 100644 --- a/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx +++ b/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx @@ -1,5 +1,5 @@ import type { ReactElement } from 'react' -import { useEffect, useMemo, useRef, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { Wand2 } from 'lucide-react' import { highlight, languages } from 'prismjs' import 'prismjs/components/prism-javascript' @@ -60,11 +60,10 @@ export function Code({ previewValue, }: CodeProps) { // Determine the AI prompt placeholder based on language - const aiPromptPlaceholder = useMemo(() => { - return language === 'json' - ? 'Describe the JSON schema you need...' - : 'Describe the function you need...' - }, [language]) + const aiPromptPlaceholder = + language === 'json' + ? 'Describe the JSON schema to generate...' + : 'Describe the JavaScript code to generate...' // State management const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlockId) diff --git a/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/eval-input.tsx b/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/eval-input.tsx index 383f7b5130..83817dda1e 100644 --- a/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/eval-input.tsx +++ b/apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/eval-input.tsx @@ -85,24 +85,21 @@ export function EvalInput({ ) } - const updateThreshold = (id: string, value: string) => { - if (isPreview) return - - // Allow empty values for clearing - const sanitizedValue = value.replace(/[^0-9.-]/g, '') - if (sanitizedValue === '') { - setStoreValue( - metrics.map((metric) => (metric.id === id ? { ...metric, threshold: undefined } : metric)) - ) - return - } - + // Validation handlers + const handleRangeBlur = (id: string, field: 'min' | 'max', value: string) => { + const sanitizedValue = value.replace(/[^\d.-]/g, '') const numValue = Number.parseFloat(sanitizedValue) setStoreValue( metrics.map((metric) => metric.id === id - ? { ...metric, threshold: Number.isNaN(numValue) ? undefined : numValue } + ? { + ...metric, + range: { + ...metric.range, + [field]: !Number.isNaN(numValue) ? numValue : 0, + }, + } : metric ) ) @@ -190,7 +187,7 @@ export function EvalInput({ type='text' value={metric.range.min} onChange={(e) => updateRange(metric.id, 'min', e.target.value)} - onBlur={(e) => updateThreshold(metric.id, e.target.value)} + onBlur={(e) => handleRangeBlur(metric.id, 'min', e.target.value)} disabled={isPreview} className='placeholder:text-muted-foreground/50' /> @@ -201,7 +198,7 @@ export function EvalInput({ type='text' value={metric.range.max} onChange={(e) => updateRange(metric.id, 'max', e.target.value)} - onBlur={(e) => updateThreshold(metric.id, e.target.value)} + onBlur={(e) => handleRangeBlur(metric.id, 'max', e.target.value)} disabled={isPreview} className='placeholder:text-muted-foreground/50' />