Files
Reims-Go/frontend/src/components/CreatingVMView.tsx
T

72 lines
2.6 KiB
TypeScript

import { LoaderCircle, Terminal, X } from 'lucide-react'
import React from 'react'
import '../i18n/domains/vm.gen'
import { I18nKey, t } from '../i18n'
import { taskDetail, taskTitle } from '../lib/tasks'
import { Locale, Task } from '../types'
import { Button, StatusShape } from '../ui/controls'
interface Props {
locale: Locale
name: string
task?: Task
onCancel?: (taskId: string) => void
onViewLogs: () => void
}
export const CreatingVMView: React.FC<Props> = ({ locale, name, task, onCancel, onViewLogs }) => {
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
const percent = task && typeof task.percent === 'number' ? task.percent : -1
const detail = task ? taskDetail(task) : ''
const stepText = task?.step?.trim() || tr('creatingPreparing')
const heading = task ? taskTitle(locale, task) : tr('taskCreate', { name })
return (
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">{name}</h1>
<div className="page-sub hstack">
<StatusShape kind="busy" />
<span>{tr('state_creating')}</span>
</div>
</div>
<div className="hstack">
<Button variant="ghost" icon={<Terminal size={14} aria-hidden="true" />} onClick={onViewLogs}>
{tr('viewLogs')}
</Button>
{task?.cancelable && onCancel && (
<Button variant="secondary" icon={<X size={14} aria-hidden="true" />} onClick={() => onCancel(task.id)}>
{tr('cancelCreate')}
</Button>
)}
</div>
</div>
<section className="section">
<div className="section-title">{tr('creatingProgressTitle')}</div>
<div className="list">
<div className="row creating-row">
<div className="creating-head">
<span className="row-title hstack">
<LoaderCircle size={15} className="spin" aria-hidden="true" />
<span>{heading}</span>
</span>
{percent >= 0 && <span className="task-pct mono">{Math.floor(percent)}%</span>}
</div>
{percent >= 0 && (
<span className="progress rg-p-progress creating-progress" aria-hidden="true">
<span className="progress-fill" style={{ transform: `scaleX(${Math.max(0, Math.min(1, percent / 100))})` }} />
</span>
)}
<div className="row-sub">
{stepText}
{detail ? ` · ${detail}` : ''}
</div>
</div>
</div>
</section>
</div>
)
}