Skip to content

Commit d13f447

Browse files
committed
feat: add codemirror engine for code-editor behind feature-flag
1 parent 9d36d99 commit d13f447

File tree

9 files changed

+140
-9
lines changed

9 files changed

+140
-9
lines changed

src/Common/CodeMirror/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
*/
1616

1717
export { default as CodeEditor } from './CodeEditor'
18-
export type { CodeEditorProps } from './types'
18+
export type { CodeEditorProps, CodeEditorHeaderProps, CodeEditorStatusBarProps } from './types'

src/Common/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export * from './ImageTags'
5151
export * from './ImageTags.Types'
5252
export { default as DebouncedSearch } from './DebouncedSearch/DebouncedSearch'
5353
export { default as Grid } from './Grid/Grid'
54-
// export { default as CodeEditor } from './CodeEditor/CodeEditor'
5554
export { default as Select } from './Select/Select'
5655
export { ClipboardButton } from './ClipboardButton/ClipboardButton'
5756
export * from './Hooks'
@@ -64,6 +63,6 @@ export * from './Pagination'
6463
export * from './Markdown'
6564
export * from './GenericDescription'
6665
export * from './SegmentedBarChart'
67-
export * from './CodeEditor'
66+
export * from './CodeEditor/types'
6867
export * from './Tooltip'
6968
export * from './SegmentedControl'

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { useMemo, useState } from 'react'
1919
import Tippy from '@tippyjs/react'
2020
import { DiffViewer } from '@Shared/Components/DiffViewer'
2121
import { renderDiffViewNoDifferenceState } from '@Shared/Components/DeploymentConfigDiff'
22-
import { CodeEditor, MODES, Toggle, YAMLStringify } from '../../../../Common'
22+
import { CodeEditor } from '@Shared/Components/CodeEditorWrapper'
23+
import { MODES, Toggle, YAMLStringify } from '../../../../Common'
2324
import { DeploymentHistoryParamsType } from './types'
2425
import { DeploymentHistorySingleValue, DeploymentTemplateHistoryType } from '../types'
2526
import { DEPLOYMENT_HISTORY_CONFIGURATION_LIST_MAP } from '../../../constants'
@@ -77,13 +78,19 @@ const DeploymentHistoryDiffView = ({
7778
) : (
7879
<CodeEditor
7980
key={codeEditorKey}
80-
value={editorValuesRHS}
81-
defaultValue={editorValuesLHS}
82-
adjustEditorHeightToContent
8381
disableSearch
8482
readOnly
8583
noParsing
8684
mode={MODES.YAML}
85+
codeEditorProps={{
86+
value: editorValuesRHS,
87+
defaultValue: editorValuesLHS,
88+
adjustEditorHeightToContent: true,
89+
}}
90+
codeMirrorProps={{
91+
value: editorValuesRHS,
92+
height: 'auto',
93+
}}
8794
/>
8895
)
8996

src/Shared/Components/CMCS/ConfigMapSecretReadyOnly.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
import { Progressing } from '@Common/Progressing'
1818
import { hasHashiOrAWS } from '@Pages/index'
19-
import { CodeEditor } from '@Common/CodeEditor'
2019

2120
import { ClipboardButton } from '@Common/ClipboardButton'
21+
import { MODES } from '@Common/Constants'
2222
import { getConfigMapSecretReadOnlyValues } from './utils'
2323
import { ConfigMapSecretReadyOnlyProps } from './types'
2424
import { renderHashiOrAwsDeprecatedInfo } from './helpers'
25+
import { CodeEditor } from '../CodeEditorWrapper'
2526

2627
const ConfigMapSecretReadyOnly = ({
2728
componentType,
@@ -73,7 +74,19 @@ const ConfigMapSecretReadyOnly = ({
7374
<ClipboardButton content={displayValues.data} />
7475
</div>
7576
<div className="dc__overflow-hidden br-4">
76-
<CodeEditor value={displayValues.data} mode="yaml" inline height={350} readOnly />
77+
<CodeEditor
78+
mode={MODES.YAML}
79+
readOnly
80+
codeEditorProps={{
81+
value: displayValues.data,
82+
inline: true,
83+
height: 350,
84+
}}
85+
codeMirrorProps={{
86+
value: displayValues.data,
87+
height: 350,
88+
}}
89+
/>
7790
</div>
7891
</div>
7992
)}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { CodeEditor } from '@Common/CodeEditor'
2+
import { CodeEditor as CodeMirror, CodeEditorHeaderProps, CodeEditorStatusBarProps } from '@Common/CodeMirror'
3+
4+
import { CodeEditorWrapperProps } from './types'
5+
6+
export const CodeEditorWrapper = <DiffView extends boolean>({
7+
codeEditorProps,
8+
codeMirrorProps,
9+
children,
10+
...restProps
11+
}: CodeEditorWrapperProps<DiffView>) =>
12+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? (
13+
<CodeMirror<DiffView> {...(codeMirrorProps as any)} {...restProps}>
14+
{children}
15+
</CodeMirror>
16+
) : (
17+
<CodeEditor {...(codeEditorProps as any)} {...restProps}>
18+
{children}
19+
</CodeEditor>
20+
)
21+
22+
const CodeEditorLanguageChangerWrapper = () =>
23+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? null : <CodeEditor.LanguageChanger />
24+
25+
const CodeEditorThemeChangerWrapper = () =>
26+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? null : <CodeEditor.ThemeChanger />
27+
28+
const CodeEditorValidationErrorWrapper = () =>
29+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? null : <CodeEditor.ValidationError />
30+
31+
const CodeEditorClipboardWrapper = () =>
32+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? <CodeMirror.Clipboard /> : <CodeEditor.Clipboard />
33+
34+
const CodeEditorHeaderWrapper = (props: CodeEditorHeaderProps) =>
35+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? <CodeMirror.Header {...props} /> : <CodeEditor.Header {...props} />
36+
37+
const CodeEditorWarningWrapper = (props: CodeEditorStatusBarProps) =>
38+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? <CodeMirror.Warning {...props} /> : <CodeEditor.Warning {...props} />
39+
40+
const CodeEditorErrorBarWrapper = (props: CodeEditorStatusBarProps) =>
41+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? <CodeMirror.ErrorBar {...props} /> : <CodeEditor.ErrorBar {...props} />
42+
43+
const CodeEditorInformationWrapper = (props: CodeEditorStatusBarProps) =>
44+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? (
45+
<CodeMirror.Information {...props} />
46+
) : (
47+
<CodeEditor.Information {...props} />
48+
)
49+
50+
const CodeEditorContainerWrapper = (props: { children: React.ReactNode; flexExpand?: boolean }) =>
51+
window._env_.FEATURE_CODE_MIRROR_ENABLE ? <CodeMirror.Container {...props} /> : null
52+
53+
CodeEditorWrapper.LanguageChanger = CodeEditorLanguageChangerWrapper
54+
CodeEditorWrapper.ThemeChanger = CodeEditorThemeChangerWrapper
55+
CodeEditorWrapper.ValidationError = CodeEditorValidationErrorWrapper
56+
CodeEditorWrapper.Clipboard = CodeEditorClipboardWrapper
57+
CodeEditorWrapper.Header = CodeEditorHeaderWrapper
58+
CodeEditorWrapper.Warning = CodeEditorWarningWrapper
59+
CodeEditorWrapper.ErrorBar = CodeEditorErrorBarWrapper
60+
CodeEditorWrapper.Information = CodeEditorInformationWrapper
61+
CodeEditorWrapper.Container = CodeEditorContainerWrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { CodeEditorWrapper as CodeEditor } from './CodeEditorWrapper'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { CodeEditorInterface } from '@Common/CodeEditor'
2+
import { CodeEditorProps } from '@Common/CodeMirror'
3+
4+
export type CodeEditorWrapperProps<DiffView extends boolean> = Pick<
5+
CodeEditorProps<DiffView>,
6+
| 'mode'
7+
| 'tabSize'
8+
| 'readOnly'
9+
| 'placeholder'
10+
| 'noParsing'
11+
| 'loading'
12+
| 'customLoader'
13+
| 'cleanData'
14+
| 'disableSearch'
15+
| 'children'
16+
> & {
17+
diffView?: DiffView
18+
codeEditorProps: Omit<
19+
CodeEditorInterface,
20+
| 'mode'
21+
| 'tabSize'
22+
| 'readOnly'
23+
| 'placeholder'
24+
| 'noParsing'
25+
| 'loading'
26+
| 'customLoader'
27+
| 'cleanData'
28+
| 'disableSearch'
29+
| 'children'
30+
>
31+
codeMirrorProps: Omit<
32+
CodeEditorProps<DiffView>,
33+
| 'mode'
34+
| 'tabSize'
35+
| 'readOnly'
36+
| 'placeholder'
37+
| 'noParsing'
38+
| 'loading'
39+
| 'customLoader'
40+
| 'cleanData'
41+
| 'disableSearch'
42+
| 'children'
43+
>
44+
}

src/Shared/Components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ export * from './RegistryIcon'
8282
export * from './GitProviderIcon'
8383
export * from './CustomInput'
8484
export * from './InfoBlock'
85+
export * from './CodeEditorWrapper'

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export interface customEnv {
105105
* @default false
106106
*/
107107
FEATURE_EXPERIMENTAL_THEMING_ENABLE?: boolean
108+
/**
109+
* If true, the code-editor will use codemirror engine
110+
* @default false
111+
*/
112+
FEATURE_CODE_MIRROR_ENABLE?: boolean
108113
}
109114
declare global {
110115
interface Window {

0 commit comments

Comments
 (0)