Skip to content

Commit

Permalink
Handle missing values gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Apr 30, 2024
1 parent 6ba832f commit 9624035
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ui/src/components/transaction/transaction-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {map} from "lit/directives/map.js";
import {LitElement, TemplateResult} from "lit";
import {BuildLiveTransactionFromState, HttpTransaction} from "@/model/http_transaction";
import transactionViewComponentCss from "./transaction-view.css";
import {KVViewComponent} from "@pb33f/cowboy-components/components/kv-view/kv-view";
import {KVViewComponent} from "@pb33f/cowboy-components/components/kv-view/kv-view.js";
import sharedCss from "@/components/shared.css";
import {SlTab, SlTabGroup} from "@shoelace-style/shoelace";
import {
Expand Down
52 changes: 33 additions & 19 deletions ui/src/components/violation/violation-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,33 +114,47 @@ export class ViolationDetailsComponent extends LitElement {
violationDetails = html`
${map(this._data, (i) => {
const formatted = Prism.highlight(i.referenceSchema,
Prism.languages.json, 'yaml');
let schemaView: TemplateResult;
if (this.selectedViolationView === SchemaType.SCHEMA) {
const formattedCode = formatted
if (i.referenceSchema) {
const formatted = Prism.highlight(i.referenceSchema,
Prism.languages.json, 'yaml');
const formattedCode = formatted
.split('\n')
.map((line, num) => `<span class="${((num+1) == i.line) ?
'line-active' : ''}"><span class="line-num ${((num+1) == i.line) ?
'line-active' : ''}">${(num + 1).toString().padStart(4, ' ')}.</span> ${line}</span>`)
.map((line, num) => `<span class="${((num + 1) == i.line) ?
'line-active' : ''}"><span class="line-num ${((num + 1) == i.line) ?
'line-active' : ''}">${(num + 1).toString().padStart(4, ' ')}.</span> ${line}</span>`)
.join('\n');
schemaView = html`
<div class="schema-violation-object">
<pre class="line-numbers"><code>${unsafeHTML(formattedCode)}</code></pre>
</div>`
} else {
schemaView = html`
<div class="schema-violation-object">
<pre><code>Schema unavailable</code></pre>
</div>`
schemaView = html`
<div class="schema-violation-object">
<pre class="line-numbers"><code>${unsafeHTML(formattedCode)}</code></pre>
</div>`
}
}
if (this.selectedViolationView === SchemaType.OBJECT) {
schemaView = html`
<div class="schema-violation-object">
<pre><code>${unsafeHTML(Prism.highlight(i.referenceObject,
Prism.languages.json, 'json'))}</code></pre>
</div>`
if (i.referenceObject) {
schemaView = html`
<div class="schema-violation-object">
<pre><code>${unsafeHTML(Prism.highlight(i.referenceObject,
Prism.languages.json, 'json'))}</code></pre>
</div>`
} else {
schemaView = html`
<div class="schema-violation-object">
<pre><code>Object unavailable</code></pre>
</div>`
}
}
if (this.selectedViolationView === SchemaType.EXAMPLE) {
// schemaView = html`
// <div class="schema-violation-object">
Expand Down

0 comments on commit 9624035

Please sign in to comment.