drone/web/src/pages/RepositorySettings/RepositorySettings.tsx
Ritik Kapoor 2d14111677 labels support in Gitness (#2456)
* fix: lint check
* fix: page overflow
* resolve comments
* resolve comments
* fix: space label addition
* resolve comments : added enum
* update: settings -> manage repository
* update: resolved comments
* update: bugbash comments
* fix: ref exact scope for individual label values call
* fix lint
* add hook to handle current scope in HC and fix scope filter
* update space delete
* prettier check
* update labelAPIs to use getConfig in base
* support for harness-code labels
* fix no result card
* resolved comments for types
* resolved comments
* added sorting in labels and handled edge cases
* fix: replacement of any value label
* fix: spacing in value filter search input
* add: update modal on click for spaces
* added search for values in filter
* fix: UI issues and some enhancements
* handle empty labels list in space and remove tooltip for PR labels
* added getConifg and any values for label filter
* change label value color to enum
* make value-id a pionter
* update ordering
* expose value id
* handle long values
* update search in label selector
* handle edge cases
* fix lint
* added FF : CODE_PULLREQ_LABELS and standalone flag to labels
* fix popover on scrolling and added strings
* fix checks
* fix checks
* swagger update
* labels support in Gitness
2024-08-20 21:05:11 +00:00

140 lines
4.9 KiB
TypeScript

/*
* 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 from 'react'
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 { LabelsPageScope, 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, normalizeGitRef } from 'utils/GitUtils'
import SecurityScanSettings from 'pages/RepositorySettings/SecurityScanSettings/SecurityScanSettings'
import LabelsListing from 'pages/Labels/LabelsListing'
import { useGetSpaceParam } from 'hooks/useGetSpaceParam'
import GeneralSettingsContent from './GeneralSettingsContent/GeneralSettingsContent'
import css from './RepositorySettings.module.scss'
export default function RepositorySettings() {
const { repoMetadata, error, loading, refetch, settingSection, gitRef, resourcePath } = useGetRepositoryMetadata()
const space = useGetSpaceParam()
const history = useHistory()
const { routes, hooks, standalone } = useAppContext()
const { CODE_PULLREQ_LABELS: isLabelEnabled } = 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}
isRepositoryEmpty={isRepositoryEmpty}
/>
</Container>
)
},
{
id: SettingsTab.branchProtection,
title: getString('branchProtection.title'),
panel: <BranchProtectionListing activeTab={activeTab} />
},
{
id: SettingsTab.security,
title: getString('security'),
panel: <SecurityScanSettings repoMetadata={repoMetadata} activeTab={activeTab} />
},
...(isLabelEnabled || standalone
? [
{
id: SettingsTab.labels,
title: getString('labels.labels'),
panel: (
<LabelsListing
activeTab={activeTab}
repoMetadata={repoMetadata}
currentPageScope={LabelsPageScope.REPOSITORY}
space={space}
/>
)
}
]
: [])
// {
// id: SettingsTab.webhooks,
// title: getString('webhooks'),
// panel: (
// <Container padding={'large'}>
// <Webhooks />
// </Container>
// )
// }
]
return (
<Container className={css.main}>
<RepositoryPageHeader
className={css.headerContainer}
repoMetadata={repoMetadata}
title={getString('manageRepository')}
dataTooltipId="repositorySettings"
/>
<PageBody error={getErrorMessage(error)} retryOnError={voidFn(refetch)}>
<LoadingSpinner visible={loading} />
{repoMetadata && (
<Container className={cx(css.main, css.tabsContainer)}>
<Tabs
id="SettingsTabs"
large={false}
defaultSelectedTabId={activeTab}
animate={false}
onChange={(id: string) => {
setActiveTab(id)
history.replace(
routes.toCODESettings({
repoPath: repoMetadata?.path as string,
settingSection: id !== SettingsTab.general ? (id as string) : ''
})
)
}}
tabList={tabListArray}></Tabs>
</Container>
)}
</PageBody>
</Container>
)
}