Skip to content

Commit afab999

Browse files
Merge pull request #456 from devtron-labs/feat/patch-dt-cm-cs
feat: Merge Strategy Patch - DT/CM/CS
2 parents f87dd5b + f5441a8 commit afab999

File tree

38 files changed

+256
-91
lines changed

38 files changed

+256
-91
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.11",
3+
"version": "1.2.13",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Assets/Icon/ic-file-code.svg

Lines changed: 2 additions & 2 deletions
Loading

src/Assets/Icon/ic-medal.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Assets/Icon/ic-stamp.svg

Lines changed: 2 additions & 4 deletions
Loading

src/Assets/Icon/ic-visibility-on.svg

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Common/CodeEditor/CodeEditor.reducer.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import YAML from 'yaml'
18+
import { noop, YAMLStringify } from '@Common/Helper'
1719
import { MODES } from '../Constants'
1820
import { Action, CodeEditorInitialValueType, CodeEditorState, CodeEditorThemesKeys } from './types'
1921

@@ -34,16 +36,39 @@ export const CodeEditorReducer = (state: CodeEditorState, action: Action) => {
3436
}
3537
}
3638

39+
export const parseValueToCode = (value: string, mode: string, tabSize: number) => {
40+
let obj = null
41+
42+
try {
43+
obj = JSON.parse(value)
44+
} catch {
45+
try {
46+
obj = YAML.parse(value)
47+
} catch {
48+
noop()
49+
}
50+
}
51+
52+
let final = value
53+
54+
if (obj) {
55+
final = mode === MODES.JSON ? JSON.stringify(obj, null, tabSize) : YAMLStringify(obj)
56+
}
57+
58+
return final
59+
}
60+
3761
export const initialState = ({
3862
mode,
3963
theme,
4064
value,
4165
diffView,
4266
noParsing,
67+
tabSize,
4368
}: CodeEditorInitialValueType): CodeEditorState => ({
4469
mode: mode as MODES,
4570
theme: (theme || CodeEditorThemesKeys.vs) as CodeEditorThemesKeys,
46-
code: value,
71+
code: parseValueToCode(value, mode, tabSize),
4772
diffMode: diffView,
4873
noParsing: [MODES.JSON, MODES.YAML].includes(mode as MODES) ? noParsing : true,
4974
})

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react'
1818
import MonacoEditor, { MonacoDiffEditor } from 'react-monaco-editor'
19-
import YAML from 'yaml'
2019
import ReactGA from 'react-ga4'
2120
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
2221
import { configureMonacoYaml } from 'monaco-yaml'
@@ -27,7 +26,7 @@ import { ReactComponent as ErrorIcon } from '../../Assets/Icon/ic-error-exclamat
2726
import './codeEditor.scss'
2827
import 'monaco-editor'
2928

30-
import { YAMLStringify, cleanKubeManifest, useJsonYaml } from '../Helper'
29+
import { cleanKubeManifest, useEffectAfterMount, useJsonYaml } from '../Helper'
3130
import { useWindowSize } from '../Hooks'
3231
import Select from '../Select/Select'
3332
import RadioGroup from '../RadioGroup/RadioGroup'
@@ -41,8 +40,8 @@ import {
4140
CodeEditorThemesKeys,
4241
InformationBarProps,
4342
} from './types'
44-
import { CodeEditorReducer, initialState } from './CodeEditor.reducer'
45-
import { MODES } from '../Constants'
43+
import { CodeEditorReducer, initialState, parseValueToCode } from './CodeEditor.reducer'
44+
import { DEFAULT_JSON_SCHEMA_URI, MODES } from '../Constants'
4645

4746
const CodeEditorContext = React.createContext(null)
4847

