From 6ee977d8c613c1b0761f0f5d4e6d393a21b4663e Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Thu, 28 Mar 2024 00:58:30 +0100 Subject: [PATCH] feat: better deploys page and single deploy page --- src/client/Deploy.jsx | 28 ++++-- src/client/Inspect.jsx | 20 +++- src/client/JobLogs.jsx | 8 +- src/client/JobsPage.jsx | 10 +- src/components/Sidebar.astro | 23 +++-- src/layouts/Layout.astro | 1 + src/lib/utils.ts | 2 +- src/pages/containers.astro | 44 ++++----- src/pages/deploys/[name]/index.astro | 31 ++++++ src/pages/deploys/index.astro | 4 +- src/pages/index.astro | 1 - src/pages/jobs/[uuid]/index.astro | 19 ++-- src/pages/jobs/[uuid]/logs.ts | 4 +- src/styles/main.scss | 141 ++++++++++++++++++++++++--- tsconfig.json | 1 - 15 files changed, 263 insertions(+), 74 deletions(-) create mode 100644 src/pages/deploys/[name]/index.astro diff --git a/src/client/Deploy.jsx b/src/client/Deploy.jsx index 333f62c..86504db 100644 --- a/src/client/Deploy.jsx +++ b/src/client/Deploy.jsx @@ -1,3 +1,4 @@ +import { normalizeURL } from '@/lib/utils' import { Value } from './Inspect.jsx' // const GitRef = ({ type, value }) => { @@ -17,15 +18,30 @@ import { Value } from './Inspect.jsx' // // +/** + * @param {{ deploy: import('@/config.js').Deploy }} param0 + */ + export const Deploy = ({ deploy }) => { return (
-
{deploy.name}
-
{deploy.type}
-
{deploy.type}
-
{deploy.type}
- - + +
{deploy.type}
+ {deploy.type === 'docker' ? ( +
{deploy.options.image}
+ ) : ( + <> +
+ {deploy.url.startsWith('/') ? ( + deploy.url + ) : ( + {deploy.url} + )} +
+ + )}
) } diff --git a/src/client/Inspect.jsx b/src/client/Inspect.jsx index 11dc320..672be24 100644 --- a/src/client/Inspect.jsx +++ b/src/client/Inspect.jsx @@ -1,8 +1,20 @@ import _ from 'lodash' import { clsx } from '@/lib/utils' -export const Value = ({ value, borderless }) => { - return Array.isArray(value) ? ( +export const Value = ({ value, borderless } = {}) => { + return value === undefined ? ( + undefined + ) : value === null ? ( + null + ) : value === true ? ( + true + ) : value === false ? ( + false + ) : typeof value === 'string' && value.trim().length === 0 ? ( + Empty string + ) : !value ? ( + value + ) : Array.isArray(value) ? ( ) : typeof value === 'object' ? ( @@ -12,7 +24,9 @@ export const Value = ({ value, borderless }) => { } export const ValueArray = ({ value, borderless }) => { - return ( + return value.length === 0 ? ( + Empty array + ) : (
{value.map(item => (
diff --git a/src/client/JobLogs.jsx b/src/client/JobLogs.jsx index f88dbe2..99a28ce 100644 --- a/src/client/JobLogs.jsx +++ b/src/client/JobLogs.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "preact/hooks" +import { useEffect, useState } from 'preact/hooks' export const JobLogs = ({}) => { const [logLines, setLogLines] = useState([]) @@ -13,13 +13,11 @@ export const JobLogs = ({}) => { const es = new EventSource(location.href + '/logs?format=sse') es.addEventListener('message', ({ data }) => { const event = JSON.parse(data) - setLogLines(lines => [ - ...lines, - event.content, - ]) + setLogLines(lines => [...lines, event.content]) }) }, []) + // prettier-ignore return (
{logLines.join('\n')}
) diff --git a/src/client/JobsPage.jsx b/src/client/JobsPage.jsx index ec1b0a8..9b27a82 100644 --- a/src/client/JobsPage.jsx +++ b/src/client/JobsPage.jsx @@ -42,12 +42,14 @@ export const JobsPage = ({}) => { const res = await fetch(location.href + '?format=json') const jobs = await res.json() - const result = {} + // const result = {} - for (const item of jobs) { - result[item.uuid] = item - } + // for (const item of jobs) { + // result[item.uuid] = item + // } + const result = _.keyBy(jobs, 'uuid') + console.log(result) setJobStore(result) // Setup SSE diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro index 9a92f06..db3f2bf 100644 --- a/src/components/Sidebar.astro +++ b/src/components/Sidebar.astro @@ -1,13 +1,16 @@