Skip to content

Commit 7bc3ec4

Browse files
authored
Merge pull request #609 from devtron-labs/feat/codemirror-diff-minimap
feat: CodeMirror - Add Diff Minimap
2 parents bbec103 + a6949e3 commit 7bc3ec4

16 files changed

+559
-243
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.8.4",
3+
"version": "1.8.5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,19 @@ const Header: React.FC<CodeEditorHeaderInterface> & CodeEditorHeaderComposition
391391
children,
392392
className,
393393
hideDefaultSplitHeader,
394-
diffViewWidth,
395394
}) => {
396-
const { defaultValue } = useCodeEditorContext()
395+
const { defaultValue, state } = useCodeEditorContext()
397396
return (
398-
<div
399-
className={className || 'code-editor__header flex right'}
400-
style={{ ...(diffViewWidth ? { width: 'calc(100% - 30px)' } : {}) }}
401-
>
402-
{children}
403-
{!hideDefaultSplitHeader && defaultValue && <SplitPane />}
397+
<div className="flexbox w-100 dc__border-bottom ">
398+
<div
399+
data-code-editor-header
400+
className={`code-editor__header flex-grow-1 bg__secondary ${className || 'px-16 pt-6 pb-5'} ${state.diffMode ? 'dc__grid-half vertical-divider' : ''}`}
401+
402+
>
403+
{children}
404+
{!hideDefaultSplitHeader && defaultValue && <SplitPane />}
405+
</div>
406+
{state.diffMode ? <div className="bg__secondary px-15 dc__align-self-stretch" /> : null}
404407
</div>
405408
)
406409
}

src/Common/CodeEditor/codeEditor.scss

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

