Skip to content

Commit 86e6d0b

Browse files
committed
refactor: clean up imports and improve code formatting in Common.service.ts and related components
1 parent 91b9796 commit 86e6d0b

File tree

6 files changed

+49
-46
lines changed

6 files changed

+49
-46
lines changed

src/Common/Common.service.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616

1717
import { MutableRefObject } from 'react'
1818
import moment from 'moment'
19-
import { sanitizeApprovalConfigData, sanitizeTargetPlatforms, sanitizeUserApprovalList, stringComparatorBySortOrder } from '@Shared/Helpers'
20-
import { PolicyBlockInfo, RuntimeParamsAPIResponseType, RuntimePluginVariables, TargetPlatformItemDTO } from '@Shared/types'
19+
import {
20+
sanitizeApprovalConfigData,
21+
sanitizeTargetPlatforms,
22+
sanitizeUserApprovalList,
23+
stringComparatorBySortOrder,
24+
} from '@Shared/Helpers'
25+
import {
26+
PolicyBlockInfo,
27+
RuntimeParamsAPIResponseType,
28+
RuntimePluginVariables,
29+
} from '@Shared/types'
2130
import { get, post } from './Api'
2231
import { GitProviderType, ROUTES } from './Constants'
2332
import { getUrlWithSearchParams, showError, sortCallback } from './Helper'
@@ -82,7 +91,9 @@ export function setImageTags(request, pipelineId: number, artifactId: number) {
8291
return post(`${ROUTES.IMAGE_TAGGING}/${pipelineId}/${artifactId}`, request)
8392
}
8493

