Skip to content

Commit 472f45a

Browse files
committed
feat: add support for null state in diff viewer
1 parent 5b7bac3 commit 472f45a

File tree

8 files changed

+80
-46
lines changed

8 files changed

+80
-46
lines changed

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

Lines changed: 24 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'
@@ -36,6 +38,7 @@ const DeploymentHistoryDiffView = ({
3638
rootClassName,
3739
sortingConfig,
3840
codeEditorKey,
41+
diffState,
3942
}: DeploymentTemplateHistoryType) => {
4043
const { historyComponent, historyComponentName } = useParams<DeploymentHistoryParamsType>()
4144
const { sortBy, sortOrder } = sortingConfig ?? { sortBy: '', sortOrder: null }
@@ -85,20 +88,26 @@ const DeploymentHistoryDiffView = ({
8588
})
8689
}, [convertVariables, currentConfiguration, sortOrder, isUnpublished])
8790

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-
)
91+
const renderDeploymentDiffViaCodeEditor = () =>
92+
previousConfigAvailable ? (
93+
<DiffViewer
94+
oldValue={editorValuesLHS}
95+
newValue={editorValuesRHS}
96+
codeFoldMessageRenderer={renderDiffViewNoDifferenceState(diffState)}
97+
/>
98+
) : (
99+
<CodeEditor
100+
key={codeEditorKey}
101+
value={editorValuesRHS}
102+
defaultValue={editorValuesLHS}
103+
adjustEditorHeightToContent
104+
disableSearch
105+
readOnly
106+
noParsing
107+
mode={MODES.YAML}
108+
theme={getTheme()}
109+
/>
110+
)
102111

