Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: hide install-package button in read mode (#9979)

Kiran Gadhave3f853cd38ac1
diff --git a/frontend/src/components/datasources/__tests__/install-package-button.test.tsx b/frontend/src/components/datasources/__tests__/install-package-button.test.tsx
index 7264850bba..6fab4f253b 100644
--- a/frontend/src/components/datasources/__tests__/install-package-button.test.tsx
+++ b/frontend/src/components/datasources/__tests__/install-package-button.test.tsx
@@ -5,6 +5,7 @@ import { Provider } from "jotai";
import React from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { MockRequestClient } from "@/__mocks__/requests";
+import { viewStateAtom } from "@/core/mode";
import { requestClientAtom } from "@/core/network/requests";
import { store } from "@/core/state/jotai";
import { InstallPackageButton } from "../install-package-button";
@@ -48,6 +49,7 @@ describe("InstallPackageButton", () => {
beforeEach(() => {
vi.clearAllMocks();
store.set(requestClientAtom, MockRequestClient.create());
+ store.set(viewStateAtom, { mode: "edit", cellAnchor: null });
});
it("should not render when packages is undefined", () => {
@@ -82,4 +84,13 @@ describe("InstallPackageButton", () => {
);
expect(screen.getByText("Install altair")).toBeInTheDocument();
});
+
+ it("should not render in read mode, where installs are not allowed", () => {
+ store.set(viewStateAtom, { mode: "read", cellAnchor: null });
+ const { container } = render(
+ <InstallPackageButton packages={["altair"]} />,
+ { wrapper },
+ );
+ expect(container.firstChild).toBeNull();
+ });
});
diff --git a/frontend/src/components/datasources/install-package-button.tsx b/frontend/src/components/datasources/install-package-button.tsx
index 2fc0d9bfa0..0d9199a6de 100644
--- a/frontend/src/components/datasources/install-package-button.tsx
+++ b/frontend/src/components/datasources/install-package-button.tsx
@@ -2,6 +2,7 @@
import React from "react";
import { Button } from "@/components/ui/button";
+import { useInstallAllowed } from "@/core/mode";
import { useInstallPackages } from "@/core/packages/useInstallPackage";
import { cn } from "@/utils/cn";
@@ -23,8 +24,9 @@ export const InstallPackageButton: React.FC<InstallPackageButtonProps> = ({
onInstall,
}) => {
const { handleInstallPackages } = useInstallPackages();
+ const installAllowed = useInstallAllowed();
- if (!packages || packages.length === 0) {
+ if (!packages || packages.length === 0 || !installAllowed) {
return null;
}