Skip to content

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

fix: Block validate button if form is dirty (changes not saved)

jordibosch20aab92eae66ad
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
index e6b17c73c4..9ba2447a75 100644
--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx
@@ -120,48 +120,56 @@ export const BlobStorageIntegrationContainer = ({
isSaving={mut.isPending}
onSubmit={handleSubmit}
>
- <Button
- variant="secondary"
- loading={mutValidate.isPending}
- disabled={!config}
- title="Test your saved configuration by uploading a small test file to your storage"
- onClick={() => {
- mutValidate.mutate({ projectId });
- }}
- >
- Validate
- </Button>
- <Button
- variant="secondary"
- loading={mutRunNow.isPending}
- disabled={!config?.enabled}
- title="Trigger an immediate export of all data since the last sync"
- onClick={() => {
- if (
- confirm(
- "Are you sure you want to run the blob storage export now? This will export all data since the last sync.",
- )
- )
- mutRunNow.mutate({ projectId });
- }}
- >
- Run Now
- </Button>
- <Button
- variant="ghost"
- loading={mutDelete.isPending}
- disabled={!config}
- onClick={() => {
- if (
- confirm(
- "Are you sure you want to reset the Blob Storage integration for this project?",
- )
- )
- mutDelete.mutate({ projectId });
- }}
- >
- Reset
- </Button>
+ {({ isDirty }) => (
+ <>
+ <Button
+ variant="secondary"
+ loading={mutValidate.isPending}
+ disabled={!config || isDirty}
+ title={
+ isDirty
+ ? "Please save latest changes before validate"
+ : "Test your saved configuration by uploading a small test file to your storage"
+ }
+ onClick={() => {
+ mutValidate.mutate({ projectId });
+ }}
+ >
+ Validate
+ </Button>
+ <Button
+ variant="secondary"
+ loading={mutRunNow.isPending}
+ disabled={!config?.enabled}
+ title="Trigger an immediate export of all data since the last sync"
+ onClick={() => {
+ if (
+ confirm(
+ "Are you sure you want to run the blob storage export now? This will export all data since the last sync.",
+ )
+ )
+ mutRunNow.mutate({ projectId });
+ }}
+ >
+ Run Now
+ </Button>
+ <Button
+ variant="ghost"
+ loading={mutDelete.isPending}
+ disabled={!config}
+ onClick={() => {
+ if (
+ confirm(
+ "Are you sure you want to reset the Blob Storage integration for this project?",
+ )
+ )
+ mutDelete.mutate({ projectId });
+ }}
+ >
+ Reset
+ </Button>
+ </>
+ )}
</BlobStorageIntegrationForm>
);
};
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
index d3a13f49f2..dfff6153bb 100644
--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.clienttest.tsx
@@ -46,10 +46,16 @@ const ui = (
persistedExportSource={null}
isSaving={false}
onSubmit={onSubmit}
- />
+ >
+ {({ isDirty }) => (
+ <span data-testid="dirty-state">{isDirty ? "dirty" : "clean"}</span>
+ )}
+ </BlobStorageIntegrationForm>
</TooltipProvider>
);
+const dirtyState = () => screen.getByTestId("dirty-state").textContent;
+
const bucketInput = () =>
screen.getByLabelText("Bucket Name") as HTMLInputElement;
@@ -169,7 +175,28 @@ describe("BlobStorageIntegrationForm draft lifetime (keyed remount)", () => {
fileType: BlobStorageIntegrationFileType.PARQUET,
enabled: true,
}),
- expect.anything(),
);
});
+
+ it("dirty state: set by an edit, cleared by save", async () => {
+ // Same-entity saves do not remount (key stays "configured"), so the
+ // form itself must rebase dirty tracking on save.
+ const onSubmit = vi.fn();
+ render(
+ ui(
+ "p1:configured",
+ buildBlobStorageFormValues(savedConfig, exportSourceCtx),
+ onSubmit,
+ ),
+ );
+ expect(dirtyState()).toBe("clean");
+
+ fireEvent.change(bucketInput(), { target: { value: "edited-bucket" } });
+ await waitFor(() => expect(dirtyState()).toBe("dirty"));
+
+ fireEvent.click(screen.getByRole("button", { name: "Save" }));
+ await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
+ await waitFor(() => expect(dirtyState()).toBe("clean"));
+ expect(bucketInput()).toHaveValue("edited-bucket");
+ });
});
diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
index 3e57b5859c..f636ee6d9b 100644
--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationForm.tsx
@@ -49,8 +49,9 @@ export const BlobStorageIntegrationForm = ({
onSubmit: (values: BlobStorageIntegrationFormSchema) => 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.
- children?: ReactNode;
+ // this draft. `isDirty` lets them refuse to act while the draft has
+ // unsaved edits that the persisted entity does not reflect.
+ children?: (state: { isDirty: boolean }) => ReactNode;
}) => {
// Block the save when the persisted source is no longer selectable rather
// than silently rewriting it (LFE-10296). The policy context is fixed for
@@ -78,13 +79,18 @@ export const BlobStorageIntegrationForm = ({
const control = blobStorageForm.control;
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.
+ const submit = blobStorageForm.handleSubmit((values) => {
+ onSubmit(values);
+ blobStorageForm.reset(blobStorageForm.getValues());
+ });
return (
<Form {...blobStorageForm}>
- <form
- className="space-y-3"
- onSubmit={blobStorageForm.handleSubmit(onSubmit)}
- >
+ <form className="space-y-3" onSubmit={submit}>
<StorageProviderFields control={control} />
<ExportScheduleFields control={control} />
<ExportSourceField
@@ -138,13 +144,10 @@ export const BlobStorageIntegrationForm = ({
/>
</form>
<div className="mt-8 flex gap-2">
- <Button
- loading={isSaving}
- onClick={blobStorageForm.handleSubmit(onSubmit)}
- >
+ <Button loading={isSaving} onClick={submit}>
Save
</Button>
- {children}
+ {children?.({ isDirty })}
</div>
</Form>
);