Skip to content

Commit 9aff8c9

Browse files
authored
Merge pull request #226 from devtron-labs/feat/config-diff-phase-2
feat: Config Diff - Phase 2 - Comparison b/w environments
2 parents 3a9d8df + ddc58ab commit 9aff8c9

32 files changed

+1194
-178
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.1.15",
3+
"version": "0.1.15-beta-22",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 10 additions & 0 deletions
Loading

src/Assets/Icon/ic-expand.svg

Lines changed: 19 additions & 0 deletions
Loading

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ import ReactGA from 'react-ga4'
2121
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
2222
import { configureMonacoYaml } from 'monaco-yaml'
2323

24-
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
2524
import { ReactComponent as Info } from '../../Assets/Icon/ic-info-filled.svg'
2625
import { ReactComponent as ErrorIcon } from '../../Assets/Icon/ic-error-exclamation.svg'
2726
import { ReactComponent as WarningIcon } from '../../Assets/Icon/ic-warning.svg'
2827
import './codeEditor.scss'
2928
import 'monaco-editor'
3029

31-
import YamlWorker from '../../yaml.worker.js?worker'
3230
import { YAMLStringify, cleanKubeManifest, useJsonYaml } from '../Helper'
3331
import { useWindowSize } from '../Hooks'
3432
import Select from '../Select/Select'
@@ -48,10 +46,18 @@ import { MODES } from '../Constants'
4846

4947
self.MonacoEnvironment = {
5048
getWorker(_, label) {
49+
const getWorkerModule = (moduleUrl: string) => {
50+
return new Worker(self.MonacoEnvironment.getWorkerUrl(moduleUrl, label), {
51+
name: label,
52+
type: 'module',
53+
})
54+
}
55+
5156
if (label === MODES.YAML) {
52-
return new YamlWorker()
57+
return getWorkerModule('../../yaml.worker.js?worker')
5358
}
54-
return new editorWorker()
59+
60+
return getWorkerModule('/monaco-editor/esm/vs/editor/editor.worker?worker')
5561
},
5662
}
5763

