Skip to content

Commit bd278b2

Browse files
committed
Fix install warning display and make it reactive
1 parent 2dda151 commit bd278b2

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

resources/scripts/api/server/getServer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export interface Server {
3939
allocations: number;
4040
backups: number;
4141
};
42-
isInstalling: boolean;
4342
isTransferring: boolean;
4443
variables: ServerEggVariable[];
4544
allocations: Allocation[];
@@ -62,7 +61,6 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
6261
limits: { ...data.limits },
6362
eggFeatures: data.egg_features || [],
6463
featureLimits: { ...data.feature_limits },
65-
isInstalling: data.status === 'installing' || data.status === 'install_failed',
6664
isTransferring: data.is_transferring,
6765
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
6866
rawDataToServerEggVariable
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ExclamationIcon } from '@heroicons/react/outline';
2+
import React from 'react';
3+
import classNames from 'classnames';
4+
5+
interface AlertProps {
6+
type: 'warning';
7+
className?: string;
8+
children: React.ReactNode;
9+
}
10+
11+
export default ({ className, children }: AlertProps) => {
12+
return (
13+
<div
14+
className={classNames(
15+
'flex items-center border-l-8 border-yellow-500 text-gray-50 bg-yellow-500/25 rounded-md shadow px-4 py-3',
16+
className
17+
)}
18+
>
19+
<ExclamationIcon className={'w-6 h-6 text-yellow-500 mr-2'} />
20+
{children}
21+
</div>
22+
);
23+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Alert } from './Alert';

resources/scripts/components/server/console/ServerConsoleContainer.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React, { memo } from 'react';
22
import { ServerContext } from '@/state/server';
33
import Can from '@/components/elements/Can';
4-
import ContentContainer from '@/components/elements/ContentContainer';
5-
import tw from 'twin.macro';
64
import ServerContentBlock from '@/components/elements/ServerContentBlock';
75
import isEqual from 'react-fast-compare';
86
import Spinner from '@/components/elements/Spinner';
@@ -11,18 +9,26 @@ import Console from '@/components/server/console/Console';
119
import StatGraphs from '@/components/server/console/StatGraphs';
1210
import PowerButtons from '@/components/server/console/PowerButtons';
1311
import ServerDetailsBlock from '@/components/server/console/ServerDetailsBlock';
12+
import { Alert } from '@/components/elements/alert';
1413

1514
export type PowerAction = 'start' | 'stop' | 'restart' | 'kill';
1615

1716
const ServerConsoleContainer = () => {
1817
const name = ServerContext.useStoreState((state) => state.server.data!.name);
1918
const description = ServerContext.useStoreState((state) => state.server.data!.description);
20-
const isInstalling = ServerContext.useStoreState((state) => state.server.data!.isInstalling);
19+
const isInstalling = ServerContext.useStoreState((state) => state.server.isInstalling);
2120
const isTransferring = ServerContext.useStoreState((state) => state.server.data!.isTransferring);
2221
const eggFeatures = ServerContext.useStoreState((state) => state.server.data!.eggFeatures, isEqual);
2322

2423
return (
2524
<ServerContentBlock title={'Console'} className={'flex flex-col gap-2 sm:gap-4'}>
25+
{(isInstalling || isTransferring) && (
26+
<Alert type={'warning'}>
27+
{isInstalling
28+
? 'This server is currently running its installation process and most actions are unavailable.'
29+
: 'This server is currently being transferred to another node and all actions are unavailable.'}
30+
</Alert>
31+
)}
2632
<div className={'grid grid-cols-4 gap-4'}>
2733
<div className={'hidden sm:block sm:col-span-2 lg:col-span-3 pr-4'}>
2834
<h1 className={'font-header text-2xl text-gray-50 leading-relaxed line-clamp-1'}>{name}</h1>
@@ -41,25 +47,6 @@ const ServerConsoleContainer = () => {
4147
</Spinner.Suspense>
4248
</div>
4349
<ServerDetailsBlock className={'col-span-4 lg:col-span-1 order-last lg:order-none'} />
44-
{isInstalling ? (
45-
<div css={tw`mt-4 rounded bg-yellow-500 p-3`}>
46-
<ContentContainer>
47-
<p css={tw`text-sm text-yellow-900`}>
48-
This server is currently running its installation process and most actions are
49-
unavailable.
50-
</p>
51-
</ContentContainer>
52-
</div>
53-
) : isTransferring ? (
54-
<div css={tw`mt-4 rounded bg-yellow-500 p-3`}>
55-
<ContentContainer>
56-
<p css={tw`text-sm text-yellow-900`}>
57-
This server is currently being transferred to another node and all actions are
58-
unavailable.
59-
</p>
60-
</ContentContainer>
61-
</div>
62-
) : null}
6350
</div>
6451
<div className={'grid grid-cols-1 md:grid-cols-3 gap-2 sm:gap-4'}>
6552
<Spinner.Suspense>

resources/scripts/state/server/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type ServerStatus = 'offline' | 'starting' | 'stopping' | 'running' | nul
1313
interface ServerDataStore {
1414
data?: Server;
1515
inConflictState: Computed<ServerDataStore, boolean>;
16+
isInstalling: Computed<ServerDataStore, boolean>;
17+
isTransferring: Computed<ServerDataStore, boolean>;
1618
permissions: string[];
1719

1820
getServer: Thunk<ServerDataStore, string, Record<string, unknown>, ServerStore, Promise<void>>;
@@ -32,6 +34,10 @@ const server: ServerDataStore = {
3234
return state.data.status !== null || state.data.isTransferring;
3335
}),
3436

37+
isInstalling: computed((state) => {
38+
return state.data?.status === 'installing' || state.data?.status === 'install_failed';
39+
}),
40+
3541
getServer: thunk(async (actions, payload) => {
3642
const [server, permissions] = await getServer(payload);
3743

0 commit comments

Comments
 (0)