|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import { Fragment, useEffect, useRef, useState } from 'react' |
| 17 | +import { Fragment, useEffect, useMemo, useRef, useState } from 'react' |
18 | 18 | import { useParams } from 'react-router'
|
19 | 19 | import Tippy from '@tippyjs/react'
|
20 | 20 | import { yamlComparatorBySortOrder } from '@Shared/Helpers'
|
@@ -66,30 +66,38 @@ const DeploymentHistoryDiffView = ({
|
66 | 66 | Object.keys(baseTemplateConfiguration?.codeEditorValue?.variableSnapshot || {}).length !== 0 ||
|
67 | 67 | Object.keys(currentConfiguration?.codeEditorValue?.variableSnapshot || {}).length !== 0
|
68 | 68 |
|
69 |
| - const editorValuesRHS = convertVariables |
70 |
| - ? baseTemplateConfiguration?.codeEditorValue?.resolvedValue |
71 |
| - : 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 |
72 | 91 |
|
73 |
| - const editorValuesLHS = convertVariables |
74 |
| - ? currentConfiguration?.codeEditorValue?.resolvedValue |
75 |
| - : currentConfiguration?.codeEditorValue?.value |
| 92 | + return YAMLStringify(JSON.parse(editorValue), { |
| 93 | + sortMapEntries: (a, b) => yamlComparatorBySortOrder(a, b, sortOrder), |
| 94 | + }) |
| 95 | + }, [convertVariables, currentConfiguration, sortOrder, isUnpublished]) |
76 | 96 |
|
77 | 97 | const renderDeploymentDiffViaCodeEditor = () => (
|
78 | 98 | <CodeEditor
|
79 |
| - value={ |
80 |
| - !baseTemplateConfiguration?.codeEditorValue?.value || isDeleteDraft |
81 |
| - ? '' |
82 |
| - : YAMLStringify(JSON.parse(editorValuesRHS), { |
83 |
| - sortMapEntries: (a, b) => yamlComparatorBySortOrder(a, b, sortOrder), |
84 |
| - }) |
85 |
| - } |
86 |
| - defaultValue={ |
87 |
| - !currentConfiguration?.codeEditorValue?.value || isUnpublished |
88 |
| - ? '' |
89 |
| - : YAMLStringify(JSON.parse(editorValuesLHS), { |
90 |
| - sortMapEntries: (a, b) => yamlComparatorBySortOrder(a, b, sortOrder), |
91 |
| - }) |
92 |
| - } |
| 99 | + value={editorValuesRHS} |
| 100 | + defaultValue={editorValuesLHS} |
93 | 101 | height={codeEditorHeight}
|
94 | 102 | diffView={previousConfigAvailable && true}
|
95 | 103 | readOnly
|
|
0 commit comments