From 7e1ff70109627bdfc935a339ec84a419fbe97fd0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 24 Jun 2026 12:59:00 +0000 Subject: [PATCH] Tweaks --- .../components/forms/fields/ApiFormField.tsx | 4 ++-- .../src/components/forms/fields/TreeField.tsx | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/frontend/src/components/forms/fields/ApiFormField.tsx b/src/frontend/src/components/forms/fields/ApiFormField.tsx index e10f70fda4..86b8ef87d6 100644 --- a/src/frontend/src/components/forms/fields/ApiFormField.tsx +++ b/src/frontend/src/components/forms/fields/ApiFormField.tsx @@ -146,7 +146,7 @@ export function ApiFormField({ case 'related field': // Redirect location or category fields to the appropriate tree field if ( - fieldDefinition.api_url == apiUrl(ApiEndpoints.stock_location_list) + fieldDefinition.api_url === apiUrl(ApiEndpoints.stock_location_list) ) { return ( ); } else if ( - fieldDefinition.api_url == apiUrl(ApiEndpoints.category_list) + fieldDefinition.api_url === apiUrl(ApiEndpoints.category_list) ) { return ( ([]); const query = useQuery({ + enabled: + !definition.disabled && + !definition.hidden && + (isDropdownOpen || selectedValue != null), queryKey: [ 'tree-field', fieldName, endpoint, + isDropdownOpen, debouncedSearch, selectedValue ], @@ -73,9 +78,10 @@ export function TreeField({ search: debouncedSearch || undefined, // Include the selected node and its ancestors in the initial response // so the node label is available before the user interacts with the field. - expand_to: - !debouncedSearch && !!selectedValue ? selectedValue : undefined, - max_level: !debouncedSearch && !!selectedValue ? 0 : undefined + max_level: debouncedSearch ? undefined : 0, + expand_to: debouncedSearch + ? undefined + : (selectedValue ?? undefined) } }) .then((res) => res.data ?? []) @@ -162,7 +168,7 @@ export function TreeField({ const onChange = useCallback( (val: string | null) => { - const pk = val ? Number.parseInt(val) : null; + const pk = val ? Number.parseInt(val, 10) : null; field.onChange(pk); definition.onValueChange?.(pk); }, @@ -244,6 +250,7 @@ export function TreeField({ return (