Skip to content

Commit f1b8bea

Browse files
arunjaindevarunjaindev
authored andcommitted
feat: use main context for super admin
1 parent dfe4383 commit f1b8bea

File tree

4 files changed

+66
-81
lines changed

4 files changed

+66
-81
lines changed

src/Shared/Components/CICDHistory/CiPipelineSourceConfig.tsx

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import webhookIcon from '../../../Assets/Icon/ic-webhook.svg'
2222
import branchIcon from '../../../Assets/Icon/ic-branch.svg'
2323
import { ReactComponent as Info } from '../../../Assets/Icon/ic-info-outlined.svg'
2424
import regexIcon from '../../../Assets/Icon/ic-regex.svg'
25+
import { _buildHoverHtmlForWebhook } from './utils'
2526

2627
export interface CIPipelineSourceConfigInterface {
2728
sourceType
@@ -51,30 +52,6 @@ export const CiPipelineSourceConfig = ({
5152
const [sourceValueAdv, setSourceValueAdv] = useState<ReactNode>('')
5253
const [loading, setLoading] = useState(!!_isWebhook)
5354

54-
function _buildHoverHtmlForWebhook(eventName, condition, selectors) {
55-
const _conditions = []
56-
Object.keys(condition).forEach((_selectorId) => {
57-
// eslint-disable-next-line eqeqeq
58-
const _selector = selectors.find((i) => i.id == _selectorId)
59-
_conditions.push({ name: _selector ? _selector.name : '', value: condition[_selectorId] })
60-
})
61-
62-
return (
63-
<>
64-
<span> {eventName} Filters </span>
65-
<br />
66-
<ul className="m-0">
67-
{_conditions.map((_condition, index) => (
68-
// eslint-disable-next-line react/no-array-index-key
69-
<li key={index}>
70-
{_condition.name} : {_condition.value}
71-
</li>
72-
))}
73-
</ul>
74-
</>
75-
)
76-
}
77-
7855
const updateSourceValue = () => {
7956
if (_isWebhook) {
8057
const _sourceValueObj = JSON.parse(sourceValue)
@@ -153,7 +130,7 @@ export const CiPipelineSourceConfig = ({
153130
regexTippyContent()
154131
}, [])
155132

156-
const getRegexOrBranchIcon = () => (_isRegex ? regexIcon : branchIcon)
133+
const isRegexOrBranchIcon = _isRegex ? regexIcon : branchIcon
157134

158135
return (
159136
<div className={`flex left ${showTooltip ? 'branch-name' : ''}`}>
@@ -162,7 +139,7 @@ export const CiPipelineSourceConfig = ({
162139
<>
163140
{showIcons && (
164141
<img
165-
src={_isWebhook ? webhookIcon : getRegexOrBranchIcon()}
142+
src={_isWebhook ? webhookIcon : isRegexOrBranchIcon}
166143
alt="branch"
167144
className="icon-dim-12 mr-5"
168145
/>

src/Shared/Components/CICDHistory/DeploymentStatusDetailRow.tsx

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ import { ErrorInfoStatusBar } from './ErrorInfoStatusBar'
2424
import { DeploymentStatusDetailRowType } from './types'
2525
import { getManualSync } from './service'
2626
import { MANIFEST_STATUS_HEADERS, TERMINAL_STATUS_MAP } from './constants'
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'
3427
import { ReactComponent as DropDownIcon } from '../../../Assets/Icon/ic-chevron-down.svg'
3528
import { ShowMoreText } from '../ShowMoreText/ShowMoreText'
3629
import AppStatusDetailsChart from './AppStatusDetailsChart'
30+
import { renderIcon } from './utils'
3731

3832
export const DeploymentStatusDetailRow = ({
3933
type,
@@ -64,33 +58,6 @@ export const DeploymentStatusDetailRow = ({
6458
toggleCollapsed(!collapsed)
6559
}
6660

67-
const renderIcon = (iconState: string): JSX.Element => {
68-
switch (iconState) {
69-
case 'success':
70-
return <Check className="icon-dim-20 green-tick" data-testid="success-green-tick" />
71-
case 'failed':
72-
return <Error className="icon-dim-20" />
73-
case 'unknown':
74-
return <ICHelpOutline className="icon-dim-20" />
75-
case 'inprogress':
76-
return (
77-
<div className="icon-dim-20">
78-
<div className="pulse-highlight" />
79-
</div>
80-
)
81-
case 'unreachable':
82-
return <Close className="icon-dim-20" />
83-
case 'loading':
84-
return <div className="dc__app-summary__icon icon-dim-20 mr-6 progressing progressing--node" />
85-
case 'disconnect':
86-
return <Disconnect className="icon-dim-20" />
87-
case 'time_out':
88-
return <TimeOut className="icon-dim-20" />
89-
default:
90-
return <Timer className="icon-dim-20 timer-icon" />
91-
}
92-
}
93-
9461
const renderDetailedData = () =>
9562
!collapsed ? (
9663
<div className="bcn-0 en-2 detail-tab_border bw-1">

src/Shared/Components/CICDHistory/History.components.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
*/
1616

1717
import Tippy from '@tippyjs/react'
18-
import { useEffect, useState } from 'react'
18+
import { useEffect } from 'react'
1919
import { useLocation } from 'react-router'
20-
import { ClipboardButton, GenericEmptyState, extractImage, getUserRole, showError, useKeyDown } from '../../../Common'
20+
import { ClipboardButton, GenericEmptyState, extractImage, useKeyDown } from '../../../Common'
2121
import { EMPTY_STATE_STATUS } from '../../constants'
2222
import { ReactComponent as DropDownIcon } from '../../../Assets/Icon/ic-chevron-down.svg'
2323
import { GitChangesType, LogResizeButtonType, ScrollerType } from './types'
2424
import GitCommitInfoGeneric from '../GitCommitInfoGeneric/GitCommitInfoGeneric'
2525
import { CIListItem } from './Artifacts'
2626
import { ReactComponent as ZoomIn } from '../../../Assets/Icon/ic-fullscreen.svg'
2727
import { ReactComponent as ZoomOut } from '../../../Assets/Icon/ic-exit-fullscreen.svg'
28+
import { useMainContext } from '../../Providers'
2829

2930
export const LogResizeButton = ({ fullScreenView, setFullScreenView }: LogResizeButtonType): JSX.Element => {
3031
const { pathname } = useLocation()
@@ -116,25 +117,7 @@ export const GitChanges = ({
116117
selectedEnvironmentName,
117118
renderCIListHeader,
118119
}: GitChangesType) => {
119-
const [isSuperAdmin, setSuperAdmin] = useState<boolean>(false)
120-
121-
async function initialise() {
122-
try {
123-
const userRole = await getUserRole()
124-
125-
const superAdmin = userRole?.result?.roles?.includes('role:super-admin___')
126-
setSuperAdmin(superAdmin)
127-
} catch (err) {
128-
showError(err)
129-
}
130-
}
131-
132-
useEffect(() => {
133-
if (artifactId) {
134-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
135-
initialise()
136-
}
137-
}, [artifactId])
120+
const { isSuperAdmin } = useMainContext()
138121

139122
if (!ciMaterials?.length || !Object.keys(gitTriggers ?? {}).length) {
140123
return (

src/Shared/Components/CICDHistory/utils.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ import {
2121
TriggerHistoryFilterCriteriaType,
2222
} from './types'
2323
import { ResourceKindType } from '../../types'
24+
import { ReactComponent as Close } from '../../../Assets/Icon/ic-close.svg'
25+
import { ReactComponent as Check } from '../../../Assets/Icon/ic-check-grey.svg'
26+
import { ReactComponent as ICHelpOutline } from '../../../Assets/Icon/ic-help-outline.svg'
27+
import { ReactComponent as Error } from '../../../Assets/Icon/ic-error-exclamation.svg'
28+
import { ReactComponent as Timer } from '../../../Assets/Icon/ic-timer.svg'
29+
import { ReactComponent as Disconnect } from '../../../Assets/Icon/ic-disconnected.svg'
30+
import { ReactComponent as TimeOut } from '../../../Assets/Icon/ic-timeout-red.svg'
2431

2532
export const getTriggerHistoryFilterCriteria = ({
2633
appId,
@@ -65,3 +72,54 @@ export const getParsedTriggerHistory = (result): DeploymentHistoryResultObject =
6572
}
6673
return parsedResult
6774
}
75+
76+
export const _buildHoverHtmlForWebhook = (eventName, condition, selectors) => {
77+
const _conditions = []
78+
Object.keys(condition).forEach((_selectorId) => {
79+
// eslint-disable-next-line eqeqeq
80+
const _selector = selectors.find((i) => i.id == _selectorId)
81+
_conditions.push({ name: _selector ? _selector.name : '', value: condition[_selectorId] })
82+
})
83+
84+
return (
85+
<>
86+
<span> {eventName} Filters </span>
87+
<br />
88+
<ul className="m-0">
89+
{_conditions.map((_condition, index) => (
90+
// eslint-disable-next-line react/no-array-index-key
91+
<li key={index}>
92+
{_condition.name} : {_condition.value}
93+
</li>
94+
))}
95+
</ul>
96+
</>
97+
)
98+
}
99+
100+
export const renderIcon = (iconState: string): JSX.Element => {
101+
switch (iconState) {
102+
case 'success':
103+
return <Check className="icon-dim-20 green-tick" data-testid="success-green-tick" />
104+
case 'failed':
105+
return <Error className="icon-dim-20" />
106+
case 'unknown':
107+
return <ICHelpOutline className="icon-dim-20" />
108+
case 'inprogress':
109+
return (
110+
<div className="icon-dim-20">
111+
<div className="pulse-highlight" />
112+
</div>
113+
)
114+
case 'unreachable':
115+
return <Close className="icon-dim-20" />
116+
case 'loading':
117+
return <div className="dc__app-summary__icon icon-dim-20 mr-6 progressing progressing--node" />
118+
case 'disconnect':
119+
return <Disconnect className="icon-dim-20" />
120+
case 'time_out':
121+
return <TimeOut className="icon-dim-20" />
122+
default:
123+
return <Timer className="icon-dim-20 timer-icon" />
124+
}
125+
}

0 commit comments

Comments
 (0)