Skip to content

Commit 8117e55

Browse files
authored
Merge pull request #463 from devtron-labs/fix/code-editor-bug
fix: CodeEditor value parsing for every mode fix, misc types and scss update, getGlobalVariables service - remove showError
2 parents 6433a45 + 0121e62 commit 8117e55

File tree

8 files changed

+28
-21
lines changed

8 files changed

+28
-21
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.17",
3+
"version": "1.2.18",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/CIPipeline.Types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,15 @@ export enum RefVariableStageType {
9999
POST_CI = 'POST_CI',
100100
}
101101

102+
export enum FilePropertyTypeSizeUnit {
103+
KB = 'KB',
104+
MB = 'MB',
105+
}
106+
102107
export interface FilePropertyType {
103108
allowedExtensions: string[]
104109
maxUploadSize: number
110+
sizeUnit: FilePropertyTypeSizeUnit
105111
}
106112

107113
export interface ConstraintType {

src/Common/CodeEditor/CodeEditor.reducer.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ export const parseValueToCode = (value: string, mode: string, tabSize: number) =
5252
let final = value
5353

5454
if (obj) {
55-
final = mode === MODES.JSON ? JSON.stringify(obj, null, tabSize) : YAMLStringify(obj)
55+
switch (mode) {
56+
case MODES.JSON:
57+
final = JSON.stringify(obj, null, tabSize)
58+
break
59+
case MODES.YAML:
60+
final = YAMLStringify(obj)
61+
break
62+
default:
63+
break
64+
}
5665
}
5766

5867
return final
@@ -68,7 +77,7 @@ export const initialState = ({
6877
}: CodeEditorInitialValueType): CodeEditorState => ({
6978
mode: mode as MODES,
7079
theme: (theme || CodeEditorThemesKeys.vs) as CodeEditorThemesKeys,
71-
code: parseValueToCode(value, mode, tabSize),
80+
code: noParsing ? value : parseValueToCode(value, mode, tabSize),
7281
diffMode: diffView,
7382
noParsing: [MODES.JSON, MODES.YAML].includes(mode as MODES) ? noParsing : true,
7483
})

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
9292
const monacoRef = useRef(null)
9393
const { width, height: windowHeight } = useWindowSize()
9494
const memoisedReducer = React.useCallback(CodeEditorReducer, [])
95-
const [state, dispatch] = useReducer(memoisedReducer, initialState({ mode, theme, value, diffView, noParsing, tabSize }))
95+
const [state, dispatch] = useReducer(
96+
memoisedReducer,
97+
initialState({ mode, theme, value, diffView, noParsing, tabSize }),
98+
)
9699
const [, json, yamlCode, error] = useJsonYaml(state.code, tabSize, state.mode, !state.noParsing)
97100
const [, originalJson, originlaYaml] = useJsonYaml(defaultValue, tabSize, state.mode, !state.noParsing)
98101
const [contentHeight, setContentHeight] = useState(

src/Common/Common.service.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { MutableRefObject } from 'react'
1818
import moment from 'moment'
1919
import { RuntimeParamsAPIResponseType, RuntimePluginVariables } from '@Shared/types'
2020
import { getIsManualApprovalSpecific, sanitizeUserApprovalConfig, stringComparatorBySortOrder } from '@Shared/Helpers'
21-
import { get, getIsRequestAborted, post } from './Api'
22-
import { API_STATUS_CODES, GitProviderType, ROUTES } from './Constants'
21+
import { get, post } from './Api'
22+
import { GitProviderType, ROUTES } from './Constants'
2323
import { getUrlWithSearchParams, showError, sortCallback } from './Helper'
2424
import {
2525
TeamList,
@@ -49,8 +49,6 @@ import { ApiResourceType } from '../Pages'
4949
import { API_TOKEN_PREFIX } from '@Shared/constants'
5050
import { DefaultUserKey } from '@Shared/types'
5151
import { RefVariableType } from './CIPipeline.Types'
52-
import { ServerErrors } from './ServerError'
53-
import { ToastManager, ToastVariantType } from '@Shared/Services'
5452

5553
export const getTeamListMin = (): Promise<TeamList> => {
5654
// ignore active field
@@ -567,16 +565,6 @@ export const getGlobalVariables = async ({
567565

568566
return variableList
569567
} catch (err) {
570-
if (!getIsRequestAborted(err)) {
571-
if (err instanceof ServerErrors && err.code === API_STATUS_CODES.PERMISSION_DENIED) {
572-
ToastManager.showToast({
573-
variant: ToastVariantType.notAuthorized,
574-
description: 'You are not authorized to access global variables',
575-
})
576-
} else {
577-
showError(err)
578-
}
579-
}
580568
throw err
581569
}
582570
}

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const DOCUMENTATION = {
3333
}
3434

3535
export const PATTERNS = {
36+
DECIMAL_NUMBERS: /^-?\d*\.?\d*$/,
3637
NATURAL_NUMBERS: /^\d*\.?\d*$/,
3738
KUBERNETES_KEY_PREFIX: /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/,
3839
KUBERNETES_KEY_NAME: /^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$/,

src/Shared/Components/DynamicDataTable/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
width: 100%;
5555

5656
> button {
57-
padding: 10px 8px;
57+
padding: 9px 8px;
5858
width: 100%;
5959
height: 100%;
6060
border-radius: 0;

0 commit comments

Comments
 (0)