diff --git a/frontend/app/maintenance/page.tsx b/frontend/app/maintenance/page.tsx index 000a341..6fbd7b1 100644 --- a/frontend/app/maintenance/page.tsx +++ b/frontend/app/maintenance/page.tsx @@ -6,6 +6,8 @@ import { useForm } from "react-hook-form"; import { AlertCircle, CheckCircle2, + ChevronLeft, + ChevronRight, Database, Filter, ListChecks, @@ -33,6 +35,7 @@ import { type MaintenanceActionResult, type MutationRequest, type ReindexRequest, + type SqlResult, type TableMaintenance, type TableSummary, type VacuumRequest, @@ -74,6 +77,8 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; const LONG_ACTION_TIMEOUT_MS = 30 * 60 * 1000; const REPORT_LIMIT = 5000; +/** Rows per page in the table maintenance list; keeps the grid responsive. */ +const TABLE_PAGE_SIZE = 100; const CELL = "px-2 py-1.5 text-xs"; const HEAD = "h-8 px-2 text-xs"; @@ -134,6 +139,9 @@ function deadTone(percent: number): string { /** Stable identity for a report row; also the selection key. */ const tableKey = (row: TableMaintenance) => `${row.schema_name ?? ""}.${row.table_name}`; +/** Stable identity for a schema table row; also its selection key. */ +const summaryKey = (row: TableSummary) => `${row.schema_name}.${row.table_name}`; + const RISKY_STATUSES: TableMaintenance["status"][] = ["WARNING", "CRITICAL"]; /** Table status filter; "ALL" shows everything. */ @@ -192,6 +200,7 @@ export default function MaintenancePage() { const [tab, setTab] = useState("vacuum"); // Only a status filter is offered, per request: OK / WARNING / CRITICAL. const [statusFilter, setStatusFilter] = useState("ALL"); + const [pageIndex, setPageIndex] = useState(0); const op = useOpControl(); // The batch run loops over many tables, so it tracks its own operation. const batchOp = useOpControl(); @@ -393,6 +402,16 @@ export default function MaintenancePage() { [tables, statusFilter] ); + const pageCount = Math.max(1, Math.ceil(visibleTables.length / TABLE_PAGE_SIZE)); + const pagedTables = useMemo( + () => visibleTables.slice(pageIndex * TABLE_PAGE_SIZE, (pageIndex + 1) * TABLE_PAGE_SIZE), + [visibleTables, pageIndex] + ); + // Keep the page index valid when the filter shrinks the list. + useEffect(() => { + setPageIndex((current) => (current > pageCount - 1 ? pageCount - 1 : current)); + }, [pageCount]); + const runningLabel = ( <> @@ -622,8 +641,18 @@ export default function MaintenancePage() { )} -
- +
+ VACUUM ANALYZE @@ -871,12 +900,16 @@ export default function MaintenancePage() {
- +
+ {/* The health tab carries its own bulk actions, so the legacy + "Tablo bakım durumu" panel is hidden while it is open. */} + {tab !== "health" && ( + <> {batchRows && batchRows.length > 0 && (
@@ -948,7 +981,10 @@ export default function MaintenancePage() { {tables.length > 0 && ( {schema && ( - - {t("maintenance.health.summary", { - tables: formatNumber(tables.length), - size: formatBytes(totalSize, 1), - })} - + <> + + {t("maintenance.health.summary", { + tables: formatNumber(tables.length), + size: formatBytes(totalSize, 1), + })} + + + {t("maintenance.health.indexSizeTotal")}: {formatBytes(totalIndexSize, 1)} + + + {t("maintenance.health.unusedSizeTotal")}: {formatBytes(totalUnusedIndexSize, 1)} + + )}
+
+ + +
+ + + + + + {bulkBusy && ( + <> + + {t("maintenance.health.batch.running", { + done: doneCount, + total: batchRows?.length ?? 0, + })} + + + + )} +
+ + +
+ + 0 ? "indeterminate" : false} + onCheckedChange={(value) => (value ? selectAll() : selectNone())} + /> + {t("maintenance.health.columns.table")} {t("maintenance.health.columns.total")} @@ -1408,7 +1817,7 @@ function TableHealthTab({ op }: { op: OpControl }) { {tables.map((row) => { - const key = `${row.schema_name}.${row.table_name}`; + const key = summaryKey(row); const isSelected = key === selectedKey; return ( setSelectedKey(isSelected ? "" : key)} > + event.stopPropagation()}> + toggleSelect(key)} + /> + {row.schema_name}. {row.table_name} @@ -1471,11 +1887,72 @@ function TableHealthTab({ op }: { op: OpControl }) { })}
+
+ + )} + + {batchRows && batchRows.length > 0 && ( +
+
+
+

+ + {t("maintenance.health.batch.resultsTitle")} +

+

+ {t("maintenance.health.batch.resultsHint")} +

+
+
+ + {t("maintenance.batch.summary", { ok: okCount, failed: failedCount })} + + {stoppedCount > 0 && ( + + {t("maintenance.batch.statusStopped")}: {formatNumber(stoppedCount)} + + )} + +
+
+ +
+ + + + {t("maintenance.table.status")} + {t("maintenance.table.table")} + {t("maintenance.result")} + + + + {batchRows.map((row) => ( + + + + + {row.label} + + {row.detail || "—"} + + + ))} + +
+
)} {selected ? ( -
+

diff --git a/frontend/lib/hooks/useConfirm.tsx b/frontend/lib/hooks/useConfirm.tsx index 84d8208..8f6e233 100644 --- a/frontend/lib/hooks/useConfirm.tsx +++ b/frontend/lib/hooks/useConfirm.tsx @@ -32,6 +32,8 @@ export interface ConfirmOptions { title: string; description: string; sql_preview?: string[]; + /** When true the SQL preview becomes an editable textarea (see ConfirmResult.sql). */ + sql_editable?: boolean; risk_level: ConfirmRiskLevel; confirm_label?: string; cancel_label?: string; @@ -41,12 +43,18 @@ export interface ConfirmOptions { confirm_name_description?: string; } +export interface ConfirmResult { + confirmed: boolean; + /** The (possibly edited) SQL when ``sql_editable`` is set, otherwise null. */ + sql: string | null; +} + interface DialogState { open: boolean; options: ConfirmOptions | null; } -let globalResolver: ((value: boolean) => void) | null = null; +let globalResolver: ((value: ConfirmResult) => void) | null = null; export function useConfirm() { const [dialogState, setDialogState] = React.useState({ @@ -54,27 +62,42 @@ export function useConfirm() { options: null, }); const [confirmNameInput, setConfirmNameInput] = React.useState(""); + const [sqlDraft, setSqlDraft] = React.useState(""); + // Read inside stable callbacks so they never capture stale options/draft. + const optionsRef = React.useRef(null); + optionsRef.current = dialogState.options; + const sqlDraftRef = React.useRef(""); + sqlDraftRef.current = sqlDraft; const close = React.useCallback((result: boolean) => { + const sql = optionsRef.current?.sql_editable ? sqlDraftRef.current : null; setDialogState({ open: false, options: null }); setConfirmNameInput(""); + setSqlDraft(""); if (globalResolver) { - globalResolver(result); + globalResolver({ confirmed: result, sql }); globalResolver = null; } }, []); - const confirm = React.useCallback( - (options: ConfirmOptions): Promise => { - return new Promise((resolve) => { + const confirmSql = React.useCallback( + (options: ConfirmOptions): Promise => { + return new Promise((resolve) => { globalResolver = resolve; setConfirmNameInput(""); + setSqlDraft((options.sql_preview ?? []).join("\n\n")); setDialogState({ open: true, options }); }); }, [] ); + const confirm = React.useCallback( + (options: ConfirmOptions): Promise => + confirmSql(options).then((result) => result.confirmed), + [confirmSql] + ); + const handleCancel = React.useCallback(() => { close(false); }, [close]); @@ -184,18 +207,33 @@ export function useConfirm() {
- SQL Onizlemesi -
-
- {opts.sql_preview.map((sql, idx) => ( -
-                    {sql}
-                  
- ))} + {tGlobal("common.sqlPreview")} + {opts.sql_editable && ( + + {tGlobal("common.sqlEditableHint")} + + )}
+ {opts.sql_editable ? ( +