@@ -73,7 +79,7 @@ function useCodeEditorContext() {
7379
* Thus as a hack we are using this objects reference to call the latest onChange reference
7480
*/
7581
const _onChange = {
76-
onChange: null
82+
onChange: null,
7783
}
7884

7985
const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.memo(

src/Common/CodeEditor/codeEditor.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
overflow: hidden;
2626
}
2727

28-
.radio-group input[type=checkbox]:checked+.radio__item-label {
28+
.radio-group input[type='checkbox']:checked + .radio__item-label {
2929
background: var(--N700);
3030
border-radius: 0;
3131
color: var(--white);
@@ -165,3 +165,9 @@
165165
.monaco-editor-hover {
166166
margin-left: 40px;
167167
}
168+
169+
.monaco-scrollable-element {
170+
& > .visible {
171+
z-index: 9;
172+
}
173+
}

src/Common/Hooks/useUrlFilters/useUrlFilters.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { useMemo } from 'react'
1818
import { useHistory, useLocation } from 'react-router-dom'
19-
import { DEFAULT_BASE_PAGE_SIZE, SortingOrder } from '../../Constants'
19+
import { DEFAULT_BASE_PAGE_SIZE, EXCLUDED_FALSY_VALUES, SortingOrder } from '../../Constants'
2020
import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
2121
import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
2222

@@ -130,7 +130,7 @@ const useUrlFilters = <T = string, K = unknown>({
130130

131131
const updateSearchParams = (paramsToSerialize: Partial<K>) => {
132132
Object.keys(paramsToSerialize).forEach((key) => {
133-
if (paramsToSerialize[key]) {
133+
if (!EXCLUDED_FALSY_VALUES.includes(paramsToSerialize[key])) {
134134
if (Array.isArray(paramsToSerialize[key])) {
135135
searchParams.delete(key)
136136
paramsToSerialize[key].forEach((val) => {
@@ -139,6 +139,8 @@ const useUrlFilters = <T = string, K = unknown>({
139139
} else {
140140
searchParams.set(key, paramsToSerialize[key])
141141
}
142+
} else {
143+
searchParams.delete(key)
142144
}
143145
})
144146
// Not replacing the params as it is being done by _resetPageNumber

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

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

17-
import { Fragment, useEffect, useRef, useState } from 'react'
17+
import { Fragment, useEffect, useMemo, useRef, useState } from 'react'
1818
import { useParams } from 'react-router'
1919
import Tippy from '@tippyjs/react'
20+
import { yamlComparatorBySortOrder } from '@Shared/Helpers'
2021
import { MODES, Toggle, YAMLStringify } from '../../../../Common'
2122
import { DeploymentHistoryParamsType } from './types'
2223
import { DeploymentHistorySingleValue, DeploymentTemplateHistoryType } from '../types'
@@ -33,6 +34,7 @@ const DeploymentHistoryDiffView = ({
3334
isDeleteDraft,
3435
rootClassName,
3536
comparisonBodyClassName,
37+
sortOrder = null,
3638
}: DeploymentTemplateHistoryType) => {
3739
const { historyComponent, historyComponentName } = useParams<DeploymentHistoryParamsType>()
3840
const ref = useRef(null)
@@ -64,26 +66,38 @@ const DeploymentHistoryDiffView = ({
6466
Object.keys(baseTemplateConfiguration?.codeEditorValue?.variableSnapshot || {}).length !== 0 ||
6567
Object.keys(currentConfiguration?.codeEditorValue?.variableSnapshot || {}).length !== 0
6668

67-
const editorValuesRHS = convertVariables
68-
? baseTemplateConfiguration?.codeEditorValue?.resolvedValue
69-
: baseTemplateConfiguration?.codeEditorValue?.value
69+
const editorValuesRHS = useMemo(() => {
70+
if (!baseTemplateConfiguration?.codeEditorValue?.value || isDeleteDraft) {
71+
return ''
72+
}
73+
74+
const editorValue = convertVariables
75+
? baseTemplateConfiguration?.codeEditorValue?.resolvedValue
76+
: baseTemplateConfiguration?.codeEditorValue?.value
77+
78+
return YAMLStringify(JSON.parse(editorValue), {
79+
sortMapEntries: (a, b) => yamlComparatorBySortOrder(a, b, sortOrder),
80+
})
81+
}, [convertVariables, baseTemplateConfiguration, sortOrder, isDeleteDraft])
82+
83+
const editorValuesLHS = useMemo(() => {
84+
if (!currentConfiguration?.codeEditorValue?.value || isUnpublished) {
85+
return ''
86+
}
87+
88+
const editorValue = convertVariables
89+
? currentConfiguration?.codeEditorValue?.resolvedValue
90+
: currentConfiguration?.codeEditorValue?.value
7091

71-
const editorValuesLHS = convertVariables
72-
? currentConfiguration?.codeEditorValue?.resolvedValue
73-
: currentConfiguration?.codeEditorValue?.value
92+
return YAMLStringify(JSON.parse(editorValue), {
93+
sortMapEntries: (a, b) => yamlComparatorBySortOrder(a, b, sortOrder),
94+
})
95+
}, [convertVariables, currentConfiguration, sortOrder, isUnpublished])
7496

7597
const renderDeploymentDiffViaCodeEditor = () => (
7698
<CodeEditor
77-
value={
78-
!baseTemplateConfiguration?.codeEditorValue?.value || isDeleteDraft
79-
? ''
80-
: YAMLStringify(JSON.parse(editorValuesRHS))
81-
}
82-
defaultValue={
83-
!currentConfiguration?.codeEditorValue?.value || isUnpublished
84-
? ''
85-
: YAMLStringify(JSON.parse(editorValuesLHS))
86-
}
99+
value={editorValuesRHS}
100+
defaultValue={editorValuesLHS}
87101
height={codeEditorHeight}
88102
diffView={previousConfigAvailable && true}
89103
readOnly

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
DeploymentAppTypes,
2626
ResponseType,
2727
PaginationProps,
28+
SortingOrder,
2829
} from '../../../Common'
2930
import { DeploymentStageType } from '../../constants'
3031
import { AggregationKeys, GitTriggers, Node, NodeType, ResourceKindType, ResourceVersionType } from '../../types'
@@ -436,6 +437,7 @@ export interface DeploymentTemplateHistoryType {
436437
isDeleteDraft?: boolean
437438
rootClassName?: string
438439
comparisonBodyClassName?: string
440+
sortOrder?: SortingOrder
439441
}
440442
export interface DeploymentHistoryDetailRes extends ResponseType {
441443
result?: DeploymentHistoryDetail
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useEffect, useState, useRef } from 'react'
2+
3+
import { CollapseProps } from './types'
4+
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+
}

0 commit comments

Comments
 (0)