The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Allow going back to snippet root collection (#63549)
Romeo Van Snickb336da1517ee
diff --git a/e2e/test/scenarios/native/snippets.cy.spec.js b/e2e/test/scenarios/native/snippets.cy.spec.jsindex 3f6cf0a072a..976f516fb04 100644--- a/e2e/test/scenarios/native/snippets.cy.spec.js+++ b/e2e/test/scenarios/native/snippets.cy.spec.js@@ -345,6 +345,31 @@ describe("scenarios > question > snippets (EE)", () => {});});+ describe("navigation", () => {+ beforeEach(() => {+ cy.signInAsNormalUser();+ createDoublyNestedSnippet();+ });++ it("should be possible to go back to parent folders (metabase#63405)", () => {+ H.startNewNativeQuestion();+ cy.findByTestId("native-query-top-bar").icon("snippet").click();+ cy.findByTestId("sidebar-right").within(() => {+ cy.findByText("Folder A").click();+ cy.findByText("Folder B").click();++ cy.log("We should reach the nested folder");+ cy.findByText("snippet 1").should("be.visible");++ cy.findByText("Folder B").click();+ cy.findByText("Folder A").click();++ cy.log("We should be back at the root folder");+ cy.findByText("Snippets").should("be.visible");+ });+ });+ });+describe("existing snippet folder", () => {beforeEach(() => {cy.intercept("GET", "/api/collection/root").as("collections");@@ -473,3 +498,27 @@ function getPermissionsForUserGroup(userGroup) {.closest("tr").find("[data-testid=permissions-select]");}++function createDoublyNestedSnippet() {+ // Create snippet folder via API+ cy.request("POST", "/api/collection", {+ name: "Folder A",+ description: null,+ parent_id: null,+ namespace: "snippets",+ }).then(({ body: { id } }) => {+ cy.request("POST", "/api/collection", {+ name: "Folder B",+ description: null,+ parent_id: id,+ namespace: "snippets",+ }).then(({ body: { id } }) => {+ // Create snippet in folder via API+ cy.request("POST", "/api/native-query-snippet", {+ content: "snippet 1",+ name: "snippet 1",+ collection_id: id,+ });+ });+ });+}diff --git a/frontend/src/metabase/query_builder/components/template_tags/SnippetSidebar/SnippetSidebar.jsx b/frontend/src/metabase/query_builder/components/template_tags/SnippetSidebar/SnippetSidebar.jsxindex 9a7a335fb55..807ca6e4f31 100644--- a/frontend/src/metabase/query_builder/components/template_tags/SnippetSidebar/SnippetSidebar.jsx+++ b/frontend/src/metabase/query_builder/components/template_tags/SnippetSidebar/SnippetSidebar.jsx@@ -93,14 +93,15 @@ class SnippetSidebarInner extends React.Component {): _.sortBy(search, "model"); // relies on "collection" sorting before "snippet";- const hasParentCollection = snippetCollection.parent_id !== null;const onSnippetCollectionBack = () => {+ const parentCollectionId = snippetCollection.parent_id ?? "root";+// if this collection's parent isn't in the list,// we don't have perms to see it, return to the root insteadconst hasPermissionToSeeParent = snippetCollections.some((collection) =>canonicalCollectionId(collection.id) ===- canonicalCollectionId(snippetCollection.parent_id),+ canonicalCollectionId(parentCollectionId),);const targetId = hasPermissionToSeeParent@@ -151,9 +152,7 @@ class SnippetSidebarInner extends React.Component {) : (<SidebarHeadertitle={snippetCollection.name}- onBack={- hasParentCollection ? onSnippetCollectionBack : null- }+ onBack={onSnippetCollectionBack}/>)}