103112
const handleShowVariablesClick = () => {
104113
setConvertVariables(!convertVariables)
@@ -176,7 +185,7 @@ const DeploymentHistoryDiffView = ({
176185
</div>
177186

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

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
import { DeploymentStageType } from '../../constants'
3333
import { AggregationKeys, GitTriggers, Node, NodeType, ResourceKindType, ResourceVersionType } from '../../types'
3434
import { TERMINAL_STATUS_MAP } from './constants'
35+
import { DeploymentConfigDiffState } from '../DeploymentConfigDiff'
3536

3637
export enum HistoryComponentType {
3738
CI = 'CI',
@@ -493,6 +494,7 @@ export interface DeploymentTemplateHistoryType {
493494
sortBy: string
494495
sortOrder: SortingOrder
495496
}
497+
diffState: DeploymentConfigDiffState
496498
}
497499
export interface DeploymentHistoryDetailRes extends ResponseType {
498500
result?: DeploymentHistoryDetail

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
AppEnvDeploymentConfigListParams,
1313
DiffHeadingDataType,
1414
prepareHistoryData,
15+
GenericSectionErrorState,
1516
} from '@Shared/Components'
1617
import { deepEqual } from '@Common/Helper'
1718

@@ -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,17 @@ export const getDefaultVersionAndPreviousDeploymentOptions = (data: TemplateList
827829
previousDeployments: [],
828830
},
829831
)
832+
833+
export const renderDiffViewNoDifferenceState = (
834+
diffState: DeploymentConfigDiffState | null,
835+
): DiffViewerProps['codeFoldMessageRenderer'] =>
836+
diffState !== DeploymentConfigDiffState.NO_DIFF
837+
? () => (
838+
<GenericSectionErrorState
839+
useInfoIcon
840+
title="There seems no difference in the compared values"
841+
subTitle="Click here to view the values"
842+
description=""
843+
/>
844+
)
845+
: null

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiffMain.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { ReactComponent as ICSortArrowDown } from '@Icons/ic-sort-arrow-down.svg
55
import { ReactComponent as ICSort } from '@Icons/ic-arrow-up-down.svg'
66
import { ReactComponent as ICViewVariableToggle } from '@Icons/ic-view-variable-toggle.svg'
77
import { Progressing } from '@Common/Progressing'
8-
import { CodeEditor } from '@Common/CodeEditor'
9-
import { MODES, SortingOrder } from '@Common/Constants'
8+
import { SortingOrder } from '@Common/Constants'
109
import ErrorScreenManager from '@Common/ErrorScreenManager'
1110
import Toggle from '@Common/Toggle/Toggle'
1211
import { ComponentSizeType } from '@Shared/constants'
12+
import { DiffViewer } from '@Shared/Components/DiffViewer'
1313

1414
import { Button, ButtonStyleType, ButtonVariantType } from '../Button'
1515
import { SelectPicker } from '../SelectPicker'
@@ -21,6 +21,7 @@ import {
2121
DeploymentConfigDiffState,
2222
DeploymentConfigDiffAccordionProps,
2323
} from './DeploymentConfigDiff.types'
24+
import { renderDiffViewNoDifferenceState } from './DeploymentConfigDiff.utils'
2425

2526
export const DeploymentConfigDiffMain = ({
2627
isLoading,
@@ -190,23 +191,13 @@ export const DeploymentConfigDiffMain = ({
190191
hideDiffState={hideDiffState}
191192
>
192193
{singleView ? (
193-
<>
194-
<div className="bcn-1 deployment-config-diff__main-content__heading dc__border-top">
195-
<div className="px-12 py-6 dc__border-right">{primaryHeading}</div>
196-
<div className="px-12 py-6">{secondaryHeading}</div>
197-
</div>
198-
<CodeEditor
199-
key={`${sortingConfig?.sortBy}-${sortingConfig?.sortOrder}-${scopeVariablesConfig?.convertVariables}`}
200-
diffView
201-
defaultValue={primaryList.codeEditorValue.value}
202-
value={secondaryList.codeEditorValue.value}
203-
mode={MODES.YAML}
204-
disableSearch
205-
adjustEditorHeightToContent
206-
noParsing
207-
readOnly
208-
/>
209-
</>
194+
<DiffViewer
195+
oldValue={primaryList.codeEditorValue.value}
196+
newValue={secondaryList.codeEditorValue.value}
197+
leftTitle={primaryHeading}
198+
rightTitle={secondaryHeading}
199+
codeFoldMessageRenderer={renderDiffViewNoDifferenceState(diffState)}
200+
/>
210201
) : (
211202
<div className="p-16">
212203
{primaryHeading && secondaryHeading && (
@@ -222,6 +213,7 @@ export const DeploymentConfigDiffMain = ({
222213
previousConfigAvailable
223214
rootClassName={`${primaryHeading && secondaryHeading ? 'dc__no-top-radius dc__no-top-border' : ''}`}
224215
sortingConfig={sortingConfig}
216+
diffState={diffState}
225217
/>
226218
</div>
227219
)}

src/Shared/Components/DiffViewer/DiffViewer.component.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer-continued'
22
import { diffViewerStyles } from './constants'
3-
import { DiffViewerProps } from './types'
3+
import { DiffViewerProps, DiffViewTitleWrapperProps } from './types'
44

5-
const DiffViewer = ({ oldValue, newValue, leftTitle, rightTitle }: DiffViewerProps) => (
5+
const DiffViewTitleWrapper = ({ title }: DiffViewTitleWrapperProps) => <div>{title}</div>
6+
7+
const DiffViewer = ({ oldValue, newValue, leftTitle, rightTitle, ...props }: DiffViewerProps) => (
68
<ReactDiffViewer
9+
{...props}
710
splitView
811
oldValue={oldValue}
912
newValue={newValue}
1013
useDarkTheme={false}
11-
leftTitle={leftTitle}
12-
rightTitle={rightTitle}
14+
leftTitle={leftTitle ? <DiffViewTitleWrapper title={leftTitle} /> : null}
15+
rightTitle={rightTitle ? <DiffViewTitleWrapper title={rightTitle} /> : null}
1316
compareMethod={DiffMethod.WORDS}
1417
styles={diffViewerStyles}
1518
/>

src/Shared/Components/DiffViewer/constants.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export const diffViewerStyles: ReactDiffViewerProps['styles'] = {
3737
lineHeight: '20px',
3838

3939
pre: {
40+
fontSize: '13px',
4041
lineHeight: '20px',
4142
fontFamily: 'Inconsolata, monospace',
43+
wordBreak: 'break-word',
4244
},
4345
},
4446
marker: {
@@ -49,6 +51,8 @@ export const diffViewerStyles: ReactDiffViewerProps['styles'] = {
4951
gutter: {
5052
padding: `0 6px`,
5153
minWidth: '36px',
54+
// Cursor would be default for all cases in gutter till we don't support highlighting
55+
cursor: 'default',
5256

5357
pre: {
5458
opacity: 1,
@@ -59,9 +63,11 @@ export const diffViewerStyles: ReactDiffViewerProps['styles'] = {
5963
},
6064
wordAdded: {
6165
paddingInline: '2px',
66+
lineHeight: '16px',
6267
},
6368
wordRemoved: {
6469
paddingInline: '2px',
70+
lineHeight: '16px',
6571
},
6672
codeFold: {
6773
fontSize: '13px',
@@ -73,6 +79,11 @@ export const diffViewerStyles: ReactDiffViewerProps['styles'] = {
7379
textDecoration: 'none !important',
7480
},
7581
},
82+
codeFoldGutter: {
83+
'+ td': {
84+
width: '12px',
85+
},
86+
},
7687
titleBlock: {
7788
padding: '8px 12px',
7889
fontSize: '12px',
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
import { ReactNode } from 'react'
12
import { ReactDiffViewerProps } from 'react-diff-viewer-continued'
23

34
export interface DiffViewerProps
4-
extends Pick<ReactDiffViewerProps, 'oldValue' | 'newValue' | 'leftTitle' | 'rightTitle'> {}
5+
extends Pick<ReactDiffViewerProps, 'oldValue' | 'newValue' | 'codeFoldMessageRenderer'> {
6+
leftTitle?: ReactDiffViewerProps['leftTitle'] | ReactNode
7+
rightTitle?: ReactDiffViewerProps['rightTitle'] | ReactNode
8+
}
9+
10+
export interface DiffViewTitleWrapperProps {
11+
title: DiffViewerProps['leftTitle']
12+
}

0 commit comments

Comments
 (0)