mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Pipeline: Add LLM and mocked user generation to the pipeline (#230)
This commit is contained in:
147
tooling/pipeline-results-viewer/src/main.ts
Normal file
147
tooling/pipeline-results-viewer/src/main.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
import initSqlJs, { type Database, type SqlValue } from "sql.js";
|
||||
import sqlWasmUrl from "sql.js/dist/sql-wasm.wasm?url";
|
||||
import "./style.scss";
|
||||
|
||||
const DB_URL = "/biergarten.sqlite";
|
||||
|
||||
const tabs = document.querySelectorAll<HTMLButtonElement>("[role='tab']");
|
||||
const panels = document.querySelectorAll<HTMLDivElement>("[role='tabpanel']");
|
||||
|
||||
const tableSelect = document.querySelector<HTMLSelectElement>("#table-select")!;
|
||||
const tableContainer =
|
||||
document.querySelector<HTMLDivElement>("#table-container")!;
|
||||
const status = document.querySelector<HTMLParagraphElement>("#status")!;
|
||||
|
||||
const queryInput = document.querySelector<HTMLTextAreaElement>("#query-input")!;
|
||||
const queryRun = document.querySelector<HTMLButtonElement>("#query-run")!;
|
||||
const queryStatus = document.querySelector<HTMLParagraphElement>("#query-status")!;
|
||||
const queryContainer =
|
||||
document.querySelector<HTMLDivElement>("#query-container")!;
|
||||
|
||||
for (const tab of tabs) {
|
||||
tab.addEventListener("click", () => {
|
||||
for (const otherTab of tabs) {
|
||||
const isActive = otherTab === tab;
|
||||
otherTab.classList.toggle("is-active", isActive);
|
||||
otherTab.setAttribute("aria-selected", String(isActive));
|
||||
}
|
||||
for (const panel of panels) {
|
||||
panel.hidden = panel.id !== tab.getAttribute("aria-controls");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const renderResultTable = (
|
||||
container: HTMLDivElement,
|
||||
columns: string[],
|
||||
values: SqlValue[][],
|
||||
) => {
|
||||
const table = document.createElement("table");
|
||||
|
||||
const head = table.createTHead().insertRow();
|
||||
for (const column of columns) {
|
||||
const th = document.createElement("th");
|
||||
th.textContent = column;
|
||||
head.append(th);
|
||||
}
|
||||
|
||||
const body = table.createTBody();
|
||||
for (const row of values) {
|
||||
const tr = body.insertRow();
|
||||
for (const cell of row) {
|
||||
const td = document.createElement("td");
|
||||
td.textContent = String(cell ?? "");
|
||||
tr.append(td);
|
||||
}
|
||||
}
|
||||
|
||||
container.append(table);
|
||||
};
|
||||
|
||||
const renderTable = (db: Database, name: string) => {
|
||||
const result = db.exec(`SELECT * FROM "${name}"`);
|
||||
tableContainer.replaceChildren();
|
||||
|
||||
if (result.length === 0) {
|
||||
tableContainer.append(
|
||||
Object.assign(document.createElement("p"), { textContent: "No rows." }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const { columns, values } = result[0];
|
||||
renderResultTable(tableContainer, columns, values);
|
||||
};
|
||||
|
||||
const runQuery = (db: Database) => {
|
||||
const sql = queryInput.value.trim();
|
||||
queryContainer.replaceChildren();
|
||||
|
||||
if (!sql) {
|
||||
queryStatus.textContent = "Enter a query to run.";
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const results = db.exec(sql);
|
||||
|
||||
if (results.length === 0) {
|
||||
queryStatus.textContent = "Query executed. No rows returned.";
|
||||
return;
|
||||
}
|
||||
|
||||
const { columns, values } = results[results.length - 1];
|
||||
renderResultTable(queryContainer, columns, values);
|
||||
queryStatus.textContent = `${values.length} row${values.length === 1 ? "" : "s"} returned.`;
|
||||
} catch (error) {
|
||||
queryStatus.textContent = `Error: ${error instanceof Error ? error.message : String(error)}`;
|
||||
}
|
||||
};
|
||||
|
||||
async function main(): Promise<void> {
|
||||
status.textContent = "Loading database...";
|
||||
|
||||
const sqlJs = await initSqlJs({ locateFile: () => sqlWasmUrl });
|
||||
const response = await fetch(DB_URL);
|
||||
const buffer = await response.arrayBuffer();
|
||||
const db = new sqlJs.Database(new Uint8Array(buffer));
|
||||
|
||||
const tables =
|
||||
db
|
||||
.exec(
|
||||
`SELECT name
|
||||
FROM sqlite_master
|
||||
WHERE
|
||||
type = 'table'
|
||||
AND
|
||||
name NOT LIKE 'sqlite_%'
|
||||
ORDER BY name`,
|
||||
)[0]
|
||||
?.values.map((row) => String(row[0])) ?? [];
|
||||
|
||||
for (const name of tables) {
|
||||
tableSelect.append(new Option(name, name));
|
||||
}
|
||||
|
||||
tableSelect.addEventListener("change", () =>
|
||||
renderTable(db, tableSelect.value),
|
||||
);
|
||||
|
||||
if (tables.length > 0) {
|
||||
renderTable(db, tables[0]);
|
||||
}
|
||||
|
||||
status.textContent = "";
|
||||
|
||||
queryRun.addEventListener("click", () => runQuery(db));
|
||||
queryInput.addEventListener("keydown", (event) => {
|
||||
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
runQuery(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error: unknown) => {
|
||||
status.textContent = `Failed to load database: ${String(error)}`;
|
||||
});
|
||||
267
tooling/pipeline-results-viewer/src/style.scss
Normal file
267
tooling/pipeline-results-viewer/src/style.scss
Normal file
@@ -0,0 +1,267 @@
|
||||
$gray-100: #dedede;
|
||||
$gray-300: #c3c3c3;
|
||||
$gray-500: #808080;
|
||||
$white: #ffffff;
|
||||
$black: #000000;
|
||||
$navy: #000080;
|
||||
$blue: #1084d0;
|
||||
$teal: #008080;
|
||||
|
||||
$color-surface: $gray-300;
|
||||
$color-surface-alt: $gray-100;
|
||||
$color-surface-sunken: $white;
|
||||
$color-border-highlight: $gray-100;
|
||||
$color-border-lowlight: $gray-500;
|
||||
$color-border-light: $white;
|
||||
$color-border-dark: $black;
|
||||
$color-text: $black;
|
||||
$color-text-on-accent: $white;
|
||||
$color-text-status: $navy;
|
||||
$color-accent-start: $navy;
|
||||
$color-accent-end: $blue;
|
||||
$color-desktop-bg: $teal;
|
||||
$color-row-stripe: $gray-100;
|
||||
$color-shadow: rgba($black, 0.4);
|
||||
$color-focus-ring: $black;
|
||||
|
||||
$bevel-size: 2px;
|
||||
$font-stack: Tahoma, "MS Sans Serif", Verdana, sans-serif;
|
||||
|
||||
@mixin bevel-raised($size: $bevel-size) {
|
||||
border-style: solid;
|
||||
border-width: $size;
|
||||
border-top-color: $color-border-highlight;
|
||||
border-left-color: $color-border-highlight;
|
||||
border-right-color: $color-border-dark;
|
||||
border-bottom-color: $color-border-dark;
|
||||
box-shadow:
|
||||
inset $size $size 0 0 $color-border-light,
|
||||
inset (-$size) (-$size) 0 0 $color-border-lowlight;
|
||||
}
|
||||
|
||||
@mixin bevel-sunken($size: $bevel-size) {
|
||||
border-style: solid;
|
||||
border-width: $size;
|
||||
border-top-color: $color-border-lowlight;
|
||||
border-left-color: $color-border-lowlight;
|
||||
border-right-color: $color-border-light;
|
||||
border-bottom-color: $color-border-light;
|
||||
box-shadow:
|
||||
inset $size $size 0 0 $color-border-dark,
|
||||
inset (-$size) (-$size) 0 0 $color-surface-alt;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 24px;
|
||||
background: $color-desktop-bg;
|
||||
font-family: $font-stack;
|
||||
color: $color-text;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
#window {
|
||||
width: 100%;
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
background: $color-surface;
|
||||
padding: 6px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
@include bevel-raised(3px);
|
||||
box-shadow: 8px 8px 0 0 $color-shadow;
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
background: linear-gradient(90deg, $color-accent-start, $color-accent-end);
|
||||
color: $color-text-on-accent;
|
||||
padding: 6px 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
letter-spacing: 0.5px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
}
|
||||
|
||||
.tab-strip {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 8px 8px 0;
|
||||
}
|
||||
|
||||
.tab {
|
||||
position: relative;
|
||||
top: 3px;
|
||||
margin-bottom: -2px;
|
||||
font-family: $font-stack;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
padding: 6px 14px;
|
||||
background: $color-surface;
|
||||
color: $color-text;
|
||||
border-style: solid;
|
||||
border-width: 2px;
|
||||
border-top-color: $color-border-light;
|
||||
border-left-color: $color-border-light;
|
||||
border-right-color: $color-border-dark;
|
||||
border-bottom-color: $color-border-dark;
|
||||
border-radius: 0;
|
||||
cursor: pointer;
|
||||
|
||||
&.is-active {
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
border-bottom-color: $color-surface;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: 1px dotted $color-focus-ring;
|
||||
outline-offset: -4px;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
border-top: 2px solid $color-border-dark;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.tab-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
|
||||
&[hidden] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.field-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
label {
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
&.field-group--stacked {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
|
||||
select#table-select {
|
||||
font-family: $font-stack;
|
||||
font-size: 13px;
|
||||
padding: 3px 6px;
|
||||
background: $color-surface-sunken;
|
||||
color: $color-text;
|
||||
border-radius: 0;
|
||||
@include bevel-sunken();
|
||||
|
||||
&:focus {
|
||||
outline: 1px dotted $color-focus-ring;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
textarea#query-input {
|
||||
font-family: $font-stack;
|
||||
font-size: 13px;
|
||||
padding: 6px;
|
||||
background: $color-surface-sunken;
|
||||
color: $color-text;
|
||||
border-radius: 0;
|
||||
resize: vertical;
|
||||
@include bevel-sunken();
|
||||
|
||||
&:focus {
|
||||
outline: 1px dotted $color-focus-ring;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.btn {
|
||||
align-self: flex-start;
|
||||
font-family: $font-stack;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
padding: 6px 16px;
|
||||
background: $color-surface;
|
||||
color: $color-text;
|
||||
cursor: pointer;
|
||||
@include bevel-raised();
|
||||
|
||||
&:active {
|
||||
@include bevel-sunken();
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: 1px dotted $color-focus-ring;
|
||||
outline-offset: -4px;
|
||||
}
|
||||
}
|
||||
|
||||
#status,
|
||||
#query-status {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
color: $color-text-status;
|
||||
}
|
||||
|
||||
#table-container,
|
||||
#query-container {
|
||||
background: $color-surface-sunken;
|
||||
padding: 4px;
|
||||
overflow-x: auto;
|
||||
@include bevel-sunken();
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: 0 auto;
|
||||
font-family: $font-stack;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
border: 1px solid $color-border-lowlight;
|
||||
padding: 4px 8px;
|
||||
text-align: left;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
th {
|
||||
background: $color-surface;
|
||||
white-space: nowrap;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
@include bevel-raised(1px);
|
||||
}
|
||||
|
||||
td {
|
||||
min-width: 120px;
|
||||
max-width: 800px;
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
background: $color-surface-sunken;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) td {
|
||||
background: $color-row-stripe;
|
||||
}
|
||||
Reference in New Issue
Block a user