From 9b7cea5d046537e49f031a5ed610df6573aac84b Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Thu, 16 Sep 2021 16:46:41 -0600 Subject: [PATCH] ui(admin): server startup fixes - when a new egg is selected, set the variable values to the egg's default, not just the placeholder - when a new egg is selected, change the server's startup command to the default; fixes #3397 - remove move un-needed code --- .../admin/servers/ServerStartupContainer.tsx | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx index 5bc05fc00..72782a92d 100644 --- a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx @@ -18,8 +18,18 @@ import { Actions, useStoreActions } from 'easy-peasy'; import Label from '@/components/elements/Label'; import { object } from 'yup'; -function ServerStartupLineContainer ({ egg }: { egg: Egg }) { - const { isSubmitting } = useFormikContext(); +function ServerStartupLineContainer ({ egg, server }: { egg: Egg; server: Server }) { + const { isSubmitting, setFieldValue } = useFormikContext(); + + useEffect(() => { + if (server.eggId === egg.id) { + setFieldValue('startup', server.container.startup); + return; + } + + // Whenever the egg is changed, set the server's startup command to the egg's default. + setFieldValue('startup', egg.startup); + }, [ egg ]); return ( @@ -43,7 +53,7 @@ function ServerStartupLineContainer ({ egg }: { egg: Egg }) { ); } -function ServerServiceContainer ({ server, egg, setEgg }: { server: Server, egg: Egg | null, setEgg: (value: Egg | null) => void }) { +function ServerServiceContainer ({ egg, setEgg, server }: { egg: Egg | null, setEgg: (value: Egg | null) => void, server: Server }) { const { isSubmitting } = useFormikContext(); const [ nestId, setNestId ] = useState(server.nestId); @@ -116,40 +126,25 @@ function ServerVariableContainer ({ variable, defaultValue }: { variable: EggVar ); } -function ServerStartupForm ({ server }: { server: Server }) { - const { isSubmitting, isValid, setFieldValue } = useFormikContext(); - - const [ egg, setEgg ] = useState(null); - - useEffect(() => { - getEgg(server.eggId, [ 'variables' ]) - .then(egg => { - if (egg.relations.variables === undefined) { - return; - } - egg.relations.variables?.forEach(v => setFieldValue('environment.' + v.envVariable, '')); - setEgg(egg); - }) - .catch(error => console.error(error)); - }, []); - - if (egg === null) { - return (<>); - } +function ServerStartupForm ({ egg, setEgg, server }: { egg: Egg, setEgg: (value: Egg | null) => void; server: Server }) { + const { isSubmitting, isValid } = useFormikContext(); return (
- +
@@ -163,7 +158,7 @@ function ServerStartupForm ({ server }: { server: Server }) { v.eggId === v2.eggId && v.envVariable === v2.envVariable)?.serverValue || ''} + defaultValue={server.relations?.variables.find(v2 => v.eggId === v2.eggId && v.envVariable === v2.envVariable)?.serverValue || v.defaultValue} /> ))}
@@ -225,7 +220,11 @@ export default function ServerStartupContainer ({ server }: { server: Server }) validationSchema={object().shape({ })} > - + ); }