Skip to content

Commit 3cbf0cc

Browse files
committed
feat: add utils for mandatory scoped variables
1 parent e7a1af3 commit 3cbf0cc

File tree

8 files changed

+75
-2
lines changed

8 files changed

+75
-2
lines changed

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const URLS = {
5858
APP_TRIGGER: 'trigger',
5959
GLOBAL_CONFIG_DOCKER: '/global-config/docker',
6060
DEPLOYMENT_HISTORY_CONFIGURATIONS: '/configuration',
61+
GLOBAL_CONFIG_SCOPED_VARIABLES: '/global-config/scoped-variables',
6162
}
6263

6364
export const ROUTES = {

src/Common/Types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ export interface RadioInterface {
235235
showTippy?: boolean
236236
tippyContent?: any
237237
tippyPlacement?: string
238+
/**
239+
* If false would make radio group controlled
240+
*/
238241
canSelect?: boolean
239242
isDisabled?: boolean
240243
tippyClass?: string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './types'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export enum ScopedVariablesFileViewType {
2+
/**
3+
* Used to show yaml editor for editing/creating variables
4+
*/
5+
YAML = 'yaml',
6+
/**
7+
* Shows the variable list view
8+
*/
9+
SAVED = 'variable-list',
10+
/**
11+
* Shows the variables in environment list view
12+
*/
13+
ENVIRONMENT_LIST = 'environments',
14+
}
15+
16+
export interface SavedVariablesViewParamsType {
17+
currentView: ScopedVariablesFileViewType
18+
}

src/Pages/GlobalConfigurations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616

1717
export * from './BuildInfra'
1818
export * from './Authorization'
19+
export * from './ScopedVariables'

src/Shared/Components/ReactSelect/utils.tsx

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

1717
import Tippy from '@tippyjs/react'
18-
import { components } from 'react-select'
18+
import { components, MenuListProps } from 'react-select'
1919
import { Progressing, stopPropagation } from '../../../Common'
2020

2121
export const getCommonSelectStyle = (styleOverrides = {}) => ({
@@ -166,3 +166,24 @@ export const GroupHeading = (props: any) => {
166166
}
167167

168168
export const commonSelectStyles = getCommonSelectStyle()
169+
170+
export const MenuListWithApplyButton = ({
171+
handleApplyFilter,
172+
...props
173+
}: MenuListProps & { handleApplyFilter: () => void }) => (
174+
<>
175+
<components.MenuList {...props} />
176+
{props.selectProps.options.length > 0 && (
177+
<div className="p-8 dc__position-sticky dc__bottom-0 dc__border-top-n1 bcn-0 dc__bottom-radius-4">
178+
<button
179+
type="button"
180+
className="dc__unset-button-styles w-100 br-4 h-28 flex bcb-5 cn-0 fw-6 lh-28 fs-12 h-28 br-4 pt-5 pr-12 pb-5 pl-12"
181+
onClick={handleApplyFilter}
182+
aria-label="Apply filters"
183+
>
184+
Apply
185+
</button>
186+
</div>
187+
)}
188+
</>
189+
)

src/Shared/validations.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,30 @@ export const validateIfImageExist = (url: string): Promise<ValidationResponseTyp
221221
})
222222
}
223223
})
224+
225+
export const validateUniqueKeys = (keys: string[]) => {
226+
const keysMap: Record<string, number> = keys.reduce(
227+
(acc, key) => {
228+
if (acc[key]) {
229+
acc[key] += 1
230+
return acc
231+
}
232+
233+
acc[key] = 1
234+
return acc
235+
},
236+
{} as Record<string, number>,
237+
)
238+
239+
const duplicateKeys = Object.keys(keysMap).filter((key) => keysMap[key] > 1)
240+
if (!duplicateKeys.length) {
241+
return {
242+
isValid: true,
243+
}
244+
}
245+
246+
return {
247+
isValid: false,
248+
message: `Duplicate variable name: ${duplicateKeys.join(', ')}`,
249+
}
250+
}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export interface customEnv {
7171
ENABLE_RESOURCE_SCAN_V2?: boolean
7272
ENABLE_GITOPS_BITBUCKET_SOURCE: boolean
7373
HIDE_RESOURCE_WATCHER?: boolean
74-
ORGANIZATION_NAME: string
74+
ORGANIZATION_NAME?: string
75+
FEATURE_SCOPED_VARIABLE_ENVIRONMENT_LIST_ENABLE?: boolean
7576
}
7677
declare global {
7778
interface Window {

0 commit comments

Comments
 (0)