From e2ed4ffdbf9f741bcd9a3908b16678e4f4d4f95b Mon Sep 17 00:00:00 2001 From: Aziz ARSLAN Date: Wed, 4 Nov 2026 17:45:50 +0300 Subject: [PATCH 1/9] chore(i18n): add bulk table health and editable SQL strings --- frontend/messages/en/common.json | 4 +++- frontend/messages/en/operate.json | 16 ++++++++++++++++ frontend/messages/tr/common.json | 4 +++- frontend/messages/tr/operate.json | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/frontend/messages/en/common.json b/frontend/messages/en/common.json index e05e2d8..a71871b 100644 --- a/frontend/messages/en/common.json +++ b/frontend/messages/en/common.json @@ -15,7 +15,9 @@ "retry": "Retry", "loading": "Loading...", "noData": "No records", - "loadFailed": "Could not load data" + "loadFailed": "Could not load data", + "sqlPreview": "SQL preview", + "sqlEditableHint": "Editable; the SQL you leave here is what runs" }, "api": { "sessionExpired": "Your session has expired, please sign in again.", diff --git a/frontend/messages/en/operate.json b/frontend/messages/en/operate.json index 91aab7e..9dd990d 100644 --- a/frontend/messages/en/operate.json +++ b/frontend/messages/en/operate.json @@ -149,6 +149,22 @@ "empty": "No unused indexes.", "scans": "Scans", "reindex": "REINDEX INDEX" + }, + "batch": { + "selected": "Selected: {count}", + "thresholdLabel": "Critical threshold (dead %)", + "thresholdInvalid": "Enter a valid threshold value.", + "selectCritical": "Select critical", + "noCritical": "No table exceeds the {threshold}% threshold.", + "running": "Applying · {done}/{total}", + "andMore": "+{count} more tables", + "apply": "Run {command}", + "confirmTitle": "Run {command} on {count} tables?", + "confirmDesc": "{command} will be applied to the selected tables.", + "confirmDescFull": "{command} will be applied to the selected tables. Each table takes an ACCESS EXCLUSIVE LOCK; run it during low traffic.", + "noSelection": "Select at least one table from the list first.", + "resultsTitle": "Bulk action result", + "resultsHint": "Tables processed and their command results" } } }, diff --git a/frontend/messages/tr/common.json b/frontend/messages/tr/common.json index 747984e..994fc65 100644 --- a/frontend/messages/tr/common.json +++ b/frontend/messages/tr/common.json @@ -15,7 +15,9 @@ "retry": "Tekrar dene", "loading": "Yükleniyor...", "noData": "Kayıt yok", - "loadFailed": "Veri alınamadı" + "loadFailed": "Veri alınamadı", + "sqlPreview": "SQL önizlemesi", + "sqlEditableHint": "Düzenlenebilir; bıraktığınız SQL çalıştırılır" }, "api": { "sessionExpired": "Oturumunuzun süresi doldu, lütfen tekrar giriş yapın.", diff --git a/frontend/messages/tr/operate.json b/frontend/messages/tr/operate.json index 7007cc7..1a840aa 100644 --- a/frontend/messages/tr/operate.json +++ b/frontend/messages/tr/operate.json @@ -149,6 +149,22 @@ "empty": "Kullanılmayan indeks yok.", "scans": "Tarama", "reindex": "REINDEX INDEX" + }, + "batch": { + "selected": "Seçili: {count}", + "thresholdLabel": "Kritik eşiği (ölü %)", + "thresholdInvalid": "Geçerli bir eşik değeri girin.", + "selectCritical": "Kritik olanları seç", + "noCritical": "%{threshold} eşiğini aşan tablo yok.", + "running": "Uygulanıyor · {done}/{total}", + "andMore": "+{count} tablo daha", + "apply": "{command} uygula", + "confirmTitle": "{count} tabloda {command} çalıştırılsın mı?", + "confirmDesc": "Seçilen tablolara {command} uygulanacak.", + "confirmDescFull": "Seçilen tablolara {command} uygulanacak. Her tablo ACCESS EXCLUSIVE LOCK alır; düşük trafikte çalıştırın.", + "noSelection": "Önce listeden en az bir tablo seçin.", + "resultsTitle": "Toplu işlem sonucu", + "resultsHint": "İşlem uygulanan tablolar ve komut sonuçları" } } }, From 7e88f17574afb317c03c0467b731ae626ba57cf6 Mon Sep 17 00:00:00 2001 From: Aziz ARSLAN Date: Wed, 4 Nov 2026 17:45:53 +0300 Subject: [PATCH 2/9] feat(ui): support an editable SQL preview in useConfirm --- frontend/lib/hooks/useConfirm.tsx | 71 ++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 16 deletions(-) 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 ? ( +