From f547821362b20924971fa07476ffd12344a0fd61 Mon Sep 17 00:00:00 2001 From: Rudraprasad Das Date: Fri, 18 Oct 2024 16:36:30 +0800 Subject: [PATCH] fix: adding branch in url for search entities (#36938) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Fixes application redirection issue from search bar ~ 1. Appends branch to the url Fixes https://github.com/appsmithorg/appsmith/issues/36782 ## Automation /ok-to-test tags="@tag.Git" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 02eb26e4911a4854daeb068f1c80004cec66de96 > Cypress dashboard. > Tags: `@tag.Git` > Spec: >
Thu, 17 Oct 2024 18:34:15 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No --- .../common/SearchBar/EntitySearchBar.tsx | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/client/src/pages/common/SearchBar/EntitySearchBar.tsx b/app/client/src/pages/common/SearchBar/EntitySearchBar.tsx index 319c4e5bfe..71e2c00ce5 100644 --- a/app/client/src/pages/common/SearchBar/EntitySearchBar.tsx +++ b/app/client/src/pages/common/SearchBar/EntitySearchBar.tsx @@ -36,6 +36,7 @@ import { getPackagesList } from "ee/selectors/packageSelectors"; import Fuse from "fuse.js"; import { useOutsideClick } from "ee/hooks"; import type { PageDefaultMeta } from "ee/api/ApplicationApi"; +import log from "loglevel"; const HeaderSection = styled.div` display: flex; @@ -135,12 +136,34 @@ function EntitySearchBar(props: any) { (app: ApplicationPayload) => app.id === applicationId, ); - const defaultPage = searchedApplication?.pages.find( + let defaultPage = searchedApplication?.pages.find( (page: PageDefaultMeta) => page.isDefault === true, ); - const viewURL = viewerURL({ - basePageId: defaultPage.baseId, - }); + + if (!defaultPage) { + defaultPage = searchedApplication?.pages[0]; + } + + if (!defaultPage) { + log.error("No default page or pages found for the application"); + } + + const isGitEnabled = !!searchedApplication?.gitApplicationMetadata; + let viewURL = null; + + if (isGitEnabled) { + const defaultBranch = + searchedApplication?.gitApplicationMetadata?.defaultBranchName; + + viewURL = viewerURL({ + basePageId: defaultPage.baseId, + branch: defaultBranch, + }); + } else { + viewURL = viewerURL({ + basePageId: defaultPage.baseId, + }); + } window.location.href = `${viewURL}`; }