fix(appstore): data files, надёжность установки/удаления и сворачиваемые диалоги
Доставка файлов приложения из каталога (data_files) до compose up, APP_PASSWORD/default_credentials для Umbrel, сворачивание диалогов долгих операций (MinimizableDialog), фильтрация pull-шума в ошибках. Исправления багов: - teardown: отсутствующий в Proxmox CT считается удалённым — orphaned-приложение теперь можно удалить из БД - install: сдвиг VMID мимо занятых записей (nextid не резервирует номер, retry мог подхватить чужой контейнер) - retry: параметры установки сохраняются в installed_apps.install_params (cores/memory/disk/storage/bridge/ip_config/port_explicit, миграция JSONB) вместо жёстких дефолтов - reconcile: недоступный сервер больше не помечает все приложения orphaned - update: реально опубликованный порт фиксируется в БД (url/health) - .env: значения с '#' кавычатся (dotenv-парсер обрезал их как inline-комментарий) - порт 80, выбранный явно в мастере, публикуется как есть - useCatalog: available_only включён в queryKey (коллизия кэша) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
75
frontend/src/components/shared/MinimizableDialog.tsx
Normal file
75
frontend/src/components/shared/MinimizableDialog.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import { Loader2, Minus, X, CheckCircle2, XCircle } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* Сворачивание модалок с долгими операциями (установка приложения, сборка
|
||||
* золотого шаблона и т.п.): кнопка «Свернуть» в шапке диалога + плавающая
|
||||
* плашка прогресса внизу справа. Родительский компонент диалога остаётся
|
||||
* смонтированным (сворачивание меняет только open у <Dialog>), поэтому
|
||||
* WS-подписки и опросы прогресса продолжают работать.
|
||||
*/
|
||||
|
||||
export function DialogMinimizeButton({ onClick, title }: { onClick: () => void; title: string }) {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="absolute top-2 right-10"
|
||||
onClick={onClick}
|
||||
title={title}
|
||||
>
|
||||
<Minus className="h-4 w-4" />
|
||||
<span className="sr-only">{title}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export type MinimizedStatus = 'idle' | 'running' | 'done' | 'failed';
|
||||
|
||||
interface PillProps {
|
||||
title: string;
|
||||
subtitle?: string | null;
|
||||
progress?: number; // 0..100; undefined → без прогресс-бара
|
||||
status: MinimizedStatus;
|
||||
onRestore: () => void; // клик по плашке — развернуть диалог
|
||||
onClose: () => void; // крестик — закрыть совсем
|
||||
}
|
||||
|
||||
export function MinimizedTaskPill({ title, subtitle, progress, status, onRestore, onClose }: PillProps) {
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
className="fixed bottom-4 right-4 z-50 w-72 cursor-pointer rounded-lg border bg-popover p-3 text-popover-foreground shadow-lg ring-1 ring-foreground/10 transition-colors hover:bg-accent/40"
|
||||
onClick={onRestore}
|
||||
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') onRestore(); }}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{status === 'running' && <Loader2 className="h-4 w-4 shrink-0 animate-spin text-primary" />}
|
||||
{status === 'done' && <CheckCircle2 className="h-4 w-4 shrink-0 text-emerald-600" />}
|
||||
{status === 'failed' && <XCircle className="h-4 w-4 shrink-0 text-destructive" />}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-medium">{title}</div>
|
||||
{subtitle && <div className="truncate text-xs text-muted-foreground">{subtitle}</div>}
|
||||
</div>
|
||||
<Button
|
||||
size="icon-sm"
|
||||
variant="ghost"
|
||||
className="shrink-0"
|
||||
onClick={(e) => { e.stopPropagation(); onClose(); }}
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
{typeof progress === 'number' && (
|
||||
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-muted">
|
||||
<div
|
||||
className={cn('h-full transition-all', status === 'failed' ? 'bg-destructive' : 'bg-primary')}
|
||||
style={{ width: `${Math.max(0, Math.min(100, progress))}%` }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,9 @@ import { useTranslation } from 'react-i18next';
|
||||
import { toast } from 'sonner';
|
||||
import { Loader2, HardDriveDownload, CheckCircle2, XCircle } from 'lucide-react';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog';
|
||||
import {
|
||||
DialogMinimizeButton, MinimizedTaskPill, type MinimizedStatus,
|
||||
} from '@/components/shared/MinimizableDialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -22,6 +25,9 @@ export default function GoldenTemplateDialog({ open, onOpenChange }: Props) {
|
||||
|
||||
const [serverId, setServerId] = useState('');
|
||||
const [node, setNode] = useState('');
|
||||
// Свёрнутое состояние: диалог скрыт, прогресс сборки — в плашке внизу справа.
|
||||
// open остаётся true, поэтому опрос статуса (useGoldenTemplateStatus) продолжается.
|
||||
const [minimized, setMinimized] = useState(false);
|
||||
const [templateStorage, setTemplateStorage] = useState('local');
|
||||
const [rootfsStorage, setRootfsStorage] = useState('local-lvm');
|
||||
const [force, setForce] = useState(false);
|
||||
@@ -67,9 +73,19 @@ export default function GoldenTemplateDialog({ open, onOpenChange }: Props) {
|
||||
);
|
||||
};
|
||||
|
||||
const handleOpenChange = (o: boolean) => {
|
||||
if (!o) setMinimized(false);
|
||||
onOpenChange(o);
|
||||
};
|
||||
|
||||
const pillStatus: MinimizedStatus =
|
||||
running ? 'running' : op?.status === 'completed' ? 'done' : op?.status === 'failed' ? 'failed' : 'idle';
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<>
|
||||
<Dialog open={open && !minimized} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="max-w-lg">
|
||||
<DialogMinimizeButton onClick={() => setMinimized(true)} title={t('appstore.minimize')} />
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<HardDriveDownload className="h-5 w-5 text-primary" />
|
||||
@@ -165,7 +181,7 @@ export default function GoldenTemplateDialog({ open, onOpenChange }: Props) {
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
<Button variant="outline" onClick={() => handleOpenChange(false)}>
|
||||
{t('common.close', 'Закрыть')}
|
||||
</Button>
|
||||
<Button onClick={handleBuild} disabled={!canSubmit}>
|
||||
@@ -177,5 +193,18 @@ export default function GoldenTemplateDialog({ open, onOpenChange }: Props) {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{open && minimized && (
|
||||
<MinimizedTaskPill
|
||||
title={t('appstore.golden.title', 'Золотой LXC-шаблон')}
|
||||
subtitle={op?.status === 'failed'
|
||||
? (op.error_text || t('appstore.golden.failed', 'Ошибка сборки'))
|
||||
: (lastStep || t('appstore.golden.working', 'Выполняется...'))}
|
||||
progress={op ? op.progress : undefined}
|
||||
status={pillStatus}
|
||||
onRestore={() => setMinimized(false)}
|
||||
onClose={() => handleOpenChange(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import { Loader2, CheckCircle2, XCircle, Copy, ExternalLink } from 'lucide-react
|
||||
import {
|
||||
Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter,
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
DialogMinimizeButton, MinimizedTaskPill, type MinimizedStatus,
|
||||
} from '@/components/shared/MinimizableDialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -92,6 +95,9 @@ export default function InstallWizard({ app, open, onOpenChange }: Props) {
|
||||
}, [storages]);
|
||||
|
||||
const [phase, setPhase] = useState<Phase>('form');
|
||||
// Свёрнутое состояние: диалог скрыт, внизу справа — плашка прогресса.
|
||||
// Компонент остаётся смонтированным, поэтому WS/опрос прогресса живут.
|
||||
const [minimized, setMinimized] = useState(false);
|
||||
const [installedAppId, setInstalledAppId] = useState<number | null>(null);
|
||||
const [op, setOp] = useState<AppOperation | null>(null);
|
||||
const [secrets, setSecrets] = useState<Record<string, string>>({});
|
||||
@@ -124,7 +130,7 @@ export default function InstallWizard({ app, open, onOpenChange }: Props) {
|
||||
);
|
||||
|
||||
const reset = () => {
|
||||
setPhase('form'); setOp(null); setInstalledAppId(null); setSecrets({});
|
||||
setPhase('form'); setMinimized(false); setOp(null); setInstalledAppId(null); setSecrets({});
|
||||
setName(app.app_id); setServerId(''); setNode(''); setAnswers({});
|
||||
setAdvanced(false); setCores(2); setMemory(2048); setDisk(8);
|
||||
setStorage('local-lvm'); setBridge('vmbr0');
|
||||
@@ -173,9 +179,21 @@ export default function InstallWizard({ app, open, onOpenChange }: Props) {
|
||||
|
||||
const progress = op?.progress ?? 0;
|
||||
|
||||
// Статус для свёрнутой плашки.
|
||||
const pillStatus: MinimizedStatus =
|
||||
phase === 'progress' ? 'running' : phase === 'done' ? 'done' : phase === 'failed' ? 'failed' : 'idle';
|
||||
const lastStep = op?.steps_log?.length ? op.steps_log[op.steps_log.length - 1].step : null;
|
||||
const pillSubtitle =
|
||||
phase === 'progress' ? (lastStep || t('appstore.installing'))
|
||||
: phase === 'done' ? t('appstore.done')
|
||||
: phase === 'failed' ? t('appstore.install_failed')
|
||||
: null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<>
|
||||
<Dialog open={open && !minimized} onOpenChange={handleClose}>
|
||||
<DialogContent className="max-w-lg">
|
||||
<DialogMinimizeButton onClick={() => setMinimized(true)} title={t('appstore.minimize')} />
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('appstore.install_title', { name: app.name })}</DialogTitle>
|
||||
</DialogHeader>
|
||||
@@ -403,6 +421,17 @@ export default function InstallWizard({ app, open, onOpenChange }: Props) {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{open && minimized && (
|
||||
<MinimizedTaskPill
|
||||
title={t('appstore.install_title', { name: app.name })}
|
||||
subtitle={pillSubtitle}
|
||||
progress={phase === 'progress' || phase === 'failed' ? progress : undefined}
|
||||
status={pillStatus}
|
||||
onRestore={() => setMinimized(false)}
|
||||
onClose={() => handleClose(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { toast } from 'sonner';
|
||||
import {
|
||||
Package, Store, ExternalLink, RotateCw, Trash2, Loader2,
|
||||
Play, Square, RefreshCcw, FileText, ArrowUpCircle, Undo2,
|
||||
Play, Square, RefreshCcw, FileText, ArrowUpCircle, Undo2, KeyRound, Copy,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import {
|
||||
useInstalledApps, useAppstoreRealtime, useRetryApp, useDeleteApp,
|
||||
useLifecycleAction, useReconcile, useAppLogs, useUpdateApp, useRollbackApp,
|
||||
useAppCredentials,
|
||||
} from '@/hooks/use-appstore';
|
||||
import { useConfirm } from '@/components/shared/ConfirmDialog';
|
||||
import type { InstalledApp } from '@/types/appstore';
|
||||
@@ -32,6 +33,7 @@ export default function MyAppsPage() {
|
||||
const update = useUpdateApp();
|
||||
const rollback = useRollbackApp();
|
||||
const [logsApp, setLogsApp] = useState<InstalledApp | null>(null);
|
||||
const [credsApp, setCredsApp] = useState<InstalledApp | null>(null);
|
||||
|
||||
// ТЗ 6.6 — реконсиляция статусов при открытии экрана.
|
||||
useEffect(() => {
|
||||
@@ -178,6 +180,9 @@ export default function MyAppsPage() {
|
||||
<FileText className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
)}
|
||||
<Button size="icon-sm" variant="ghost" title={t('appstore.credentials_btn')} onClick={() => setCredsApp(a)}>
|
||||
<KeyRound className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
{a.update_available && ['running', 'stopped', 'update_failed'].includes(a.status) && (
|
||||
<Button size="icon-sm" variant="ghost" className="text-primary" title={t('appstore.update')} onClick={() => handleUpdate(a)} disabled={busy}>
|
||||
<ArrowUpCircle className="h-3.5 w-3.5" />
|
||||
@@ -208,10 +213,50 @@ export default function MyAppsPage() {
|
||||
)}
|
||||
|
||||
<LogsDialog app={logsApp} onClose={() => setLogsApp(null)} />
|
||||
<CredentialsDialog app={credsApp} onClose={() => setCredsApp(null)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CredentialsDialog({ app, onClose }: { app: InstalledApp | null; onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const { data: creds, isFetching } = useAppCredentials(app?.id ?? 0, !!app);
|
||||
const entries = Object.entries(creds ?? {});
|
||||
|
||||
const copy = (v: string) => {
|
||||
navigator.clipboard.writeText(v);
|
||||
toast.success(t('appstore.copied'));
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={!!app} onOpenChange={(o) => { if (!o) onClose(); }}>
|
||||
<DialogContent className="max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('appstore.credentials_title', { name: app?.name ?? '' })}</DialogTitle>
|
||||
</DialogHeader>
|
||||
{isFetching && !creds ? (
|
||||
<div className="py-8 text-center text-sm text-muted-foreground">{t('appstore.loading')}</div>
|
||||
) : entries.length === 0 ? (
|
||||
<p className="py-4 text-sm text-muted-foreground">{t('appstore.no_credentials')}</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<p className="text-xs text-muted-foreground">{t('appstore.credentials_hint')}</p>
|
||||
{entries.map(([k, v]) => (
|
||||
<div key={k} className="flex items-center gap-2 rounded-md border bg-muted/40 px-3 py-2">
|
||||
<span className="font-mono text-xs text-muted-foreground">{k}</span>
|
||||
<span className="ml-auto truncate font-mono text-sm">{v}</span>
|
||||
<Button size="icon-sm" variant="ghost" title={t('appstore.copy')} onClick={() => copy(v)}>
|
||||
<Copy className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function LogsDialog({ app, onClose }: { app: InstalledApp | null; onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const { data: logs, isFetching, refetch } = useAppLogs(app?.id ?? 0, !!app);
|
||||
|
||||
@@ -8,8 +8,8 @@ import type {
|
||||
} from '@/types/appstore';
|
||||
|
||||
export const appstoreKeys = {
|
||||
catalog: (q?: string, category?: string, source?: string) =>
|
||||
['appstore-catalog', q ?? '', category ?? '', source ?? ''] as const,
|
||||
catalog: (q?: string, category?: string, source?: string, availableOnly = false) =>
|
||||
['appstore-catalog', q ?? '', category ?? '', source ?? '', availableOnly] as const,
|
||||
catalogMeta: ['appstore-catalog-meta'] as const,
|
||||
catalogApp: (id: string) => ['appstore-catalog-app', id] as const,
|
||||
installed: ['appstore-installed'] as const,
|
||||
@@ -27,7 +27,7 @@ export function useCatalog(q?: string, category?: string, source?: string, avail
|
||||
if (availableOnly) params.set('available_only', 'true');
|
||||
const qs = params.toString();
|
||||
return useQuery({
|
||||
queryKey: appstoreKeys.catalog(q, category, source),
|
||||
queryKey: appstoreKeys.catalog(q, category, source, availableOnly),
|
||||
queryFn: () => apiClient.get<CatalogListResponse>(`/api/appstore/catalog${qs ? `?${qs}` : ''}`),
|
||||
});
|
||||
}
|
||||
@@ -201,6 +201,17 @@ export function useReconcile() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useAppCredentials(id: number, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: ['appstore-credentials', id],
|
||||
queryFn: () =>
|
||||
apiClient.get<{ credentials: Record<string, string> }>(`/api/appstore/apps/${id}/credentials`)
|
||||
.then((r) => r.credentials),
|
||||
enabled: enabled && id > 0,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useAppLogs(id: number, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: ['appstore-logs', id],
|
||||
|
||||
@@ -139,6 +139,11 @@
|
||||
"installing": "Installing…",
|
||||
"install_started": "Installation started",
|
||||
"credentials": "Credentials (shown once — copy them now)",
|
||||
"credentials_title": "Credentials — {{name}}",
|
||||
"credentials_btn": "Credentials",
|
||||
"no_credentials": "No stored credentials for this app. Check the app logs or its documentation.",
|
||||
"credentials_hint": "Default login and password from the catalog plus secrets generated at install time. Change the password in the app after first login.",
|
||||
"minimize": "Minimize",
|
||||
"copy": "Copy",
|
||||
"copied": "Copied",
|
||||
"done": "Done",
|
||||
|
||||
@@ -139,6 +139,11 @@
|
||||
"installing": "Установка…",
|
||||
"install_started": "Установка запущена",
|
||||
"credentials": "Учётные данные (показаны один раз — скопируйте сейчас)",
|
||||
"credentials_title": "Учётные данные — {{name}}",
|
||||
"credentials_btn": "Учётные данные",
|
||||
"no_credentials": "Для этого приложения нет сохранённых учётных данных. Проверьте логи приложения или его документацию.",
|
||||
"credentials_hint": "Логин и пароль по умолчанию из каталога и секреты, сгенерированные при установке. После первого входа смените пароль в самом приложении.",
|
||||
"minimize": "Свернуть",
|
||||
"copy": "Копировать",
|
||||
"copied": "Скопировано",
|
||||
"done": "Готово",
|
||||
|
||||
Reference in New Issue
Block a user