/* * Copyright 2023 Harness, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React, { useMemo } from 'react' import { Container, Layout, Button, FlexExpander, ButtonVariation, Text, ButtonSize } from '@harnessio/uicore' import cx from 'classnames' import { Icon } from '@harnessio/icons' import { Color } from '@harnessio/design-system' import { Breadcrumbs, IBreadcrumbProps } from '@blueprintjs/core' import { Link, useHistory } from 'react-router-dom' import { compact, isEmpty } from 'lodash-es' import { useStrings } from 'framework/strings' import { useAppContext } from 'AppContext' import { CloneButtonTooltip } from 'components/CloneButtonTooltip/CloneButtonTooltip' import { CodeIcon, GitInfoProps, isDir, isGitRev, isRefATag } from 'utils/GitUtils' import { BranchTagSelect } from 'components/BranchTagSelect/BranchTagSelect' import { useCreateBranchModal } from 'components/CreateBranchModal/CreateBranchModal' // import KeywordSearch from 'components/CodeSearch/KeywordSearch' import { useGetSpaceParam } from 'hooks/useGetSpaceParam' import { permissionProps } from 'utils/Utils' import CodeSearch from 'components/CodeSearch/CodeSearch' import { useDocumentTitle } from 'hooks/useDocumentTitle' import { CopyButton } from 'components/CopyButton/CopyButton' import css from './ContentHeader.module.scss' export function ContentHeader({ repoMetadata, gitRef = repoMetadata.default_branch as string, resourcePath, resourceContent }: Pick) { const { getString } = useStrings() const { routes, standalone, hooks, isCurrentSessionPublic } = useAppContext() const history = useHistory() const _isDir = isDir(resourceContent) const space = useGetSpaceParam() const repoPath = compact([repoMetadata.uid, resourceContent?.path]) useDocumentTitle(isEmpty(resourceContent?.path) ? getString('pageTitle.repository') : repoPath.join('/')) const permPushResult = hooks?.usePermissionTranslate?.( { resource: { resourceType: 'CODE_REPOSITORY', resourceIdentifier: repoMetadata?.uid as string }, permissions: ['code_repo_push'] }, [space] ) const openCreateNewBranchModal = useCreateBranchModal({ repoMetadata, onSuccess: branchInfo => { history.push( routes.toCODERepository({ repoPath: repoMetadata.path as string, gitRef: branchInfo.name }) ) }, suggestedSourceBranch: gitRef, showSuccessMessage: true }) const breadcrumbs = useMemo(() => { return resourcePath.split('/').map((_path, index, paths) => { const pathAtIndex = paths.slice(0, index + 1).join('/') const href = routes.toCODERepository({ repoPath: repoMetadata.path as string, gitRef, resourcePath: pathAtIndex }) return { href, text: _path } }) }, [resourcePath, gitRef, repoMetadata.path, routes]) return ( { history.push( routes.toCODERepository({ repoPath: repoMetadata.path as string, gitRef: ref, resourcePath }) ) }} onCreateBranch={openCreateNewBranchModal} /> / { return ( {text} ) }} /> {resourcePath && } {_isDir && ( <>