Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: New JSON viewer #4541

Merged
merged 5 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions ui/app/components/json-viewer.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { run } from '@ember/runloop';
import { copy } from '@ember/object/internals';
import JSONFormatter from 'json-formatter-js';

export default Component.extend({
classNames: ['json-viewer'],

json: null,
expandDepth: Infinity,

formatter: computed('json', 'expandDepth', function() {
return new JSONFormatter(copy(this.get('json'), true), this.get('expandDepth'), {
theme: 'nomad',
});
jsonStr: computed('json', function() {
return JSON.stringify(this.get('json'), null, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ that JSON makes pretty-printing so easy - in Vault, we have this as a template helper because we have some places we render object values in the UI that aren't in a code mirror instance (though thinking about it now, maybe they should be 🤔 ).

}),

didReceiveAttrs() {
const json = this.get('json');
if (!json) {
return;
}

run.scheduleOnce('afterRender', this, embedViewer);
},
});

function embedViewer() {
this.$()
.empty()
.append(this.get('formatter').render());
}
2 changes: 1 addition & 1 deletion ui/app/styles/components.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './components/accordion';
@import './components/badge';
@import './components/boxed-section';
@import './components/codemirror';
@import './components/cli-window';
@import './components/dropdown';
@import './components/ember-power-select';
Expand All @@ -10,7 +11,6 @@
@import './components/gutter-toggle';
@import './components/inline-definitions';
@import './components/job-diff';
@import './components/json-viewer';
@import './components/loading-spinner';
@import './components/metrics';
@import './components/node-status-light';
Expand Down
2 changes: 1 addition & 1 deletion ui/app/styles/components/boxed-section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}

&.is-dark {
background: darken($dark, 5%);
background: $dark-2;
border-color: lighten($dark, 30%);
color: $white;
}
Expand Down
127 changes: 127 additions & 0 deletions ui/app/styles/components/codemirror.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
$dark-bright: lighten($dark, 15%);

.CodeMirror {
height: auto;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work by itself? I remember reading something that you'd have to also pass bottom margin Infinity in the code mirror instantiation if you wanted it to auto-size (just assuming you wanted auto-size from this though).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for this context because job definitions always have a value. I ran into the problem I think you are talking about with new job. The empty editor is still only one line tall. I'll look into the bottom margin Infinity trick.

}

.cm-s-hashi,
.cm-s-hashi-read-only {
&.CodeMirror {
background-color: $dark-3;
color: $grey-blue;
border: none;
font-family: $family-monospace;
-webkit-font-smoothing: auto;
line-height: 1.4;
}

.CodeMirror-gutters {
background-color: $dark-2;
border: none;
}

.CodeMirror-cursor {
border-left: solid thin $white-ter;
}

.CodeMirror-linenumber {
color: $dark-bright;
}

&.CodeMirror-focused div.CodeMirror-selected {
background: rgba(255, 255, 255, 0.1);
}

.CodeMirror-line::selection,
.CodeMirror-line > span::selection,
.CodeMirror-line > span > span::selection {
background: rgba(255, 255, 255, 0.1);
}

span.cm-comment {
color: $grey-light;
}

span.cm-string,
span.cm-string-2 {
color: $nomad-green;
}

span.cm-number {
color: $serf-red;
}

span.cm-variable {
color: $packer-blue;
}

span.cm-variable-2 {
color: $packer-blue;
}

span.cm-def {
color: $nomad-green;
}

span.cm-operator {
color: $grey;
}
span.cm-keyword {
color: $yellow;
}

span.cm-atom {
color: $terraform-purple-bright;
}

span.cm-meta {
color: $nomad-green;
}

span.cm-tag {
color: $nomad-green;
}

span.cm-attribute {
color: $consul-pink;
}

span.cm-qualifier {
color: $consul-pink;
}

span.cm-property {
color: $nomad-green;
}

span.cm-variable-3 {
color: $consul-pink;
}

span.cm-builtin {
color: $consul-pink;
}

.CodeMirror-activeline-background {
background: $black-ter;
}

.CodeMirror-matchingbracket {
text-decoration: underline;
color: $white;
}
}

.cm-s-auto-height.CodeMirror {
height: auto;
}

.cm-s-hashi-read-only {
&.CodeMirror {
background-color: $dark-2;
}

.CodeMirror-gutters {
background-color: $dark-2;
}
}
146 changes: 0 additions & 146 deletions ui/app/styles/components/json-viewer.scss

This file was deleted.

2 changes: 2 additions & 0 deletions ui/app/styles/core/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $warning-invert: $white;
$danger: $red;
$info: $blue;
$dark: #234;
$dark-2: darken($dark, 5%);
$dark-3: darken($dark, 10%);

$radius: 2px;

Expand Down
3 changes: 3 additions & 0 deletions ui/app/styles/utils/product-colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $consul-pink-dark: #c62a71;
$packer-blue: #1daeff;
$packer-blue-dark: #1d94dd;

$terraform-purple-bright: #807dea;
$terraform-purple: #5c4ee5;
$terraform-purple-dark: #4040b2;

Expand All @@ -13,3 +14,5 @@ $vagrant-blue-dark: #104eb2;
$nomad-green: #25ba81;
$nomad-green-dark: #1d9467;
$nomad-green-darker: #16704d;

$serf-red: #dd4e58;
16 changes: 0 additions & 16 deletions ui/app/templates/components/freestyle/sg-json-viewer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,3 @@
</div>
</div>
{{/freestyle-usage}}

{{#freestyle-collection defaultKey=0 as |collection|}}
{{#each (array 0 1 2 3 4 5) as |depth|}}
{{#collection.variant key=depth}}
{{#freestyle-usage
(concat "json-viewer-truncated-" depth)
title=(concat "JSON Viewer Expand Depth " depth)}}
<div class="boxed-section">
<div class="boxed-section-body is-dark">
{{json-viewer json=jsonLarge expandDepth=depth}}
</div>
</div>
{{/freestyle-usage}}
{{/collection.variant}}
{{/each}}
{{/freestyle-collection}}
9 changes: 9 additions & 0 deletions ui/app/templates/components/json-viewer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ivy-codemirror
value=jsonStr
options=(hash
mode="javascript"
theme="hashi-read-only"
tabSize=2
lineNumbers=true
readOnly=true
)}}
2 changes: 1 addition & 1 deletion ui/app/templates/jobs/job/definition.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{partial "jobs/job/subnav"}}
<section class="section">
<div class="boxed-section">
<div class="boxed-section-body is-dark">
<div class="boxed-section-body is-full-bleed">
{{json-viewer data-test-definition-view json=model.definition}}
</div>
</div>
Expand Down
Loading