Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
49ee3bd
Merge branch 'main' into feat/webhook-ui
shivani170 Oct 17, 2024
58eba54
chore: wip received playload
shivani170 Oct 17, 2024
cbcc969
feat: ui for tag & PR info card
shivani170 Oct 18, 2024
dc1b079
feat: commit info card ui modification
shivani170 Oct 18, 2024
0bda2bb
chore: code refactoring
shivani170 Oct 21, 2024
81a597a
Merge branch 'develop' into feat/webhook-ui
shivani170 Oct 21, 2024
b1c724d
chore: hrlpers utils refactoring
shivani170 Oct 21, 2024
3de590e
chore: code refactoring
shivani170 Oct 22, 2024
0464aa4
chore: getFormattedSchema added
shivani170 Oct 22, 2024
7cf8784
Merge branch 'develop' into feat/webhook-ui
shivani170 Oct 22, 2024
18aa6d6
chore: version bump
shivani170 Oct 22, 2024
96ddc7f
chore: version bump
shivani170 Oct 22, 2024
64e213c
chore: hash icon added
shivani170 Nov 4, 2024
e037f5b
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 4, 2024
3d74f3f
chore: version bump
shivani170 Nov 5, 2024
f2ff268
chore: version bump
shivani170 Nov 5, 2024
12b10e9
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 6, 2024
18d50f0
chore: version bump
shivani170 Nov 6, 2024
d9dcd51
chore: ui fixes for commint card in git info
shivani170 Nov 7, 2024
36f3a51
chore: version bump
shivani170 Nov 7, 2024
f5aff4c
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 7, 2024
e1efe70
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 8, 2024
212190e
chore: code refactoring
shivani170 Nov 8, 2024
378bae3
chore: version bump
shivani170 Nov 8, 2024
1191329
chore: overflow-issue fix
shivani170 Nov 11, 2024
47039cc
version bump
shivani170 Nov 11, 2024
ae81e5b
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 12, 2024
046e893
chore: version bump
shivani170 Nov 12, 2024
6251625
chore: copy icon added in pr tag
shivani170 Nov 12, 2024
51f0f41
chore: version bump
shivani170 Nov 12, 2024
f86f5cb
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 13, 2024
9dbcdc1
chore: version bump
shivani170 Nov 13, 2024
95013f6
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 14, 2024
dd84db6
chore: version bump
shivani170 Nov 14, 2024
65e2cb9
chore: version bump
shivani170 Nov 14, 2024
a740210
chore: removed see more see less view in info card
shivani170 Nov 15, 2024
0571ac0
chore: git info fix
shivani170 Nov 15, 2024
9781e4c
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 18, 2024
3bdfedc
chore: version bump to 1.0.5-beta-3
shivani170 Nov 18, 2024
3fdf3fc
chore: version bump 1.0.6
shivani170 Nov 18, 2024
f375263
chore: version bump to 1.0.7
shivani170 Nov 18, 2024
1e25064
Merge branch 'develop' into feat/webhook-ui
shivani170 Nov 18, 2024
d02d2c5
chore: version bump
shivani170 Nov 18, 2024
8ca0002
chore: version bump to 1.0.7
shivani170 Nov 18, 2024
343d223
chore: removed unused code
shivani170 Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtron-labs/devtron-fe-common-lib",
"version": "0.7.2-beta-2",
"version": "1.0.5",
"description": "Supporting common component library",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Common.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export function getWebhookEventsForEventId(eventId: string | number) {
*/
export const getGitBranchUrl = (gitUrl: string, branchName: string): string | null => {
if (!gitUrl) return null
const trimmedGitUrl = gitUrl.trim().replace(/\/$/, '') // Remove any trailing slash
const trimmedGitUrl = gitUrl.trim().replace('.git', '').replace(/\/$/, '') // Remove any trailing slash
if (trimmedGitUrl.includes(GitProviderType.GITLAB)) return `${trimmedGitUrl}/-/tree/${branchName}`
else if (trimmedGitUrl.includes(GitProviderType.GITHUB)) return `${trimmedGitUrl}/tree/${branchName}`
else if (trimmedGitUrl.includes(GitProviderType.BITBUCKET)) return `${trimmedGitUrl}/branch/${branchName}`
Expand Down
44 changes: 40 additions & 4 deletions src/Common/Helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,7 @@ export const powerSetOfSubstringsFromStart = (strings: string[], regex: RegExp)
})

