From cf1cc973405b9f1ae7560bfc4633d967c7457a70 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 23 Oct 2021 15:19:41 -0600 Subject: [PATCH] ui(admin): rough layout on new server page --- .../admin/servers/NewServerContainer.tsx | 126 +++++++++++++++++- .../components/admin/servers/OwnerSelect.tsx | 4 +- .../admin/servers/ServerStartupContainer.tsx | 10 +- .../servers/settings/BaseSettingsBox.tsx | 4 +- .../admin/servers/settings/NetworkingBox.tsx | 12 +- .../servers/settings/ServerResourceBox.tsx | 4 - 6 files changed, 141 insertions(+), 19 deletions(-) diff --git a/resources/scripts/components/admin/servers/NewServerContainer.tsx b/resources/scripts/components/admin/servers/NewServerContainer.tsx index 2b121915..61abd51d 100644 --- a/resources/scripts/components/admin/servers/NewServerContainer.tsx +++ b/resources/scripts/components/admin/servers/NewServerContainer.tsx @@ -1,8 +1,30 @@ -import React from 'react'; +import { Egg } from '@/api/admin/egg'; +import AdminBox from '@/components/admin/AdminBox'; +import { ServerImageContainer, ServerServiceContainer, ServerVariableContainer } from '@/components/admin/servers/ServerStartupContainer'; +import BaseSettingsBox from '@/components/admin/servers/settings/BaseSettingsBox'; +import FeatureLimitsBox from '@/components/admin/servers/settings/FeatureLimitsBox'; +import ServerResourceBox from '@/components/admin/servers/settings/ServerResourceBox'; +import Button from '@/components/elements/Button'; +import Field from '@/components/elements/Field'; +import Label from '@/components/elements/Label'; +import Select from '@/components/elements/Select'; +import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; +import FlashMessageRender from '@/components/FlashMessageRender'; +import { faNetworkWired } from '@fortawesome/free-solid-svg-icons'; +import { Form, Formik } from 'formik'; +import React, { useState } from 'react'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; +import { object } from 'yup'; +import { Values } from '@/api/admin/servers/updateServer'; export default () => { + const [ egg, setEgg ] = useState(null); + + const submit = (_: Values) => { + // + }; + return (
@@ -11,6 +33,108 @@ export default () => {

Add a new server to the panel.

+ + + + + {({ isSubmitting, isValid }) => ( +
+
+
+ + + {/* TODO: in networking box only show primary allocation and additional allocations */} + {/* TODO: add node select */} + +
+
+ +
+
+ + +
+
+
+ + +
+ + + + + + + +
+ {egg?.relationships.variables?.map((v, i) => ( + + ))} +
+ +
+
+ +
+
+
+
+ )} +
); }; diff --git a/resources/scripts/components/admin/servers/OwnerSelect.tsx b/resources/scripts/components/admin/servers/OwnerSelect.tsx index 38a4f819..75c3b73d 100644 --- a/resources/scripts/components/admin/servers/OwnerSelect.tsx +++ b/resources/scripts/components/admin/servers/OwnerSelect.tsx @@ -3,10 +3,10 @@ import { useFormikContext } from 'formik'; import SearchableSelect, { Option } from '@/components/elements/SearchableSelect'; import { User, searchUserAccounts } from '@/api/admin/user'; -export default ({ selected }: { selected: User }) => { +export default ({ selected }: { selected?: User }) => { const context = useFormikContext(); - const [ user, setUser ] = useState(selected); + const [ user, setUser ] = useState(selected || null); const [ users, setUsers ] = useState(null); const onSearch = async (query: string) => { diff --git a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx index cce7ecbe..76ff3c54 100644 --- a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx @@ -57,10 +57,10 @@ function ServerStartupLineContainer ({ egg, server }: { egg: Egg | null; server: ); } -function ServerServiceContainer ({ egg, setEgg, server }: { egg: Egg | null, setEgg: (value: Egg | null) => void, server: Server }) { +export function ServerServiceContainer ({ egg, setEgg, nestId: _nestId }: { egg: Egg | null, setEgg: (value: Egg | null) => void, nestId: number }) { const { isSubmitting } = useFormikContext(); - const [ nestId, setNestId ] = useState(server.nestId); + const [ nestId, setNestId ] = useState(_nestId); return ( @@ -77,7 +77,7 @@ function ServerServiceContainer ({ egg, setEgg, server }: { egg: Egg | null, set ); } -function ServerImageContainer () { +export function ServerImageContainer () { const { isSubmitting } = useFormikContext(); return ( @@ -98,7 +98,7 @@ function ServerImageContainer () { ); } -function ServerVariableContainer ({ variable, defaultValue }: { variable: EggVariable, defaultValue: string }) { +export function ServerVariableContainer ({ variable, defaultValue }: { variable: EggVariable, defaultValue: string }) { const key = 'environment.' + variable.environmentVariable; const { isSubmitting, setFieldValue } = useFormikContext(); @@ -140,7 +140,7 @@ function ServerStartupForm ({ egg, setEgg, server }: { egg: Egg | null, setEgg: diff --git a/resources/scripts/components/admin/servers/settings/BaseSettingsBox.tsx b/resources/scripts/components/admin/servers/settings/BaseSettingsBox.tsx index 898bd62d..dfa0450d 100644 --- a/resources/scripts/components/admin/servers/settings/BaseSettingsBox.tsx +++ b/resources/scripts/components/admin/servers/settings/BaseSettingsBox.tsx @@ -11,14 +11,12 @@ export default () => { const { data: server } = useServerFromRoute(); const { isSubmitting } = useFormikContext(); - if (!server) return null; - return (
- +
); diff --git a/resources/scripts/components/admin/servers/settings/NetworkingBox.tsx b/resources/scripts/components/admin/servers/settings/NetworkingBox.tsx index 864d8fa9..a75a321a 100644 --- a/resources/scripts/components/admin/servers/settings/NetworkingBox.tsx +++ b/resources/scripts/components/admin/servers/settings/NetworkingBox.tsx @@ -13,9 +13,13 @@ export default () => { const { isSubmitting } = useFormikContext(); const { data: server } = useServerFromRoute(); - if (!server) return null; - const loadOptions = async (inputValue: string, callback: (options: Option[]) => void) => { + if (!server) { + // eslint-disable-next-line node/no-callback-literal + callback([] as Option[]); + return; + } + const allocations = await getAllocations(server.nodeId, { ip: inputValue, server_id: '0' }); callback(allocations.map(a => { @@ -29,7 +33,7 @@ export default () => {
@@ -45,7 +49,7 @@ export default () => { id={'removeAllocations'} name={'removeAllocations'} label={'Remove Allocations'} - options={server.relationships.allocations?.map(a => { + options={server?.relationships.allocations?.map(a => { return { value: a.id.toString(), label: a.getDisplayText() }; }) || []} isMulti diff --git a/resources/scripts/components/admin/servers/settings/ServerResourceBox.tsx b/resources/scripts/components/admin/servers/settings/ServerResourceBox.tsx index b121eeeb..c715c593 100644 --- a/resources/scripts/components/admin/servers/settings/ServerResourceBox.tsx +++ b/resources/scripts/components/admin/servers/settings/ServerResourceBox.tsx @@ -5,13 +5,9 @@ import tw from 'twin.macro'; import Field from '@/components/elements/Field'; import FormikSwitch from '@/components/elements/FormikSwitch'; import React from 'react'; -import { useServerFromRoute } from '@/api/admin/server'; export default () => { const { isSubmitting } = useFormikContext(); - const { data: server } = useServerFromRoute(); - - if (!server) return null; return (