Update typescript bindings with new status field
This commit is contained in:
parent
8db3a05498
commit
805952ac38
3 changed files with 15 additions and 7 deletions
|
@ -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),
|
||||
|
|
2
resources/scripts/api/server/types.d.ts
vendored
2
resources/scripts/api/server/types.d.ts
vendored
|
@ -1,3 +1,5 @@
|
|||
export type ServerStatus = 'installing' | 'install_failed' | 'suspended' | 'restoring_backup' | null;
|
||||
|
||||
export interface ServerBackup {
|
||||
uuid: string;
|
||||
isSuccessful: boolean;
|
||||
|
|
|
@ -41,7 +41,7 @@ const StatusIndicatorBox = styled(GreyRowBox)<{ $status: ServerPowerState | unde
|
|||
|
||||
export default ({ server, className }: { server: Server; className?: string }) => {
|
||||
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 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 ?
|
||||
<div css={tw`flex-1 text-center`}>
|
||||
<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>
|
||||
</div>
|
||||
:
|
||||
|
|
Loading…
Reference in a new issue