Skip to content

Commit

Permalink
Feat: [code-1576] Add support to delete empty repository (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapoor10 authored and Harness committed Apr 15, 2024
1 parent 2e33568 commit 9b561a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion web/src/hooks/useDisableCodeMainLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export function useDisableCodeMainLinks(disabled: boolean) {
const nav = document.querySelectorAll('[data-code-repo-section]')

nav?.forEach(element => {
if (element.getAttribute('data-code-repo-section') !== 'files') {
if (
element.getAttribute('data-code-repo-section') !== 'files' &&
element.getAttribute('data-code-repo-section') !== 'settings'
) {
element.setAttribute('aria-disabled', 'true')
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ interface GeneralSettingsProps {
repoMetadata: TypesRepository | undefined
refetch: () => void
gitRef: string
isRepositoryEmpty: boolean
}

const GeneralSettingsContent = (props: GeneralSettingsProps) => {
const { repoMetadata, refetch, gitRef } = props
const { repoMetadata, refetch, gitRef, isRepositoryEmpty } = props
const { openModal: openDeleteRepoModal } = useDeleteRepoModal()
const [currentGitRef, setCurrentGitRef] = useState(gitRef)
const [editDesc, setEditDesc] = useState(ACCESS_MODES.VIEW)
Expand Down Expand Up @@ -258,6 +259,7 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
<BranchTagSelect
forBranchesOnly={true}
disableBranchCreation={true}
disableViewAllBranches={isRepositoryEmpty}
disabled={defaultBranch !== ACCESS_MODES.EDIT}
hidePopoverContent={defaultBranch !== ACCESS_MODES.EDIT}
repoMetadata={repoMetadata}
Expand Down
21 changes: 17 additions & 4 deletions web/src/pages/RepositorySettings/RepositorySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,46 @@ import cx from 'classnames'
import { PageBody, Container, Tabs } from '@harnessio/uicore'
import { useHistory } from 'react-router-dom'
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
import { useDisableCodeMainLinks } from 'hooks/useDisableCodeMainLinks'
import { useGetResourceContent } from 'hooks/useGetResourceContent'
import { useStrings } from 'framework/strings'

import { RepositoryPageHeader } from 'components/RepositoryPageHeader/RepositoryPageHeader'
import { getErrorMessage, voidFn } from 'utils/Utils'
import { LoadingSpinner } from 'components/LoadingSpinner/LoadingSpinner'
// import Webhooks from 'pages/Webhooks/Webhooks'
import { useAppContext } from 'AppContext'
import BranchProtectionListing from 'components/BranchProtection/BranchProtectionListing'
import { SettingsTab } from 'utils/GitUtils'
import { SettingsTab, normalizeGitRef } from 'utils/GitUtils'
import SecurityScanSettings from 'pages/RepositorySettings/SecurityScanSettings/SecurityScanSettings'
import GeneralSettingsContent from './GeneralSettingsContent/GeneralSettingsContent'
import css from './RepositorySettings.module.scss'

export default function RepositorySettings() {
const { repoMetadata, error, loading, refetch, settingSection, gitRef } = useGetRepositoryMetadata()
const { repoMetadata, error, loading, refetch, settingSection, gitRef, resourcePath } = useGetRepositoryMetadata()
const history = useHistory()
const { routes, hooks, standalone } = useAppContext()
const { SEMANTIC_SEARCH_ENABLED } = hooks?.useFeatureFlags()
const [activeTab, setActiveTab] = React.useState<string>(settingSection || SettingsTab.general)
const { getString } = useStrings()
const { isRepositoryEmpty } = useGetResourceContent({
repoMetadata,
gitRef: normalizeGitRef(gitRef) as string,
resourcePath
})

useDisableCodeMainLinks(!!isRepositoryEmpty)
const tabListArray = [
{
id: SettingsTab.general,
title: getString('settings'),
panel: (
<Container padding={'large'}>
<GeneralSettingsContent repoMetadata={repoMetadata} refetch={refetch} gitRef={gitRef} />
<GeneralSettingsContent
repoMetadata={repoMetadata}
refetch={refetch}
gitRef={gitRef}
isRepositoryEmpty={isRepositoryEmpty}
/>
</Container>
)
},
Expand Down

0 comments on commit 9b561a3

Please sign in to comment.