Skip to content

Commit ba63f76

Browse files
feat(services): add AutoDeployBadge component as header for services with git source QOV-1504 (#2338)
* feat(services): add AutoDeployBadge component as header for services with git source (QOV-1504) * refacto(services): refactor AutoDeployBadge component for improved styling and structure
1 parent fbca1c5 commit ba63f76

3 files changed

Lines changed: 88 additions & 9 deletions

File tree

libs/domains/services/feature/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './lib/auto-deploy-badge/auto-deploy-badge'
12
export * from './lib/auto-deploy-setting/auto-deploy-setting'
23
export * from './lib/auto-deploy-section/auto-deploy-section'
34
export * from './lib/git-webhook-status-badge/git-webhook-status-badge'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { type IconName } from '@fortawesome/fontawesome-common-types'
2+
import { type GitWebhookStatusResponse } from 'qovery-typescript-axios'
3+
import { useParams } from 'react-router-dom'
4+
import { APPLICATION_SETTINGS_GENERAL_URL, APPLICATION_SETTINGS_URL, APPLICATION_URL } from '@qovery/shared/routes'
5+
import { Icon, Link, LoaderSpinner, Tooltip } from '@qovery/shared/ui'
6+
import { useGitWebhookStatus } from '../hooks/use-git-webhook-status/use-git-webhook-status'
7+
8+
export interface AutoDeployBadgeProps {
9+
serviceId: string
10+
}
11+
12+
const webhookStatusConfig: Record<
13+
GitWebhookStatusResponse['status'],
14+
{
15+
icon: IconName
16+
iconClassName: string
17+
tooltip: string
18+
}
19+
> = {
20+
ACTIVE: {
21+
icon: 'circle-check',
22+
iconClassName: 'text-green-500',
23+
tooltip: 'Webhook is correctly configured. Auto-deploy will trigger on git events.',
24+
},
25+
NOT_CONFIGURED: {
26+
icon: 'circle-question',
27+
iconClassName: 'text-red-500',
28+
tooltip: 'No webhook found for auto-deployment. Click to configure it in settings.',
29+
},
30+
MISCONFIGURED: {
31+
icon: 'triangle-exclamation',
32+
iconClassName: 'text-yellow-500',
33+
tooltip: 'Webhook is missing required events. Click to fix it in settings.',
34+
},
35+
UNABLE_TO_VERIFY: {
36+
icon: 'circle-exclamation',
37+
iconClassName: 'text-neutral-350',
38+
tooltip:
39+
"Couldn't verify webhook status. This could be due to expired credentials, insufficient permissions, or git provider API unavailability.",
40+
},
41+
}
42+
43+
export function AutoDeployBadge({ serviceId }: AutoDeployBadgeProps) {
44+
const { organizationId = '', projectId = '', environmentId = '', applicationId = '' } = useParams()
45+
const { data: webhookStatus, isLoading } = useGitWebhookStatus({ serviceId })
46+
47+
const config = webhookStatus ? webhookStatusConfig[webhookStatus.status] : undefined
48+
const tooltipContent = config?.tooltip ?? 'Auto-deploy enabled. Click to view settings.'
49+
50+
const settingsUrl =
51+
APPLICATION_URL(organizationId, projectId, environmentId, applicationId) +
52+
APPLICATION_SETTINGS_URL +
53+
APPLICATION_SETTINGS_GENERAL_URL
54+
55+
return (
56+
<Tooltip content={tooltipContent}>
57+
<Link as="button" color="neutral" variant="surface" size="xs" to={settingsUrl}>
58+
<Icon className="text-neutral-350" iconName="arrows-rotate" />
59+
<span className="ml-1.5">Auto-deploy</span>
60+
{isLoading ? (
61+
<LoaderSpinner classWidth="w-3" />
62+
) : (
63+
config && <Icon iconName={config.icon} className={`ml-1 text-xs ${config.iconClassName}`} />
64+
)}
65+
</Link>
66+
</Tooltip>
67+
)
68+
}
69+
70+
export default AutoDeployBadge

libs/pages/application/src/lib/ui/container/container.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useCluster } from '@qovery/domains/clusters/feature'
66
import { EnvironmentMode, useEnvironment } from '@qovery/domains/environments/feature'
77
import { type AnyService, type Database } from '@qovery/domains/services/data-access'
88
import {
9+
AutoDeployBadge,
910
NeedRedeployFlag,
1011
ServiceActionToolbar,
1112
ServiceAvatar,
@@ -15,7 +16,7 @@ import {
1516
useService,
1617
} from '@qovery/domains/services/feature'
1718
import { VariablesProvider } from '@qovery/domains/variables/feature'
18-
import { IconEnum } from '@qovery/shared/enums'
19+
import { IconEnum, isHelmGitSource, isJobGitSource } from '@qovery/shared/enums'
1920
import {
2021
APPLICATION_DEPLOYMENTS_URL,
2122
APPLICATION_GENERAL_URL,
@@ -155,14 +156,21 @@ export function Container({ children }: ContainerProps) {
155156
</Link>
156157
</Tooltip>
157158
</Skeleton>
158-
<Skeleton width={22} height={24} show={!service}>
159-
{service && 'auto_deploy' in service && service.auto_deploy && (
160-
<Tooltip content="Auto-deploy">
161-
<Badge variant="outline">
162-
<Icon className="text-neutral-350" iconName="arrows-rotate" />
163-
</Badge>
164-
</Tooltip>
165-
)}
159+
<Skeleton width={120} height={24} show={!service}>
160+
{service &&
161+
'auto_deploy' in service &&
162+
service.auto_deploy &&
163+
match(service)
164+
.with({ serviceType: 'APPLICATION' }, { serviceType: 'TERRAFORM' }, () => (
165+
<AutoDeployBadge serviceId={service.id} />
166+
))
167+
.with({ serviceType: 'JOB' }, (job) =>
168+
isJobGitSource(job.source) ? <AutoDeployBadge serviceId={service.id} /> : null
169+
)
170+
.with({ serviceType: 'HELM' }, (helm) =>
171+
isHelmGitSource(helm.source) ? <AutoDeployBadge serviceId={service.id} /> : null
172+
)
173+
.otherwise(() => null)}
166174
</Skeleton>
167175
</div>
168176
</div>

0 commit comments

Comments
 (0)