@@ -76,7 +75,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
7675
customLoader,
7776
focus,
7877
validatorSchema,
79-
chartVersion,
78+
schemaURI = DEFAULT_JSON_SCHEMA_URI,
8079
isKubernetes = true,
8180
cleanData = false,
8281
onBlur,
@@ -93,16 +92,13 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
9392
const monacoRef = useRef(null)
9493
const { width, height: windowHeight } = useWindowSize()
9594
const memoisedReducer = React.useCallback(CodeEditorReducer, [])
96-
const [state, dispatch] = useReducer(memoisedReducer, initialState({ mode, theme, value, diffView, noParsing }))
95+
const [state, dispatch] = useReducer(memoisedReducer, initialState({ mode, theme, value, diffView, noParsing, tabSize }))
9796
const [, json, yamlCode, error] = useJsonYaml(state.code, tabSize, state.mode, !state.noParsing)
9897
const [, originalJson, originlaYaml] = useJsonYaml(defaultValue, tabSize, state.mode, !state.noParsing)
9998
const [contentHeight, setContentHeight] = useState(
10099
adjustEditorHeightToContent ? INITIAL_HEIGHT_WHEN_DYNAMIC_HEIGHT : height,
101100
)
102-
/**
103-
* TODO: can be removed with this new merge into react-monaco-editor :)
104-
* see: https://github.com/react-monaco-editor/react-monaco-editor/pull/955
105-
* */
101+
// TODO: upgrade to 0.56.2 to remove this
106102
const onChangeRef = useRef(onChange)
107103
onChangeRef.current = onChange
108104
monaco.editor.defineTheme(CodeEditorThemesKeys.vsDarkDT, {
@@ -230,7 +226,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
230226
isKubernetes,
231227
schemas: [
232228
{
233-
uri: `https://github.com/devtron-labs/devtron/tree/main/scripts/devtron-reference-helm-charts/reference-chart_${chartVersion}/schema.json`, // id of the first schema
229+
uri: schemaURI,
234230
fileMatch: ['*'], // associate with our model
235231
schema: validatorSchema,
236232
},
@@ -240,7 +236,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
240236
config.dispose()
241237
}
242238
// eslint-disable-next-line react-hooks/exhaustive-deps
243-
}, [validatorSchema, chartVersion])
239+
}, [validatorSchema, schemaURI])
244240
useEffect(() => {
245241
if (!editorRef.current) {
246242
return
@@ -260,28 +256,18 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
260256
onChangeRef.current?.(value)
261257
}
262258

263-
useEffect(() => {
259+
useEffectAfterMount(() => {
264260
if (noParsing) {
265261
setCode(value)
266262

267263
return
268264
}
269-
let obj
265+
270266
if (value === state.code) {
271267
return
272268
}
273-
try {
274-
obj = JSON.parse(value)
275-
} catch (err) {
276-
try {
277-
obj = YAML.parse(value)
278-
} catch (err) {}
279-
}
280-
let final = value
281-
if (obj) {
282-
final = state.mode === 'json' ? JSON.stringify(obj, null, tabSize) : YAMLStringify(obj)
283-
}
284-
setCode(final)
269+
270+
setCode(parseValueToCode(value, state.mode, tabSize))
285271
}, [value, noParsing])
286272

287273
useEffect(() => {

src/Common/CodeEditor/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface CodeEditorBaseInterface {
4646
validatorSchema?: any
4747
isKubernetes?: boolean
4848
cleanData?: boolean
49-
chartVersion?: any
49+
schemaURI?: string
5050
/**
5151
* If true, disable the in-built search of monaco editor
5252
* @default false
@@ -109,6 +109,7 @@ export interface CodeEditorInitialValueType {
109109
theme?: string
110110
value: string
111111
noParsing?: boolean
112+
tabSize: number
112113
}
113114

114115
export interface CodeEditorState {

src/Common/Constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const Host = window?.__ORCHESTRATOR_ROOT__ ?? '/orchestrator'
2323
export const DOCUMENTATION_HOME_PAGE = 'https://docs.devtron.ai'
2424
export const DOCUMENTATION_VERSION = '/v/v0.7'
2525
export const DISCORD_LINK = 'https://discord.devtron.ai/'
26+
export const DEFAULT_JSON_SCHEMA_URI = 'https://json-schema.org/draft/2020-12/schema'
2627
export const DOCUMENTATION = {
2728
APP_METRICS: `${DOCUMENTATION_HOME_PAGE}${DOCUMENTATION_VERSION}/usage/applications/app-details/app-metrics`,
2829
APP_TAGS: `${DOCUMENTATION_HOME_PAGE}${DOCUMENTATION_VERSION}/usage/applications/create-application#tags`,
@@ -516,6 +517,7 @@ export const API_STATUS_CODES = {
516517
EXPECTATION_FAILED: 417,
517518
UNPROCESSABLE_ENTITY: 422,
518519
LOCKED: 423,
520+
UNPROCESSABLE_CONTENT: 422,
519521
}
520522

521523
export enum SERVER_MODE {
@@ -577,3 +579,8 @@ export enum GitProviderType {
577579
* Formats the schema removing any irregularity in the existing schema
578580
*/
579581
export const getFormattedSchema = (schema?: string) => JSON.stringify(JSON.parse(schema ?? '{}'), null, 2)
582+
583+
export const UNCHANGED_ARRAY_ELEMENT_SYMBOL = Symbol(
584+
`The element at this index remains unchanged from the original object.
585+
This symbol is used by @buildObjectFromPath & later consumed by @recursivelyRemoveSymbolFromArraysInObject`,
586+
)

0 commit comments

Comments
 (0)