Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): fix scorer create field cursor behavior #3307

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -167,11 +167,24 @@ const NestedForm: React.FC<{
const [currentValue, setCurrentValue] = useState(
getNestedValue(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]);
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;

if (unwrappedSchema instanceof z.ZodDiscriminatedUnion) {
return (
Expand Down Expand Up @@ -294,15 +307,15 @@ const NestedForm: React.FC<{
} else if (isZodType(fieldSchema, s => s instanceof z.ZodBoolean)) {
fieldType = 'checkbox';
}
const isOptional = fieldSchema instanceof z.ZodOptional;

return (
<TextFieldWithLabel
isOptional={isOptional}
label={!hideLabel ? keyName : undefined}
type={fieldType}
value={currentValue ?? ''}
onChange={value => updateConfig(currentPath, value, config, setConfig)}
onChange={handleChange}
onBlur={handleBlur}
autoFocus={autoFocus}
/>
);
Expand Down
Loading