Skip to content

Commit 5f3046d

Browse files
authored
Merge pull request #410 from devtron-labs/feat/react-diff-viewer
feat: add support for react diff viewer
2 parents 6ac8369 + 0a17867 commit 5f3046d

File tree

14 files changed

+317
-91
lines changed

14 files changed

+317
-91
lines changed

package-lock.json

Lines changed: 61 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 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.1.2",
3+
"version": "1.1.3",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -97,6 +97,7 @@
9797
"fast-json-patch": "^3.1.1",
9898
"jsonpath-plus": "^10.0.0",
9999
"react-dates": "^21.8.0",
100+
"react-diff-viewer-continued": "^3.4.0",
100101
"react-monaco-editor": "^0.54.0",
101102
"sass": "^1.69.7",
102103
"tslib": "2.7.0"

src/Assets/Icon/ic-info-outline.svg

Lines changed: 4 additions & 0 deletions
Loading

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { useParams } from 'react-router-dom'
1818
import { useMemo, useState } from 'react'
1919
import Tippy from '@tippyjs/react'
2020
import { yamlComparatorBySortOrder } from '@Shared/Helpers'
21+
import { DiffViewer } from '@Shared/Components/DiffViewer'
22+
import { renderDiffViewNoDifferenceState } from '@Shared/Components/DeploymentConfigDiff'
2123
import { MODES, Toggle, YAMLStringify } from '../../../../Common'
2224
import { DeploymentHistoryParamsType } from './types'
2325
import { DeploymentHistorySingleValue, DeploymentTemplateHistoryType } from '../types'
@@ -85,20 +87,26 @@ const DeploymentHistoryDiffView = ({
8587
})
8688
}, [convertVariables, currentConfiguration, sortOrder, isUnpublished])
8789

88-
const renderDeploymentDiffViaCodeEditor = () => (
89-
<CodeEditor
90-
key={codeEditorKey}
91-
value={editorValuesRHS}
92-
defaultValue={editorValuesLHS}
93-
adjustEditorHeightToContent
94-
disableSearch
95-
diffView={previousConfigAvailable && true}
96-
readOnly
97-
noParsing
98-
mode={MODES.YAML}
99-
theme={getTheme()}
100-
/>
101-
)
90+
const renderDeploymentDiffViaCodeEditor = () =>
91+
previousConfigAvailable ? (
92+
<DiffViewer
93+
oldValue={editorValuesLHS}
94+
newValue={editorValuesRHS}
95+
codeFoldMessageRenderer={renderDiffViewNoDifferenceState(editorValuesLHS, editorValuesRHS)}
96+
/>
97+
) : (
98+
<CodeEditor
99+
key={codeEditorKey}
100+
value={editorValuesRHS}
101+
defaultValue={editorValuesLHS}
102+
adjustEditorHeightToContent
103+
disableSearch
104+
readOnly
105+
noParsing
106+
mode={MODES.YAML}
107+
theme={getTheme()}
108+
/>
109+
)
102110

103111
const handleShowVariablesClick = () => {
104112
setConvertVariables(!convertVariables)
@@ -176,7 +184,7 @@ const DeploymentHistoryDiffView = ({
176184
</div>
177185

178186
{(currentConfiguration?.codeEditorValue?.value || baseTemplateConfiguration?.codeEditorValue?.value) && (
179-
<div className="en-2 bw-1 br-4 mt-16">
187+
<div className="en-2 bw-1 br-4 mt-16 dc__overflow-auto">
180188
<div
181189
className="code-editor-header-value px-12 py-8 fs-13 fw-6 cn-9 bcn-0 dc__top-radius-4 dc__border-bottom"
182190
data-testid="configuration-link-comparison-body-heading"

src/Shared/Components/CICDHistory/cicdHistory.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@
171171
color: var(--N900) !important;
172172
}
173173

174-
.code-editor-green-diff {
175-
background: #eaf1dd;
176-
}
177-
178-
.code-editor-red-diff {
179-
background: #ffd4d1;
180-
}
181-
182174
.left-50 {
183175
left: 50px;
184176
}

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323

2424
&__main-content {
2525
flex-grow: 1;
26-
27-
&__heading {
28-
display: grid;
29-
// -15px to accommodate the right side bar of the code-editor
30-
grid-template-columns: calc(50% - 15px) calc(50% - 15px);
31-
grid-template-rows: auto;
32-
}
3326
}
3427

3528
& .react-monaco-editor-container {

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.utils.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import {
1212
AppEnvDeploymentConfigListParams,
1313
DiffHeadingDataType,
1414
prepareHistoryData,
15+
GenericSectionErrorState,
1516
} from '@Shared/Components'
16-
import { deepEqual } from '@Common/Helper'
17+
import { deepEqual, noop } from '@Common/Helper'
1718

1819
import { ManifestTemplateDTO } from '@Pages/Applications'
1920
import {
@@ -27,6 +28,7 @@ import {
2728
TemplateListDTO,
2829
TemplateListType,
2930
} from '../../Services/app.types'
31+
import { DiffViewerProps } from '../DiffViewer/types'
3032

3133
export const getDeploymentTemplateData = (data: DeploymentTemplateDTO) => {
3234
const parsedDraftData = JSON.parse(data?.deploymentDraftData?.configData[0].draftMetadata.data || null)
@@ -827,3 +829,21 @@ export const getDefaultVersionAndPreviousDeploymentOptions = (data: TemplateList
827829
previousDeployments: [],
828830
},
829831
)
832+
833+
export const renderDiffViewNoDifferenceState = (
834+
lhsValue: string,
835+
rhsValue: string,
836+
): DiffViewerProps['codeFoldMessageRenderer'] =>
837+
lhsValue === rhsValue
838+
? () => (
839+
<GenericSectionErrorState
840+
useInfoIcon
841+
title="No diff in configurations"
842+
subTitle=""
843+
description=""
844+
buttonText="View values"
845+
// Click event is handled at the parent level
846+
reload={noop}
847+
/>
848+
)
849+
: null

0 commit comments

Comments
 (0)