Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions app/client/src/pages/common/SearchBar/EntitySearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brayn003 Out of curiosity, shouldn't the routeBuilder have taken care of this routing? This way, we would have been sure that all instances of this route builder are routing accurately and are taking the Git default branch into account. Can you help me understand why that is either not possible, or complicated?

basePageId: defaultPage.baseId,
branch: defaultBranch,
});
} else {
viewURL = viewerURL({
basePageId: defaultPage.baseId,
});
}

window.location.href = `${viewURL}`;
}
Expand Down