-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* staying with jsondiff * routing setup * send compare against data to component after using new adapater method to return the version data. * functionality * fix issue on route transition not calling model hook * formatting * update version * changelog * glimmerize the json-editor component * catch up * passing tracked property from child to parent * pull out of jsonEditor * fix issue with message * icon * fix some issues with right selection * changes and convert to component * integration test * tests * fixes * cleanup * cleanup 2 * fixes * fix test by spread attributes * remove log * remove
- Loading branch information
1 parent
4339cfa
commit 720db8e
Showing
19 changed files
with
495 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui: Add version diff view for KV V2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* eslint-disable no-undef */ | ||
import Component from '@glimmer/component'; | ||
import { inject as service } from '@ember/service'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
/** | ||
* @module DiffVersionSelector | ||
* DiffVersionSelector component includes a toolbar and diff view between KV 2 versions. It uses the library jsondiffpatch. | ||
* | ||
* @example | ||
* ```js | ||
* <DiffVersionSelector @model={model}/> | ||
* ``` | ||
* @param {object} model - model that comes from secret-v2-version | ||
*/ | ||
|
||
export default class DiffVersionSelector extends Component { | ||
@tracked leftSideVersionDataSelected = null; | ||
@tracked leftSideVersionSelected = null; | ||
@tracked rightSideVersionDataSelected = null; | ||
@tracked rightSideVersionSelected = null; | ||
@tracked statesMatch = false; | ||
@tracked visualDiff = null; | ||
@service store; | ||
|
||
adapter = this.store.adapterFor('secret-v2-version'); | ||
|
||
constructor() { | ||
super(...arguments); | ||
this.createVisualDiff(); | ||
} | ||
|
||
get leftSideDataInit() { | ||
let string = `["${this.args.model.engineId}", "${this.args.model.id}", "${this.args.model.currentVersion}"]`; | ||
return this.adapter | ||
.querySecretDataByVersion(string) | ||
.then(response => response.data) | ||
.catch(() => null); | ||
} | ||
get rightSideDataInit() { | ||
let string = `["${this.args.model.engineId}", "${this.args.model.id}", "${this.rightSideVersionInit}"]`; | ||
return this.adapter | ||
.querySecretDataByVersion(string) | ||
.then(response => response.data) | ||
.catch(() => null); | ||
} | ||
get rightSideVersionInit() { | ||
// initial value of right side version is one less than the current version | ||
return this.args.model.currentVersion === 1 ? 0 : this.args.model.currentVersion - 1; | ||
} | ||
|
||
async createVisualDiff() { | ||
let diffpatcher = jsondiffpatch.create({}); | ||
let leftSideVersionData = this.leftSideVersionDataSelected || (await this.leftSideDataInit); | ||
let rightSideVersionData = this.rightSideVersionDataSelected || (await this.rightSideDataInit); | ||
let delta = diffpatcher.diff(rightSideVersionData, leftSideVersionData); | ||
if (delta === undefined) { | ||
this.statesMatch = true; | ||
this.visualDiff = JSON.stringify(leftSideVersionData, undefined, 2); // params: value, replacer (all properties included), space (white space and indentation, line break, etc.) | ||
} else { | ||
this.statesMatch = false; | ||
this.visualDiff = jsondiffpatch.formatters.html.format(delta, rightSideVersionData); | ||
} | ||
} | ||
|
||
@action | ||
async selectVersion(selectedVersion, actions, side) { | ||
let string = `["${this.args.model.engineId}", "${this.args.model.id}", "${selectedVersion}"]`; | ||
let secretData = await this.adapter.querySecretDataByVersion(string); | ||
if (side === 'left') { | ||
this.leftSideVersionDataSelected = secretData.data; | ||
this.leftSideVersionSelected = selectedVersion; | ||
} | ||
if (side === 'right') { | ||
this.rightSideVersionDataSelected = secretData.data; | ||
this.rightSideVersionSelected = selectedVersion; | ||
} | ||
await this.createVisualDiff(); | ||
// close dropdown menu. | ||
actions.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Controller from '@ember/controller'; | ||
import BackendCrumbMixin from 'vault/mixins/backend-crumb'; | ||
|
||
export default class DiffController extends Controller.extend(BackendCrumbMixin) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Route from '@ember/routing/route'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class diff extends Route { | ||
@service store; | ||
|
||
beforeModel() { | ||
let { backend } = this.paramsFor('vault.cluster.secrets.backend'); | ||
this.backend = backend; | ||
} | ||
|
||
model(params) { | ||
let { id } = params; | ||
return this.store.queryRecord('secret-v2', { | ||
backend: this.backend, | ||
id, | ||
}); | ||
} | ||
|
||
setupController(controller, model) { | ||
controller.set('backend', this.backend); // for backendCrumb | ||
controller.set('id', model.id); // for navigation on tabs | ||
controller.set('model', model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.visual-diff { | ||
background-color: black; | ||
|
||
pre { | ||
color: $ui-gray-010; | ||
} | ||
} | ||
|
||
.jsondiffpatch-deleted .jsondiffpatch-property-name, | ||
.jsondiffpatch-deleted pre, | ||
.jsondiffpatch-modified .jsondiffpatch-left-value pre, | ||
.jsondiffpatch-textdiff-deleted { | ||
background: $red-500; | ||
} | ||
.jsondiffpatch-added .jsondiffpatch-property-name, | ||
.jsondiffpatch-added .jsondiffpatch-value pre, | ||
.jsondiffpatch-modified .jsondiffpatch-right-value pre, | ||
.jsondiffpatch-textdiff-added { | ||
background: $green-500; | ||
} | ||
|
||
.jsondiffpatch-property-name { | ||
color: $ui-gray-300; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<Toolbar> | ||
<div class="version-diff-toolbar" data-test-version-diff-toolbar> | ||
{{!-- Left side version --}} | ||
<BasicDropdown | ||
@class="popup-menu" | ||
@horizontalPosition="auto-right" | ||
@verticalPosition="below" | ||
as |D| | ||
> | ||
<D.trigger | ||
data-test-popup-menu-trigger="left-version" | ||
@class={{concat "toolbar-link" (if D.isOpen " is-active")}} | ||
@tagName="button" | ||
> | ||
Version {{or this.leftSideVersionSelected this.args.model.currentVersion}} | ||
<Chevron @direction="down" @isButton={{true}} /> | ||
</D.trigger> | ||
<D.content @class="popup-menu-content"> | ||
<nav class="box menu"> | ||
<ul class="menu-list"> | ||
{{#each (reverse this.args.model.versions) as |leftSideSecretVersion|}} | ||
<li class="action" data-test-leftSide-version={{leftSideSecretVersion.version}}> | ||
<button | ||
class="link" | ||
{{on "click" (fn this.selectVersion leftSideSecretVersion.version D.actions "left")}} | ||
> | ||
Version {{leftSideSecretVersion.version}} | ||
{{#if (and (eq leftSideSecretVersion.version (or this.leftSideVersionSelected this.args.model.currentVersion)) (not leftSideSecretVersion.destroyed) (not leftSideSecretVersion.deleted))}} | ||
<Icon @glyph="check-circle-outline" class="has-text-success is-pulled-right" /> | ||
{{else if leftSideSecretVersion.destroyed}} | ||
<Icon @glyph="cancel-square-fill" class="has-text-danger is-pulled-right" /> | ||
{{else if leftSideSecretVersion.deleted}} | ||
<Icon @glyph="cancel-square-fill" class="has-text-grey is-pulled-right" /> | ||
{{/if}} | ||
</button> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</nav> | ||
</D.content> | ||
</BasicDropdown> | ||
{{!-- Right side version --}} | ||
<BasicDropdown | ||
@class="popup-menu" | ||
@horizontalPosition="right" | ||
@verticalPosition="below" | ||
as |D| | ||
> | ||
<D.trigger | ||
@class={{concat "toolbar-link" (if D.isOpen " is-active")}} | ||
@tagName="button" | ||
data-test-popup-menu-trigger="right-version" | ||
> | ||
Version {{or this.rightSideVersionSelected this.rightSideVersionInit}} | ||
<Chevron @direction="down" @isButton={{true}} /> | ||
</D.trigger> | ||
<D.content @class="popup-menu-content"> | ||
<nav class="box menu"> | ||
<ul class="menu-list"> | ||
{{#each (reverse this.args.model.versions) as |rightSideSecretVersion|}} | ||
<li class="action"> | ||
<button | ||
class="link" | ||
{{on "click" (fn this.selectVersion rightSideSecretVersion.version D.actions "right")}} | ||
data-test-rightSide-version={{rightSideSecretVersion.version}} | ||
> | ||
Version {{rightSideSecretVersion.version}} | ||
{{#if (and (eq rightSideSecretVersion.version (or this.rightSideVersionSelected this.rightSideVersionInit)) (not rightSideSecretVersion.destroyed) (not rightSideSecretVersion.deleted))}} | ||
<Icon @glyph="check-circle-outline" class="has-text-success is-pulled-right" /> | ||
{{else if rightSideSecretVersion.destroyed}} | ||
<Icon @glyph="cancel-square-fill" class="has-text-danger is-pulled-right" /> | ||
{{else if rightSideSecretVersion.deleted}} | ||
<Icon @glyph="cancel-square-fill" class="has-text-grey is-pulled-right" /> | ||
{{/if}} | ||
</button> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</nav> | ||
</D.content> | ||
</BasicDropdown> | ||
{{!-- Status --}} | ||
{{#if this.statesMatch}} | ||
<div class="diff-status"> | ||
<span>States match</span> | ||
<Icon @glyph="check-circle-fill" class="has-text-success" /> | ||
</div> | ||
{{/if}} | ||
</div> | ||
</Toolbar> | ||
|
||
<div class="form-section visual-diff"> | ||
<pre>{{{this.visualDiff}}}</pre> | ||
</div> |
Oops, something went wrong.