import React, { useMemo } from 'react' import { Container, TableV2 as Table, Text, Avatar, Layout, ButtonVariation, ButtonSize, Button, FlexExpander, StringSubstitute, Popover } from '@harnessio/uicore' import { Icon } from '@harnessio/icons' import { Color } from '@harnessio/design-system' import type { CellProps, Column } from 'react-table' import { noop, orderBy } from 'lodash-es' import { Link, useHistory } from 'react-router-dom' import { useStrings } from 'framework/strings' import { useAppContext } from 'AppContext' import type { TypesCommit } from 'services/code' import { CommitActions } from 'components/CommitActions/CommitActions' import { NoResultCard } from 'components/NoResultCard/NoResultCard' import { ThreadSection } from 'components/ThreadSection/ThreadSection' import { FileSection, formatDate, PullRequestSection } from 'utils/Utils' import { CodeIcon, GitInfoProps } from 'utils/GitUtils' import type { CODERoutes } from 'RouteDefinitions' import css from './CommitsView.module.scss' interface CommitsViewProps extends Pick { commits: TypesCommit[] | null emptyTitle: string emptyMessage: string prStatsChanged?: number handleRefresh?: () => void showFileHistoryIcons?: boolean resourcePath?: string setActiveTab?: React.Dispatch> pullRequestMetadata?: GitInfoProps['pullRequestMetadata'] } export function CommitsView({ repoMetadata, commits, emptyTitle, emptyMessage, handleRefresh = noop, prStatsChanged, showFileHistoryIcons = false, resourcePath = '', setActiveTab, pullRequestMetadata }: CommitsViewProps) { const history = useHistory() const { getString } = useStrings() const { routes } = useAppContext() const columns: Column[] = useMemo( () => [ { id: 'author', width: '20%', Cell: ({ row }: CellProps) => { return ( {row.original.author?.identity?.name} ) } }, { id: 'commit', width: 'calc(80% - 100px)', Cell: ({ row }: CellProps) => { return ( {renderPullRequestLinkFromCommitMessage(repoMetadata, routes, row.original.message)} ) } }, { id: 'sha', width: '100px', Cell: ({ row }: CellProps) => { return ( ) } }, { id: 'buttons', width: showFileHistoryIcons ? '60px' : '0px', Cell: ({ row }: CellProps) => { if (showFileHistoryIcons) { return ( {getString('viewFile')} } interactionKind="hover"> { history.push( routes.toCODERepository({ repoPath: repoMetadata.path as string, gitRef: row.original.sha, resourcePath }) ) if (setActiveTab) { setActiveTab(FileSection.CONTENT) } }} />