85-
export const sanitizeUserApprovalMetadata = (userApprovalMetadata: UserApprovalMetadataType): UserApprovalMetadataType => ({
94+
export const sanitizeUserApprovalMetadata = (
95+
userApprovalMetadata: UserApprovalMetadataType,
96+
): UserApprovalMetadataType => ({
8697
...userApprovalMetadata,
8798
hasCurrentUserApproved: userApprovalMetadata?.hasCurrentUserApproved ?? false,
8899
canCurrentUserApprove: userApprovalMetadata?.canCurrentUserApprove ?? false,
@@ -154,9 +165,7 @@ const cdMaterialListModal = ({
154165
vulnerable: material.vulnerable,
155166
runningOnParentCd: material.runningOnParentCd,
156167
artifactStatus: artifactStatusValue,
157-
userApprovalMetadata: sanitizeUserApprovalMetadata(
158-
material.userApprovalMetadata,
159-
),
168+
userApprovalMetadata: sanitizeUserApprovalMetadata(material.userApprovalMetadata),
160169
triggeredBy: material.triggeredBy,
161170
isVirtualEnvironment: material.isVirtualEnvironment,
162171
imageComment: material.imageComment,
@@ -197,7 +206,7 @@ const cdMaterialListModal = ({
197206
configuredInReleases: material.configuredInReleases ?? [],
198207
appWorkflowId: material.appWorkflowId ?? null,
199208
deploymentBlockedState: sanitizeDeploymentBlockedState(material.deploymentBlockedState),
200-
targetPlatforms: sanitizeTargetPlatforms(material.targetPlatforms)
209+
targetPlatforms: sanitizeTargetPlatforms(material.targetPlatforms),
201210
}
202211
})
203212
return materials
@@ -211,7 +220,9 @@ const sanitizeDeploymentApprovalInfo = (
211220
approverList: sanitizeUserApprovalList(deploymentApprovalInfo?.eligibleApprovers?.anyUsers?.approverList),
212221
},
213222
specificUsers: {
214-
approverList: sanitizeUserApprovalList(deploymentApprovalInfo?.eligibleApprovers?.specificUsers?.approverList),
223+
approverList: sanitizeUserApprovalList(
224+
deploymentApprovalInfo?.eligibleApprovers?.specificUsers?.approverList,
225+
),
215226
},
216227
userGroups: (deploymentApprovalInfo?.eligibleApprovers?.userGroups ?? []).map(
217228
({ groupName, groupIdentifier, approverList }) => ({
@@ -239,25 +250,22 @@ const processCDMaterialsApprovalInfo = (enableApproval: boolean, cdMaterialsResu
239250
}
240251

241252
export const parseRuntimeParams = (response: RuntimeParamsAPIResponseType): RuntimePluginVariables[] => {
242-
const envVariables = Object.entries(response?.envVariables || {}).map<RuntimePluginVariables>(
243-
([key, value]) => ({
244-
name: key,
245-
value,
246-
defaultValue: '',
247-
format: VariableTypeFormat.STRING,
248-
isRequired: false,
249-
valueType: RefVariableType.NEW,
250-
variableStepScope: RefVariableType.GLOBAL,
251-
stepName: null,
252-
stepType: null,
253-
// TODO: (Rohit/Eshank) Replace this with getUniqueId (nanoId method)
254-
stepVariableId: Math.floor(new Date().valueOf() * Math.random()),
255-
valueConstraint: null,
256-
description: null,
257-
fileReferenceId: null,
258-
fileMountDir: null,
259-
}),
260-
)
253+
const envVariables = Object.entries(response?.envVariables || {}).map<RuntimePluginVariables>(([key, value]) => ({
254+
name: key,
255+
value,
256+
defaultValue: '',
257+
format: VariableTypeFormat.STRING,
258+
isRequired: false,
259+
valueType: RefVariableType.NEW,
260+
variableStepScope: RefVariableType.GLOBAL,
261+
stepName: null,
262+
stepType: null,
263+
stepVariableId: Math.floor(new Date().valueOf() * Math.random()),
264+
valueConstraint: null,
265+
description: null,
266+
fileReferenceId: null,
267+
fileMountDir: null,
268+
}))
261269

262270
const runtimeParams = (response?.runtimePluginVariables ?? []).map<RuntimePluginVariables>((variable) => ({
263271
...variable,

src/Shared/Components/CICDHistory/Artifacts.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616

1717
import { useParams } from 'react-router-dom'
1818
import { useDownload } from '@Shared/Hooks'
19+
import { ReactComponent as Download } from '@Icons/ic-download.svg'
20+
import { ReactComponent as MechanicalOperation } from '@Icons/ic-mechanical-operation.svg'
21+
import { ReactComponent as OpenInNew } from '@Icons/ic-arrow-out.svg'
22+
import { ReactComponent as Down } from '@Icons/ic-arrow-forward.svg'
23+
import { ReactComponent as ICHelpOutline } from '@Icons/ic-help.svg'
24+
import noartifact from '@Images/no-artifact@2x.png'
25+
import folder from '@Icons/ic-folder.svg'
26+
import docker from '@Icons/ic-docker.svg'
27+
import { TargetPlatformBadgeList } from '../TargetPlatforms'
1928
import {
2029
GenericEmptyState,
2130
ImageTagsContainer,
@@ -24,18 +33,9 @@ import {
2433
DOCUMENTATION,
2534
useSuperAdmin,
2635
} from '../../../Common'
27-
import { ReactComponent as Download } from '../../../Assets/Icon/ic-download.svg'
28-
import { ReactComponent as MechanicalOperation } from '../../../Assets/Icon/ic-mechanical-operation.svg'
29-
import { ReactComponent as OpenInNew } from '../../../Assets/Icon/ic-arrow-out.svg'
30-
import { ReactComponent as ICHelpOutline } from '../../../Assets/Icon/ic-help.svg'
31-
import { ReactComponent as Down } from '../../../Assets/Icon/ic-arrow-forward.svg'
32-
import docker from '../../../Assets/Icon/ic-docker.svg'
33-
import folder from '../../../Assets/Icon/ic-folder.svg'
34-
import noartifact from '../../../Assets/Img/no-artifact@2x.png'
3536
import { ArtifactType, CIListItemType } from './types'
3637
import { TERMINAL_STATUS_MAP } from './constants'
3738
import { EMPTY_STATE_STATUS } from '../../constants'
38-
import { TargetPlatformBadgeList } from '../TargetPlatforms'
3939

4040
const CIProgressView = (): JSX.Element => (
4141
<GenericEmptyState

src/Shared/Components/CICDHistory/LogStageAccordion.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import DOMPurify from 'dompurify'
33
import { getTimeDifference } from '@Shared/Helpers'
44
import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
55
import { ReactComponent as ICStack } from '@Icons/ic-stack.svg'
6+
import { TargetPlatformListTooltip } from '../TargetPlatforms'
67
import { LogStageAccordionProps } from './types'
78
import { getLogSearchIndex, getStageStatusIcon } from './utils'
8-
import { TargetPlatformListTooltip } from '../TargetPlatforms'
99

1010
const LogsItemContainer = ({ children }: { children: React.ReactNode }) => (
1111
<div className="display-grid dc__column-gap-10 dc__align-start logs-renderer__log-item">{children}</div>
@@ -87,7 +87,7 @@ const LogStageAccordion = ({
8787
<>
8888
<TargetPlatformListTooltip targetPlatforms={targetPlatforms}>
8989
<div className="flexbox dc__gap-4 dc__align-items-center">
90-
<ICStack className="scn-0 dc__no-shrink icon-stroke__white icon-dim-12" />
90+
<ICStack className="dc__no-shrink icon-stroke__white icon-dim-12" />
9191
<span className="text__white fs-13 fw-4 lh-20">
9292
{targetPlatforms.length}&nbsp;target platform
9393
{targetPlatforms.length > 1 ? 's' : ''}

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,8 @@ export type CIListItemType = Pick<History, 'promotionApprovalMetadata'> & {
399399
triggeredBy?: string
400400
children: any
401401

402-
imageReleaseTags?: ReleaseTag[]
403-
appReleaseTagNames?: string[]
404-
tagsEditable?: boolean
405-
hideImageTaggingHardDelete?: boolean
406402
appliedFilters?: FilterConditionsListType[]
407403
appliedFiltersTimestamp?: string
408-
isSuperAdmin?: boolean
409404
selectedEnvironmentName?: string
410405
renderCIListHeader: (renderCIListHeaderProps: RenderCIListHeaderProps) => JSX.Element
411406
} & (

src/Shared/Components/ImageCard/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface ArtifactInfoProps {
3131
approvalInfoTippy?: ReactNode
3232
}
3333

34-
export interface SequentialCDCardTitleProps {
34+
export interface SequentialCDCardTitleProps extends Pick<CDMaterialType, 'targetPlatforms'> {
3535
isLatest: boolean
3636
isRunningOnParentCD: boolean
3737
artifactStatus: string
@@ -42,7 +42,6 @@ export interface SequentialCDCardTitleProps {
4242
environmentName?: string
4343
parentEnvironmentName?: string
4444
additionalInfo?: ReactNode
45-
targetPlatforms: CDMaterialType['targetPlatforms']
4645
}
4746

4847
export interface ImageCardProps {

src/Shared/Helpers.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,12 @@ export const sanitizeTargetPlatforms = (
989989

990990
const filteredPlatforms = targetPlatforms
991991
.filter(({ name }) => !!name)
992-
.sort((platformA, platformB) => stringComparatorBySortOrder(platformA.name, platformB.name))
992+
.sort(({ name: nameA }, { name: nameB }) => stringComparatorBySortOrder(nameA, nameB))
993993

994994
// They should be unique
995995
const uniquePlatforms: TargetPlatformItemDTO[] = []
996996
const platformExistenceMap: Record<string, true> = {}
997+
997998
filteredPlatforms.forEach(({ name }) => {
998999
if (!platformExistenceMap[name]) {
9991000
platformExistenceMap[name] = true

0 commit comments

Comments
 (0)