2022-06-12 11:56:00 -04:00
|
|
|
import React, { memo } from 'react';
|
2019-07-09 21:25:57 -07:00
|
|
|
import { ServerContext } from '@/state/server';
|
2020-03-29 22:12:50 -07:00
|
|
|
import Can from '@/components/elements/Can';
|
2020-08-25 21:39:00 -07:00
|
|
|
import ServerContentBlock from '@/components/elements/ServerContentBlock';
|
2020-10-03 19:36:26 -07:00
|
|
|
import isEqual from 'react-fast-compare';
|
2021-05-16 12:35:49 -07:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2022-06-12 11:56:00 -04:00
|
|
|
import Features from '@feature/Features';
|
2022-06-21 18:43:59 -04:00
|
|
|
import Console from '@/components/server/console/Console';
|
|
|
|
import StatGraphs from '@/components/server/console/StatGraphs';
|
2022-06-20 17:26:47 -04:00
|
|
|
import PowerButtons from '@/components/server/console/PowerButtons';
|
2022-06-21 18:43:59 -04:00
|
|
|
import ServerDetailsBlock from '@/components/server/console/ServerDetailsBlock';
|
2022-06-27 20:36:24 -04:00
|
|
|
import { Alert } from '@/components/elements/alert';
|
2019-09-17 22:33:14 -07:00
|
|
|
|
2020-07-04 15:40:41 -07:00
|
|
|
export type PowerAction = 'start' | 'stop' | 'restart' | 'kill';
|
2019-09-28 13:29:49 -07:00
|
|
|
|
2022-06-21 18:43:59 -04:00
|
|
|
const ServerConsoleContainer = () => {
|
2022-06-26 15:13:52 -04:00
|
|
|
const name = ServerContext.useStoreState((state) => state.server.data!.name);
|
|
|
|
const description = ServerContext.useStoreState((state) => state.server.data!.description);
|
2022-06-27 20:36:24 -04:00
|
|
|
const isInstalling = ServerContext.useStoreState((state) => state.server.isInstalling);
|
2022-06-26 15:13:52 -04:00
|
|
|
const isTransferring = ServerContext.useStoreState((state) => state.server.data!.isTransferring);
|
|
|
|
const eggFeatures = ServerContext.useStoreState((state) => state.server.data!.eggFeatures, isEqual);
|
2022-11-07 00:02:30 +01:00
|
|
|
const isNodeUnderMaintenance = ServerContext.useStoreState((state) => state.server.data!.isNodeUnderMaintenance);
|
2020-05-16 03:16:06 -04:00
|
|
|
|
2019-06-29 16:59:50 -07:00
|
|
|
return (
|
2022-06-30 20:30:01 -04:00
|
|
|
<ServerContentBlock title={'Console'}>
|
2022-11-07 00:02:30 +01:00
|
|
|
{(isNodeUnderMaintenance || isInstalling || isTransferring) && (
|
2022-06-30 20:30:01 -04:00
|
|
|
<Alert type={'warning'} className={'mb-4'}>
|
2022-11-07 00:02:30 +01:00
|
|
|
{isNodeUnderMaintenance
|
|
|
|
? 'The node of this server is currently under maintenance and all actions are unavailable.'
|
|
|
|
: isInstalling
|
2022-06-27 20:36:24 -04:00
|
|
|
? 'This server is currently running its installation process and most actions are unavailable.'
|
|
|
|
: 'This server is currently being transferred to another node and all actions are unavailable.'}
|
|
|
|
</Alert>
|
|
|
|
)}
|
2022-06-30 20:30:01 -04:00
|
|
|
<div className={'grid grid-cols-4 gap-4 mb-4'}>
|
2022-06-27 19:56:26 -04:00
|
|
|
<div className={'hidden sm:block sm:col-span-2 lg:col-span-3 pr-4'}>
|
2022-06-20 17:26:47 -04:00
|
|
|
<h1 className={'font-header text-2xl text-gray-50 leading-relaxed line-clamp-1'}>{name}</h1>
|
|
|
|
<p className={'text-sm line-clamp-2'}>{description}</p>
|
|
|
|
</div>
|
2022-06-27 19:56:26 -04:00
|
|
|
<div className={'col-span-4 sm:col-span-2 lg:col-span-1 self-end'}>
|
2022-06-26 15:13:52 -04:00
|
|
|
<Can action={['control.start', 'control.stop', 'control.restart']} matchAny>
|
|
|
|
<PowerButtons className={'flex sm:justify-end space-x-2'} />
|
2022-06-20 17:26:47 -04:00
|
|
|
</Can>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-30 20:30:01 -04:00
|
|
|
<div className={'grid grid-cols-4 gap-2 sm:gap-4 mb-4'}>
|
|
|
|
<div className={'flex col-span-4 lg:col-span-3'}>
|
2022-06-21 18:43:59 -04:00
|
|
|
<Spinner.Suspense>
|
2022-06-26 15:13:52 -04:00
|
|
|
<Console />
|
2022-06-21 18:43:59 -04:00
|
|
|
</Spinner.Suspense>
|
|
|
|
</div>
|
2022-06-27 19:56:26 -04:00
|
|
|
<ServerDetailsBlock className={'col-span-4 lg:col-span-1 order-last lg:order-none'} />
|
2019-09-17 21:59:35 -07:00
|
|
|
</div>
|
2022-06-21 18:43:59 -04:00
|
|
|
<div className={'grid grid-cols-1 md:grid-cols-3 gap-2 sm:gap-4'}>
|
2021-05-16 12:35:49 -07:00
|
|
|
<Spinner.Suspense>
|
2022-06-26 15:13:52 -04:00
|
|
|
<StatGraphs />
|
2021-05-16 12:35:49 -07:00
|
|
|
</Spinner.Suspense>
|
2019-09-29 13:23:15 -07:00
|
|
|
</div>
|
2022-06-26 15:13:52 -04:00
|
|
|
<Features enabled={eggFeatures} />
|
2020-08-25 21:39:00 -07:00
|
|
|
</ServerContentBlock>
|
2019-06-29 16:59:50 -07:00
|
|
|
);
|
|
|
|
};
|
2020-10-03 19:36:26 -07:00
|
|
|
|
2022-06-21 18:43:59 -04:00
|
|
|
export default memo(ServerConsoleContainer, isEqual);
|