Skip to content

Commit

Permalink
Fix some visualization errors introduced in previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Cabezas committed Apr 18, 2022
1 parent 25ee4b0 commit ea5b1ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cli/template/src/__tests__/entities/utils.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ describe('TerraformPlanResourceChangeField', () => {
expect(sensitiveBool.type).toBe('boolean')
expect(sensitiveBool.sensitive).toBe(true)

expect(array.value).toStrictEqual(['aaa', '(sensitive)', '(null)', 42])
expect(array.value).toBe(JSON.stringify(['aaa', '(sensitive)', '(null)', 42], null, 4))
expect(array.type).toBe('array')
expect(array.sensitive).toBe(true)

expect(hash.value).toStrictEqual({'a': 'aaa', 'b': '(sensitive)', 'c': '(null)', 'd': 42, 'e': ['(sensitive)', 'a']})
expect(hash.value).toBe(JSON.stringify({'a': 'aaa', 'b': '(sensitive)', 'c': '(null)', 'd': 42, 'e': ['(sensitive)', 'a']}, null, 4))
expect(hash.type).toBe('object')
expect(hash.sensitive).toBe(true)
})
Expand Down
10 changes: 5 additions & 5 deletions cli/template/src/data/entities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export const TerraformPlanResourceChangeField = {
value,
sensitive || {},
)
if (data.type != 'string' && !sensitive && value !== null) {
data.value = JSON.stringify(data.value, null, 4)
}
if (value === null) {
data.type = 'null'
} else if (Array.isArray(value)){
data.type = 'array'
}
if (['number', 'boolean', 'array', 'object'].includes(data.type) && data.value != '(sensitive)') {
data.value = JSON.stringify(data.value, null, 4)
}
return data
},
renderValue(
Expand Down Expand Up @@ -158,9 +158,9 @@ export const TerraformPlanResourceChangeChange = {
// Compute structured diff for better readibility
for (const field of Object.keys(diff)) {
const diffChange = diff[field]
const before = diffChange.src.value ? diffChange.src.value : ''
const before = diffChange.src.value && !diffChange.src.sensitive ? diffChange.src.value : ''
const beforeLines = (before.match(/\n/g) || '').length + 1
const after = diffChange.dst.value ? diffChange.dst.value : ''
const after = diffChange.dst.value && !diffChange.dst.sensitive ? diffChange.dst.value : ''
const afterLines = (after.match(/\n/g) || '').length + 1

if (beforeLines > 4 || afterLines > 4) {
Expand Down

0 comments on commit ea5b1ae

Please sign in to comment.