diff --git a/resources/scripts/api/server/getServer.ts b/resources/scripts/api/server/getServer.ts index 959149f9d..30dc0b2ff 100644 --- a/resources/scripts/api/server/getServer.ts +++ b/resources/scripts/api/server/getServer.ts @@ -1,6 +1,6 @@ import http, { FractalResponseData, FractalResponseList } from '@/api/http'; import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers'; -import { ServerEggVariable } from '@/api/server/types'; +import { ServerEggVariable, ServerStatus } from '@/api/server/types'; export interface Allocation { id: number; @@ -17,6 +17,7 @@ export interface Server { uuid: string; name: string; node: string; + status: ServerStatus; sftpDetails: { ip: string; port: number; @@ -38,6 +39,10 @@ export interface Server { allocations: number; backups: number; }; + // Only isSuspended got marked as deprecated since the isInstalling is a nice helper + // since you'd have to check multiple potential values for that. isSuspended should + // be replaced with status !== 'suspended'. + /** @deprecated */ isSuspended: boolean; isInstalling: boolean; isTransferring: boolean; @@ -51,6 +56,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData) uuid: data.uuid, name: data.name, node: data.node, + status: data.status, invocation: data.invocation, dockerImage: data.docker_image, sftpDetails: { @@ -61,8 +67,8 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData) limits: { ...data.limits }, eggFeatures: data.egg_features || [], featureLimits: { ...data.feature_limits }, - isSuspended: data.is_suspended, - isInstalling: data.is_installing, + isSuspended: data.status === 'suspended', + isInstalling: data.status === 'installing' || data.status === 'install_failed', isTransferring: data.is_transferring, variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerEggVariable), allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(rawDataToServerAllocation), diff --git a/resources/scripts/api/server/types.d.ts b/resources/scripts/api/server/types.d.ts index b37fae402..dd871162c 100644 --- a/resources/scripts/api/server/types.d.ts +++ b/resources/scripts/api/server/types.d.ts @@ -1,3 +1,5 @@ +export type ServerStatus = 'installing' | 'install_failed' | 'suspended' | 'restoring_backup' | null; + export interface ServerBackup { uuid: string; isSuccessful: boolean; diff --git a/resources/scripts/components/dashboard/ServerRow.tsx b/resources/scripts/components/dashboard/ServerRow.tsx index 7db977311..017f933b2 100644 --- a/resources/scripts/components/dashboard/ServerRow.tsx +++ b/resources/scripts/components/dashboard/ServerRow.tsx @@ -41,7 +41,7 @@ const StatusIndicatorBox = styled(GreyRowBox)<{ $status: ServerPowerState | unde export default ({ server, className }: { server: Server; className?: string }) => { const interval = useRef(null); - const [ isSuspended, setIsSuspended ] = useState(server.isSuspended); + const [ isSuspended, setIsSuspended ] = useState(server.status === 'suspended'); const [ stats, setStats ] = useState(null); const getStats = () => getServerResourceUsage(server.uuid) @@ -49,8 +49,8 @@ export default ({ server, className }: { server: Server; className?: string }) = .catch(error => console.error(error)); useEffect(() => { - setIsSuspended(stats?.isSuspended || server.isSuspended); - }, [ stats?.isSuspended, server.isSuspended ]); + setIsSuspended(stats?.isSuspended || server.status === 'suspended'); + }, [ stats?.isSuspended, server.status ]); useEffect(() => { // Don't waste a HTTP request if there is nothing important to show to the user because @@ -107,7 +107,7 @@ export default ({ server, className }: { server: Server; className?: string }) = isSuspended ?
- {server.isSuspended ? 'Suspended' : 'Connection Error'} + {server.status === 'suspended' ? 'Suspended' : 'Connection Error'}
: