2026-10-05 18:10:18 -04:00
|
|
|
import { useCurrentServer } from '@/api/server/queries';
|
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';
|
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';
|
2026-10-05 18:10:18 -04:00
|
|
|
import Slot from '@/extensions/Slot';
|
2019-09-17 22:33:14 -07:00
|
|
|
|
2026-10-08 16:53:20 -04:00
|
|
|
const getUnavailableMessage = (
|
|
|
|
|
isNodeUnderMaintenance: boolean,
|
|
|
|
|
isInstalling: boolean,
|
|
|
|
|
isTransferring: boolean
|
|
|
|
|
): string | null => {
|
|
|
|
|
if (isNodeUnderMaintenance) {
|
|
|
|
|
return 'The node of this server is currently under maintenance and all actions are unavailable.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isInstalling) {
|
|
|
|
|
return 'This server is currently running its installation process and most actions are unavailable.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isTransferring) {
|
|
|
|
|
return 'This server is currently being transferred to another node and all actions are unavailable.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
const ServerConsoleContainer = ({ active = true }: { active?: boolean }) => {
|
|
|
|
|
const server = useCurrentServer()!;
|
|
|
|
|
const name = server.attributes.name;
|
|
|
|
|
const description = server.attributes.description;
|
|
|
|
|
const isInstalling = server.attributes.status === 'installing' || server.attributes.status === 'install_failed';
|
|
|
|
|
const isTransferring = server.attributes.is_transferring;
|
|
|
|
|
const eggFeatures = server.attributes.egg_features;
|
|
|
|
|
const isNodeUnderMaintenance = server.attributes.is_node_under_maintenance;
|
2026-10-08 16:53:20 -04:00
|
|
|
const unavailableMessage = getUnavailableMessage(isNodeUnderMaintenance, isInstalling, isTransferring);
|
2020-05-16 03:16:06 -04:00
|
|
|
|
2019-06-29 16:59:50 -07:00
|
|
|
return (
|
2026-10-05 18:10:18 -04:00
|
|
|
<ServerContentBlock title={active ? 'Console' : undefined}>
|
2026-10-08 16:53:20 -04:00
|
|
|
{unavailableMessage && (
|
|
|
|
|
<Alert type='warning' className='mb-4'>
|
|
|
|
|
{unavailableMessage}
|
2022-06-27 20:36:24 -04:00
|
|
|
</Alert>
|
|
|
|
|
)}
|
2026-10-08 16:53:20 -04:00
|
|
|
<Slot name='server.console.before' data={server} />
|
|
|
|
|
<div className='grid grid-cols-4 gap-4 mb-4'>
|
|
|
|
|
<div className='hidden sm:block sm:col-span-2 lg:col-span-3 pr-4'>
|
|
|
|
|
<h1 className='font-header font-medium text-2xl text-foreground leading-relaxed line-clamp-1'>
|
2025-12-20 16:37:54 -08:00
|
|
|
{name}
|
|
|
|
|
</h1>
|
2026-10-08 16:53:20 -04:00
|
|
|
<p className='text-sm line-clamp-2'>{description}</p>
|
2022-06-20 17:26:47 -04:00
|
|
|
</div>
|
2026-10-08 16:53:20 -04:00
|
|
|
<div className='col-span-4 sm:col-span-2 lg:col-span-1 self-end'>
|
|
|
|
|
<Slot name='server.console.power.before' data={server} />
|
2022-06-26 15:13:52 -04:00
|
|
|
<Can action={['control.start', 'control.stop', 'control.restart']} matchAny>
|
2026-10-08 16:53:20 -04:00
|
|
|
<PowerButtons className='flex sm:justify-end space-x-2' />
|
2022-06-20 17:26:47 -04:00
|
|
|
</Can>
|
2026-10-08 16:53:20 -04:00
|
|
|
<Slot name='server.console.power.after' data={server} />
|
2022-06-20 17:26:47 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-10-08 16:53:20 -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>
|
2026-10-08 16:53:20 -04:00
|
|
|
<ServerDetailsBlock className='col-span-4 lg:col-span-1 order-last lg:order-0' />
|
2019-09-17 21:59:35 -07:00
|
|
|
</div>
|
2026-10-08 16:53:20 -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>
|
2026-10-08 16:53:20 -04:00
|
|
|
<Slot name='server.console.after' data={server} />
|
2026-10-05 18:10:18 -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
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
export default ServerConsoleContainer;
|