Skip to content

Commit

Permalink
fix(weave): Ensure newVars are passed in when expanding a panel op (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
domphan-wandb authored Nov 22, 2024
1 parent 585752e commit 0cc26d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions weave-js/src/components/Panel2/PanelExpression/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import {
} from 'react';
import {DropdownProps} from 'semantic-ui-react';

import {useWeaveFeaturesContext} from '../../../context';
import {useWeaveContext} from '../../../context';
import {useWeaveContext, useWeaveFeaturesContext} from '../../../context';
import {usePrevious} from '../../../hookUtils';
import {useExpandedNode} from '../../../react';
import {PanelStack, usePanelStacksForType} from '../availablePanels';
Expand Down Expand Up @@ -237,8 +236,10 @@ export function usePanelExpressionState(props: PanelExpressionProps) {
? exp
: refinedExpressionLoader.result;

const {loading: isExpanding, result: expanded} =
useExpandedNode(refinedExpression);
const {loading: isExpanding, result: expanded} = useExpandedNode(
refinedExpression,
newVars
);

// Call the user's expression. If the expression contains variables that
// are no longer present in the frame, then the result is void.
Expand Down
9 changes: 7 additions & 2 deletions weave-js/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,15 @@ export const useNodeWithServerType: typeof useNodeWithServerTypeDoNotCallMeDirec
};

export const useExpandedNode = (
node: NodeOrVoidNode
node: NodeOrVoidNode,
newVars?: {[key: string]: Node} | null
): {loading: boolean; result: NodeOrVoidNode} => {
const [error, setError] = useState();
const {stack} = usePanelContext();
const {stack: origStack} = usePanelContext();

const stack = useMemo(() => {
return pushFrame(origStack, newVars ?? {});
}, [newVars, origStack]);

let dereffedNode: NodeOrVoidNode;
({node, dereffedNode} = useRefEqualExpr(node, stack));
Expand Down

0 comments on commit 0cc26d3

Please sign in to comment.