1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 17:12:30 +01:00

Update typescript bindings with new status field

This commit is contained in:
Dane Everitt 2021-01-17 16:13:49 -08:00
parent 8db3a05498
commit 805952ac38
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 15 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import http, { FractalResponseData, FractalResponseList } from '@/api/http'; import http, { FractalResponseData, FractalResponseList } from '@/api/http';
import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers'; import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers';
import { ServerEggVariable } from '@/api/server/types'; import { ServerEggVariable, ServerStatus } from '@/api/server/types';
export interface Allocation { export interface Allocation {
id: number; id: number;
@ -17,6 +17,7 @@ export interface Server {
uuid: string; uuid: string;
name: string; name: string;
node: string; node: string;
status: ServerStatus;
sftpDetails: { sftpDetails: {
ip: string; ip: string;
port: number; port: number;
@ -38,6 +39,10 @@ export interface Server {
allocations: number; allocations: number;
backups: 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; isSuspended: boolean;
isInstalling: boolean; isInstalling: boolean;
isTransferring: boolean; isTransferring: boolean;
@ -51,6 +56,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
uuid: data.uuid, uuid: data.uuid,
name: data.name, name: data.name,
node: data.node, node: data.node,
status: data.status,
invocation: data.invocation, invocation: data.invocation,
dockerImage: data.docker_image, dockerImage: data.docker_image,
sftpDetails: { sftpDetails: {
@ -61,8 +67,8 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
limits: { ...data.limits }, limits: { ...data.limits },
eggFeatures: data.egg_features || [], eggFeatures: data.egg_features || [],
featureLimits: { ...data.feature_limits }, featureLimits: { ...data.feature_limits },
isSuspended: data.is_suspended, isSuspended: data.status === 'suspended',
isInstalling: data.is_installing, isInstalling: data.status === 'installing' || data.status === 'install_failed',
isTransferring: data.is_transferring, isTransferring: data.is_transferring,
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerEggVariable), variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerEggVariable),
allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(rawDataToServerAllocation), allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(rawDataToServerAllocation),

View File

@ -1,3 +1,5 @@
export type ServerStatus = 'installing' | 'install_failed' | 'suspended' | 'restoring_backup' | null;
export interface ServerBackup { export interface ServerBackup {
uuid: string; uuid: string;
isSuccessful: boolean; isSuccessful: boolean;

View File

@ -41,7 +41,7 @@ const StatusIndicatorBox = styled(GreyRowBox)<{ $status: ServerPowerState | unde
export default ({ server, className }: { server: Server; className?: string }) => { export default ({ server, className }: { server: Server; className?: string }) => {
const interval = useRef<number>(null); const interval = useRef<number>(null);
const [ isSuspended, setIsSuspended ] = useState(server.isSuspended); const [ isSuspended, setIsSuspended ] = useState(server.status === 'suspended');
const [ stats, setStats ] = useState<ServerStats | null>(null); const [ stats, setStats ] = useState<ServerStats | null>(null);
const getStats = () => getServerResourceUsage(server.uuid) const getStats = () => getServerResourceUsage(server.uuid)
@ -49,8 +49,8 @@ export default ({ server, className }: { server: Server; className?: string }) =
.catch(error => console.error(error)); .catch(error => console.error(error));
useEffect(() => { useEffect(() => {
setIsSuspended(stats?.isSuspended || server.isSuspended); setIsSuspended(stats?.isSuspended || server.status === 'suspended');
}, [ stats?.isSuspended, server.isSuspended ]); }, [ stats?.isSuspended, server.status ]);
useEffect(() => { useEffect(() => {
// Don't waste a HTTP request if there is nothing important to show to the user because // 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 ? isSuspended ?
<div css={tw`flex-1 text-center`}> <div css={tw`flex-1 text-center`}>
<span css={tw`bg-red-500 rounded px-2 py-1 text-red-100 text-xs`}> <span css={tw`bg-red-500 rounded px-2 py-1 text-red-100 text-xs`}>
{server.isSuspended ? 'Suspended' : 'Connection Error'} {server.status === 'suspended' ? 'Suspended' : 'Connection Error'}
</span> </span>
</div> </div>
: :