Skip to content

Commit 2170719

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-lib into fix/copy-button
2 parents 2ff4de5 + cf6db00 commit 2170719

File tree

14 files changed

+300
-307
lines changed

14 files changed

+300
-307
lines changed

src/Assets/Icon/ic-hash.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Assets/Icon/ic-pull-request.svg

Lines changed: 2 additions & 2 deletions
Loading

src/Assets/Icon/ic-tag.svg

Lines changed: 2 additions & 3 deletions
Loading

src/Common/Common.service.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import moment from 'moment'
1818
import { RuntimeParamsAPIResponseType, RuntimeParamsListItemType } from '@Shared/types'
1919
import { getIsManualApprovalSpecific, sanitizeUserApprovalConfig, stringComparatorBySortOrder } from '@Shared/Helpers'
2020
import { get, post } from './Api'
21-
import { ROUTES } from './Constants'
21+
import { GitProviderType, ROUTES } from './Constants'
2222
import { getUrlWithSearchParams, sortCallback } from './Helper'
2323
import {
2424
TeamList,
@@ -250,7 +250,7 @@ const getImageApprovalPolicyDetailsFromMaterialResult = (cdMaterialsResult): Ima
250250
const validGroups = userApprovalConfig.userGroups.map((group) => group.identifier)
251251

252252
// Have moved from Object.keys(imageApprovalUsersInfo) to approvalUsers since backend is not filtering out the users without approval
253-
// TODO: This check should be on BE. Need to remove this once BE is updated
253+
// TODO: This check should be on BE. Need to remove this once BE is updated
254254
const usersList = approvalUsers.filter((user) => user !== DefaultUserKey.system)
255255
const groupIdentifierToUsersMap = usersList.reduce(
256256
(acc, user) => {
@@ -511,3 +511,19 @@ export function getWebhookEventsForEventId(eventId: string | number) {
511511
const URL = `${ROUTES.GIT_HOST_EVENT}/${eventId}`
512512
return get(URL)
513513
}
514+
515+
/**
516+
*
517+
* @param gitUrl Git URL of the repository
518+
* @param branchName Branch name
519+
* @returns URL to the branch in the Git repository
520+
*/
521+
export const getGitBranchUrl = (gitUrl: string, branchName: string): string | null => {
522+
if (!gitUrl) return null
523+
const trimmedGitUrl = gitUrl.trim().replace(/\.git$/, '').replace(/\/$/, '') // Remove any trailing slash
524+
if (trimmedGitUrl.includes(GitProviderType.GITLAB)) return `${trimmedGitUrl}/-/tree/${branchName}`
525+
else if (trimmedGitUrl.includes(GitProviderType.GITHUB)) return `${trimmedGitUrl}/tree/${branchName}`
526+
else if (trimmedGitUrl.includes(GitProviderType.BITBUCKET)) return `${trimmedGitUrl}/branch/${branchName}`
527+
else if (trimmedGitUrl.includes(GitProviderType.AZURE)) return `${trimmedGitUrl}/src/branch/${branchName}`
528+
return null
529+
}

src/Common/Constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,20 @@ export const VULNERABILITIES_SORT_PRIORITY = {
558558

559559
// TODO: might not work need to verify
560560
export const IS_PLATFORM_MAC_OS = window.navigator.userAgent.toUpperCase().includes('MAC')
561+
562+
/**
563+
* Git provider types
564+
*/
565+
566+
export enum GitProviderType {
567+
GITHUB = 'github',
568+
GITLAB = 'gitlab',
569+
BITBUCKET = 'bitbucket',
570+
AZURE = 'azure',
571+
GITEA = 'gitea',
572+
}
573+
574+
/**
575+
* Formats the schema removing any irregularity in the existing schema
576+
*/
577+
export const getFormattedSchema = (schema?: string) => JSON.stringify(JSON.parse(schema ?? '{}'), null, 2)

src/Common/Helper.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ import {
4040
ToastManager,
4141
ToastVariantType,
4242
versionComparatorBySortOrder,
43+
WebhookEventNameType,
4344
} from '../Shared'
44-
import { ReactComponent as ArrowDown } from '../Assets/Icon/ic-chevron-down.svg'
45+
import { ReactComponent as ArrowDown } from '@Icons/ic-chevron-down.svg'
46+
import webhookIcon from '@Icons/ic-webhook.svg'
47+
import branchIcon from '@Icons/ic-branch.svg'
48+
import regexIcon from '@Icons/ic-regex.svg'
49+
import pullRequest from '@Icons/ic-pull-request.svg'
50+
import tagIcon from '@Icons/ic-tag.svg'
51+
import { SourceTypeMap } from '@Common/Common.service'
4552

4653
export function showError(serverError, showToastOnUnknownError = true, hideAccessError = false) {
4754
if (serverError instanceof ServerErrors && Array.isArray(serverError.errors)) {
@@ -962,6 +969,29 @@ export const throttle = <T extends (...args: unknown[]) => unknown>(
962969
}
963970
}
964971

972+
/**
973+
*
974+
* @param sourceType - SourceTypeMap
975+
* @param _isRegex - boolean
976+
* @param webhookEventName - WebhookEventNameType
977+
* @returns - Icon
978+
*/
979+
export const getBranchIcon = (sourceType, _isRegex?: boolean, webhookEventName?: string) => {
980+
if (sourceType === SourceTypeMap.WEBHOOK) {
981+
if (webhookEventName === WebhookEventNameType.PULL_REQUEST) {
982+
return pullRequest
983+
}
984+
if (webhookEventName === WebhookEventNameType.TAG_CREATION) {
985+
return tagIcon
986+
}
987+
return webhookIcon
988+
}
989+
if (sourceType === SourceTypeMap.BranchRegex || _isRegex) {
990+
return regexIcon
991+
}
992+
return branchIcon
993+
}
994+
965995
// TODO: Might need to expose sandbox and referrer policy
966996
export const getSanitizedIframe = (iframeString: string) =>
967997
DOMPurify.sanitize(iframeString, {

src/Shared/Components/CICDHistory/CiPipelineSourceConfig.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,11 @@
1616

1717
import { useState, useEffect, ReactNode } from 'react'
1818
import Tippy from '@tippyjs/react'
19-
import { getWebhookEventsForEventId, SourceTypeMap } from '../../../Common'
19+
import { ReactComponent as Info } from '@Icons/ic-info-outlined.svg'
20+
import { getBranchIcon, getWebhookEventsForEventId, SourceTypeMap } from '../../../Common'
2021
import { GIT_BRANCH_NOT_CONFIGURED, DEFAULT_GIT_BRANCH_VALUE } from './constants'
21-
import webhookIcon from '../../../Assets/Icon/ic-webhook.svg'
22-
import branchIcon from '../../../Assets/Icon/ic-branch.svg'
23-
import { ReactComponent as Info } from '../../../Assets/Icon/ic-info-outlined.svg'
24-
import regexIcon from '../../../Assets/Icon/ic-regex.svg'
2522
import { buildHoverHtmlForWebhook } from './utils'
26-
27-
export interface CIPipelineSourceConfigInterface {
28-
sourceType
29-
sourceValue
30-
showTooltip?: boolean
31-
showIcons?: boolean
32-
baseText?: string
33-
regex?: any
34-
isRegex?: boolean
35-
primaryBranchAfterRegex?: string
36-
}
23+
import { CIPipelineSourceConfigInterface } from './types'
3724

3825
export const CiPipelineSourceConfig = ({
3926
sourceType,
@@ -44,11 +31,12 @@ export const CiPipelineSourceConfig = ({
4431
regex,
4532
isRegex,
4633
primaryBranchAfterRegex,
34+
rootClassName = '',
4735
}: CIPipelineSourceConfigInterface) => {
4836
const _isWebhook = sourceType === SourceTypeMap.WEBHOOK
4937
const _isRegex = sourceType === SourceTypeMap.BranchRegex || !!regex || isRegex
5038

51-
const [sourceValueBase, setSourceValueBase] = useState<ReactNode>('')
39+
const [sourceValueBase, setSourceValueBase] = useState('')
5240
const [sourceValueAdv, setSourceValueAdv] = useState<ReactNode>('')
5341
const [loading, setLoading] = useState(!!_isWebhook)
5442

@@ -97,7 +85,7 @@ export const CiPipelineSourceConfig = ({
9785
)}
9886
</>
9987
)
100-
// for non webhook case, data is already set in use state initialisation
88+
// for non webhook case, data is already set in use state initialization
10189
function _init() {
10290
if (!_isWebhook) {
10391
return
@@ -130,16 +118,14 @@ export const CiPipelineSourceConfig = ({
130118
regexTippyContent()
131119
}, [])
132120

133-
const isRegexOrBranchIcon = _isRegex ? regexIcon : branchIcon
134-
135121
return (
136-
<div className={`flex left ${showTooltip ? 'branch-name' : ''}`}>
122+
<div className={`flex left ${showTooltip ? 'fw-5' : ''} ${rootClassName}`}>
137123
{loading && showIcons && <span className="dc__loading-dots">loading</span>}
138124
{!loading && (
139125
<div className="flex dc__gap-4">
140126
{showIcons && (
141127
<img
142-
src={_isWebhook ? webhookIcon : isRegexOrBranchIcon}
128+
src={getBranchIcon(sourceType, _isRegex, sourceValueBase)}
143129
alt="branch"
144130
className="icon-dim-12"
145131
/>
@@ -170,7 +156,7 @@ export const CiPipelineSourceConfig = ({
170156
</>
171157
)}
172158
{baseText && (
173-
<span className="cursor" style={{ borderBottom: '1px solid #3b444c' }}>
159+
<span className="dc__border-dashed--n3-bottom fw-6 fs-13 lh-19-imp">
174160
{baseText}
175161
</span>
176162
)}

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,3 +791,15 @@ export type CreateMarkupPropsType =
791791
export type TriggerHistoryFilterCriteriaType = `${string}|${string}|${string}`[]
792792
export const terminalStatus = new Set(['error', 'healthy', 'succeeded', 'cancelled', 'failed', 'aborted'])
793793
export const statusSet = new Set(['starting', 'running', 'pending'])
794+
795+
export interface CIPipelineSourceConfigInterface {
796+
sourceType: string
797+
sourceValue: any // TODO: need to make source value consistent
798+
showTooltip?: boolean
799+
showIcons?: boolean
800+
baseText?: string
801+
regex?: any
802+
isRegex?: boolean
803+
primaryBranchAfterRegex?: string
804+
rootClassName?: string
805+
}

src/Shared/Components/CICDHistory/utils.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616
import { TIMELINE_STATUS } from '@Shared/constants'
1717
import { ReactComponent as ICAborted } from '@Icons/ic-aborted.svg'
1818
import { ReactComponent as ICErrorCross } from '@Icons/ic-error-cross.svg'
19+
import { ReactComponent as Close } from '@Icons/ic-close.svg'
20+
import { ReactComponent as Check } from '@Icons/ic-check-grey.svg'
21+
import { ReactComponent as ICHelpOutline } from '@Icons/ic-help-outline.svg'
22+
import { ReactComponent as Error } from '@Icons/ic-error-exclamation.svg'
23+
import { ReactComponent as Timer } from '@Icons/ic-timer.svg'
24+
import { ReactComponent as Disconnect } from '@Icons/ic-disconnected.svg'
25+
import { ReactComponent as TimeOut } from '@Icons/ic-timeout-red.svg'
26+
import { ReactComponent as ICCheck } from '@Icons/ic-check.svg'
27+
import { ReactComponent as ICInProgress } from '@Icons/ic-in-progress.svg'
28+
import { TERMINAL_STATUS_MAP } from './constants'
29+
import { ResourceKindType } from '../../types'
1930
import {
2031
TriggerHistoryFilterCriteriaProps,
2132
DeploymentHistoryResultObject,
2233
DeploymentHistory,
2334
TriggerHistoryFilterCriteriaType,
2435
StageStatusType,
2536
} from './types'
26-
import { ResourceKindType } from '../../types'
27-
import { ReactComponent as Close } from '../../../Assets/Icon/ic-close.svg'
28-
import { ReactComponent as Check } from '../../../Assets/Icon/ic-check-grey.svg'
29-
import { ReactComponent as ICHelpOutline } from '../../../Assets/Icon/ic-help-outline.svg'
30-
import { ReactComponent as Error } from '../../../Assets/Icon/ic-error-exclamation.svg'
31-
import { ReactComponent as Timer } from '../../../Assets/Icon/ic-timer.svg'
32-
import { ReactComponent as Disconnect } from '../../../Assets/Icon/ic-disconnected.svg'
33-
import { ReactComponent as TimeOut } from '../../../Assets/Icon/ic-timeout-red.svg'
34-
import { ReactComponent as ICCheck } from '../../../Assets/Icon/ic-check.svg'
35-
import { ReactComponent as ICInProgress } from '../../../Assets/Icon/ic-in-progress.svg'
36-
import { TERMINAL_STATUS_MAP } from './constants'
3737

3838
export const getTriggerHistoryFilterCriteria = ({
3939
appId,

0 commit comments

Comments
 (0)