2020-08-26 04:25:31 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2020-08-22 22:43:28 +00:00
|
|
|
import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
|
|
|
import tw from 'twin.macro';
|
2020-08-23 01:13:59 +00:00
|
|
|
import VariableBox from '@/components/server/startup/VariableBox';
|
2020-08-23 02:05:43 +00:00
|
|
|
import ServerContentBlock from '@/components/elements/ServerContentBlock';
|
2020-08-26 04:25:31 +00:00
|
|
|
import getServerStartup from '@/api/swr/getServerStartup';
|
|
|
|
import Spinner from '@/components/elements/Spinner';
|
|
|
|
import ServerError from '@/components/screens/ServerError';
|
|
|
|
import { httpErrorToHuman } from '@/api/http';
|
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import { useDeepCompareEffect } from '@/plugins/useDeepCompareEffect';
|
2020-08-22 22:43:28 +00:00
|
|
|
|
|
|
|
const StartupContainer = () => {
|
2020-08-26 04:25:31 +00:00
|
|
|
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
|
|
|
const invocation = ServerContext.useStoreState(state => state.server.data!.invocation);
|
|
|
|
const variables = ServerContext.useStoreState(state => state.server.data!.variables);
|
|
|
|
|
|
|
|
const { data, error, isValidating, mutate } = getServerStartup(uuid, { invocation, variables });
|
|
|
|
|
|
|
|
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// Since we're passing in initial data this will not trigger on mount automatically. We
|
|
|
|
// want to always fetch fresh information from the API however when we're loading the startup
|
|
|
|
// information.
|
|
|
|
mutate();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useDeepCompareEffect(() => {
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
setServerFromState(s => ({
|
|
|
|
...s,
|
|
|
|
invocation: data.invocation,
|
|
|
|
variables: data.variables,
|
|
|
|
}));
|
|
|
|
}, [ data ]);
|
2020-08-22 22:43:28 +00:00
|
|
|
|
|
|
|
return (
|
2020-08-26 04:25:31 +00:00
|
|
|
!data ?
|
|
|
|
(!error || (error && isValidating)) ?
|
|
|
|
<Spinner centered size={Spinner.Size.LARGE}/>
|
|
|
|
:
|
|
|
|
<ServerError
|
|
|
|
title={'Oops!'}
|
|
|
|
message={httpErrorToHuman(error)}
|
|
|
|
onRetry={() => mutate()}
|
|
|
|
/>
|
|
|
|
:
|
|
|
|
<ServerContentBlock title={'Startup Settings'}>
|
|
|
|
<TitledGreyBox title={'Startup Command'}>
|
|
|
|
<div css={tw`px-1 py-2`}>
|
|
|
|
<p css={tw`font-mono bg-neutral-900 rounded py-2 px-4`}>
|
|
|
|
{data.invocation}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</TitledGreyBox>
|
|
|
|
<div css={tw`grid gap-8 grid-cols-2 mt-10`}>
|
|
|
|
{data.variables.map(variable => <VariableBox key={variable.envVariable} variable={variable}/>)}
|
2020-08-22 22:43:28 +00:00
|
|
|
</div>
|
2020-08-26 04:25:31 +00:00
|
|
|
</ServerContentBlock>
|
2020-08-22 22:43:28 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default StartupContainer;
|