From 52d3bba6f6c2acec8f002ae1b588a526db08e6ff Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 20 Nov 2023 13:49:23 +0100 Subject: [PATCH] Move instance buttons out of InstanceViewPage Break out the button row at the top of the instance page into its own component to reduce the complexity of InstanceViewPage. --- .../src/components/InstanceViewPage.tsx | 76 ++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/packages/web_ui/src/components/InstanceViewPage.tsx b/packages/web_ui/src/components/InstanceViewPage.tsx index e00fd6d4..8bde1bec 100644 --- a/packages/web_ui/src/components/InstanceViewPage.tsx +++ b/packages/web_ui/src/components/InstanceViewPage.tsx @@ -60,42 +60,13 @@ function InstanceDescription(props: InstanceDescriptionProps) { ; } -export default function InstanceViewPage() { - let params = useParams(); - let instanceId = Number(params.id); - - let navigate = useNavigate(); - +function InstanceButtons(props: { instance: InstanceState }) { let account = useAccount(); let control = useContext(ControlContext); - let [instance] = useInstance(instanceId); - let [host] = useHost(Number(instance.assignedHost)); - + let navigate = useNavigate(); let [exportingData, setExportingData] = useState(false); - - let nav = [{ name: "Instances", path: "/instances" }, { name: instance.name || "Unknown" }]; - if (instance.loading) { - return ; - } - - if (instance.missing || instance.status === "deleted") { - return - Instance with id {instanceId} was not found on the controller.} - type="warning" - action={ - - } - /> - ; - } + let instance = props.instance; + let instanceId = instance.id!; let instanceButtonMenuItems: ItemType[] = []; if (account.hasPermission("core.instance.export_data")) { @@ -174,7 +145,7 @@ export default function InstanceViewPage() { } }, }; - let instanceButtons = + return { account.hasAnyPermission("core.instance.start", "core.instance.stop") && @@ -189,11 +160,46 @@ export default function InstanceViewPage() { } ; +} + +export default function InstanceViewPage() { + let params = useParams(); + let instanceId = Number(params.id); + + let navigate = useNavigate(); + + let account = useAccount(); + let [instance] = useInstance(instanceId); + let [host] = useHost(Number(instance.assignedHost)); + + let nav = [{ name: "Instances", path: "/instances" }, { name: instance.name || "Unknown" }]; + if (instance.loading) { + return ; + } + + if (instance.missing || instance.status === "deleted") { + return + Instance with id {instanceId} was not found on the controller.} + type="warning" + action={ + + } + /> + ; + } return } />