Skip to content

Commit

Permalink
Add visualization for action reason and replace paths (forces replace…
Browse files Browse the repository at this point in the history
…ment)
  • Loading branch information
Victor Cabezas committed Apr 21, 2022
1 parent ea5b1ae commit 4851bc0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.
17 changes: 10 additions & 7 deletions cli/template/src/__tests__/entities/utils.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const diffBase = {
},
after_unknown: {
fff: {}
}
},
replace_paths: [
'eee'
]
}

describe('TerraformPlanResourceChangeFieldDiff', () => {
Expand Down Expand Up @@ -185,12 +188,12 @@ describe('TerraformPlanResourceChangeChange', () => {
it('getDiff', () => {
const diff = Entities.Utils.TerraformPlanResourceChangeChange.getDiff(diffBase)

expect(diff.aaa).toStrictEqual({src: {value: 'aaa', type: 'string', sensitive: false}, dst: {value: 'aaa', type: 'string', sensitive: false}})
expect(diff.bbb).toStrictEqual({src: {value: '(sensitive)', type: 'string', sensitive: true}, dst: {value: '(sensitive)', type: 'string', sensitive: true}})
expect(diff.ccc).toStrictEqual({src: {value: 'ccc', type: 'string', sensitive: false}, dst: {value: 'eee', type: 'string', sensitive: false}})
expect(diff.ddd).toStrictEqual({src: {value: '(sensitive)', type: 'string', sensitive: true}, dst: {value: '(sensitive)', type: 'string', sensitive: true}})
expect(diff.eee).toStrictEqual({src: {}, dst: {value: 'zzz', sensitive: false, type: 'string'}})
expect(diff.fff).toStrictEqual({src: {}, dst: {value: '(known after apply)', unknown_after: true}})
expect(diff.aaa).toStrictEqual({forces_replacement: false, src: {value: 'aaa', type: 'string', sensitive: false}, dst: {value: 'aaa', type: 'string', sensitive: false}})
expect(diff.bbb).toStrictEqual({forces_replacement: false, src: {value: '(sensitive)', type: 'string', sensitive: true}, dst: {value: '(sensitive)', type: 'string', sensitive: true}})
expect(diff.ccc).toStrictEqual({forces_replacement: false, src: {value: 'ccc', type: 'string', sensitive: false}, dst: {value: 'eee', type: 'string', sensitive: false}})
expect(diff.ddd).toStrictEqual({forces_replacement: false, src: {value: '(sensitive)', type: 'string', sensitive: true}, dst: {value: '(sensitive)', type: 'string', sensitive: true}})
expect(diff.eee).toStrictEqual({forces_replacement: true, src: {}, dst: {value: 'zzz', sensitive: false, type: 'string'}})
expect(diff.fff).toStrictEqual({forces_replacement: false, src: {}, dst: {value: '(known after apply)', unknown_after: true}})
expect(diff.multiline.src).toStrictEqual({value: '[\n 1,\n 2,\n 3,\n 4,\n 5\n]', type: 'string', sensitive: false})
expect(diff.multiline.dst).toStrictEqual({value: '[\n 5,\n 4,\n 3,\n 2,\n 1\n]', type: 'string', sensitive: false})
expect(diff.multiline.diff).toBeTruthy()
Expand Down
5 changes: 4 additions & 1 deletion cli/template/src/__tests__/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,10 @@
],
"weighted_routing_policy": []
},
"after_sensitive": false
"after_sensitive": false,
"replace_paths": [
"records"
]
},
"action_reason": "delete_because_each_key"
},
Expand Down
36 changes: 29 additions & 7 deletions cli/template/src/components/focused-view/focused-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styles from '@app/components/focused-view/focused-view.module.css'
import React, { useState } from 'react';
import capitalize from 'lodash/capitalize';
import { Entities } from '@app/data'
import { BsLink45Deg, BsCheckCircle, BsSlashCircle, BsHash } from 'react-icons/bs'
import { BsFillInfoSquareFill, BsLink45Deg, BsCheckCircle, BsSlashCircle, BsHash } from 'react-icons/bs'
import { RiBracesLine, RiBracketsLine } from "react-icons/ri";
import { FaEquals, FaChevronRight } from 'react-icons/fa'

Expand All @@ -14,6 +14,7 @@ import Col from 'react-bootstrap/Col'
import ToggleButton from 'react-bootstrap/ToggleButton'
import OverlayTrigger from 'react-bootstrap/OverlayTrigger'
import Tooltip from 'react-bootstrap/Tooltip'
import Button from 'react-bootstrap/Button'

interface Props {
resource?: Entities.TerraformPlanResourceChange
Expand All @@ -33,6 +34,7 @@ export const C = (props: Props) => {
const diff = Entities.Utils.TerraformPlanResourceChangeChange.getDiff(resource.change)
const actionAlias = Entities.Utils.TerraformPlanResourceChangeChange.getActionAlias(resource.change)
const unchangedCount = Entities.Utils.TerraformPlanResourceChangeChangeDiff.getUnchangedFields(diff)
const reasonTooltip = resource.action_reason ? resource.action_reason.replaceAll('_', ' ') : null

return (
<Container fluid className={cx(styles.container, "py-2")}>
Expand All @@ -42,10 +44,28 @@ export const C = (props: Props) => {
</Col>
<Col>
<Row className="d-flex align-items-center">
<Col md={{ span: 2, offset: 2 }}>
<Actions actions={resource.change.actions} />
<Col md={{ span: 5, offset: 1 }}>
<Row className="d-flex align-items-center">
{ resource.action_reason ?
(
<Col md={{ span: 2 }}>
<OverlayTrigger
placement="right"
overlay={<Tooltip className="text-capitalize">{reasonTooltip}</Tooltip>}
>
<Button variant="outline-light" size="sm">
<BsFillInfoSquareFill title={resource.action_reason}/>
</Button>
</OverlayTrigger>
</Col>
) : null
}
<Col md={{ span: 10, offset: resource.action_reason ? 0 : 2 }}>
<Actions actions={resource.change.actions} />
</Col>
</Row>
</Col>
<Col md={{ span: 6, offset: 2 }}>
<Col md={{ span: 6 }}>
<UnchangedToggle toggleValue={showUnchanged} toggleFn={setShowUnchanged} count={Object.keys(unchangedCount).length}/>
</Col>
</Row>
Expand Down Expand Up @@ -79,7 +99,7 @@ const Actions = (props: ActionsProps) => {
)

if (i !== actions.length - 1) {
actionElems.push(<span key={2 * i + 1}> then </span>)
actionElems.push(<span key={2 * i + 1}>&nbsp;then&nbsp;</span>)
}
}

Expand Down Expand Up @@ -162,12 +182,14 @@ const ChangedField = (props: ChangedFieldProps) => {
<UnifiedDiffView changes={changes.diff} /> :
<ColumsFieldView changes={changes} actionAlias={actionAlias} />

const fieldTitle = changes.forces_replacement ? `${field} (Forces replacement)`: field

return (
<Row className={cx(styles.row, {'d-none': !showRow})}>
<Col md={2}>
<div title={field}>
<div title={fieldTitle}>
<Row className="align-items-center d-flex">
<Col md={{span: 10}} className="text-truncate">
<Col md={{span: 10}} className={ cx("text-truncate", {[styles.colorRed]: changes.forces_replacement}) }>
{fieldType} <strong>{field}</strong>
</Col>
<Col md={{span: 2}} >
Expand Down
3 changes: 3 additions & 0 deletions cli/template/src/data/entities/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface TerraformPlan {
export interface TerraformPlanResourceChange {
address: string
module_address?: string
action_reason?: string
type: string
name: string
change: TerraformPlanResourceChangeChange
Expand All @@ -42,6 +43,7 @@ export interface TerraformPlanResourceChangeChange {
after: { [key: string]: unknown } | null
after_sensitive: { [key: string]: unknown } | null
after_unknown: { [key: string]: unknown }
replace_paths?: string[]
}

export enum TerraformPlanResourceChangeChangeAction {
Expand Down Expand Up @@ -71,6 +73,7 @@ export interface TerraformPlanResourceChangeField {
export interface TerraformPlanResourceChangeFieldDiff {
src: TerraformPlanResourceChangeField
dst: TerraformPlanResourceChangeField
forces_replacement: boolean
diff?: Diff.ParsedDiff
}

Expand Down
9 changes: 9 additions & 0 deletions cli/template/src/data/entities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const TerraformPlanResourceChangeChange = {
diff[field] = {
src: {} as Entities.TerraformPlanResourceChangeField,
dst: {} as Entities.TerraformPlanResourceChangeField,
forces_replacement: false,
}
}

Expand All @@ -134,6 +135,7 @@ export const TerraformPlanResourceChangeChange = {
diff[field] = {
src: {} as Entities.TerraformPlanResourceChangeField,
dst: {} as Entities.TerraformPlanResourceChangeField,
forces_replacement: false,
}
}
diff[field].dst = TerraformPlanResourceChangeField.setValueType(
Expand All @@ -144,11 +146,18 @@ export const TerraformPlanResourceChangeChange = {
}
}

if (change.replace_paths) {
for (const field of change.replace_paths) {
diff[field].forces_replacement = true
}
}

for (const field of Object.keys(change.after_unknown)) {
if (!diff[field]) {
diff[field] = {
src: {} as Entities.TerraformPlanResourceChangeField,
dst: {} as Entities.TerraformPlanResourceChangeField,
forces_replacement: false,
}
}
diff[field].dst.unknown_after = true
Expand Down

0 comments on commit 4851bc0

Please sign in to comment.