From ea5b1aed4ca3d69abddb899b135353c86edb7dc3 Mon Sep 17 00:00:00 2001 From: Victor Cabezas Date: Mon, 18 Apr 2022 10:45:53 +0200 Subject: [PATCH] Fix some visualization errors introduced in previous commits --- cli/template/src/__tests__/entities/utils.test.jsx | 4 ++-- cli/template/src/data/entities/utils.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/template/src/__tests__/entities/utils.test.jsx b/cli/template/src/__tests__/entities/utils.test.jsx index 822bcbd1..404bda54 100644 --- a/cli/template/src/__tests__/entities/utils.test.jsx +++ b/cli/template/src/__tests__/entities/utils.test.jsx @@ -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) }) diff --git a/cli/template/src/data/entities/utils.ts b/cli/template/src/data/entities/utils.ts index f0589ca7..4e7e6ed8 100644 --- a/cli/template/src/data/entities/utils.ts +++ b/cli/template/src/data/entities/utils.ts @@ -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( @@ -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) {