Skip to content

Commit 666ef51

Browse files
Merge pull request #477 from devtron-labs/fix/disable-timeout
fix: disable fields not supported by buildX in build infra
2 parents da45d75 + 2bffcfa commit 666ef51

File tree

6 files changed

+135
-47
lines changed

6 files changed

+135
-47
lines changed

src/Common/InfoColorBar/InfoColourbar.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React from 'react'
1817
import { Link } from 'react-router-dom'
1918
import { InfoColourBarType } from '../Types'
19+
import { Tooltip } from '@Common/Tooltip'
2020
import './infoColourBar.scss'
2121

2222
const InfoColourBar = ({
@@ -33,6 +33,7 @@ const InfoColourBar = ({
3333
internalLink,
3434
styles,
3535
hideIcon = false,
36+
textConfig,
3637
}: InfoColourBarType) => {
3738
const renderLink = () => {
3839
if (!linkText) {
@@ -79,6 +80,29 @@ const InfoColourBar = ({
7980
)
8081
}
8182

83+
const renderMessageWrapper = () => {
84+
if (textConfig) {
85+
const { heading, description } = textConfig
86+
87+
return (
88+
<div className="flexbox-col">
89+
{heading && <h6 className="m-0 cn-9 fs-13 fw-6 lh-20 dc__truncate">{heading}</h6>}
90+
91+
<Tooltip content={description}>
92+
<p className="dc__truncate--clamp-3 m-0 cn-9 fs-13 fw-4 lh-20">{description}</p>
93+
</Tooltip>
94+
</div>
95+
)
96+
}
97+
98+
return (
99+
<div className={`info-bar-message-wrapper ${linkClass || ''}`}>
100+
<span className={linkText && redirectLink ? 'mr-5' : ''}>{message}</span>
101+
{renderLink()}
102+
</div>
103+
)
104+
}
105+
82106
return (
83107
<div className="info-bar-container">
84108
<div
@@ -91,10 +115,7 @@ const InfoColourBar = ({
91115
<Icon className={`icon-dim-${iconSize ?? '20'} ${iconClass || ''} mr-8`} />
92116
</div>
93117
)}
94-
<div className={`info-bar-message-wrapper ${linkClass || ''}`}>
95-
<span className={linkText && redirectLink ? 'mr-5' : ''}>{message}</span>
96-
{renderLink()}
97-
</div>
118+
{renderMessageWrapper()}
98119
</div>
99120
{typeof renderActionButton === 'function' && renderActionButton()}
100121
</div>

src/Common/Types.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,43 @@ export enum ImageType {
207207
SMALL = 'small',
208208
}
209209

210-
export interface InfoColourBarType {
211-
message: React.ReactNode
210+
interface InfoColourBarTextConfigType {
211+
/**
212+
* If given would be shown above the description, in bold
213+
*/
214+
heading?: string
215+
/**
216+
* If given would be shown below the heading (if given)
217+
*/
218+
description: string
219+
}
220+
221+
type InfoColourBarMessageProp = {
222+
message: ReactNode
223+
linkText?: ReactNode
224+
redirectLink?: string
225+
linkOnClick?: () => void
226+
linkClass?: string
227+
internalLink?: boolean
228+
229+
textConfig?: never
230+
} | {
231+
textConfig: InfoColourBarTextConfigType
232+
233+
message?: never
234+
linkText?: never
235+
redirectLink?: never
236+
linkOnClick?: () => never
237+
linkClass?: never
238+
internalLink?: never
239+
}
240+
241+
export type InfoColourBarType = InfoColourBarMessageProp & {
212242
classname: string
213243
Icon
214244
iconClass?: string
215245
iconSize?: number // E.g. 16, 20, etc.. Currently, there are around 12 sizes supported. Check `icons.css` or `base.scss` for supported sizes or add new size (class names starts with `icon-dim-`).
216246
renderActionButton?: () => JSX.Element
217-
linkText?: React.ReactNode
218-
redirectLink?: string
219-
linkOnClick?: () => void
220-
linkClass?: string
221-
internalLink?: boolean
222247
styles?: CSSProperties
223248
/**
224249
* If true, the icon is not shown

src/Pages/GlobalConfigurations/BuildInfra/UseBuildInfraForm.tsx

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
updateBuildInfraProfile,
3333
UseBuildInfraFormProps,
3434
UseBuildInfraFormResponseType,
35+
ValidateNodeSelectorParamsType,
3536
ValidateRequestLimitResponseType,
3637
ValidateRequestLimitType,
3738
} from '@Pages/index'
@@ -132,8 +133,10 @@ const validateLabelKeyWithNoDuplicates = (
132133
return existingValidations
133134
}
134135

135-
const isDuplicate = existingKeys.includes(key)
136-
if (isDuplicate) {
136+
// existing keys would include the key itself
137+
const keyCount = existingKeys.filter((existingKey) => existingKey === key).length
138+
139+
if (keyCount > 1) {
137140
return {
138141
isValid: false,
139142
messages: ['Key should be unique'],
@@ -240,6 +243,44 @@ const validateRequestLimit = ({
240243
return requestLimitValidationResponse
241244
}
242245

246+
const validateNodeSelector = ({
247+
selector: { key, value, id },
248+
existingKeys,
249+
profileInputErrors: currentInputErrors,
250+
}: ValidateNodeSelectorParamsType) => {
251+
const keyErrorMessages = validateLabelKeyWithNoDuplicates(key, existingKeys).messages
252+
const valueErrorMessages = validateLabelValue(value).messages
253+
254+
const isEmptyRow = !key && !value
255+
const hasError = !isEmptyRow && (keyErrorMessages.length > 0 || valueErrorMessages.length > 0)
256+
257+
if (!currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR]?.[id]) {
258+
if (!currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR]) {
259+
// eslint-disable-next-line no-param-reassign
260+
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR] = {}
261+
}
262+
// eslint-disable-next-line no-param-reassign
263+
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR][id] = {}
264+
}
265+
266+
// eslint-disable-next-line no-param-reassign
267+
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR][id] = {
268+
...(keyErrorMessages.length > 0 && { [NodeSelectorHeaderType.KEY]: keyErrorMessages }),
269+
...(valueErrorMessages.length > 0 && { [NodeSelectorHeaderType.VALUE]: valueErrorMessages }),
270+
}
271+
272+
if (!hasError) {
273+
// Would delete id, and if not key left then delete key
274+
// eslint-disable-next-line no-param-reassign
275+
delete currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR][id]
276+
277+
if (Object.keys(currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR]).length === 0) {
278+
// eslint-disable-next-line no-param-reassign
279+
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR] = null
280+
}
281+
}
282+
}
283+
243284
const useBuildInfraForm = ({
244285
name,
245286
editProfile,
@@ -552,13 +593,6 @@ const useBuildInfraForm = ({
552593

553594
const { id, key, value } = data
554595

555-
const existingKeys = currentConfiguration[BuildInfraConfigTypes.NODE_SELECTOR].value
556-
.filter((selector) => selector.key && selector.id !== id)
557-
.map((selector) => selector.key)
558-
559-
const keyErrorMessages = validateLabelKeyWithNoDuplicates(key, existingKeys).messages
560-
const valueErrorMessages = validateLabelValue(value).messages
561-
562596
const nodeSelector = currentConfiguration[BuildInfraConfigTypes.NODE_SELECTOR].value.find(
563597
(selector) => selector.id === id,
564598
)
@@ -574,30 +608,18 @@ const useBuildInfraForm = ({
574608
nodeSelector.value = value
575609
}
576610

577-
const isEmptyRow = !key && !value
578-
579-
const hasError = !isEmptyRow && (keyErrorMessages.length > 0 || valueErrorMessages.length > 0)
580-
581-
if (!currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR]?.[id]) {
582-
if (!currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR]) {
583-
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR] = {}
584-
}
585-
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR][id] = {}
586-
}
587-
588-
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR][id] = {
589-
...(keyErrorMessages.length > 0 && { [NodeSelectorHeaderType.KEY]: keyErrorMessages }),
590-
...(valueErrorMessages.length > 0 && { [NodeSelectorHeaderType.VALUE]: valueErrorMessages }),
591-
}
592-
593-
if (!hasError) {
594-
// Would delete id, and if not key left then delete key
595-
delete currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR][id]
596-
if (Object.keys(currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR]).length === 0) {
597-
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR] = null
598-
}
599-
}
611+
// Will validate all the keys since checking duplicates
612+
const existingKeys = currentConfiguration[BuildInfraConfigTypes.NODE_SELECTOR].value.map(
613+
(selector) => selector.key,
614+
)
600615

616+
currentConfiguration[BuildInfraConfigTypes.NODE_SELECTOR].value.forEach((selector) => {
617+
validateNodeSelector({
618+
selector,
619+
existingKeys,
620+
profileInputErrors: currentInputErrors,
621+
})
622+
})
601623
break
602624
}
603625

src/Pages/GlobalConfigurations/BuildInfra/constants.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export const BUILD_INFRA_TEST_IDS = {
188188
CANCEL_BUTTON: 'build-infra-cancel-button',
189189
} as const
190190

191-
export const BUILD_INFRA_DEFAULT_PLATFORM_NAME = 'default'
191+
export const BUILD_INFRA_DEFAULT_PLATFORM_NAME = 'runner'
192192
export const BUILD_INFRA_LATEST_API_VERSION: BuildInfraAPIVersionType = BuildInfraAPIVersionType.ALPHA1
193193
export const TARGET_PLATFORM_ERROR_FIELDS_MAP: Record<TargetPlatformErrorFields, true> = {
194194
[BuildInfraConfigTypes.BUILD_TIMEOUT]: true,
@@ -252,3 +252,7 @@ export const ACTION_TO_PERSISTED_VALUE_MAP: Readonly<
252252

253253
export const DEFAULT_TOLERANCE_EFFECT = BuildInfraToleranceEffectType.NO_SCHEDULE
254254
export const DEFAULT_TOLERANCE_OPERATOR = BuildInfraToleranceOperatorType.EQUALS
255+
256+
export const INFRA_CONFIG_NOT_SUPPORTED_BY_BUILD_X: Partial<Record<BuildInfraConfigTypes, true>> = {
257+
[BuildInfraConfigTypes.BUILD_TIMEOUT]: true,
258+
}

src/Pages/GlobalConfigurations/BuildInfra/types.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { FormEvent, FunctionComponent, ReactNode } from 'react'
18-
import { BUILD_INFRA_INHERIT_ACTIONS } from '@Pages/index'
18+
import { BUILD_INFRA_INHERIT_ACTIONS, useBuildInfraForm } from '@Pages/index'
1919
import { Breadcrumb } from '../../../Common/BreadCrumb/Types'
2020
import { ValidationResponseType } from '../../../Shared'
2121
import { ServerErrors } from '../../../Common'
@@ -538,3 +538,9 @@ export type RequestLimitConfigType = Extract<
538538
| BuildInfraConfigTypes.MEMORY_LIMIT
539539
| BuildInfraConfigTypes.MEMORY_REQUEST
540540
>
541+
542+
export interface ValidateNodeSelectorParamsType
543+
extends Pick<ReturnType<typeof useBuildInfraForm>, 'profileInputErrors'> {
544+
selector: BuildInfraNodeSelectorValueType
545+
existingKeys: string[]
546+
}

src/Pages/GlobalConfigurations/BuildInfra/utils.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ import {
4040
CREATE_PROFILE_BASE_VALUE,
4141
BUILD_INFRA_DEFAULT_PLATFORM_NAME,
4242
BUILD_INFRA_LATEST_API_VERSION,
43+
INFRA_CONFIG_NOT_SUPPORTED_BY_BUILD_X,
4344
} from './constants'
4445
import { getUniqueId } from '../../../Shared'
4546

4647
export const parsePlatformConfigIntoValue = (
47-
configuration: BuildInfraConfigInfoType,
48+
configuration: BuildInfraConfigValuesType,
4849
addUniqueId: boolean = true,
4950
): BuildInfraConfigValuesType => {
5051
switch (configuration?.key) {
@@ -297,6 +298,15 @@ export const getBuildInfraProfilePayload = (
297298
return acc
298299
}, {})
299300

301+
// Deleting un-supported locators in case target platform is not default platform
302+
Object.entries(configurations).forEach(([platformName, platformConfigurations]) => {
303+
if (platformName !== BUILD_INFRA_DEFAULT_PLATFORM_NAME) {
304+
configurations[platformName] = platformConfigurations.filter(
305+
(config) => !INFRA_CONFIG_NOT_SUPPORTED_BY_BUILD_X[config.key],
306+
)
307+
}
308+
})
309+
300310
const payload: BuildInfraProfileInfoDTO = {
301311
name: profileInput.name,
302312
description: profileInput.description,

0 commit comments

Comments
 (0)