Skip to content

Commit

Permalink
clean up dev ui code
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Dec 4, 2023
1 parent 18ab50d commit 699f323
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 130 deletions.
44 changes: 8 additions & 36 deletions core/deployment/src/main/resources/dev-ui/qwc-aiservices.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { LitElement, html, css} from 'lit';
import { JsonRpc } from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import '@vaadin/text-field';
import '@vaadin/text-area';
import '@vaadin/form-layout';
import '@vaadin/progress-bar';
import '@vaadin/checkbox';
import { LitElement, html} from 'lit';
import '@vaadin/grid';
import 'qui-alert';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';

Expand All @@ -17,50 +8,31 @@ import {aiservices} from 'build-time-data';

export class QwcAiservices extends LitElement {

static styles = css`
.button {
cursor: pointer;
}
.clearIcon {
color: orange;
}
.message {
padding: 15px;
text-align: center;
margin-left: 20%;
margin-right: 20%;
border: 2px solid orange;
border-radius: 10px;
font-size: large;
}
`;

static properties = {
"_aiservices": {state: true},
"_message": {state: true}
}

connectedCallback() {
super.connectedCallback();
constructor() {
super();
this._aiservices = aiservices;
}

render() {
if (this._aiservices) {
return this._renderAiServiceTable();
} else {
return html`<span>Loading AI services...</span>`;
return html`<span>No AI services found</span>`;
}
}

_renderAiServiceTable() {
return html`
${this._message}
<vaadin-grid .items="${this._aiservices}" class="datatable" theme="no-border">
<vaadin-grid-column auto-width
<vaadin-grid .items="${this._aiservices}" theme="no-border">
<vaadin-grid-sort-column auto-width
path="clazz"
header="Name"
${columnBodyRenderer(this._nameRenderer, [])}>
</vaadin-grid-column>
</vaadin-grid-sort-column>
<vaadin-grid-column auto-width
header="Tools"
${columnBodyRenderer(this._toolsRenderer, [])}>
Expand Down
39 changes: 6 additions & 33 deletions core/deployment/src/main/resources/dev-ui/qwc-embedding-store.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { LitElement, html, css} from 'lit';
import { LitElement, html} from 'lit';
import { JsonRpc } from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import '@vaadin/text-field';
import '@vaadin/text-area';
import '@vaadin/form-layout';
import '@vaadin/progress-bar';
import '@vaadin/checkbox';
import '@vaadin/grid';
import 'qui-alert';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
Expand All @@ -17,33 +13,11 @@ export class QwcEmbeddingStore extends LitElement {

jsonRpc = new JsonRpc(this);

static styles = css`
.button {
cursor: pointer;
}
.clearIcon {
color: orange;
}
.message {
padding: 15px;
text-align: center;
margin-left: 20%;
margin-right: 20%;
border: 2px solid orange;
border-radius: 10px;
font-size: large;
}
`;

static properties = {
"_addEmbeddingConfirmation": {state: true},
"_relevantEmbeddingsOutput": {state: true}
}

connectedCallback() {
super.connectedCallback();
}

render() {
return html`
<h3>Add a new embedding</h3>
Expand Down Expand Up @@ -92,11 +66,11 @@ export class QwcEmbeddingStore extends LitElement {
this._relevantEmbeddingsOutput = '';
this.jsonRpc.findRelevant({text: text, limit: limit}).then(jsonRpcResponse => {
this._relevantEmbeddingsOutput = html`
<vaadin-grid id="relevant-embeddings" .items=${jsonRpcResponse.result} class="datatable">
<vaadin-grid-column path="embeddingId" header="ID" ${columnBodyRenderer(this._embeddingMatchIdRenderer, [])}></vaadin-grid-column>
<vaadin-grid-column path="score" header="Score" ${columnBodyRenderer(this._embeddingMatchScoreRenderer, [])}></vaadin-grid-column>
<vaadin-grid-column path="embedded" header="Text segment" ${columnBodyRenderer(this._embeddingMatchEmbeddedRenderer, [])}></vaadin-grid-column>
<vaadin-grid-column path="metadata" header="Metadata" ${columnBodyRenderer(this._embeddingMatchMetadataRenderer, [])}></vaadin-grid-column>
<vaadin-grid id="relevant-embeddings" .items=${jsonRpcResponse.result}>
<vaadin-grid-sort-column path="embeddingId" header="ID" ${columnBodyRenderer(this._embeddingMatchIdRenderer, [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="score" header="Score" ${columnBodyRenderer(this._embeddingMatchScoreRenderer, [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="embedded" header="Text segment" ${columnBodyRenderer(this._embeddingMatchEmbeddedRenderer, [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="metadata" header="Metadata" ${columnBodyRenderer(this._embeddingMatchMetadataRenderer, [])}></vaadin-grid-sort-column>
</vaadin-grid>
`;
});
Expand All @@ -115,7 +89,6 @@ export class QwcEmbeddingStore extends LitElement {
}

_embeddingMatchMetadataRenderer(match) {
// return html`${ match.metadata }`
if (match.metadata && match.metadata.length > 0) {
return html`<vaadin-vertical-layout>
${match.metadata.map((entry) =>
Expand Down
74 changes: 13 additions & 61 deletions core/deployment/src/main/resources/dev-ui/qwc-tools.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,46 @@
import { LitElement, html, css} from 'lit';
import { JsonRpc } from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import '@vaadin/text-field';
import '@vaadin/text-area';
import '@vaadin/form-layout';
import '@vaadin/progress-bar';
import '@vaadin/checkbox';
import { LitElement, html} from 'lit';
import '@vaadin/grid';
import 'qui-alert';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';

import {tools} from 'build-time-data';


export class QwcTools extends LitElement {

static styles = css`
.button {
cursor: pointer;
}
.clearIcon {
color: orange;
}
.message {
padding: 15px;
text-align: center;
margin-left: 20%;
margin-right: 20%;
border: 2px solid orange;
border-radius: 10px;
font-size: large;
}
`;

static properties = {
"_tools": {state: true},
}

connectedCallback() {
super.connectedCallback();
constructor() {
super();
this._tools = tools;
}

render() {
if (this._tools) {
return this._renderToolTable();
} else {
return html`<span>Loading tools...</span>`;
return html`<span>No tools found</span>`;
}
}

_renderToolTable() {
return html`
<vaadin-grid .items="${this._tools}" class="datatable" theme="no-border">
<vaadin-grid .items="${this._tools}" theme="no-border">
<vaadin-grid-sort-column auto-width
path="className"
header="Class name">
</vaadin-grid-sort-column>
<vaadin-grid-column auto-width
header="Class name"
${columnBodyRenderer(this._classNameRenderer, [])}>
path="name"
header="Tool name">
</vaadin-grid-column>
<vaadin-grid-column auto-width
header="Tool name"
${columnBodyRenderer(this._nameRenderer, [])}>
</vaadin-grid-column>
<vaadin-grid-column auto-width
header="Description"
${columnBodyRenderer(this._descriptionRenderer, [])}>
path="description"
header="Description">
</vaadin-grid-column>
</vaadin-grid>`;
}

_actionRenderer(tool) {
return html`
<vaadin-button theme="small" @click=${() => this._reset(ds)} class="button">
<vaadin-icon class="clearIcon" icon="font-awesome-solid:broom"></vaadin-icon> Reset
</vaadin-button>`;
}

_classNameRenderer(tool) {
return html`${tool.className}`;
}


_nameRenderer(tool) {
return html`${tool.name}`;
}

_descriptionRenderer(tool) {
return html`${tool.description}`;
}

}
customElements.define('qwc-tools', QwcTools);

0 comments on commit 699f323

Please sign in to comment.