Skip to content

Commit 98534d3

Browse files
authored
Merge pull request #248 from devtron-labs/feat/deployment-charts
feat: editable gui schema on deployment charts
2 parents 7ef87b1 + 925e94b commit 98534d3

File tree

15 files changed

+570
-13
lines changed

15 files changed

+570
-13
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": "0.2.2",
3+
"version": "0.2.6",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { useEffect, useReducer, useRef } from 'react'
17+
import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react'
1818
import MonacoEditor, { MonacoDiffEditor } from 'react-monaco-editor'
1919
import YAML from 'yaml'
2020
import ReactGA from 'react-ga4'
@@ -66,12 +66,9 @@ function useCodeEditorContext() {
6666
}
6767

6868
/**
69-
* NOTE: once monaco editor mounts it doesn't update it's internal onChange state.
70-
* Since most of the time onChange methods are declared inside the render body of a component
71-
* we should use the latest references of onChange.
72-
* Please see: https://github.com/react-monaco-editor/react-monaco-editor/issues/704
73-
* Thus as a hack we are using this objects reference to call the latest onChange reference
74-
*/
69+
* TODO: can be removed with this new merge into react-monaco-editor :)
70+
* see: https://github.com/react-monaco-editor/react-monaco-editor/pull/955
71+
* */
7572
const _onChange = {
7673
onChange: null
7774
}
@@ -101,6 +98,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
10198
cleanData = false,
10299
onBlur,
103100
onFocus,
101+
adjustEditorHeightToContent,
104102
}) => {
105103
if (cleanData) {
106104
value = cleanKubeManifest(value)
@@ -114,6 +112,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
114112
const [state, dispatch] = useReducer(memoisedReducer, initialState({ mode, theme, value, diffView, noParsing }))
115113
const [, json, yamlCode, error] = useJsonYaml(state.code, tabSize, state.mode, !state.noParsing)
116114
const [, originalJson, originlaYaml] = useJsonYaml(defaultValue, tabSize, state.mode, !state.noParsing)
115+
const [contentHeight, setContentHeight] = useState(height)
117116
monaco.editor.defineTheme(CodeEditorThemesKeys.vsDarkDT, {
118117
base: 'vs-dark',
119118
inherit: true,
@@ -166,10 +165,24 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
166165
}
167166
}
168167

168+
if (adjustEditorHeightToContent) {
169+
setContentHeight(editor.getContentHeight())
170+
editor.onDidContentSizeChange(() => {
171+
setContentHeight(editor.getContentHeight())
172+
})
173+
}
174+
169175
editorRef.current = editor
170176
monacoRef.current = monaco
171177
}
172178

179+
const editorHeight = useMemo(() => {
180+
if (!adjustEditorHeightToContent) {
181+
return height
182+
}
183+
return contentHeight
184+
}, [height, contentHeight, adjustEditorHeightToContent])
185+
173186
useEffect(() => {
174187
if (!validatorSchema) {
175188
return
@@ -282,7 +295,9 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
282295
}
283296

284297
return (
285-
<CodeEditorContext.Provider value={{ dispatch, state, handleLanguageChange, error, defaultValue, height }}>
298+
<CodeEditorContext.Provider
299+
value={{ dispatch, state, handleLanguageChange, error, defaultValue, height: editorHeight }}
300+
>
286301
{children}
287302
{loading ? (
288303
<CodeEditorPlaceholder customLoader={customLoader} />
@@ -300,7 +315,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
300315
options={diffViewOptions}
301316
theme={state.theme.toLowerCase().split(' ').join('-')}
302317
editorDidMount={editorDidMount}
303-
height={height}
318+
height={editorHeight}
304319
width="100%"
305320
/>
306321
) : (
@@ -311,7 +326,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
311326
options={options}
312327
onChange={handleOnChange}
313328
editorDidMount={editorDidMount}
314-
height={height}
329+
height={editorHeight}
315330
width="100%"
316331
/>
317332
)}

src/Common/CodeEditor/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface CodeEditorInterface {
4848
isKubernetes?: boolean
4949
cleanData?: boolean
5050
chartVersion?: any
51+
adjustEditorHeightToContent?: boolean
5152
}
5253

5354
export interface CodeEditorHeaderInterface {

src/Common/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const URLS = {
6262
GLOBAL_CONFIG_DOCKER: '/global-config/docker',
6363
DEPLOYMENT_HISTORY_CONFIGURATIONS: '/configuration',
6464
GLOBAL_CONFIG_SCOPED_VARIABLES: '/global-config/scoped-variables',
65+
GLOBAL_CONFIG_DEPLOYMENT_CHARTS_LIST: '/global-config/deployment-charts',
6566
}
6667

6768
export const ROUTES = {
@@ -101,6 +102,7 @@ export const ROUTES = {
101102
PLUGIN_GLOBAL_LIST_DETAIL_V2: 'plugin/global/list/detail/v2',
102103
PLUGIN_GLOBAL_LIST_V2: 'plugin/global/list/v2',
103104
PLUGIN_GLOBAL_LIST_TAGS: 'plugin/global/list/tags',
105+
DEPLOYMENT_CHARTS_LIST: 'deployment/template/fetch',
104106
}
105107

106108
export enum KEY_VALUE {

src/Common/RJSF/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ export const PLACEHOLDERS = {
2121
}
2222

2323
export const DEFAULT_FIELD_TITLE = 'Key not available'
24+
25+
export const HIDE_SUBMIT_BUTTON_UI_SCHEMA = {
26+
'ui:submitButtonOptions': {
27+
norender: true,
28+
},
29+
}

src/Common/RJSF/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
export { RJSFForm } from './Form'
1818
export * from './types'
1919
export { getInferredTypeFromValueType, getRedirectionProps } from './utils'
20+
export { HIDE_SUBMIT_BUTTON_UI_SCHEMA } from './constants'

0 commit comments

Comments
 (0)