Skip to content

Commit 3af95d8

Browse files
authored
Merge pull request #452 from devtron-labs/feat/runtime-params-global-variables
Feat: runtime params global variables, code refactor
2 parents 9441efb + d20e521 commit 3af95d8

File tree

20 files changed

+299
-74
lines changed

20 files changed

+299
-74
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.2.4-beta-11",
3+
"version": "1.2.4-beta-16",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Assets/Icon/ic-var-initial.svg

Lines changed: 25 additions & 0 deletions
Loading

src/Common/CIPipeline.Types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ export interface ErrorObj {
292292
export interface TaskErrorObj {
293293
isValid: boolean
294294
name: ErrorObj
295-
inlineStepDetail?: { inputVariables?: ErrorObj[]; outputVariables?: ErrorObj[] }
296-
pluginRefStepDetail?: { inputVariables?: ErrorObj[]; outputVariables?: ErrorObj[] }
295+
inlineStepDetail?: { inputVariables?: ErrorObj[]; outputVariables?: ErrorObj[]; isValid?: boolean }
296+
pluginRefStepDetail?: { inputVariables?: ErrorObj[]; outputVariables?: ErrorObj[]; isValid?: boolean }
297297
}
298298
export interface FormErrorObjectType {
299299
name: ErrorObj

src/Common/Common.service.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { MutableRefObject } from 'react'
1718
import moment from 'moment'
1819
import { RuntimeParamsAPIResponseType, RuntimeParamsListItemType } from '@Shared/types'
1920
import { getIsManualApprovalSpecific, sanitizeUserApprovalConfig, stringComparatorBySortOrder } from '@Shared/Helpers'
20-
import { get, post } from './Api'
21-
import { GitProviderType, ROUTES } from './Constants'
22-
import { getUrlWithSearchParams, sortCallback } from './Helper'
21+
import { get, getIsRequestAborted, post } from './Api'
22+
import { API_STATUS_CODES, GitProviderType, ROUTES } from './Constants'
23+
import { getUrlWithSearchParams, showError, sortCallback } from './Helper'
2324
import {
2425
TeamList,
2526
ResponseType,
@@ -41,10 +42,15 @@ import {
4142
UserApprovalMetadataType,
4243
UserApprovalConfigType,
4344
CDMaterialListModalServiceUtilProps,
45+
GlobalVariableDTO,
46+
GlobalVariableOptionType,
4447
} from './Types'
4548
import { ApiResourceType } from '../Pages'
4649
import { API_TOKEN_PREFIX } from '@Shared/constants'
4750
import { DefaultUserKey } from '@Shared/types'
51+
import { RefVariableType } from './CIPipeline.Types'
52+
import { ServerErrors } from './ServerError'
53+
import { ToastManager, ToastVariantType } from '@Shared/Services'
4854

4955
export const getTeamListMin = (): Promise<TeamList> => {
5056
// ignore active field
@@ -530,3 +536,49 @@ export const getGitBranchUrl = (gitUrl: string, branchName: string): string | nu
530536
else if (trimmedGitUrl.includes(GitProviderType.AZURE)) return `${trimmedGitUrl}/src/branch/${branchName}`
531537
return null
532538
}
539+
540+
export const getGlobalVariables = async ({
541+
appId,
542+
isCD = false,
543+
abortControllerRef,
544+
}: {
545+
appId: number
546+
isCD?: boolean
547+
abortControllerRef?: MutableRefObject<AbortController>
548+
}): Promise<GlobalVariableOptionType[]> => {
549+
try {
550+
const { result } = await get<GlobalVariableDTO[]>(
551+
getUrlWithSearchParams(ROUTES.PLUGIN_GLOBAL_VARIABLES, { appId }),
552+
{
553+
abortControllerRef,
554+
},
555+
)
556+
const variableList = (result ?? [])
557+
.filter((item) => (isCD ? item.stageType !== 'ci' : item.stageType === 'ci'))
558+
.map<GlobalVariableOptionType>((variable) => {
559+
const { name, ...updatedVariable } = variable
560+
561+
return {
562+
...updatedVariable,
563+
label: name,
564+
value: name,
565+
description: updatedVariable.description || '',
566+
variableType: RefVariableType.GLOBAL,
567+
}
568+
})
569+
570+
return variableList
571+
} catch (err) {
572+
if (!getIsRequestAborted(err)) {
573+
if (err instanceof ServerErrors && err.code === API_STATUS_CODES.PERMISSION_DENIED) {
574+
ToastManager.showToast({
575+
variant: ToastVariantType.notAuthorized,
576+
description: 'You are not authorized to access global variables',
577+
})
578+
} else {
579+
showError(err)
580+
}
581+
}
582+
throw err
583+
}
584+
}

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const ROUTES = {
117117
CONFIG_DATA: 'config/data',
118118
K8S_RESOURCE_LIST: 'k8s/resource/list',
119119
FILE_UPLOAD: 'file/upload',
120+
PLUGIN_GLOBAL_VARIABLES: 'plugin/global/list/global-variable',
120121
}
121122

122123
export enum KEY_VALUE {

src/Common/Helper.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,10 @@ export const getIframeWithDefaultAttributes = (iframeString: string, defaultName
10311031

10321032
return iframeString
10331033
}
1034+
1035+
export const getGoLangFormattedDateWithTimezone = (dateFormat: string) => {
1036+
const now = moment()
1037+
const formattedDate = now.format(dateFormat)
1038+
const timezone = now.format('Z').replace(/([+/-])(\d{2})[:.](\d{2})/, '$1$2$3')
1039+
return formattedDate.replace('Z', timezone)
1040+
}

src/Common/PopupMenu.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const PopupMenu = ({
3434
autoClose = false,
3535
autoPosition = false,
3636
shouldPreventDefault = false,
37-
disableClose,
3837
}: PopupMenuType) => {
3938
const [popupPosition, setPopupPosition] = React.useState(null)
4039
const [opacity, setOpacity] = React.useState(0)
@@ -115,7 +114,7 @@ const PopupMenu = ({
115114
}
116115

117116
const handleClose = (e, inOrOut) => {
118-
if (!disableClose && (autoClose || inOrOut === 'out')) {
117+
if (autoClose || inOrOut === 'out') {
119118
if (observer && observer.current && observer.current.disconnect) observer.current.disconnect()
120119
setOpacity(0)
121120
setPopupPosition(null)

src/Common/TippyCustomized.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,19 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
4343
}
4444

4545
const closeTippy = (e) => {
46-
stopPropagation(e)
47-
if (tippyRef.current?.hide) {
48-
tippyRef.current.hide()
49-
tippyRef.current = null
46+
if (!props.disableClose) {
47+
stopPropagation(e)
48+
if (tippyRef.current?.hide) {
49+
tippyRef.current.hide()
50+
tippyRef.current = null
5051

51-
if (props.onClose) {
52-
props.onClose()
52+
if (props.onClose) {
53+
props.onClose()
54+
}
5355
}
56+
setShowHeadingInfo(false)
57+
document.removeEventListener('keydown', closeOnEsc)
5458
}
55-
setShowHeadingInfo(false)
56-
document.removeEventListener('keydown', closeOnEsc)
5759
}
5860

5961
const toggleHeadingInfo = (e) => {

src/Common/Types.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ import { TippyProps } from '@tippyjs/react'
1919
import { Placement } from 'tippy.js'
2020
import { UserGroupDTO } from '@Pages/GlobalConfigurations'
2121
import { ImageComment, ReleaseTag } from './ImageTags.Types'
22-
import { MandatoryPluginBaseStateType, RegistryType, RuntimePluginVariables, Severity } from '../Shared'
22+
import {
23+
MandatoryPluginBaseStateType,
24+
RegistryType,
25+
RuntimePluginVariables,
26+
Severity,
27+
} from '../Shared'
2328
import {
2429
ACTION_STATE,
25-
ConsequenceType,
2630
DEPLOYMENT_WINDOW_TYPE,
2731
DockerConfigOverrideType,
32+
RefVariableType,
2833
SortingOrder,
2934
TaskErrorObj,
35+
VariableTypeFormat,
3036
} from '.'
3137

3238
/**
@@ -125,6 +131,7 @@ export interface TippyCustomizedProps extends Pick<TippyProps, 'appendTo'> {
125131
documentationLink?: string
126132
documentationLinkText?: string
127133
children: React.ReactElement<any>
134+
disableClose?: boolean
128135
}
129136

130137
export interface InfoIconTippyProps
@@ -288,7 +295,6 @@ export interface PopupMenuType {
288295
autoClose?: boolean
289296
autoPosition?: boolean
290297
shouldPreventDefault?: boolean
291-
disableClose?: boolean
292298
}
293299

294300
export interface PopupMenuButtonType {
@@ -1014,3 +1020,16 @@ export interface WidgetEventDetails {
10141020
age: string
10151021
lastSeen: string
10161022
}
1023+
1024+
export interface GlobalVariableDTO {
1025+
name: string
1026+
format: VariableTypeFormat
1027+
description: string
1028+
stageType: 'cd' | 'post-cd' | 'ci'
1029+
}
1030+
1031+
export type GlobalVariableOptionType = Omit<GlobalVariableDTO, 'name'> & {
1032+
label: string
1033+
value: string
1034+
variableType: Extract<RefVariableType, RefVariableType.GLOBAL>
1035+
}

0 commit comments

Comments
 (0)