Revert "feat: [code-566]: fix routing for commit list and diff page (#177)"

This reverts commit 8cddf04706.
This commit is contained in:
Calvin Lee 2023-07-05 19:26:07 +00:00 committed by calvin
parent f8092fe117
commit cd5fe7c418
13 changed files with 48 additions and 134 deletions

View File

@ -28,10 +28,9 @@ module.exports = {
'./Repository': './src/pages/Repository/Repository.tsx', './Repository': './src/pages/Repository/Repository.tsx',
'./FileEdit': './src/pages/RepositoryFileEdit/RepositoryFileEdit.tsx', './FileEdit': './src/pages/RepositoryFileEdit/RepositoryFileEdit.tsx',
'./Commits': './src/pages/RepositoryCommits/RepositoryCommits.tsx', './Commits': './src/pages/RepositoryCommits/RepositoryCommits.tsx',
'./Commit': './src/pages/RepositoryCommit/RepositoryCommit.tsx',
'./Branches': './src/pages/RepositoryBranches/RepositoryBranches.tsx', './Branches': './src/pages/RepositoryBranches/RepositoryBranches.tsx',
'./PullRequests': './src/pages/PullRequests/PullRequests.tsx', './PullRequests': './src/pages/PullRequests/PullRequests.tsx',
'./Tags': './src/pages/RepositoryTags/RepositoryTags.tsx', './Tags':'./src/pages/RepositoryTags/RepositoryTags.tsx',
'./PullRequest': './src/pages/PullRequest/PullRequest.tsx', './PullRequest': './src/pages/PullRequest/PullRequest.tsx',
'./Compare': './src/pages/Compare/Compare.tsx', './Compare': './src/pages/Compare/Compare.tsx',
'./Settings': './src/pages/RepositorySettings/RepositorySettings.tsx', './Settings': './src/pages/RepositorySettings/RepositorySettings.tsx',

View File

@ -36,7 +36,6 @@ export interface CODERoutes {
toCODERepository: (args: RequiredField<Pick<CODEProps, 'repoPath' | 'gitRef' | 'resourcePath'>, 'repoPath'>) => string toCODERepository: (args: RequiredField<Pick<CODEProps, 'repoPath' | 'gitRef' | 'resourcePath'>, 'repoPath'>) => string
toCODEFileEdit: (args: Required<Pick<CODEProps, 'repoPath' | 'gitRef' | 'resourcePath'>>) => string toCODEFileEdit: (args: Required<Pick<CODEProps, 'repoPath' | 'gitRef' | 'resourcePath'>>) => string
toCODECommits: (args: Required<Pick<CODEProps, 'repoPath' | 'commitRef'>>) => string toCODECommits: (args: Required<Pick<CODEProps, 'repoPath' | 'commitRef'>>) => string
toCODECommit: (args: Required<Pick<CODEProps, 'repoPath' | 'commitRef'>>) => string
toCODEPullRequests: (args: Required<Pick<CODEProps, 'repoPath'>>) => string toCODEPullRequests: (args: Required<Pick<CODEProps, 'repoPath'>>) => string
toCODEPullRequest: ( toCODEPullRequest: (
args: RequiredField< args: RequiredField<
@ -62,7 +61,6 @@ export const routes: CODERoutes = {
`/${repoPath}/${gitRef ? '/' + gitRef : ''}${resourcePath ? '/~/' + resourcePath : ''}`, `/${repoPath}/${gitRef ? '/' + gitRef : ''}${resourcePath ? '/~/' + resourcePath : ''}`,
toCODEFileEdit: ({ repoPath, gitRef, resourcePath }) => `/${repoPath}/edit/${gitRef}/~/${resourcePath}`, toCODEFileEdit: ({ repoPath, gitRef, resourcePath }) => `/${repoPath}/edit/${gitRef}/~/${resourcePath}`,
toCODECommits: ({ repoPath, commitRef }) => `/${repoPath}/commits/${commitRef}`, toCODECommits: ({ repoPath, commitRef }) => `/${repoPath}/commits/${commitRef}`,
toCODECommit: ({ repoPath, commitRef }) => `/${repoPath}/commit/${commitRef}`,
toCODEPullRequests: ({ repoPath }) => `/${repoPath}/pulls`, toCODEPullRequests: ({ repoPath }) => `/${repoPath}/pulls`,
toCODEPullRequest: ({ repoPath, pullRequestId, pullRequestSection }) => toCODEPullRequest: ({ repoPath, pullRequestId, pullRequestSection }) =>
`/${repoPath}/pulls/${pullRequestId}${pullRequestSection ? '/' + pullRequestSection : ''}`, `/${repoPath}/pulls/${pullRequestId}${pullRequestSection ? '/' + pullRequestSection : ''}`,

View File

@ -13,7 +13,7 @@ interface CodeCommentStatusSelectProps extends Pick<GitInfoProps, 'repoMetadata'
commentItems: CommentItem<TypesPullReqActivity>[] commentItems: CommentItem<TypesPullReqActivity>[]
onCommentUpdate: () => void onCommentUpdate: () => void
refetchActivities?: () => void refetchActivities: () => void
} }
export const CodeCommentStatusSelect: React.FC<CodeCommentStatusSelectProps> = ({ export const CodeCommentStatusSelect: React.FC<CodeCommentStatusSelectProps> = ({
@ -77,9 +77,7 @@ export const CodeCommentStatusSelect: React.FC<CodeCommentStatusSelectProps> = (
commentItems[0].payload.resolved = Date.now() commentItems[0].payload.resolved = Date.now()
} }
} }
if (refetchActivities) {
refetchActivities() refetchActivities()
}
}) })
.catch(_exception => { .catch(_exception => {
showError(getErrorMessage(_exception), 0, getString('pr.failedToUpdateCommentStatus')) showError(getErrorMessage(_exception), 0, getString('pr.failedToUpdateCommentStatus'))

View File

@ -87,7 +87,7 @@ export function CommitsView({
return ( return (
<CommitActions <CommitActions
sha={row.original.sha as string} sha={row.original.sha as string}
href={routes.toCODECommit({ href={routes.toCODECommits({
repoPath: repoMetadata.path as string, repoPath: repoMetadata.path as string,
commitRef: row.original.sha as string commitRef: row.original.sha as string
})} })}

View File

@ -20,7 +20,7 @@ interface LatestCommitProps extends Pick<GitInfoProps, 'repoMetadata'> {
export function LatestCommitForFolder({ repoMetadata, latestCommit, standaloneStyle }: LatestCommitProps) { export function LatestCommitForFolder({ repoMetadata, latestCommit, standaloneStyle }: LatestCommitProps) {
const { routes } = useAppContext() const { routes } = useAppContext()
const commitURL = routes.toCODECommit({ const commitURL = routes.toCODECommits({
repoPath: repoMetadata.path as string, repoPath: repoMetadata.path as string,
commitRef: latestCommit?.sha as string commitRef: latestCommit?.sha as string
}) })
@ -49,7 +49,7 @@ export function LatestCommitForFolder({ repoMetadata, latestCommit, standaloneSt
export function LatestCommitForFile({ repoMetadata, latestCommit, standaloneStyle, size }: LatestCommitProps) { export function LatestCommitForFile({ repoMetadata, latestCommit, standaloneStyle, size }: LatestCommitProps) {
const { routes } = useAppContext() const { routes } = useAppContext()
const commitURL = routes.toCODECommit({ const commitURL = routes.toCODECommits({
repoPath: repoMetadata.path as string, repoPath: repoMetadata.path as string,
commitRef: latestCommit?.sha as string commitRef: latestCommit?.sha as string
}) })

View File

@ -1,3 +1,4 @@
import { noop } from 'lodash-es'
import React from 'react' import React from 'react'
import { import {
Container, Container,
@ -11,8 +12,8 @@ import {
IconName, IconName,
useToaster useToaster
} from '@harness/uicore' } from '@harness/uicore'
import { useMutate } from 'restful-react'
import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButton' import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButton'
import { useMutate } from 'restful-react'
import { useStrings } from 'framework/strings' import { useStrings } from 'framework/strings'
import type { TypesPullReq, TypesRepository } from 'services/code' import type { TypesPullReq, TypesRepository } from 'services/code'
import { getErrorMessage } from 'utils/Utils' import { getErrorMessage } from 'utils/Utils'

View File

@ -50,7 +50,7 @@ export function FolderContent({
className={css.rowText} className={css.rowText}
onClick={() => { onClick={() => {
history.push( history.push(
routes.toCODECommit({ routes.toCODECommits({
repoPath: repoMetadata.path as string, repoPath: repoMetadata.path as string,
commitRef: row.original.latest_commit?.sha as string commitRef: row.original.latest_commit?.sha as string
}) })

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react' import React, { useMemo, useState } from 'react'
import { Container, Layout, FlexExpander, ButtonVariation } from '@harness/uicore' import { Container, Layout, FlexExpander, DropDown, ButtonVariation } from '@harness/uicore'
import { useStrings } from 'framework/strings' import { useStrings } from 'framework/strings'
import { GitBranchType, CodeIcon, GitInfoProps } from 'utils/GitUtils' import { GitBranchType, CodeIcon, GitInfoProps } from 'utils/GitUtils'
import { SearchInputWithSpinner } from 'components/SearchInputWithSpinner/SearchInputWithSpinner' import { SearchInputWithSpinner } from 'components/SearchInputWithSpinner/SearchInputWithSpinner'

View File

@ -1,18 +0,0 @@
.main {
min-height: var(--page-min-height, 100%);
background-color: var(--primary-bg) !important;
}
.resourceContent {
background-color: var(--primary-bg);
}
.contentHeader {
> div {
align-items: center;
}
}
.changesContainer {
padding: 0 0 var(--spacing-xlarge) 0 !important;
}

View File

@ -1,9 +0,0 @@
/* eslint-disable */
// this is an auto-generated file
declare const styles: {
readonly main: string
readonly resourceContent: string
readonly contentHeader: string
readonly changesContainer: string
}
export default styles

View File

@ -1,87 +0,0 @@
import React, { useMemo } from 'react'
import { Container, FlexExpander, Layout, PageBody } from '@harness/uicore'
import { useGet } from 'restful-react'
import { noop } from 'lodash-es'
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
import { useAppContext } from 'AppContext'
import type { TypesCommit } from 'services/code'
import { voidFn, getErrorMessage, LIST_FETCHING_LIMIT } from 'utils/Utils'
import { useStrings } from 'framework/strings'
import { RepositoryPageHeader } from 'components/RepositoryPageHeader/RepositoryPageHeader'
import { LoadingSpinner } from 'components/LoadingSpinner/LoadingSpinner'
import { Changes } from 'components/Changes/Changes'
import CommitInfo from 'components/CommitInfo/CommitInfo'
import css from './RepositoryCommit.module.scss'
export default function RepositoryCommits() {
const { repoMetadata, error, loading, commitRef, refetch } = useGetRepositoryMetadata()
const { routes } = useAppContext()
const { getString } = useStrings()
const {
data: commits,
error: errorCommits,
loading: loadingCommits
} = useGet<{ commits: TypesCommit[] }>({
path: `/api/v1/repos/${repoMetadata?.path}/+/commits`,
queryParams: {
limit: LIST_FETCHING_LIMIT,
git_ref: commitRef || repoMetadata?.default_branch
},
lazy: !repoMetadata
})
const ChangesTab = useMemo(() => {
if (repoMetadata) {
return (
<Container className={css.changesContainer}>
<Changes
readOnly
repoMetadata={repoMetadata}
targetBranch={`${commitRef}~1`}
sourceBranch={commitRef}
emptyTitle={getString('noChanges')}
emptyMessage={getString('noChangesCompare')}
onCommentUpdate={noop}
/>
</Container>
)
}
}, [repoMetadata, commitRef, getString])
return (
<Container className={css.main}>
<RepositoryPageHeader
repoMetadata={repoMetadata}
title={getString('commits')}
dataTooltipId="repositoryCommits"
extraBreadcrumbLinks={
commitRef && repoMetadata
? [
{
label: getString('commits'),
url: routes.toCODECommits({ repoPath: repoMetadata.path as string, commitRef: '' })
}
]
: undefined
}
/>
<PageBody error={getErrorMessage(error || errorCommits)} retryOnError={voidFn(refetch)}>
<LoadingSpinner visible={loading || loadingCommits} withBorder={!!commits && loadingCommits} />
{(repoMetadata && commitRef && !!commits?.commits?.length && (
<Container padding="xlarge" className={css.resourceContent}>
<Container className={css.contentHeader}>
<Layout.Horizontal>
<CommitInfo repoMetadata={repoMetadata} commitRef={commitRef} />
<FlexExpander />
</Layout.Horizontal>
</Container>
{ChangesTab}
</Container>
)) ||
null}
</PageBody>
</Container>
)
}

View File

@ -1,7 +1,8 @@
import React, { useEffect } from 'react' import React, { useEffect, useMemo } from 'react'
import { Container, FlexExpander, Layout, PageBody } from '@harness/uicore' import { Container, FlexExpander, Layout, PageBody } from '@harness/uicore'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import { useGet } from 'restful-react' import { useGet } from 'restful-react'
import { noop } from 'lodash-es'
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata' import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
import { useAppContext } from 'AppContext' import { useAppContext } from 'AppContext'
import { usePageIndex } from 'hooks/usePageIndex' import { usePageIndex } from 'hooks/usePageIndex'
@ -15,6 +16,8 @@ import { LoadingSpinner } from 'components/LoadingSpinner/LoadingSpinner'
import { ResourceListingPagination } from 'components/ResourceListingPagination/ResourceListingPagination' import { ResourceListingPagination } from 'components/ResourceListingPagination/ResourceListingPagination'
import { BranchTagSelect } from 'components/BranchTagSelect/BranchTagSelect' import { BranchTagSelect } from 'components/BranchTagSelect/BranchTagSelect'
import { CommitsView } from 'components/CommitsView/CommitsView' import { CommitsView } from 'components/CommitsView/CommitsView'
import { Changes } from 'components/Changes/Changes'
import CommitInfo from 'components/CommitInfo/CommitInfo'
import css from './RepositoryCommits.module.scss' import css from './RepositoryCommits.module.scss'
export default function RepositoryCommits() { export default function RepositoryCommits() {
@ -49,6 +52,24 @@ export default function RepositoryCommits() {
} }
}, [setPage]) // eslint-disable-line react-hooks/exhaustive-deps }, [setPage]) // eslint-disable-line react-hooks/exhaustive-deps
const ChangesTab = useMemo(() => {
if (repoMetadata) {
return (
<Container className={css.changesContainer}>
<Changes
readOnly
repoMetadata={repoMetadata}
targetBranch={`${commitRef}~1`}
sourceBranch={commitRef}
emptyTitle={getString('noChanges')}
emptyMessage={getString('noChangesCompare')}
onCommentUpdate={noop}
/>
</Container>
)
}
}, [repoMetadata, commitRef, getString, response])
return ( return (
<Container className={css.main}> <Container className={css.main}>
<RepositoryPageHeader <RepositoryPageHeader
@ -69,8 +90,19 @@ export default function RepositoryCommits() {
<PageBody error={getErrorMessage(error || errorCommits)} retryOnError={voidFn(refetch)}> <PageBody error={getErrorMessage(error || errorCommits)} retryOnError={voidFn(refetch)}>
<LoadingSpinner visible={loading || loadingCommits} withBorder={!!commits && loadingCommits} /> <LoadingSpinner visible={loading || loadingCommits} withBorder={!!commits && loadingCommits} />
{(repoMetadata && commitRef && !pageBrowser.page && !!commits?.commits?.length && (
{(repoMetadata && !!commits?.commits?.length && ( <Container padding="xlarge" className={css.resourceContent}>
<Container className={css.contentHeader}>
<Layout.Horizontal>
<CommitInfo repoMetadata={repoMetadata} commitRef={commitRef} />
<FlexExpander />
</Layout.Horizontal>
</Container>
{ChangesTab}
</Container>
)) ||
null}
{(repoMetadata && (!commitRef || pageBrowser.page) && !!commits?.commits?.length && (
<Container padding="xlarge" className={css.resourceContent}> <Container padding="xlarge" className={css.resourceContent}>
<Container className={css.contentHeader}> <Container className={css.contentHeader}>
<Layout.Horizontal spacing="medium"> <Layout.Horizontal spacing="medium">
@ -84,7 +116,7 @@ export default function RepositoryCommits() {
history.push( history.push(
routes.toCODECommits({ routes.toCODECommits({
repoPath: repoMetadata.path as string, repoPath: repoMetadata.path as string,
commitRef: `${ref}` commitRef: `${ref}?page=1`
}) })
) )
}} }}

View File

@ -78,7 +78,7 @@ export function TagsContent({ repoMetadata, searchTerm = '', branches, onDeleteS
return ( return (
<CommitActions <CommitActions
sha={row.original.commit?.sha as string} sha={row.original.commit?.sha as string}
href={routes.toCODECommit({ href={routes.toCODECommits({
repoPath: repoMetadata.path as string, repoPath: repoMetadata.path as string,
commitRef: row.original.commit?.sha as string commitRef: row.original.commit?.sha as string
})} })}