import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid"; import { ruRU } from "@mui/x-data-grid/locales"; import { languageStore, snapshotStore } from "@shared"; import { useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { DatabaseBackup, Trash2 } from "lucide-react"; import { CreateButton, DeleteModal, SnapshotRestore } from "@widgets"; import { Box, CircularProgress } from "@mui/material"; export const SnapshotListPage = observer(() => { const { snapshots, getSnapshots, deleteSnapshot, restoreSnapshot } = snapshotStore; const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [rowId, setRowId] = useState(null); // Lifted state const { language } = languageStore; const [isRestoreModalOpen, setIsRestoreModalOpen] = useState(false); const [isLoading, setIsLoading] = useState(false); useEffect(() => { const fetchSnapshots = async () => { setIsLoading(true); await getSnapshots(); setIsLoading(false); }; fetchSnapshots(); }, [language]); const columns: GridColDef[] = [ { field: "name", headerName: "Название", flex: 1, }, { field: "parent", headerName: "Родитель", flex: 1, }, { field: "actions", headerName: "Действия", width: 300, headerAlign: "center", renderCell: (params: GridRenderCellParams) => { return (
); }, }, ]; const rows = snapshots.map((snapshot) => ({ id: snapshot.ID, name: snapshot.Name, parent: snapshots.find((s) => s.ID === snapshot.ParentID)?.Name, })); return ( <>

Снапшоты

( {isLoading ? : "Нет снапшотов"} ), }} />
{ if (rowId) { await deleteSnapshot(rowId); } setIsDeleteModalOpen(false); setRowId(null); }} onCancel={() => { setIsDeleteModalOpen(false); setRowId(null); }} /> { setIsLoading(true); if (rowId) { await restoreSnapshot(rowId); } setIsRestoreModalOpen(false); setRowId(null); setIsLoading(false); }} onCancel={() => { setIsRestoreModalOpen(false); setRowId(null); }} /> ); });