Skip to content

Commit

Permalink
add query details to query view page (#62)
Browse files Browse the repository at this point in the history
* add query details to query view page

* query params values should not be links

* Update server/app/query/view/[id]/page.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix copy paste error

* create queryParams variable to simply templating code

* make the query-details template less repetative

* add a JSONSafeParse function to handle parsing errors

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
eriktaubeneck and coderabbitai[bot] authored Jun 28, 2024
1 parent 3246245 commit 7c4f9cf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 11 deletions.
82 changes: 71 additions & 11 deletions server/app/query/view/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
initialRunTimeByRemoteServer,
} from "@/app/query/servers";
import { StatsComponent } from "@/app/query/view/[id]/charts";
import { JSONSafeParse } from "@/app/utils";
import { getQuery, Query } from "@/data/query";

export default function QueryPage({ params }: { params: { id: string } }) {
Expand Down Expand Up @@ -76,6 +77,10 @@ export default function QueryPage({ params }: { params: { id: string } }) {
}
}

const queryParams = Object.entries(
JSONSafeParse((query?.params as string) || "{}"),
);

const kill = async (remoteServers: RemoteServersType) => {
const query: Query = await getQuery(params.id);

Expand Down Expand Up @@ -122,18 +127,73 @@ export default function QueryPage({ params }: { params: { id: string } }) {

return (
<>
<div className="inline-flex items-center">
<h2 className="text-2xl font-bold leading-7 text-gray-900 dark:text-gray-100 sm:truncate sm:text-3xl sm:tracking-tight">
Query Details: {params.id}
</h2>
<div className="flex justify-between items-center">
<div>
<h2 className="text-2xl font-bold leading-7 text-gray-900 dark:text-gray-100 sm:truncate sm:text-3xl sm:tracking-tight">
Query Details
</h2>
</div>
<div>
<button
onClick={() => kill(IPARemoteServers)}
type="button"
className="ml-3 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
>
Kill Query
</button>
</div>
</div>

<button
onClick={() => kill(IPARemoteServers)}
type="button"
className="ml-3 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
>
Kill Query
</button>
<div className="mt-6 border-t border-b border-gray-300 dark:border-gray-700">
<dl className="divide-y divide-gray-200 dark:divide-gray-800">
{[
["Display name", params.id],
["UUID", query?.uuid],
["Created at", query?.createdAt],
["Type", query?.type],
].map(([name, value]) => {
return (
<div
className="px-4 py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0"
key={name?.toLowerCase().replaceAll(" ", "_")}
>
<dt className="text-sm font-medium leading-6 text-gray-900 dark:text-gray-100">
{name}:
</dt>
<dd className="mt-1 text-sm leading-6 text-gray-700 dark:text-gray-300 sm:col-span-2 sm:mt-0">
{value}
</dd>
</div>
);
})}

<div className="px-4 py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
<dt className="text-sm font-medium leading-6 text-gray-900 dark:text-gray-100">
Params:
</dt>
<dd className="mt-2 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
<ul className="divide-y divide-gray-200 rounded-md border border-gray-200">
{queryParams.map(([key, value]) => {
return (
<li
className="flex items-center justify-between py-1 pl-4 pr-5 text-sm leading-6"
key={key}
>
<div className="flex w-0 flex-1 items-center">
<div className="ml-4 flex min-w-0 flex-1 gap-2">
<span className="truncate font-medium"> {key}</span>
</div>
</div>
<div className="ml-4 flex-shrink-0 font-medium text-sky-700">
{value as string}
</div>
</li>
);
})}
</ul>
</dd>
</div>
</dl>
</div>

<div className="w-full text-left mx-auto max-w-7xl overflow-hidden rounded-lg bg-slate-50 dark:bg-slate-950 shadow mt-10">
Expand Down
12 changes: 12 additions & 0 deletions server/app/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function JSONSafeParse(s: string) {
try {
return JSON.parse(s);
} catch (error) {
if (error instanceof SyntaxError) {
console.error(`${error}`);
console.error(`Failed to parse JSON from string ${s}`);
return {};
}
throw error;
}
}

0 comments on commit 7c4f9cf

Please sign in to comment.