Skip to content

Commit eca9e5d

Browse files
authored
Merge pull request #277 from devtron-labs/feat/disable-editor-search
feat: disable search and use dynamic height in config diff
2 parents da93ad7 + 7cfd923 commit eca9e5d

File tree

10 files changed

+91
-54
lines changed

10 files changed

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

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const _onChange = {
6262
onChange: null,
6363
}
6464

65+
const INITIAL_HEIGHT_WHEN_DYNAMIC_HEIGHT = 100
66+
6567
const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.memo(
6668
({
6769
value,
@@ -88,6 +90,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
8890
onBlur,
8991
onFocus,
9092
adjustEditorHeightToContent = false,
93+
disableSearch = false,
9194
}) => {
9295
if (cleanData) {
9396
value = cleanKubeManifest(value)
@@ -101,7 +104,9 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
101104
const [state, dispatch] = useReducer(memoisedReducer, initialState({ mode, theme, value, diffView, noParsing }))
102105
const [, json, yamlCode, error] = useJsonYaml(state.code, tabSize, state.mode, !state.noParsing)
103106
const [, originalJson, originlaYaml] = useJsonYaml(defaultValue, tabSize, state.mode, !state.noParsing)
104-
const [contentHeight, setContentHeight] = useState(height)
107+
const [contentHeight, setContentHeight] = useState(
108+
adjustEditorHeightToContent ? INITIAL_HEIGHT_WHEN_DYNAMIC_HEIGHT : height,
109+
)
105110
monaco.editor.defineTheme(CodeEditorThemesKeys.vsDarkDT, {
106111
base: 'vs-dark',
107112
inherit: true,
@@ -146,7 +151,19 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
146151
},
147152
})
148153

149-
function editorDidMount(editor, monaco) {
154+
useEffect(() => {
155+
const rule = !disableSearch
156+
? null
157+
: monaco.editor.addKeybindingRule({
158+
command: null,
159+
keybinding: monaco.KeyCode.KeyF | monaco.KeyMod.CtrlCmd,
160+
})
161+
return () => {
162+
rule?.dispose()
163+
}
164+
}, [disableSearch])
165+
166+
const editorDidMount = (editor, monaco) => {
150167
if (
151168
mode === MODES.YAML &&
152169
editor &&
@@ -166,11 +183,33 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
166183
}
167184
}
168185

169-
if (adjustEditorHeightToContent) {
170-
setContentHeight(editor.getContentHeight())
171-
editor.onDidContentSizeChange(() => {
186+
if (adjustEditorHeightToContent && editor) {
187+
if (!('getModifiedEditor' in editor)) {
188+
editor.onDidContentSizeChange(() => {
189+
setContentHeight(editor.getContentHeight())
190+
})
172191
setContentHeight(editor.getContentHeight())
192+
return
193+
}
194+
const modifiedEditor = editor.getModifiedEditor()
195+
const originalEditor = editor.getOriginalEditor()
196+
originalEditor.onDidContentSizeChange(() => {
197+
setContentHeight(
198+
Math.max(
199+
typeof contentHeight === 'number' ? contentHeight : Number.MIN_SAFE_INTEGER,
200+
originalEditor.getContentHeight(),
201+
),
202+
)
203+
})
204+
modifiedEditor.onDidContentSizeChange(() => {
205+
setContentHeight(
206+
Math.max(
207+
typeof contentHeight === 'number' ? contentHeight : Number.MIN_SAFE_INTEGER,
208+
modifiedEditor.getContentHeight(),
209+
),
210+
)
173211
})
212+
setContentHeight(Math.max(modifiedEditor.getContentHeight(), modifiedEditor.getContentHeight()))
174213
}
175214

176215
editorRef.current = editor
@@ -278,12 +317,24 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
278317
lineDecorationsWidth,
279318
automaticLayout: true,
280319
scrollBeyondLastLine: false,
320+
...(adjustEditorHeightToContent
321+
? {
322+
overviewRulerLanes: adjustEditorHeightToContent ? 0 : 1,
323+
}
324+
: {}),
281325
minimap: {
282326
enabled: false,
283327
},
284328
scrollbar: {
285329
alwaysConsumeMouseWheel: false,
286330
vertical: inline ? 'hidden' : 'auto',
331+
...(adjustEditorHeightToContent
332+
? {
333+
vertical: 'hidden',
334+
verticalScrollbarSize: 0,
335+
verticalSliderSize: 0,
336+
}
337+
: {}),
287338
},
288339
lineNumbers(lineNumber) {
289340
return `<span style="padding-right:6px">${lineNumber}</span>`

src/Common/CodeEditor/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ interface CodeEditorBaseInterface {
4747
isKubernetes?: boolean
4848
cleanData?: boolean
4949
chartVersion?: any
50+
/**
51+
* If true, disable the in-built search of monaco editor
52+
* @default false
53+
*/
54+
disableSearch?: boolean
5055
}
5156

5257
export type CodeEditorInterface = CodeEditorBaseInterface &

src/Shared/Components/CICDHistory/DeploymentHistoryDiff/DeploymentHistoryDetailedView.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ const DeploymentHistoryDetailedView = ({
116116
{loader ? (
117117
<Progressing pageLoader />
118118
) : (
119-
<DeploymentHistoryDiffView
120-
currentConfiguration={currentConfiguration}
121-
baseTemplateConfiguration={baseTemplateConfiguration}
122-
previousConfigAvailable={previousConfigAvailable}
123-
/>
119+
<div className="dc__overflow-scroll">
120+
<DeploymentHistoryDiffView
121+
currentConfiguration={currentConfiguration}
122+
baseTemplateConfiguration={baseTemplateConfiguration}
123+
previousConfigAvailable={previousConfigAvailable}
124+
/>
125+
</div>
124126
)}
125127
</div>
126128
</>

src/Shared/Components/CICDHistory/DeploymentHistoryDiff/DeploymentHistoryDiffView.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { useParams } from 'react-router-dom'
18-
import { Fragment, useEffect, useMemo, useRef, useState } from 'react'
18+
import { Fragment, useMemo, useState } from 'react'
1919
import Tippy from '@tippyjs/react'
2020
import { yamlComparatorBySortOrder } from '@Shared/Helpers'
2121
import { MODES, Toggle, YAMLStringify } from '../../../../Common'
@@ -25,6 +25,7 @@ import CodeEditor from '../../../../Common/CodeEditor/CodeEditor'
2525
import { DEPLOYMENT_HISTORY_CONFIGURATION_LIST_MAP } from '../../../constants'
2626
import { ReactComponent as Info } from '../../../../Assets/Icon/ic-info-filled.svg'
2727
import { ReactComponent as ViewVariablesIcon } from '../../../../Assets/Icon/ic-view-variable-toggle.svg'
28+
import './styles.scss'
2829

2930
const DeploymentHistoryDiffView = ({
3031
currentConfiguration,
@@ -37,20 +38,9 @@ const DeploymentHistoryDiffView = ({
3738
sortOrder = null,
3839
}: DeploymentTemplateHistoryType) => {
3940
const { historyComponent, historyComponentName } = useParams<DeploymentHistoryParamsType>()
40-
const ref = useRef(null)
41-
const [codeEditorHeight, setCodeEditorHeight] = useState('')
42-
const { innerHeight } = window
4341

4442
const [convertVariables, setConvertVariables] = useState(false)
4543

46-
useEffect(() => {
47-
if (ref.current) {
48-
// eslint-disable-next-line no-unsafe-optional-chaining
49-
const dynamicHeight = ref.current?.clientHeight + 255 + (!previousConfigAvailable ? 55 : 0)
50-
setCodeEditorHeight(`${innerHeight - dynamicHeight < 400 ? 400 : innerHeight - dynamicHeight}px`)
51-
}
52-
}, [ref.current?.clientHeight])
53-
5444
const getTheme = () => {
5545
if (isDeleteDraft) {
5646
return 'delete-draft'
@@ -98,7 +88,8 @@ const DeploymentHistoryDiffView = ({
9888
<CodeEditor
9989
value={editorValuesRHS}
10090
defaultValue={editorValuesLHS}
101-
height={codeEditorHeight}
91+
adjustEditorHeightToContent
92+
disableSearch
10293
diffView={previousConfigAvailable && true}
10394
readOnly
10495
noParsing
@@ -127,7 +118,7 @@ const DeploymentHistoryDiffView = ({
127118
)
128119

129120
return (
130-
<div>
121+
<div className="deployment-history-diff-view">
131122
{!previousConfigAvailable && (
132123
<div className="bcb-1 eb-2 pt-8 pb-8 br-4 flexbox pl-4 cn-9 fs-13 mt-16 mb-16 mr-20 ml-20">
133124
<Info className="mr-8 ml-14 icon-dim-20" />
@@ -145,7 +136,6 @@ const DeploymentHistoryDiffView = ({
145136
className={`en-2 bw-1 br-4 bcn-0 mt-16 mb-16 mr-20 ml-20 pt-2 pb-2 ${
146137
previousConfigAvailable ? 'deployment-diff__upper' : ''
147138
} ${rootClassName ?? ''}`}
148-
ref={ref}
149139
data-testid={`configuration-link-${
150140
previousConfigAvailable ? 'previous-deployment' : 'no-previous-deployment'
151141
}`}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.deployment-history-diff-view {
2+
& .react-monaco-editor-container {
3+
min-height: 100px;
4+
}
5+
}
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
1-
import { useEffect, useState, useRef } from 'react'
2-
31
import { CollapseProps } from './types'
42

5-
export const Collapse = ({ expand, onTransitionEnd, children }: CollapseProps) => {
6-
const ref = useRef<HTMLDivElement>(null)
7-
const [contentHeight, setContentHeight] = useState(0)
8-
9-
useEffect(() => {
10-
if (ref.current) {
11-
setContentHeight(ref.current.clientHeight)
12-
}
13-
}, [children])
14-
15-
return (
16-
<div
17-
style={{
18-
height: expand ? contentHeight : 0,
19-
transition: 'height 200ms ease-out',
20-
overflow: 'hidden',
21-
}}
22-
onTransitionEnd={onTransitionEnd}
23-
>
24-
<div ref={ref}>{children}</div>
25-
</div>
26-
)
27-
}
3+
export const Collapse = ({ expand, children }: CollapseProps) => (
4+
// TODO: removed animation because of miscalculations (broken with auto editor height)
5+
<div>{expand ? children : null}</div>
6+
)

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
margin: 16px 0 0;
2626
}
2727
}
28+
29+
& .react-monaco-editor-container {
30+
min-height: 100px;
31+
}
2832
}

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiffMain.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ export const DeploymentConfigDiffMain = ({
141141
defaultValue={primaryList.codeEditorValue.value}
142142
value={secondaryList.codeEditorValue.value}
143143
mode={MODES.YAML}
144-
height="650px"
144+
disableSearch
145+
adjustEditorHeightToContent
145146
noParsing
146147
readOnly
147148
/>

0 commit comments

Comments
 (0)