Skip to content

Commit

Permalink
fix: Fix route definition for PR compare (#806)
Browse files Browse the repository at this point in the history
* fix route definition for PR compare

* prettier fix
  • Loading branch information
vardanbansal-harness authored Jan 23, 2025
1 parent 43fba25 commit 6e69ea5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
4 changes: 3 additions & 1 deletion apps/gitness/src/components-v2/file-content-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export default function FileContentViewer({ repoContent }: FileContentViewerProp
if (!isNewBranch) {
navigate(`${routes.toRepoFiles({ spaceId, repoId })}${parentPath ? `/~/${parentPath}` : ''}`)
} else {
navigate(`${routes.toPullRequestCompare({ spaceId, repoId })}/${selectedBranchTag.name}...${newBranchName}`)
navigate(
routes.toPullRequestCompare({ spaceId, repoId, diffRefs: `${selectedBranchTag.name}...${newBranchName}` })
)
}
}}
currentBranch={fullGitRef || selectedBranchTag?.name || ''}
Expand Down
2 changes: 1 addition & 1 deletion apps/gitness/src/components-v2/file-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const FileEditor: FC<FileEditorProps> = ({ repoDetails, defaultBranch })
if (!isNewBranch) {
navigate(`${routes.toRepoFiles({ spaceId, repoId })}/${fullGitRef}/~/${fileResourcePath}`)
} else {
navigate(`${routes.toPullRequestCompare({ spaceId, repoId })}/${defaultBranch}...${newBranchName}`)
navigate(routes.toPullRequestCompare({ spaceId, repoId, diffRefs: `${defaultBranch}...${newBranchName}` }))
}
}}
currentBranch={fullGitRef || selectedBranchTag?.name}
Expand Down
9 changes: 7 additions & 2 deletions apps/gitness/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,15 @@ const repoRoutes: CustomRouteObject[] = [
{ index: true, element: <PullRequestListPage /> },
{
path: 'compare/:diffRefs',
element: <CreatePullRequest />,
handle: {
breadcrumb: () => <Text>Compare</Text>,
asLink: false,
routeName: RouteConstants.toPullRequestCompare
}
},
children: [
{ index: true, element: <CreatePullRequest /> },
{ path: '*', element: <CreatePullRequest /> }
]
},
{
path: ':pullRequestId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const BranchesList: FC<BranchListPageProps> = ({
size="xs"
asChild
>
<Link to={toPullRequest({ pullRequestId: branch.pullRequests[0].number })}>
<Link to={toPullRequest?.({ pullRequestId: branch.pullRequests[0].number }) || ''}>
<Icon
name={
getPrState(
Expand Down Expand Up @@ -226,11 +226,11 @@ export const BranchesList: FC<BranchListPageProps> = ({
actions={[
{
title: t('views:repos.newPullReq', 'New pull request'),
to: toPullRequestCompare({ diffRefs: `${defaultBranch}...${branch.name}` })
to: toPullRequestCompare?.({ diffRefs: `${defaultBranch}...${branch.name}` }) || ''
},
{
title: t('views:repos.viewRules', 'View Rules'),
to: toBranchRules()
to: toBranchRules?.()
},
{
isDanger: true,
Expand Down
10 changes: 3 additions & 7 deletions packages/ui/src/views/repo/repo-branch/repo-branch-list-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export const RepoBranchListView: FC<RepoBranchListViewProps> = ({
isCreatingBranch,
searchQuery,
setSearchQuery,
toPullRequest,
toBranchRules,
toPullRequestCompare,
onDeleteBranch,
searchBranches,
setCreateBranchSearchQuery
setCreateBranchSearchQuery,
...routingProps
}) => {
const { t } = useTranslationStore()
const { branchList, defaultBranch, xNextPage, xPrevPage, page, setPage } = useRepoBranchesStore()
Expand Down Expand Up @@ -107,11 +105,9 @@ export const RepoBranchListView: FC<RepoBranchListViewProps> = ({
useTranslationStore={useTranslationStore}
setCreateBranchDialogOpen={setCreateBranchDialogOpen}
handleResetFiltersAndPages={handleResetFiltersAndPages}
toPullRequest={toPullRequest}
toBranchRules={toBranchRules}
toPullRequestCompare={toPullRequestCompare}
onDeleteBranch={onDeleteBranch}
isDirtyList={isDirtyList}
{...routingProps}
/>
{!isLoading && (
<PaginationComponent
Expand Down
8 changes: 1 addition & 7 deletions packages/ui/src/views/repo/repo-branch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface BranchProps {
interface RoutingProps {
toBranchRules: () => string
toPullRequestCompare: ({ diffRefs }: { diffRefs: string }) => string
toCommitDetails?: ({ sha }: { sha: string }) => string
toPullRequest: ({ pullRequestId }: { pullRequestId: number }) => string
}

export interface BranchListPageProps extends Partial<RoutingProps> {
Expand All @@ -49,9 +49,6 @@ export interface BranchListPageProps extends Partial<RoutingProps> {
useTranslationStore: () => TranslationStore
setCreateBranchDialogOpen: (isOpen: boolean) => void
handleResetFiltersAndPages: () => void
toPullRequest: ({ pullRequestId }: { pullRequestId: number }) => string
toBranchRules: () => string
toPullRequestCompare: ({ diffRefs }: { diffRefs: string }) => string
onDeleteBranch: (branchName: string) => void
isDirtyList: boolean
}
Expand All @@ -67,9 +64,6 @@ export interface RepoBranchListViewProps extends Partial<RoutingProps> {
createBranchError?: string
searchQuery: string | null
setSearchQuery: (query: string | null) => void
toPullRequest: ({ pullRequestId }: { pullRequestId: number }) => string
toBranchRules: () => string
toPullRequestCompare: ({ diffRefs }: { diffRefs: string }) => string
onDeleteBranch: (branchName: string) => void
searchBranches: Branch[]
setCreateBranchSearchQuery: Dispatch<SetStateAction<string>>
Expand Down

0 comments on commit 6e69ea5

Please sign in to comment.