Skip to content

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

python library (#67173)

Aleksandr Lesnenko3e913649554c
diff --git a/e2e/test/scenarios/data-studio/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
index 4743481da0b..b5a0435b47d 100644
--- a/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
@@ -1875,6 +1875,7 @@ LIMIT
getRowNames().should("deep.equal", [
"Middle Transform",
+ "Python library",
"Reports",
"Alpha Transform",
"Zebra Transform",
@@ -1886,6 +1887,7 @@ LIMIT
"Zebra Transform",
"Reports",
"Alpha Transform",
+ "Python library",
"Middle Transform",
]);
@@ -1894,6 +1896,7 @@ LIMIT
getRowNames().should("deep.equal", [
"Reports",
"Alpha Transform",
+ "Python library",
"Middle Transform",
"Zebra Transform",
]);
@@ -1905,6 +1908,7 @@ LIMIT
"Middle Transform",
"Reports",
"Alpha Transform",
+ "Python library",
]);
});
@@ -1987,9 +1991,24 @@ LIMIT
getTransformsList().within(() => {
cy.findByText("Archive Me").should("not.exist");
cy.findByText("Transform In Collection").should("not.exist");
- cy.findByText("No transforms yet").should("be.visible");
+ cy.findByText("Python library").should("be.visible");
});
});
+
+ it("should show Python library item and navigate to it", () => {
+ visitTransformListPage();
+
+ cy.log("Python library should be visible in the list");
+ getTransformsList().within(() => {
+ cy.findByText("Python library").should("be.visible");
+ });
+
+ cy.log("clicking Python library should navigate to the library editor");
+ getTransformsList().findByText("Python library").click();
+
+ cy.url().should("include", "/data-studio/transforms/library/common.py");
+ cy.findByTestId("python-library-header").should("be.visible");
+ });
});
});
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/TransformListPage.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/TransformListPage.tsx
index 4de98bb8d5d..e3b3e08485b 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/TransformListPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/TransformListPage.tsx
@@ -15,6 +15,7 @@ import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErr
import CS from "metabase/css/core/index.css";
import { useDispatch } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
+import { PLUGIN_TRANSFORMS_PYTHON } from "metabase/plugins";
import type { TreeTableColumnDef } from "metabase/ui";
import {
Card,
@@ -33,6 +34,7 @@ import { PaneHeader } from "metabase-enterprise/data-studio/common/components/Pa
import { CreateTransformMenu } from "metabase-enterprise/transforms/components/CreateTransformMenu";
import { ListEmptyState } from "metabase-enterprise/transforms/components/ListEmptyState";
import { ListLoadingState } from "metabase-enterprise/transforms/components/ListLoadingState";
+import { SHARED_LIB_IMPORT_PATH } from "metabase-enterprise/transforms-python/constants";
import { CollectionRowMenu } from "./CollectionRowMenu";
import { type TreeNode, getCollectionNodeId, isCollectionNode } from "./types";
@@ -54,6 +56,13 @@ const countTransforms = (node: TreeNode): number => {
}, 0);
};
+const NODE_ICON_COLORS: Record<TreeNode["nodeType"], string> = {
+ folder: "text-medium",
+ transform: "brand",
+ library: "text-dark",
+};
+
+const getNodeIconColor = (node: TreeNode) => NODE_ICON_COLORS[node.nodeType];
const globalFilterFn = (
row: { original: TreeNode },
_columnId: string,
@@ -100,10 +109,19 @@ export const TransformListPage = ({ location }: WithRouterProps) => {
const isLoading = isLoadingCollections || isLoadingTransforms;
const error = collectionsError ?? transformsError;
- const treeData = useMemo(
- () => buildTreeData(collections, transforms),
- [collections, transforms],
- );
+ const treeData = useMemo(() => {
+ const data = buildTreeData(collections, transforms);
+ if (PLUGIN_TRANSFORMS_PYTHON.isEnabled) {
+ data.push({
+ id: "library",
+ name: t`Python library`,
+ nodeType: "library",
+ icon: "snippet",
+ url: Urls.transformPythonLibrary({ path: SHARED_LIB_IMPORT_PATH }),
+ });
+ }
+ return data;
+ }, [collections, transforms]);
const defaultExpanded = useMemo(
() => getDefaultExpandedIds(targetCollectionId, targetCollection),
@@ -122,9 +140,7 @@ export const TransformListPage = ({ location }: WithRouterProps) => {
<EntityNameCell
data-testid="tree-node-name"
icon={row.original.icon}
- iconColor={
- row.original.nodeType === "folder" ? "text-medium" : "brand"
- }
+ iconColor={getNodeIconColor(row.original)}
name={row.original.name}
/>
),
@@ -183,9 +199,11 @@ export const TransformListPage = ({ location }: WithRouterProps) => {
(row: Row<TreeNode>) => {
if (row.original.nodeType === "transform" && row.original.transformId) {
navigateToTransform(row.original.transformId);
+ } else if (row.original.nodeType === "library" && row.original.url) {
+ dispatch(push(row.original.url));
}
},
- [navigateToTransform],
+ [navigateToTransform, dispatch],
);
const treeTableInstance = useTreeTableInstance({
@@ -211,9 +229,11 @@ export const TransformListPage = ({ location }: WithRouterProps) => {
row.original.transformId
) {
navigateToTransform(row.original.transformId);
+ } else if (row.original.nodeType === "library" && row.original.url) {
+ dispatch(push(row.original.url));
}
},
- [navigateToTransform],
+ [navigateToTransform, dispatch],
);
useEffect(() => {
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/types.ts b/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/types.ts
index f0a3782b932..5edd9fab440 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/transforms/pages/TransformListPage/types.ts
@@ -1,7 +1,7 @@
import type { IconName } from "metabase/ui";
import type { Transform } from "metabase-types/api";
-export type TreeNodeType = "folder" | "transform";
+export type TreeNodeType = "folder" | "transform" | "library";
export type TreeNode = {
id: string;
@@ -13,6 +13,7 @@ export type TreeNode = {
children?: TreeNode[];
transformId?: number;
collectionId?: number;
+ url?: string;
};
export function isCollectionNode(