From ce0fafd30a01bdf6af8034276e49899f2bc7ba17 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 26 Aug 2024 16:28:37 +0200 Subject: [PATCH 1/4] UI: add back button & improve machine layout --- .../app/src/components/BackButton.tsx | 10 + .../app/src/routes/machines/[name]/view.tsx | 298 +++++++++--------- 2 files changed, 162 insertions(+), 146 deletions(-) create mode 100644 pkgs/webview-ui/app/src/components/BackButton.tsx diff --git a/pkgs/webview-ui/app/src/components/BackButton.tsx b/pkgs/webview-ui/app/src/components/BackButton.tsx new file mode 100644 index 000000000..e113739cb --- /dev/null +++ b/pkgs/webview-ui/app/src/components/BackButton.tsx @@ -0,0 +1,10 @@ +import { useNavigate } from "@solidjs/router"; + +export const BackButton = () => { + const navigate = useNavigate(); + return ( + + ); +}; diff --git a/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx b/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx index 43622b589..4acfcc694 100644 --- a/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx @@ -1,5 +1,6 @@ import { callApi, SuccessData } from "@/src/api"; import { activeURI } from "@/src/App"; +import { BackButton } from "@/src/components/BackButton"; import { FileInput } from "@/src/components/FileInput"; import { SelectInput } from "@/src/components/SelectInput"; import { TextInput } from "@/src/components/TextInput"; @@ -420,159 +421,163 @@ const MachineForm = (props: MachineDetailsProps) => { } }; return ( -
-
-
-
-
- devices} - > - - +
+
+ +
+
+
+ devices + } + > + + +
-
-
Details
- - {(field, props) => ( - - )} - - - {(field, props) => ( - - )} - +
Details
+ + {(field, props) => ( + + )} + + + {(field, props) => ( + + )} + -
- - -
- - {(field, props) => ( - - )} - - - {(field, props) => ( - <> - { - event.preventDefault(); // Prevent the native file dialog from opening - const input = event.target; - const files = await selectSshKeys(); - - // Set the files - Object.defineProperty(input, "files", { - value: files, - writable: true, - }); - // Define the files property on the input element - const changeEvent = new Event("input", { - bubbles: true, - cancelable: true, - }); - input.dispatchEvent(changeEvent); - }} - placeholder={"When empty the default key(s) will be used"} - value={field.value} +
+ + +
+ + {(field, props) => ( + - - )} - + )} + + + {(field, props) => ( + <> + { + event.preventDefault(); // Prevent the native file dialog from opening + const input = event.target; + const files = await selectSshKeys(); + + // Set the files + Object.defineProperty(input, "files", { + value: files, + writable: true, + }); + // Define the files property on the input element + const changeEvent = new Event("input", { + bubbles: true, + cancelable: true, + }); + input.dispatchEvent(changeEvent); + }} + placeholder={"When empty the default key(s) will be used"} + value={field.value} + error={field.error} + helperText="Provide the SSH key used to connect to the machine" + label="SSH Key" + /> + + )} + +
-
-
- -
- -
Remote Interactions
-
- - Installs the system for the first time. Used to bootstrap the remote - device. - -
- -
- - - - - Update the system if changes should be synced after the installation - process. - -
- + + + + + + Update the system if changes should be synced after the installation + process. + +
+ +
@@ -602,7 +607,8 @@ export const MachineDetails = () => { })); return ( - <> +
+ } @@ -615,6 +621,6 @@ export const MachineDetails = () => { }} /> - +
); }; From 2ee08913a56245c59be68edfb29fbe0a4a9ebe07 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 26 Aug 2024 16:28:57 +0200 Subject: [PATCH 2/4] UI: add quicklink for machine details --- .../app/src/components/MachineListItem.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx index 6a41b23b6..17a833b25 100644 --- a/pkgs/webview-ui/app/src/components/MachineListItem.tsx +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -3,7 +3,7 @@ import { callApi, SuccessData } from "../api"; import { Menu } from "./Menu"; import { activeURI } from "../App"; import toast from "solid-toast"; -import { useNavigate } from "@solidjs/router"; +import { A, useNavigate } from "@solidjs/router"; type MachineDetails = SuccessData<"list_inventory_machines">["data"][string]; @@ -116,14 +116,16 @@ export const MachineListItem = (props: MachineListItemProps) => {
-

- {name} -

+ +

+ {name} +

+
{(d) => d()?.description}
From 0f5062fa451bf0a108814e0226b13095e40d9c66 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 26 Aug 2024 16:29:29 +0200 Subject: [PATCH 3/4] UI: improve welcome workflow --- .../app/src/routes/clan/clanDetails.tsx | 87 ++++++++++--------- .../app/src/routes/welcome/index.tsx | 10 +-- 2 files changed, 45 insertions(+), 52 deletions(-) diff --git a/pkgs/webview-ui/app/src/routes/clan/clanDetails.tsx b/pkgs/webview-ui/app/src/routes/clan/clanDetails.tsx index 7c857591e..0e33ffeb3 100644 --- a/pkgs/webview-ui/app/src/routes/clan/clanDetails.tsx +++ b/pkgs/webview-ui/app/src/routes/clan/clanDetails.tsx @@ -7,7 +7,9 @@ import { SubmitHandler, } from "@modular-forms/solid"; import toast from "solid-toast"; -import { setActiveURI } from "@/src/App"; +import { setActiveURI, setClanList } from "@/src/App"; +import { TextInput } from "@/src/components/TextInput"; +import { useNavigate } from "@solidjs/router"; type CreateForm = Meta & { template: string; @@ -21,10 +23,10 @@ export const ClanForm = () => { template: "minimal", }, }); + const navigate = useNavigate(); const handleSubmit: SubmitHandler = async (values, event) => { const { template, ...meta } = values; - const response = await callApi("open_file", { file_request: { mode: "save" }, }); @@ -39,29 +41,31 @@ export const ClanForm = () => { return; } - await toast.promise( - (async () => { - await callApi("create_clan", { - options: { - directory: target_dir[0], - template, - initial: { - meta, - services: {}, - machines: {}, - }, - }, - }); - setActiveURI(target_dir[0]); - // setRoute("machines"); - })(), - { - loading: "Creating clan...", - success: "Clan Successfully Created", - error: "Failed to create clan", + const loading_toast = toast.loading("Creating Clan...."); + const r = await callApi("create_clan", { + options: { + directory: target_dir[0], + template, + initial: { + meta, + services: {}, + machines: {}, + }, }, - ); - reset(formStore); + }); + toast.dismiss(loading_toast); + + if (r.status === "error") { + toast.error("Failed to create clan"); + return; + } + if (r.status === "success") { + toast.success("Clan Successfully Created"); + setActiveURI(target_dir[0]); + setClanList((list) => [...list, target_dir[0]]); + navigate("/machines"); + reset(formStore); + } }; return ( @@ -108,7 +112,7 @@ export const ClanForm = () => { {...props} disabled={formStore.submitting} required - placeholder="Clan Name" + placeholder="Give your Clan a legendary name" class="input input-bordered" classList={{ "input-error": !!field.error }} value={field.value} @@ -133,7 +137,7 @@ export const ClanForm = () => { disabled={formStore.submitting} required type="text" - placeholder="Some words about your clan" + placeholder="Tell us what makes your Clan legendary" class="input input-bordered" classList={{ "input-error": !!field.error }} value={field.value || ""} @@ -152,23 +156,20 @@ export const ClanForm = () => {
- + clan-core # + ), + position: "start", + }} + formStore={formStore} + inputProps={props} + label="Template to use" + value={field.value ?? ""} + error={field.error} + required + />
)} diff --git a/pkgs/webview-ui/app/src/routes/welcome/index.tsx b/pkgs/webview-ui/app/src/routes/welcome/index.tsx index ce760c366..aae282d1c 100644 --- a/pkgs/webview-ui/app/src/routes/welcome/index.tsx +++ b/pkgs/webview-ui/app/src/routes/welcome/index.tsx @@ -13,7 +13,7 @@ export const Welcome = () => {
@@ -29,14 +29,6 @@ export const Welcome = () => { > Or select folder -
From 3b48dfd2e0617b975b245fc9efb6a3d767771e5e Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 26 Aug 2024 16:30:44 +0200 Subject: [PATCH 4/4] UI: add create machine suggestion --- .../app/src/routes/machines/create.tsx | 113 +++++++++--------- .../app/src/routes/machines/view.tsx | 12 +- 2 files changed, 70 insertions(+), 55 deletions(-) diff --git a/pkgs/webview-ui/app/src/routes/machines/create.tsx b/pkgs/webview-ui/app/src/routes/machines/create.tsx index 3af89edd4..0c8e7e12c 100644 --- a/pkgs/webview-ui/app/src/routes/machines/create.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/create.tsx @@ -59,68 +59,73 @@ export function CreateMachine() { } }; return ( -
- Create new Machine -
- - {(field, props) => ( - - )} - - - {(field, props) => ( - - )} - - - {(field, props) => ( - <> +
+
+ Create new Machine + + + {(field, props) => ( + )} + + + {(field, props) => ( + - - )} - - - + )} + +
+ +
+ +
); } diff --git a/pkgs/webview-ui/app/src/routes/machines/view.tsx b/pkgs/webview-ui/app/src/routes/machines/view.tsx index 6f051e90f..e7c849f41 100644 --- a/pkgs/webview-ui/app/src/routes/machines/view.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/view.tsx @@ -113,7 +113,17 @@ export const MachineListView: Component = () => { nixOnlyMachines()?.length === 0 } > - No machines found +
+ + No machines defined yet. Click below to define one. + + +