export const convertJSONPointerToJSONPath = (pointer: string) =>
pointer
.replace(/\/([\*0-9]+)\//g, '[$1].')
.replace(/\//g, '.')
.replace(/\./, '$.')
unescapePathComponent(pointer.replace(/\/([\*0-9]+)\//g, '[$1].').replace(/\//g, '.').replace(/\./, '$.'))

export const flatMapOfJSONPaths = (
paths: string[],
Expand Down Expand Up @@ -988,3 +985,42 @@ export const getBranchIcon = (sourceType, _isRegex?: boolean, webhookEventName?:
}
return branchIcon
}

// TODO: Might need to expose sandbox and referrer policy
export const getSanitizedIframe = (iframeString: string) =>
DOMPurify.sanitize(iframeString, {
ADD_TAGS: ['iframe'],
ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'],
})

/**
* This method adds default attributes to iframe - title, loading ="lazy", width="100%", height="100%"
*/
export const getIframeWithDefaultAttributes = (iframeString: string, defaultName?: string): string => {
const parentDiv = document.createElement('div')
parentDiv.innerHTML = getSanitizedIframe(iframeString)


const iframe = parentDiv.querySelector('iframe')
if (iframe) {
if (!iframe.hasAttribute('title') && !!defaultName) {
iframe.setAttribute('title', defaultName)
}

if (!iframe.hasAttribute('loading')) {
iframe.setAttribute('loading', 'lazy')
}

if (!iframe.hasAttribute('width')) {
iframe.setAttribute('width', '100%')
}

if (!iframe.hasAttribute('height')) {
iframe.setAttribute('height', '100%')
}

return parentDiv.innerHTML
}

return iframeString
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const CiPipelineSourceConfig = ({
}, [])

return (
<div className={`flex left ${showTooltip ? 'branch-name' : ''} ${rootClassName}`}>
<div className={`flex left ${showTooltip ? 'fw-5' : ''} ${rootClassName}`}>
{loading && showIcons && <span className="dc__loading-dots">loading</span>}
{!loading && (
<div className="flex dc__gap-4">
Expand Down Expand Up @@ -156,7 +156,7 @@ export const CiPipelineSourceConfig = ({
</>
)}
{baseText && (
<span className="cursor dc__border-dashed--n3-bottom fw-6 lh-20 fs-13">
<span className="dc__border-dashed--n3-bottom fw-6 fs-13 lh-19-imp">
{baseText}
</span>
)}
Expand Down
168 changes: 50 additions & 118 deletions src/Shared/Components/GitCommitInfoGeneric/GitCommitInfoGeneric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

/* eslint-disable eqeqeq */
import { useState } from 'react'
import moment from 'moment'
import Tippy from '@tippyjs/react'
import ClipboardButton from '@Common/ClipboardButton/ClipboardButton'
Expand All @@ -29,7 +28,7 @@ import { ReactComponent as Check } from '@Icons/ic-check-circle.svg'
import { ReactComponent as Abort } from '@Icons/ic-abort.svg'
import { SourceTypeMap, createGitCommitUrl, getGitBranchUrl } from '@Common/Common.service'
import { stopPropagation } from '@Common/Helper'
import { DATE_TIME_FORMATS } from '@Common/Constants'
import { DATE_TIME_FORMATS, GitProviderType } from '@Common/Constants'
import { ReactComponent as Tag } from '@Icons/ic-tag.svg'
import { getLowerCaseObject, getWebhookDate } from '@Shared/Helpers'
import { ReactComponent as Hash } from '@Icons/ic-hash.svg'
Expand All @@ -48,8 +47,6 @@ const GitCommitInfoGeneric = ({
index,
isExcluded = false,
}: GitCommitInfoGenericProps) => {
const [showSeeMore, setShowSeeMore] = useState(true)

const lowerCaseCommitInfo = getLowerCaseObject(commitInfo)
const _isWebhook =
materialSourceType === SourceTypeMap.WEBHOOK ||
Expand All @@ -75,19 +72,21 @@ const GitCommitInfoGeneric = ({
</a>
) : null

function renderBasicGitCommitInfoForWebhook() {
function renderBasicGitCommitInfoForWebhook(isPRWebhook?: boolean) {
const _date = getWebhookDate(materialSourceType, commitInfo)
return (
<div className="flex column dc__gap-4 w-100">
<div className="flex left lh-20 dc__gap-8 w-100">
<PullRequestIcon className="icon-dim-16" />
<div className="flex left dc__gap-4">
Merge commit into&nbsp;
{renderBranchName(_webhookData.data['target branch name'])}
&nbsp;from&nbsp;
{renderBranchName(_webhookData.data['source branch name'])}
{isPRWebhook ? (
<div className="flex left lh-20 dc__gap-8 w-100">
<PullRequestIcon className="icon-dim-16" />
<div className="flex left dc__gap-4">
Merge commit into&nbsp;
{renderBranchName(_webhookData.data['target branch name'])}
&nbsp;from&nbsp;
{renderBranchName(_webhookData.data['source branch name'])}
</div>
</div>
</div>
) : null}
{_webhookData.data.author ? (
<div className="material-history__text lh-20 flex left dc__gap-8 w-100">
<PersonIcon className="icon-dim-16" /> {_webhookData.data.author}
Expand All @@ -109,80 +108,6 @@ const GitCommitInfoGeneric = ({
)
}

function renderMoreDataForWebhook(_moreData) {
return !showSeeMore ? (
<div className="material-history__all-changes">
<div className="material-history__body mt-4">
{Object.keys(_moreData).map((_key, idx) => {
let classes
if (idx % 2 == 0) {
classes = 'bcn-1'
}
return (
<div
key={_key}
className={`material-history__text material-history__grid left pt-4 pb-4 ${classes}`}
>
<div>{_key}</div>
<div>{_moreData[_key]}</div>
</div>
)
})}
</div>
</div>
) : null
}

function renderSeeMoreButtonForWebhook() {
return (
<button
type="button"
className="fs-12 fw-6 pt-12 mt-12 pl-12 pr-12 w-100 bcn-0 flex left br-4 dc__box-shadow-top cb-5 dc__no-border"
onClick={(event) => {
event.stopPropagation()
setShowSeeMore(!showSeeMore)
}}
>
{showSeeMore ? 'See More' : 'See Less'}
</button>
)
}

function handleMoreDataForWebhook() {
const _moreData = {}
if (_webhookData.eventactiontype === WEBHOOK_EVENT_ACTION_TYPE.MERGED) {
Object.keys(_webhookData.data).forEach((_key) => {
if (
_key != 'author' &&
_key != 'date' &&
_key != 'git url' &&
_key != 'source branch name' &&
_key != 'source checkout' &&
_key != 'target branch name' &&
_key != 'target checkout' &&
_key != 'title'
) {
_moreData[_key] = _webhookData.data[_key]
}
})
} else if (_webhookData.eventactiontype === WEBHOOK_EVENT_ACTION_TYPE.NON_MERGED) {
Object.keys(_webhookData.data).forEach((_key) => {
if (_key !== 'author' && _key !== 'date' && _key !== 'target checkout') {
_moreData[_key] = _webhookData.data[_key]
}
})
}

const _hasMoreData = Object.keys(_moreData).length > 0

return (
<>
{_hasMoreData && renderMoreDataForWebhook(_moreData)}
{_hasMoreData && renderSeeMoreButtonForWebhook()}
</>
)
}

const matSelectionText = (): JSX.Element => {
if (isExcluded) {
return (
Expand Down Expand Up @@ -218,10 +143,10 @@ const GitCommitInfoGeneric = ({
_webhookData.data.title ? <span className="flex left cn-9 fw-6 fs-13">{_webhookData.data.title}</span> : null

const renderPullRequestId = (pullRequestUrl: string) => {
const pullRequestId = pullRequestUrl.split('/').pop()
const pullRequestId = pullRequestUrl?.split('/').pop()

return (
<div className="w-100">
<div className="w-100 flex left dc__gap-4">
<a
href={pullRequestUrl}
target="_blank"
Expand All @@ -231,14 +156,17 @@ const GitCommitInfoGeneric = ({
>
<Hash /> <span>{Number.isNaN(pullRequestId) ? 'PR' : pullRequestId}</span>
</a>
<span className="git-commit-info-generic__copy dc__visibility-hidden p-2" data-testid="git-commit-copy">
<ClipboardButton content={pullRequestUrl} />
</span>
</div>
)
}

const renderTagCreationId = () => (
const renderTagCreationId = (tagRequestUrl: string) => (
<div className="commit-hash px-6 dc__w-fit-content dc__gap-4 fs-13">
<Tag className="icon-dim-14 scb-5" />
{_webhookData.data['target checkout']}
{tagRequestUrl}
</div>
)

Expand All @@ -252,32 +180,38 @@ const GitCommitInfoGeneric = ({
return null
}

const renderPRInfoCard = () =>
_isWebhook &&
_webhookData.eventactiontype === WEBHOOK_EVENT_ACTION_TYPE.MERGED && (
<div className="flex column left dc__gap-8">
<div className="flex dc__content-space w-100">
{renderPullRequestId(_webhookData.data['git url'])}
{getCheckUncheckIcon()}
</div>
{renderWebhookTitle()}
{renderBasicGitCommitInfoForWebhook()}
{handleMoreDataForWebhook()}
const renderPRInfoCard = () => (
<div className="flex column left dc__gap-8">
<div className="flex dc__content-space w-100">
{renderPullRequestId(_webhookData.data['git url'])}
{getCheckUncheckIcon()}
</div>
)
{renderWebhookTitle()}
{renderBasicGitCommitInfoForWebhook(true)}
</div>
)

const renderTagInfoCard = () =>
_isWebhook &&
_webhookData.eventactiontype === WEBHOOK_EVENT_ACTION_TYPE.NON_MERGED && (
<>
<div className="flex left dc__content-space">
{renderTagCreationId()}
{getCheckUncheckIcon()}
</div>
{renderBasicGitCommitInfoForWebhook()}
{handleMoreDataForWebhook()}
</>
)
const renderTagInfoCard = () => (
<>
<div className="flex left dc__content-space">
{renderTagCreationId(_webhookData.data['target checkout'])}
{getCheckUncheckIcon()}
</div>
{renderBasicGitCommitInfoForWebhook()}
</>
)

const renderWebhookGitInfoCard = () => {
if (!_isWebhook) return null

const isMerged = _webhookData.eventactiontype === WEBHOOK_EVENT_ACTION_TYPE.MERGED

if (materialUrl.includes(GitProviderType.GITLAB)) {
// TODO: This is a temporary fix for the issue where the eventActionType data incorrect
return isMerged ? renderTagInfoCard() : renderPRInfoCard()
}
return isMerged ? renderPRInfoCard() : renderTagInfoCard()
}

return (
<div className="git-commit-info-generic__wrapper cn-9 fs-12">
Expand Down Expand Up @@ -351,9 +285,7 @@ const GitCommitInfoGeneric = ({
</div>
</>
)}

{renderPRInfoCard()}
{renderTagInfoCard()}
{renderWebhookGitInfoCard()}
</div>
</div>
)
Expand Down