Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-2868 [FIX] Stop the connector modal reporting a HITL save it discarded (#2286)

Kirtiman Mishraf3001ff99c5e
diff --git a/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx b/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx
index d91a205e5..3df2ac526 100644
--- a/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx
+++ b/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx
@@ -700,6 +700,9 @@ function ConfigureConnectorModal({
key: item.key,
label: item.label,
disabled: item.disabled,
+ // One Save writes both panes, so leaving one must not
+ // discard the edits it holds.
+ keepMounted: true,
children: (
<div className={roClass}>
{item.key === "1" && (
diff --git a/frontend/src/components/ui/shims/antd-structure.test.jsx b/frontend/src/components/ui/shims/antd-structure.test.jsx
index 5d19daae9..d3fd8e6e1 100644
--- a/frontend/src/components/ui/shims/antd-structure.test.jsx
+++ b/frontend/src/components/ui/shims/antd-structure.test.jsx
@@ -6,6 +6,7 @@ import {
within,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
+import { createRef, forwardRef, useEffect, useImperativeHandle } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
@@ -119,6 +120,106 @@ describe("antd-compatible structural shims (P4)", () => {
expect(screen.getByText("second")).toBeInTheDocument();
});
+ // A pane plus a live count of how many copies are mounted.
+ const mountProbe = (text) => {
+ const state = { mounts: 0 };
+ function Pane() {
+ useEffect(() => {
+ state.mounts += 1;
+ return () => {
+ state.mounts -= 1;
+ };
+ }, []);
+ return <div>{text}</div>;
+ }
+ return [Pane, state];
+ };
+
+ // Radix drops the pane behind an inactive tab; antd keeps it. The connector
+ // modal saves both panes through a ref, so a dropped pane loses both.
+ it("Tabs keep an opened keepMounted pane across a switch", () => {
+ const [Pane, probe] = mountProbe("hitl-pane");
+ const items = [
+ { key: "1", label: "Settings", children: <div>settings-pane</div> },
+ {
+ key: "MANUALREVIEW",
+ label: "Manual Review",
+ keepMounted: true,
+ children: <Pane />,
+ },
+ ];
+ const { rerender } = render(
+ <Tabs activeKey="MANUALREVIEW" items={items} />,
+ );
+ expect(probe.mounts).toBe(1);
+ rerender(<Tabs activeKey="1" items={items} />);
+ expect(probe.mounts).toBe(1);
+ // Mounted is not shown, and jsdom has no Tailwind -- assert the class.
+ const pane = screen.getByText("hitl-pane").closest(".ant-tabs-tabpane");
+ expect(pane).toHaveAttribute("data-state", "inactive");
+ expect(pane).toHaveClass("data-[state=inactive]:hidden");
+ });
+
+ // The failure this fixes is a ref, not a mount count: the modal saves the
+ // pane through one, and a dropped pane nulls it, so the save is skipped.
+ it("Tabs keep a ref into a kept pane usable after a switch", () => {
+ const ref = createRef();
+ const Pane = forwardRef((_props, r) => {
+ useImperativeHandle(r, () => ({ save: () => "saved" }));
+ return <div>hitl-pane</div>;
+ });
+ Pane.displayName = "Pane";
+ const items = [
+ { key: "1", label: "Settings", children: <div>settings-pane</div> },
+ {
+ key: "MANUALREVIEW",
+ label: "Manual Review",
+ keepMounted: true,
+ children: <Pane ref={ref} />,
+ },
+ ];
+ const { rerender } = render(
+ <Tabs activeKey="MANUALREVIEW" items={items} />,
+ );
+ expect(ref.current?.save()).toBe("saved");
+ rerender(<Tabs activeKey="1" items={items} />);
+ expect(ref.current?.save()).toBe("saved");
+ });
+
+ // Held from first open, not from render: a pane that loads on mount would
+ // otherwise alert for a tab nobody opened.
+ it("Tabs do not mount a keepMounted pane before it is opened", () => {
+ const [Pane, probe] = mountProbe("unopened-pane");
+ render(
+ <Tabs
+ activeKey="1"
+ items={[
+ { key: "1", label: "Settings", children: <div>settings-pane</div> },
+ {
+ key: "2",
+ label: "Manual Review",
+ keepMounted: true,
+ children: <Pane />,
+ },
+ ]}
+ />,
+ );
+ expect(probe.mounts).toBe(0);
+ });
+
+ // Per pane on purpose: panes that refetch on remount keep today's default.
+ it("Tabs still unmount a pane that did not ask to be kept", () => {
+ const [Pane, probe] = mountProbe("plain-pane");
+ const items = [
+ { key: "1", label: "One", children: <div>one</div> },
+ { key: "2", label: "Two", children: <Pane /> },
+ ];
+ const { rerender } = render(<Tabs activeKey="2" items={items} />);
+ expect(probe.mounts).toBe(1);
+ rerender(<Tabs activeKey="1" items={items} />);
+ expect(probe.mounts).toBe(0);
+ });
+
/*
* The real CombinedOutput shape: a conditional pane followed by a `.map()`.
* That nesting makes React.Children.toArray use a ".N:$" prefix rather than
diff --git a/frontend/src/components/ui/shims/antd-structure.tsx b/frontend/src/components/ui/shims/antd-structure.tsx
index c47161507..3aade4cb9 100644
--- a/frontend/src/components/ui/shims/antd-structure.tsx
+++ b/frontend/src/components/ui/shims/antd-structure.tsx
@@ -105,7 +105,10 @@ interface CardProps
interface TabsProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
- items?: Array<KeyedItem & { children?: React.ReactNode }>;
+ /** `keepMounted` holds an opened pane, as antd does; Radix drops it. */
+ items?: Array<
+ KeyedItem & { children?: React.ReactNode; keepMounted?: boolean }
+ >;
activeKey?: string;
defaultActiveKey?: string;
onChange?: (key: string) => void;
@@ -523,6 +526,7 @@ const TabsBase = React.forwardRef<HTMLDivElement, TabsProps>(function Tabs(
icon?: React.ReactNode;
children?: React.ReactNode;
disabled?: boolean;
+ keepMounted?: boolean;
"data-testid"?: string;
}> => React.isValidElement(c),
)
@@ -547,10 +551,27 @@ const TabsBase = React.forwardRef<HTMLDivElement, TabsProps>(function Tabs(
icon: c.props.icon,
children: c.props.children,
disabled: c.props.disabled,
+ keepMounted: c.props.keepMounted,
}));
const first = panes[0]?.key;
+ // Held from first open: mounting up front runs a pane's loaders, and its
+ // failure alert, behind a tab nobody looked at.
+ const shownKey = String(activeKey ?? defaultActiveKey ?? first ?? "");
+ const [openedKeys, setOpenedKeys] = React.useState<ReadonlySet<string>>(
+ () => new Set(shownKey ? [shownKey] : []),
+ );
+ const noteOpened = React.useCallback((key: string) => {
+ setOpenedKeys((prev) => (prev.has(key) ? prev : new Set(prev).add(key)));
+ }, []);
+ // Controlled; the uncontrolled case arrives via onValueChange.
+ React.useEffect(() => {
+ if (shownKey) {
+ noteOpened(shownKey);
+ }
+ }, [shownKey, noteOpened]);
+
return (
<ShadcnTabs
// Radix treats a present-but-undefined `value` as controlled, which
@@ -559,7 +580,10 @@ const TabsBase = React.forwardRef<HTMLDivElement, TabsProps>(function Tabs(
{...(activeKey != null
? { value: String(activeKey) }
: { defaultValue: String(defaultActiveKey ?? first ?? "") })}
- onValueChange={(v) => onChange?.(v)}
+ onValueChange={(v) => {
+ noteOpened(v);
+ onChange?.(v);
+ }}
className={cn("ant-tabs", className)}
data-testid={testId}
// Radix Root takes value/defaultValue/onValueChange/orientation only;
@@ -632,15 +656,23 @@ const TabsBase = React.forwardRef<HTMLDivElement, TabsProps>(function Tabs(
</TabsList>
{tabBarExtraContent}
</div>
- {panes.map((p) => (
- <TabsContent
- key={String(p.key)}
- value={String(p.key)}
- className="ant-tabs-content ant-tabs-tabpane"
- >
- {p.children}
- </TabsContent>
- ))}
+ {panes.map((p) => {
+ const held = Boolean(p.keepMounted && openedKeys.has(String(p.key)));
+ return (
+ <TabsContent
+ key={String(p.key)}
+ value={String(p.key)}
+ // Radix leaves `hidden` off a force-mounted pane, so hide on state.
+ forceMount={held || undefined}
+ className={cn(
+ "ant-tabs-content ant-tabs-tabpane",
+ held && "data-[state=inactive]:hidden",
+ )}
+ >
+ {p.children}
+ </TabsContent>
+ );
+ })}
</ShadcnTabs>
);
});