From ca0d1efda2b491205ea95014cff63cd16099145c Mon Sep 17 00:00:00 2001 From: gtarpenning Date: Mon, 9 Dec 2024 18:26:55 -0800 Subject: [PATCH 1/3] fix(ui): fix error state saving in human feedback form --- .../StructuredFeedback/HumanAnnotation.tsx | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx index 7facffe9556..ba560b219b7 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/HumanAnnotation.tsx @@ -53,17 +53,11 @@ export const HumanAnnotationCell: React.FC = props => { const feedbackSpecRef = props.hfSpec.ref; useEffect(() => { - if (!props.readOnly) { - // We don't need to listen for feedback changes if the cell is editable - // it is being controlled by local state - return; - } return getTsClient().registerOnFeedbackListener( props.callRef, query.refetch ); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [props.callRef]); + }, [props.callRef, query.refetch]); useEffect(() => { if (foundFeedbackCallRef && props.callRef !== foundFeedbackCallRef) { @@ -183,6 +177,14 @@ const FeedbackComponentSelector: React.FC<{ }) => { const wrappedOnAddFeedback = useCallback( async (value: any) => { + if (value == null || value === foundValue || value === '') { + // Remove from unsaved changes if value is invalid + setUnsavedFeedbackChanges(curr => { + const {[feedbackSpecRef]: _, ...rest} = curr; + return rest; + }); + return true; + } setUnsavedFeedbackChanges(curr => ({ ...curr, [feedbackSpecRef]: () => onAddFeedback(value), @@ -346,21 +348,10 @@ export const NumericalFeedbackColumn = ({ focused?: boolean; isInteger?: boolean; }) => { - const debouncedFn = useMemo( - () => - _.debounce((val: number | null) => onAddFeedback?.(val), DEBOUNCE_VAL), - [onAddFeedback] - ); - useEffect(() => { - return () => { - debouncedFn.cancel(); - }; - }, [debouncedFn]); - return ( onAddFeedback?.(value)} min={min} max={max} isInteger={isInteger} @@ -446,7 +437,7 @@ export const EnumFeedbackColumn = ({ })); return opts; }, [options]); - const [value, setValue] = useState