Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: add async conditional state check

jordibosch20e27d5fb1ff6b
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
index 9ba2447a75..d77def925d 100644
--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
@@ -95,12 +95,12 @@ export const BlobStorageIntegrationContainer = ({
return <IntegrationSettingsSkeleton />;
}
- const handleSubmit = (values: BlobStorageIntegrationFormSchema) => {
+ const handleSubmit = (
+ values: BlobStorageIntegrationFormSchema,
+ onSaved: () => void,
+ ) => {
capture("integrations:blob_storage_form_submitted");
- mut.mutate({
- projectId,
- ...values,
- });
+ mut.mutate({ projectId, ...values }, { onSuccess: onSaved });
};
return (
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
index dfff6153bb..283397d40f 100644
--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
@@ -1,4 +1,10 @@
-import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@testing-library/react";
import {
BlobStorageIntegrationFileType,
BlobStorageIntegrationType,
@@ -36,7 +42,7 @@ const savedConfig: Partial<BlobStorageIntegration> = {
const ui = (
key: string,
initialValues: BlobStorageFormValues,
- onSubmit: (values: unknown) => void = () => {},
+ onSubmit: (values: unknown, onSaved: () => void) => void = () => {},
) => (
<TooltipProvider>
<BlobStorageIntegrationForm
@@ -175,12 +181,13 @@ describe("BlobStorageIntegrationForm draft lifetime (keyed remount)", () => {
fileType: BlobStorageIntegrationFileType.PARQUET,
enabled: true,
}),
+ expect.any(Function),
);
});
- it("dirty state: set by an edit, cleared by save", async () => {
+ it("dirty state: cleared only by a successful save", async () => {
// Same-entity saves do not remount (key stays "configured"), so the
- // form itself must rebase dirty tracking on save.
+ // form itself must rebase dirty tracking once the save is confirmed.
const onSubmit = vi.fn();
render(
ui(
@@ -194,9 +201,20 @@ describe("BlobStorageIntegrationForm draft lifetime (keyed remount)", () => {
fireEvent.change(bucketInput(), { target: { value: "edited-bucket" } });
await waitFor(() => expect(dirtyState()).toBe("dirty"));
+ // Failed save: the container never calls onSaved.
fireEvent.click(screen.getByRole("button", { name: "Save" }));
await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
+ expect(dirtyState()).toBe("dirty");
+
+ // Successful save: the submitted values become the clean baseline.
+ fireEvent.click(screen.getByRole("button", { name: "Save" }));
+ await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(2));
+ act(() => onSubmit.mock.calls[1][1]());
await waitFor(() => expect(dirtyState()).toBe("clean"));
expect(bucketInput()).toHaveValue("edited-bucket");
+
+ // Later edits are dirty again against the new baseline.
+ fireEvent.change(bucketInput(), { target: { value: "edited-again" } });
+ await waitFor(() => expect(dirtyState()).toBe("dirty"));
});
});
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
index f636ee6d9b..8c5d1cd785 100644
--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
@@ -46,7 +46,12 @@ export const BlobStorageIntegrationForm = ({
exportSourceCtx: ExportSourceContext;
persistedExportSource: AnalyticsIntegrationExportSource | null | undefined;
isSaving: boolean;
- onSubmit: (values: BlobStorageIntegrationFormSchema) => void;
+ // Call `onSaved` once the values are persisted; a failed save never calls
+ // it, so the draft stays dirty.
+ onSubmit: (
+ values: BlobStorageIntegrationFormSchema,
+ onSaved: () => void,
+ ) => void;
// Entity-scoped action buttons (Validate / Run Now / Reset) rendered by
// the container next to Save — they act on the persisted entity, not on
// this draft. `isDirty` lets them refuse to act while the draft has
@@ -81,11 +86,14 @@ export const BlobStorageIntegrationForm = ({
const fileType = useWatch({ control, name: "fileType" });
const { isDirty } = blobStorageForm.formState;
- // Rebase dirty tracking on the submitted values: same-entity saves do not
- // remount (see container key), so the draft would otherwise stay dirty.
+ // After a successful save, the submitted values become the clean baseline.
+ // Same-entity saves do not remount (see container key), so without this the
+ // draft would stay dirty. keepValues preserves anything typed mid-save.
const submit = blobStorageForm.handleSubmit((values) => {
- onSubmit(values);
- blobStorageForm.reset(blobStorageForm.getValues());
+ const submitted = blobStorageForm.getValues();
+ onSubmit(values, () =>
+ blobStorageForm.reset(submitted, { keepValues: true }),
+ );
});
return (