ui/clan: wire up service create
This commit is contained in:
@@ -36,6 +36,11 @@ import { createForm, FieldValues, reset } from "@modular-forms/solid";
|
|||||||
import { Sidebar } from "@/src/components/Sidebar/Sidebar";
|
import { Sidebar } from "@/src/components/Sidebar/Sidebar";
|
||||||
import { UseQueryResult } from "@tanstack/solid-query";
|
import { UseQueryResult } from "@tanstack/solid-query";
|
||||||
import { ListClansModal } from "@/src/modals/ListClansModal/ListClansModal";
|
import { ListClansModal } from "@/src/modals/ListClansModal/ListClansModal";
|
||||||
|
import {
|
||||||
|
InventoryInstance,
|
||||||
|
ServiceWorkflow,
|
||||||
|
} from "@/src/workflows/Service/Service";
|
||||||
|
import { useApiClient } from "@/src/hooks/ApiClient";
|
||||||
|
|
||||||
interface ClanContextProps {
|
interface ClanContextProps {
|
||||||
clanURI: string;
|
clanURI: string;
|
||||||
@@ -179,7 +184,10 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [dialogHandlers, setDialogHandlers] = createSignal<{
|
const [showService, setShowService] = createSignal(false);
|
||||||
|
|
||||||
|
const [showModal, setShowModal] = createSignal(false);
|
||||||
|
const [currentPromise, setCurrentPromise] = createSignal<{
|
||||||
resolve: ({ id }: { id: string }) => void;
|
resolve: ({ id }: { id: string }) => void;
|
||||||
reject: (err: unknown) => void;
|
reject: (err: unknown) => void;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
@@ -187,7 +195,15 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
const onCreate = async (): Promise<{ id: string }> => {
|
const onCreate = async (): Promise<{ id: string }> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setShowModal(true);
|
setShowModal(true);
|
||||||
setDialogHandlers({ resolve, reject });
|
setCurrentPromise({ resolve, reject });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onAddService = async (): Promise<{ id: string }> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setShowService(true);
|
||||||
|
console.log("setting current promise");
|
||||||
|
setCurrentPromise({ resolve, reject });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -217,8 +233,6 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
return { id: values.name };
|
return { id: values.name };
|
||||||
};
|
};
|
||||||
|
|
||||||
const [showModal, setShowModal] = createSignal(false);
|
|
||||||
|
|
||||||
const [loadingError, setLoadingError] = createSignal<
|
const [loadingError, setLoadingError] = createSignal<
|
||||||
{ title: string; description: string } | undefined
|
{ title: string; description: string } | undefined
|
||||||
>();
|
>();
|
||||||
@@ -265,6 +279,26 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const client = useApiClient();
|
||||||
|
const handleSubmitService = async (instance: InventoryInstance) => {
|
||||||
|
console.log("Create Instance", instance);
|
||||||
|
const call = client.fetch("create_service_instance", {
|
||||||
|
flake: {
|
||||||
|
identifier: ctx.clanURI,
|
||||||
|
},
|
||||||
|
module_ref: instance.module,
|
||||||
|
roles: instance.roles,
|
||||||
|
});
|
||||||
|
const result = await call.result;
|
||||||
|
|
||||||
|
if (result.status === "error") {
|
||||||
|
console.error("Error creating service instance", result.errors);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
currentPromise()?.resolve({ id: "0" });
|
||||||
|
setShowService(false);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Show when={loadingError()}>
|
<Show when={loadingError()}>
|
||||||
@@ -274,15 +308,15 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
<MockCreateMachine
|
<MockCreateMachine
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
dialogHandlers()?.reject(new Error("User cancelled"));
|
currentPromise()?.reject(new Error("User cancelled"));
|
||||||
}}
|
}}
|
||||||
onSubmit={async (values) => {
|
onSubmit={async (values) => {
|
||||||
try {
|
try {
|
||||||
const result = await sendCreate(values);
|
const result = await sendCreate(values);
|
||||||
dialogHandlers()?.resolve(result);
|
currentPromise()?.resolve(result);
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
dialogHandlers()?.reject(err);
|
currentPromise()?.reject(err);
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -297,10 +331,22 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CubeScene
|
<CubeScene
|
||||||
|
onAddService={onAddService}
|
||||||
selectedIds={selectedIds}
|
selectedIds={selectedIds}
|
||||||
onSelect={onMachineSelect}
|
onSelect={onMachineSelect}
|
||||||
isLoading={ctx.isLoading()}
|
isLoading={ctx.isLoading()}
|
||||||
cubesQuery={ctx.machinesQuery}
|
cubesQuery={ctx.machinesQuery}
|
||||||
|
toolbarPopup={
|
||||||
|
<Show when={showService()}>
|
||||||
|
<ServiceWorkflow
|
||||||
|
handleSubmit={handleSubmitService}
|
||||||
|
onClose={() => {
|
||||||
|
setShowService(false);
|
||||||
|
currentPromise()?.resolve({ id: "0" });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
|
}
|
||||||
onCreate={onCreate}
|
onCreate={onCreate}
|
||||||
clanURI={ctx.clanURI}
|
clanURI={ctx.clanURI}
|
||||||
sceneStore={() => store.sceneData?.[ctx.clanURI]}
|
sceneStore={() => store.sceneData?.[ctx.clanURI]}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* <div class="absolute bottom-4 left-1/2 flex -translate-x-1/2 flex-col items-center">
|
||||||
|
<Show when={show()}> */
|
||||||
.toolbar-container {
|
.toolbar-container {
|
||||||
@apply absolute bottom-10 z-10 w-full;
|
@apply absolute bottom-10 z-10 w-full;
|
||||||
@apply flex justify-center items-center;
|
@apply flex justify-center items-center;
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import { createSignal, createEffect, onCleanup, onMount, on } from "solid-js";
|
import {
|
||||||
|
createSignal,
|
||||||
|
createEffect,
|
||||||
|
onCleanup,
|
||||||
|
onMount,
|
||||||
|
on,
|
||||||
|
JSX,
|
||||||
|
} from "solid-js";
|
||||||
import "./cubes.css";
|
import "./cubes.css";
|
||||||
|
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
@@ -34,12 +41,14 @@ function garbageCollectGroup(group: THREE.Group) {
|
|||||||
export function CubeScene(props: {
|
export function CubeScene(props: {
|
||||||
cubesQuery: MachinesQueryResult;
|
cubesQuery: MachinesQueryResult;
|
||||||
onCreate: () => Promise<{ id: string }>;
|
onCreate: () => Promise<{ id: string }>;
|
||||||
|
onAddService: () => Promise<{ id: string }>;
|
||||||
selectedIds: Accessor<Set<string>>;
|
selectedIds: Accessor<Set<string>>;
|
||||||
onSelect: (v: Set<string>) => void;
|
onSelect: (v: Set<string>) => void;
|
||||||
sceneStore: Accessor<SceneData>;
|
sceneStore: Accessor<SceneData>;
|
||||||
setMachinePos: (machineId: string, pos: [number, number] | null) => void;
|
setMachinePos: (machineId: string, pos: [number, number] | null) => void;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
clanURI: string;
|
clanURI: string;
|
||||||
|
toolbarPopup?: JSX.Element;
|
||||||
}) {
|
}) {
|
||||||
let container: HTMLDivElement;
|
let container: HTMLDivElement;
|
||||||
let scene: THREE.Scene;
|
let scene: THREE.Scene;
|
||||||
@@ -213,7 +222,7 @@ export function CubeScene(props: {
|
|||||||
controls = new MapControls(camera, renderer.domElement);
|
controls = new MapControls(camera, renderer.domElement);
|
||||||
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
|
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
|
||||||
controls.mouseButtons.RIGHT = null;
|
controls.mouseButtons.RIGHT = null;
|
||||||
controls.enableRotate = false;
|
// controls.enableRotate = false;
|
||||||
controls.minZoom = 1.2;
|
controls.minZoom = 1.2;
|
||||||
controls.maxZoom = 3.5;
|
controls.maxZoom = 3.5;
|
||||||
controls.addEventListener("change", () => {
|
controls.addEventListener("change", () => {
|
||||||
@@ -543,6 +552,9 @@ export function CubeScene(props: {
|
|||||||
<>
|
<>
|
||||||
<div class="cubes-scene-container" ref={(el) => (container = el)} />
|
<div class="cubes-scene-container" ref={(el) => (container = el)} />
|
||||||
<div class="toolbar-container">
|
<div class="toolbar-container">
|
||||||
|
<div class="absolute bottom-full left-1/2 mb-2 -translate-x-1/2">
|
||||||
|
{props.toolbarPopup}
|
||||||
|
</div>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
description="Select machine"
|
description="Select machine"
|
||||||
@@ -563,7 +575,8 @@ export function CubeScene(props: {
|
|||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
description="Add new Service"
|
description="Add new Service"
|
||||||
name="modules"
|
name="modules"
|
||||||
icon="Modules"
|
icon="Services"
|
||||||
|
onClick={props.onAddService}
|
||||||
/>
|
/>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
icon="Reload"
|
icon="Reload"
|
||||||
|
|||||||
Reference in New Issue
Block a user