Skip to content

Commit c103775

Browse files
committed
fix: CodeEditor value parsing for every mode fix, misc types and scss update, getGlobalVariables service - remove showError
1 parent 6433a45 commit c103775

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

src/Common/CIPipeline.Types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export enum RefVariableStageType {
102102
export interface FilePropertyType {
103103
allowedExtensions: string[]
104104
maxUploadSize: number
105+
sizeUnit: 'KB' | 'MB'
105106
}
106107

107108
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)