Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix empty Python Library not showing placeholder/comment (#68826)

Andersonee030befe20e
diff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.ts
index 00fde9dcb91..beff92bba3a 100644
--- a/e2e/support/helpers/e2e-data-studio-helpers.ts
+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts
@@ -23,6 +23,10 @@ export const DataStudio = {
settingsTab: () => DataStudio.Transforms.header().findByText("Settings"),
dependenciesTab: () =>
DataStudio.Transforms.header().findByText("Dependencies"),
+ visit: () => {
+ cy.visit("/data-studio/transforms");
+ DataStudio.Transforms.list().should("be.visible");
+ },
pythonResults: () => cy.findByTestId("python-results"),
},
Jobs: {
diff --git a/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.ts
new file mode 100644
index 00000000000..6beaab1ca67
--- /dev/null
+++ b/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.ts
@@ -0,0 +1,49 @@
+const { H } = cy;
+
+describe("scenarios > data studio > transforms > python library", () => {
+ beforeEach(() => {
+ H.restore("postgres-writable");
+ H.resetTestTable({ type: "postgres", table: "many_schemas" });
+ H.resetSnowplow();
+ cy.signInAsAdmin();
+ H.activateToken("bleeding-edge");
+ });
+
+ afterEach(() => {
+ H.expectNoBadSnowplowEvents();
+ });
+
+ it("should allow editing the python library", () => {
+ H.DataStudio.Transforms.visit();
+ cy.findByRole("link", { name: /Python library/ }).click();
+
+ H.DataStudio.PythonLibrary.editor().should("be.visible");
+
+ cy.log("make sure placeholder with help comment is displayed");
+ H.DataStudio.PythonLibrary.editor()
+ .findByText(/# This is your Python library/)
+ .should("be.visible");
+ H.DataStudio.PythonLibrary.editor()
+ .findByText(/# You can add functions and classes here/)
+ .should("be.visible");
+
+ cy.log("modify and save the python library");
+ H.DataStudio.PythonLibrary.editor()
+ .findByRole("textbox")
+ .click()
+ .realType("print('hello world')");
+
+ cy.findByRole("button", { name: "Save" }).should("be.visible").click();
+
+ H.undoToast()
+ .findByText(/Python library saved/)
+ .should("be.visible");
+
+ cy.log("refresh the page and check the content is persisted");
+ cy.url().reload();
+
+ H.DataStudio.PythonLibrary.editor()
+ .findByText(/hello world/)
+ .should("be.visible");
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/pages/PythonLibraryEditorPage/PythonLibraryEditorPage.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/pages/PythonLibraryEditorPage/PythonLibraryEditorPage.tsx
index 25e0f21bacf..7a07419597b 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/pages/PythonLibraryEditorPage/PythonLibraryEditorPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/pages/PythonLibraryEditorPage/PythonLibraryEditorPage.tsx
@@ -76,14 +76,14 @@ export function PythonLibraryEditorPage({
// When the library loads, set the source to the current library source
useLayoutEffect(() => {
- if (library != null) {
+ if (library?.source) {
setSource(library.source);
} else {
setSource(EMPTY_LIBRARY_SOURCE);
}
}, [library]);
- const isDirty = source !== (library?.source ?? EMPTY_LIBRARY_SOURCE);
+ const isDirty = source !== (library?.source || EMPTY_LIBRARY_SOURCE);
if (isLoading || (error && !isResourceNotFoundError(error))) {
return (