Skip to content

Commit 0607a7c

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-lib into feat/multi-select-picker
2 parents 101d1f4 + 82d0b43 commit 0607a7c

File tree

17 files changed

+582
-22
lines changed

17 files changed

+582
-22
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.9-beta-2",
3+
"version": "0.2.12",
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'
@@ -55,12 +55,9 @@ function useCodeEditorContext() {
5555
}
5656

5757
/**
58-
* NOTE: once monaco editor mounts it doesn't update it's internal onChange state.
59-
* Since most of the time onChange methods are declared inside the render body of a component
60-
* we should use the latest references of onChange.
61-
* Please see: https://github.com/react-monaco-editor/react-monaco-editor/issues/704
62-
* Thus as a hack we are using this objects reference to call the latest onChange reference
63-
*/
58+
* TODO: can be removed with this new merge into react-monaco-editor :)
59+
* see: https://github.com/react-monaco-editor/react-monaco-editor/pull/955
60+
* */
6461
const _onChange = {
6562
onChange: null,
6663
}
@@ -90,6 +87,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
9087
cleanData = false,
9188
onBlur,
9289
onFocus,
90+
adjustEditorHeightToContent,
9391
}) => {
9492
if (cleanData) {
9593
value = cleanKubeManifest(value)
@@ -103,6 +101,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
103101
const [state, dispatch] = useReducer(memoisedReducer, initialState({ mode, theme, value, diffView, noParsing }))
104102
const [, json, yamlCode, error] = useJsonYaml(state.code, tabSize, state.mode, !state.noParsing)
105103
const [, originalJson, originlaYaml] = useJsonYaml(defaultValue, tabSize, state.mode, !state.noParsing)
104+
const [contentHeight, setContentHeight] = useState(height)
106105
monaco.editor.defineTheme(CodeEditorThemesKeys.vsDarkDT, {
107106
base: 'vs-dark',
108107
inherit: true,
@@ -167,10 +166,24 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
167166
}
168167
}
169168

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

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

285298
return (
286-
<CodeEditorContext.Provider value={{ dispatch, state, handleLanguageChange, error, defaultValue, height }}>
299+
<CodeEditorContext.Provider
300+
value={{ dispatch, state, handleLanguageChange, error, defaultValue, height: editorHeight }}
301+
>
287302
{children}
288303
{loading ? (
289304
<CodeEditorPlaceholder customLoader={customLoader} />
@@ -301,7 +316,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
301316
options={diffViewOptions}
302317
theme={state.theme.toLowerCase().split(' ').join('-')}
303318
editorDidMount={editorDidMount}
304-
height={height}
319+
height={editorHeight}
305320
width="100%"
306321
/>
307322
) : (
@@ -312,7 +327,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
312327
options={options}
313328
onChange={handleOnChange}
314329
editorDidMount={editorDidMount}
315-
height={height}
330+
height={editorHeight}
316331
width="100%"
317332
/>
318333
)}

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
NETWORK_STATUS_INTERFACE: '/network-status-interface',
6667
}
6768

@@ -105,6 +106,7 @@ export const ROUTES = {
105106
PLUGIN_GLOBAL_LIST_DETAIL_V2: 'plugin/global/list/detail/v2',
106107
PLUGIN_GLOBAL_LIST_V2: 'plugin/global/list/v2',
107108
PLUGIN_GLOBAL_LIST_TAGS: 'plugin/global/list/tags',
109+
DEPLOYMENT_CHARTS_LIST: 'deployment/template/fetch',
108110
CONFIG_DATA: 'config/data',
109111
}
110112

src/Common/Helper.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,10 @@ export const processDeployedTime = (lastDeployed, isArgoInstalled) => {
562562
* @param url URL to which the search params needs to be added
563563
* @param params Object for the search parameters
564564
*/
565-
export const getUrlWithSearchParams = (url: string, params: Record<string | number, any> = {}) => {
565+
export const getUrlWithSearchParams = <T extends string | number = string | number>(
566+
url: string,
567+
params = {} as Partial<Record<T, any>>,
568+
) => {
566569
const searchParams = new URLSearchParams()
567570
Object.keys(params).forEach((key) => {
568571
if (!EXCLUDED_FALSY_VALUES.includes(params[key])) {

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)