From 910cfdc1f30a3f38f1ae1a27b319150b38ab099f Mon Sep 17 00:00:00 2001 From: gtarpenning Date: Mon, 23 Dec 2024 09:27:29 -0800 Subject: [PATCH 1/2] chore(ui): fix scorer create field cursor behavior --- .../pages/ScorersPage/ZodSchemaForm.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx index 94106a7a3b20..26837bc67d46 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx @@ -6,7 +6,7 @@ import { InputLabel, } from '@material-ui/core'; import {Button} from '@wandb/weave/components/Button'; -import React, {useEffect, useMemo, useState} from 'react'; +import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {z} from 'zod'; import { @@ -167,11 +167,20 @@ const NestedForm: React.FC<{ const [currentValue, setCurrentValue] = useState( getNestedValue(config, currentPath) ); - useEffect(() => { - setCurrentValue(getNestedValue(config, currentPath)); - }, [config, currentPath]); + + // Only update parent config on blur, for string fields + const handleBlur = useCallback(() => { + if (currentValue !== getNestedValue(config, currentPath)) { + updateConfig(currentPath, currentValue, config, setConfig); + } + }, [currentValue, currentPath, config, setConfig]); + // Handle local changes without updating parent immediately for string fields + const handleChange = useCallback((value: string) => { + setCurrentValue(value); + }, []); const unwrappedSchema = unwrapSchema(fieldSchema); + const isOptional = fieldSchema instanceof z.ZodOptional; if (unwrappedSchema instanceof z.ZodDiscriminatedUnion) { return ( @@ -294,7 +303,6 @@ const NestedForm: React.FC<{ } else if (isZodType(fieldSchema, s => s instanceof z.ZodBoolean)) { fieldType = 'checkbox'; } - const isOptional = fieldSchema instanceof z.ZodOptional; return ( updateConfig(currentPath, value, config, setConfig)} + onChange={handleChange} + onBlur={handleBlur} autoFocus={autoFocus} /> ); From 68b8c44f5b98dafe95ff1315a4e208b26b9984fb Mon Sep 17 00:00:00 2001 From: gtarpenning Date: Tue, 7 Jan 2025 08:55:14 -0800 Subject: [PATCH 2/2] fix --- .../Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx index 26837bc67d46..1a03082e9c47 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/ZodSchemaForm.tsx @@ -174,11 +174,15 @@ const NestedForm: React.FC<{ updateConfig(currentPath, currentValue, config, setConfig); } }, [currentValue, currentPath, config, setConfig]); - // Handle local changes without updating parent immediately for string fields const handleChange = useCallback((value: string) => { setCurrentValue(value); }, []); + // set current value for non-string fields + useEffect(() => { + setCurrentValue(getNestedValue(config, currentPath)); + }, [config, currentPath]); + const unwrappedSchema = unwrapSchema(fieldSchema); const isOptional = fieldSchema instanceof z.ZodOptional;