Skip to content

Commit

Permalink
Merge pull request #176 from codefori/feature/133_show_state_and_code
Browse files Browse the repository at this point in the history
Cleanup of result set UI
  • Loading branch information
worksofliam authored Dec 5, 2023
2 parents 3005c04 + 0e3a59c commit 4fc2010
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 21 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"description": "Page size for Schema browser",
"default": 500
},
"vscode-db2i.collapsedResultSet": {
"type": "boolean",
"description": "Make larger cells collapsed by default",
"default": false
},
"vscode-db2i.alwaysStartSQLJob": {
"type": "string",
"description": "Name of configuration to use when auto starting a job. 'new' for brand new default job, 'ask' to be asked, 'never' to never start, or a name of a stored configuration",
Expand Down
14 changes: 10 additions & 4 deletions src/connection/query.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { changedCache} from "../language/providers/completionItemCache";
import Document from "../language/sql/document";

import { SQLJob } from "./sqlJob";
import { CLCommandResult, JobLogEntry, QueryOptions, QueryResult, ServerResponse } from "./types";
import { QueryOptions, QueryResult } from "./types";
export enum QueryState {
NOT_YET_RUN = 1,
RUN_MORE_DATA_AVAILABLE = 2,
Expand Down Expand Up @@ -95,7 +94,14 @@ export class Query<T> {

if (queryResult.success !== true && !this.isCLCommand) {
this.state = QueryState.ERROR;
throw new Error(queryResult.error || `Failed to run query (unknown error)`);

let errorList = [queryResult.error, queryResult.sql_state, queryResult.sql_rc].filter(e => e !== undefined);

if (errorList.length === 0) {
errorList.push(`Failed to run query (unknown error)`);
}

throw new Error(errorList.join(', '));
}
this.correlationId = queryResult.id;

Expand Down
4 changes: 2 additions & 2 deletions src/connection/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Server } from "http";

export interface ServerResponse {
id: string;
success: boolean;
error?: string;
sql_rc: number;
sql_state: string;
}

export interface ConnectionResult extends ServerResponse {
Expand Down
32 changes: 28 additions & 4 deletions src/views/html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

export const head = /*html*/`
export function getHeader(options: {withCollapsed?: boolean} = {}): string {
return /*html*/`
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
Expand All @@ -19,13 +20,35 @@ export const head = /*html*/`
#resultset th,
#resultset td {
padding: 12px 15px;
padding: 5px 15px;
}
#resultset tbody tr {
border-bottom: 1px solid var(--vscode-activityBar-border);
}
${options.withCollapsed ? /*css*/`
.hoverable {
/* your initial height */
height: 12px;
/* stop content from "spilling" */
overflow: hidden;
text-overflow: ellipsis;
max-width: 200px;
text-wrap: nowrap;
}
.hoverable:hover {
/* or height: auto then it will expand to text height */
max-width: initial;
height: auto;
text-wrap: initial;
}
#resultset tbody tr {
overflow: hidden;
}
` : ''}
.center-screen {
overflow: hidden;
display: grid;
Expand Down Expand Up @@ -107,8 +130,9 @@ export const head = /*html*/`
background-size: 80px 80px;
}
}
</style>`;

</style>
`;
}

export const escapeHTML = str => str.replace(/[&<>'"]/g,
tag => ({
Expand Down
4 changes: 2 additions & 2 deletions src/views/jobManager/jobLog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ViewColumn, window } from "vscode";
import { JobInfo } from "../../connection/manager";
import { escapeHTML, head } from "../html";
import { escapeHTML, getHeader } from "../html";
import { JobLogEntry } from "../../connection/types";
import { JobManager } from "../../config";

Expand All @@ -22,7 +22,7 @@ function generatePage(rows: JobLogEntry[]) {
<!DOCTYPE html>
<html lang="en">
<head>
${head}
${getHeader()}
</head>
<body>
<table id="resultset">
Expand Down
25 changes: 16 additions & 9 deletions src/views/results/html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Webview } from "vscode";
import { head } from "../html";
import { getHeader } from "../html";

import Configuration from "../../configuration";

export function setLoadingText(webview: Webview, text: string) {
webview.postMessage({
Expand All @@ -13,7 +15,7 @@ export function getLoadingHTML(): string {
<!DOCTYPE html>
<html lang="en">
<head>
${head}
${getHeader()}
<script>
window.addEventListener("message", (event) => {
const command = event.data.command;
Expand All @@ -37,11 +39,13 @@ export function getLoadingHTML(): string {
}

export function generateScroller(basicSelect: string, isCL: boolean): string {
const withCollapsed = Configuration.get<boolean>('collapsedResultSet');

return /*html*/`
<!DOCTYPE html>
<html lang="en">
<head>
${head}
${getHeader({withCollapsed})}
<script>
/*
${new Date().getTime()}
Expand Down Expand Up @@ -142,15 +146,20 @@ export function generateScroller(basicSelect: string, isCL: boolean): string {
for (const row of arrayOfObjects) {
// Insert a row at the end of table
var newRow = tBodyRef.insertRow();
var newRow = tBodyRef.insertRow()
for (const cell of row) {
// Insert a cell at the end of the row
var newCell = newRow.insertCell();
// Append a text node to the cell
var newText = document.createTextNode(cell === undefined ? 'null' : cell);
newCell.appendChild(newText);
//TODO: handle cell formatting here
var newDiv = document.createElement("div");
newDiv.className = "hoverable";
newDiv.appendChild(document.createTextNode(cell === undefined ? 'null' : cell));
newCell.appendChild(newDiv);
}
}
Expand All @@ -170,6 +179,4 @@ export function generateScroller(basicSelect: string, isCL: boolean): string {
</body>
</html>
`;
}

interface ColumnDetail {title: string, columnDataKey: string|number, transform?: (row: object) => string|number};
}

0 comments on commit 4fc2010

Please sign in to comment.