import React, { useMemo } from 'react' import { Container, Color, TableV2 as Table, Text, Utils } from '@harness/uicore' import type { CellProps, Column } from 'react-table' import { Render } from 'react-jsx-match' import { sortBy } from 'lodash-es' import { useHistory } from 'react-router-dom' import { useAppContext } from 'AppContext' import type { OpenapiContentInfo, OpenapiDirContent } from 'services/code' import { formatDate } from 'utils/Utils' import { findReadmeInfo, CodeIcon, GitInfoProps, isFile } from 'utils/GitUtils' import { LatestCommitForFolder } from 'components/LatestCommit/LatestCommit' import { Readme } from './Readme' import css from './FolderContent.module.scss' export function FolderContent({ repoMetadata, resourceContent, gitRef }: Pick) { const history = useHistory() const { routes } = useAppContext() const columns: Column[] = useMemo( () => [ { id: 'name', width: '40%', Cell: ({ row }: CellProps) => { return ( {row.original.name} ) } }, { id: 'message', width: 'calc(60% - 100px)', Cell: ({ row }: CellProps) => { return ( { history.push( routes.toCODECommit({ repoPath: repoMetadata.path as string, commitRef: row.original.latest_commit?.sha as string }) ) }}> {row.original.latest_commit?.title} ) } }, { id: 'when', width: '100px', Cell: ({ row }: CellProps) => { return ( {formatDate(row.original.latest_commit?.author?.when as string)} ) } } ], [] // eslint-disable-line react-hooks/exhaustive-deps ) const readmeInfo = useMemo(() => findReadmeInfo(resourceContent), [resourceContent]) return ( className={css.table} hideHeaders columns={columns} data={sortBy((resourceContent.content as OpenapiDirContent)?.entries || [], ['type', 'name'])} onRowClick={data => { history.push( routes.toCODERepository({ repoPath: repoMetadata.path as string, gitRef, resourcePath: data.path }) ) }} getRowClassName={() => css.row} /> ) }