1717
.code-editor__header {
18-
height: 40px;
19-
background: var(--N100);
20-
padding: 0 16px;
21-
border-bottom: 1px solid var(--N200);
22-
2318
.radio-group {
2419
height: 24px;
2520
overflow: hidden;

src/Common/CodeEditor/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export interface CodeEditorHeaderInterface {
8282
children?: any
8383
className?: string
8484
hideDefaultSplitHeader?: boolean
85-
diffViewWidth?: boolean
8685
}
8786
export interface CodeEditorComposition {
8887
Header?: React.FC<any>

src/Common/CodeMirror/CodeEditor.components.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,42 @@ import { ReactComponent as Info } from '@Icons/ic-info-filled.svg'
2121
import { ReactComponent as ErrorIcon } from '@Icons/ic-error-exclamation.svg'
2222
import { ReactComponent as ICCompare } from '@Icons/ic-compare.svg'
2323
import { ClipboardButton } from '@Common/ClipboardButton'
24+
import { getComponentSpecificThemeClass } from '@Shared/Providers'
2425

2526
import { useCodeEditorContext } from './CodeEditor.context'
2627
import { CodeEditorHeaderProps, CodeEditorStatusBarProps } from './types'
2728

2829
const SplitPane = () => {
29-
const { state, dispatch, readOnly } = useCodeEditorContext()
30+
const { diffMode, setDiffMode, readOnly } = useCodeEditorContext()
3031

3132
const handleToggle = () => {
3233
if (readOnly) {
3334
return
3435
}
35-
dispatch({ type: 'setDiff', value: !state.diffMode })
36+
setDiffMode(!diffMode)
3637
}
3738

3839
return (
3940
<div className="code-editor__split-pane flex pointer cn-7 fcn-7 ml-auto" onClick={handleToggle}>
4041
<ICCompare className="icon-dim-20 mr-4" />
41-
{state.diffMode ? 'Hide comparison' : 'Compare with default'}
42+
{diffMode ? 'Hide comparison' : 'Compare with default'}
4243
</div>
4344
)
4445
}
4546

4647
export const Header = ({ children, className, hideDefaultSplitHeader }: CodeEditorHeaderProps) => {
47-
const { state, hasCodeEditorContainer } = useCodeEditorContext()
48+
const { diffMode, lhsValue, hasCodeEditorContainer, theme } = useCodeEditorContext()
4849

4950
return (
50-
<div
51-
data-code-editor-header
52-
className={`${hasCodeEditorContainer ? 'dc__top-radius-4' : ''} ${className || 'code-editor__header flex right bcn-1 pt-10 pb-9 px-16 dc__border-bottom'}`}
53-
>
54-
{children}
55-
{!hideDefaultSplitHeader && state.lhsCode && <SplitPane />}
51+
<div className={`${getComponentSpecificThemeClass(theme)} flexbox w-100 border__primary--bottom`}>
52+
<div
53+
data-code-editor-header
54+
className={`${hasCodeEditorContainer ? 'dc__top-radius-4' : ''} code-editor__header flex-grow-1 bg__secondary ${className || 'px-16 pt-6 pb-5'} ${diffMode ? 'dc__grid-half vertical-divider' : ''}`}
55+
>
56+
{children}
57+
{!hideDefaultSplitHeader && lhsValue && <SplitPane />}
58+
</div>
59+
{diffMode ? <div className="bg__secondary px-5 dc__align-self-stretch" /> : null}
5660
</div>
5761
)
5862
}
@@ -86,9 +90,9 @@ export const Information = ({ className, children, text }: CodeEditorStatusBarPr
8690
)
8791

8892
export const Clipboard = () => {
89-
const { state } = useCodeEditorContext()
93+
const { value } = useCodeEditorContext()
9094

91-
return <ClipboardButton content={state.code} iconSize={16} />
95+
return <ClipboardButton content={value} iconSize={16} />
9296
}
9397

9498
export const Container = ({ children, flexExpand }: { children: ReactNode; flexExpand?: boolean }) => (

src/Common/CodeMirror/CodeEditor.constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ export const REPLACE_ALL_SHORTCUT_KEYS: SupportedKeyboardKeysType[] = [
2828
export const CLOSE_SEARCH_SHORTCUT_KEYS: SupportedKeyboardKeysType[] = ['Escape']
2929

3030
export const READ_ONLY_TOOLTIP_TIMEOUT = 2000
31+
32+
export const CODE_EDITOR_FONT_SIZE = 15
33+
34+
export const CODE_EDITOR_LINE_HEIGHT = 1.4
35+
36+
export const CODE_EDITOR_MIN_OVERLAY_HEIGHT = 20

src/Common/CodeMirror/CodeEditor.reducer.ts

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

src/Common/CodeMirror/CodeEditor.theme.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { EditorView } from '@uiw/react-codemirror'
1818
import { githubDarkInit, githubLightInit } from '@uiw/codemirror-theme-github'
1919
import { tags } from '@lezer/highlight'
2020

21+
import { CODE_EDITOR_FONT_SIZE } from './CodeEditor.constants'
22+
2123
export const getCodeEditorTheme = (isDark: boolean) => {
2224
const themeInit = isDark ? githubDarkInit : githubLightInit
2325
const styles = isDark
@@ -71,7 +73,7 @@ export const getCodeEditorTheme = (isDark: boolean) => {
7173
}),
7274
codeEditorTheme: themeInit({
7375
settings: {
74-
fontSize: '15px',
76+
fontSize: `${CODE_EDITOR_FONT_SIZE}px`,
7577
fontFamily: 'Inconsolata, monospace',
7678
background: 'var(--bg-code-editor-base)',
7779
foreground: 'var(--fg-code-editor)',
@@ -80,6 +82,8 @@ export const getCodeEditorTheme = (isDark: boolean) => {
8082
gutterForeground: 'var(--N500)',
8183
gutterBorder: 'transparent',
8284
lineHighlight: 'var(--active-line)',
85+
selection: 'var(--selection-color)',
86+
selectionMatch: 'var(--selection-match-color)',
8387
},
8488
styles,
8589
theme: isDark ? 'dark' : 'light',

0 commit comments

Comments
 (0)