@libredb/studio 0.9.7 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-34YQUUCM.mjs +319 -0
- package/dist/chunk-34YQUUCM.mjs.map +1 -0
- package/dist/chunk-4LVB3K53.mjs +37 -0
- package/dist/chunk-4LVB3K53.mjs.map +1 -0
- package/dist/chunk-6DRZXXNT.mjs +100 -0
- package/dist/chunk-6DRZXXNT.mjs.map +1 -0
- package/dist/chunk-CZVV3JJB.mjs +160 -0
- package/dist/chunk-CZVV3JJB.mjs.map +1 -0
- package/dist/chunk-D4WVWWWF.js +332 -0
- package/dist/chunk-D4WVWWWF.js.map +1 -0
- package/dist/chunk-DY3KXE44.mjs +3 -0
- package/dist/chunk-DY3KXE44.mjs.map +1 -0
- package/dist/chunk-DZ2UB3C6.mjs +6679 -0
- package/dist/chunk-DZ2UB3C6.mjs.map +1 -0
- package/dist/chunk-FYSE52VB.js +242 -0
- package/dist/chunk-FYSE52VB.js.map +1 -0
- package/dist/chunk-G4WYE6TI.js +4 -0
- package/dist/chunk-G4WYE6TI.js.map +1 -0
- package/dist/chunk-JOGLIOFO.js +1310 -0
- package/dist/chunk-JOGLIOFO.js.map +1 -0
- package/dist/chunk-JZO5KRZN.js +165 -0
- package/dist/chunk-JZO5KRZN.js.map +1 -0
- package/dist/chunk-KV356UXJ.js +253 -0
- package/dist/chunk-KV356UXJ.js.map +1 -0
- package/dist/chunk-PPODO6HX.mjs +237 -0
- package/dist/chunk-PPODO6HX.mjs.map +1 -0
- package/dist/chunk-PTIRB2JO.js +258 -0
- package/dist/chunk-PTIRB2JO.js.map +1 -0
- package/dist/chunk-Q6LRDBK7.js +42 -0
- package/dist/chunk-Q6LRDBK7.js.map +1 -0
- package/dist/chunk-QJP5FZRY.mjs +255 -0
- package/dist/chunk-QJP5FZRY.mjs.map +1 -0
- package/dist/chunk-R3POCJK6.mjs +248 -0
- package/dist/chunk-R3POCJK6.mjs.map +1 -0
- package/dist/chunk-RBVDMLFV.js +6747 -0
- package/dist/chunk-RBVDMLFV.js.map +1 -0
- package/dist/chunk-RCQB4FCE.js +186 -0
- package/dist/chunk-RCQB4FCE.js.map +1 -0
- package/dist/chunk-SR5DRGBX.mjs +174 -0
- package/dist/chunk-SR5DRGBX.mjs.map +1 -0
- package/dist/chunk-VLCRUZX7.js +102 -0
- package/dist/chunk-VLCRUZX7.js.map +1 -0
- package/dist/chunk-VWVRUCQO.mjs +1289 -0
- package/dist/chunk-VWVRUCQO.mjs.map +1 -0
- package/dist/components.d.mts +273 -0
- package/dist/components.d.ts +273 -0
- package/dist/components.js +59 -0
- package/dist/components.js.map +1 -0
- package/dist/components.mjs +6 -0
- package/dist/components.mjs.map +1 -0
- package/dist/custom-BNDOYC5P.js +134 -0
- package/dist/custom-BNDOYC5P.js.map +1 -0
- package/dist/custom-S2EKFMP3.mjs +132 -0
- package/dist/custom-S2EKFMP3.mjs.map +1 -0
- package/dist/gemini-4ASHNK4H.js +81 -0
- package/dist/gemini-4ASHNK4H.js.map +1 -0
- package/dist/gemini-C5RBLQEJ.mjs +79 -0
- package/dist/gemini-C5RBLQEJ.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mongodb-XMZEZA4A.mjs +748 -0
- package/dist/mongodb-XMZEZA4A.mjs.map +1 -0
- package/dist/mongodb-YQJJTLX3.js +750 -0
- package/dist/mongodb-YQJJTLX3.js.map +1 -0
- package/dist/mssql-PMOU4D36.js +916 -0
- package/dist/mssql-PMOU4D36.js.map +1 -0
- package/{src/lib/db/providers/sql/mssql.ts → dist/mssql-ZH5VP2C5.mjs} +268 -423
- package/dist/mssql-ZH5VP2C5.mjs.map +1 -0
- package/{src/lib/db/providers/sql/mysql.ts → dist/mysql-I3WJQXN2.mjs} +277 -428
- package/dist/mysql-I3WJQXN2.mjs.map +1 -0
- package/dist/mysql-Y3MSA5QY.js +833 -0
- package/dist/mysql-Y3MSA5QY.js.map +1 -0
- package/dist/ollama-26BYLVEV.mjs +115 -0
- package/dist/ollama-26BYLVEV.mjs.map +1 -0
- package/dist/ollama-HVWAGKQC.js +117 -0
- package/dist/ollama-HVWAGKQC.js.map +1 -0
- package/dist/openai-4U56KPG7.mjs +111 -0
- package/dist/openai-4U56KPG7.mjs.map +1 -0
- package/dist/openai-AK3R37BS.js +113 -0
- package/dist/openai-AK3R37BS.js.map +1 -0
- package/dist/oracle-L6VEAVXO.js +917 -0
- package/dist/oracle-L6VEAVXO.js.map +1 -0
- package/{src/lib/db/providers/sql/oracle.ts → dist/oracle-P2G7T4P4.mjs} +321 -454
- package/dist/oracle-P2G7T4P4.mjs.map +1 -0
- package/{src/lib/db/providers/sql/postgres.ts → dist/postgres-O5KOQUVP.mjs} +261 -471
- package/dist/postgres-O5KOQUVP.mjs.map +1 -0
- package/dist/postgres-RLCWNFFX.js +971 -0
- package/dist/postgres-RLCWNFFX.js.map +1 -0
- package/dist/providers.d.mts +149 -0
- package/dist/providers.d.ts +149 -0
- package/dist/providers.js +44 -0
- package/dist/providers.js.map +1 -0
- package/dist/providers.mjs +7 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/redis-4WMQOVLX.mjs +435 -0
- package/dist/redis-4WMQOVLX.mjs.map +1 -0
- package/dist/redis-QVQ6YU62.js +441 -0
- package/dist/redis-QVQ6YU62.js.map +1 -0
- package/dist/sqlite-4I2P2OGQ.js +554 -0
- package/dist/sqlite-4I2P2OGQ.js.map +1 -0
- package/dist/sqlite-OA4YJX5S.mjs +531 -0
- package/dist/sqlite-OA4YJX5S.mjs.map +1 -0
- package/dist/types-BJvJfxSY.d.mts +141 -0
- package/dist/types-BJvJfxSY.d.ts +141 -0
- package/dist/types-ClAg_v5k.d.mts +343 -0
- package/dist/types-Der_X8E8.d.ts +343 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/dist/workspace.d.mts +80 -0
- package/dist/workspace.d.ts +80 -0
- package/dist/workspace.js +4182 -0
- package/dist/workspace.js.map +1 -0
- package/dist/workspace.mjs +4155 -0
- package/dist/workspace.mjs.map +1 -0
- package/package.json +60 -5
- package/.claude/settings.local.json +0 -127
- package/.cursorrules +0 -426
- package/.devin/wiki.json +0 -143
- package/.dockerignore +0 -80
- package/.env.example +0 -159
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -49
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -29
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -57
- package/.github/workflows/ci.yml +0 -185
- package/.github/workflows/codeql.yml +0 -57
- package/.github/workflows/docker-build-push.yml +0 -118
- package/.github/workflows/helm-release.yml +0 -113
- package/CLAUDE.md +0 -265
- package/CODE_OF_CONDUCT.md +0 -124
- package/CONTRIBUTING.md +0 -154
- package/Dockerfile +0 -73
- package/SECURITY.md +0 -107
- package/artifacthub-repo.yml +0 -4
- package/bun.lock +0 -1714
- package/bunfig.toml +0 -3
- package/charts/libredb-studio/.helmignore +0 -11
- package/charts/libredb-studio/Chart.lock +0 -6
- package/charts/libredb-studio/Chart.yaml +0 -50
- package/charts/libredb-studio/README.md +0 -206
- package/charts/libredb-studio/templates/NOTES.txt +0 -59
- package/charts/libredb-studio/templates/_helpers.tpl +0 -135
- package/charts/libredb-studio/templates/configmap.yaml +0 -37
- package/charts/libredb-studio/templates/deployment.yaml +0 -184
- package/charts/libredb-studio/templates/hpa.yaml +0 -32
- package/charts/libredb-studio/templates/ingress.yaml +0 -41
- package/charts/libredb-studio/templates/networkpolicy.yaml +0 -50
- package/charts/libredb-studio/templates/pdb.yaml +0 -18
- package/charts/libredb-studio/templates/pvc.yaml +0 -23
- package/charts/libredb-studio/templates/secret.yaml +0 -30
- package/charts/libredb-studio/templates/seed-configmap.yaml +0 -11
- package/charts/libredb-studio/templates/service.yaml +0 -22
- package/charts/libredb-studio/templates/serviceaccount.yaml +0 -13
- package/charts/libredb-studio/values.schema.json +0 -246
- package/charts/libredb-studio/values.yaml +0 -286
- package/components.json +0 -22
- package/conductor/code_styleguides/typescript.md +0 -43
- package/conductor/product-guidelines.md +0 -43
- package/conductor/product.md +0 -3
- package/conductor/setup_state.json +0 -1
- package/conductor/tech-stack.md +0 -39
- package/conductor/tracks/enhance_postgres_monitoring_20251227/metadata.json +0 -8
- package/conductor/tracks/enhance_postgres_monitoring_20251227/plan.md +0 -44
- package/conductor/tracks/enhance_postgres_monitoring_20251227/spec.md +0 -31
- package/conductor/tracks.md +0 -8
- package/conductor/workflow.md +0 -333
- package/database-compose.yml +0 -55
- package/docker/postgres-init/01-extensions.sql +0 -10
- package/docker/postgres-init/02-sample-data.sql +0 -585
- package/docker/postgres.yml +0 -68
- package/docker-compose.yml +0 -38
- package/docs/AI_PLAN.md +0 -74
- package/docs/API_DOCS.md +0 -875
- package/docs/ARCHITECTURE.md +0 -218
- package/docs/DATABASE_PROVIDERS.md +0 -358
- package/docs/FEATURES.md +0 -116
- package/docs/HELM_CHART.md +0 -252
- package/docs/LOGIN_PAGE.md +0 -178
- package/docs/MONACO_EDITOR_PERFORMANCE.md +0 -315
- package/docs/OIDC_ARCH.md +0 -681
- package/docs/OIDC_SETUP.md +0 -322
- package/docs/POSTGRES_METRICS.md +0 -516
- package/docs/QUERY_OPTIMIZATION.md +0 -370
- package/docs/SEED_CONNECTIONS.md +0 -468
- package/docs/SQL_ALIAS_COMPLETION.md +0 -190
- package/docs/STORAGE_ARCHITECTURE.md +0 -565
- package/docs/STORAGE_QUICK_SETUP.md +0 -419
- package/docs/TECHNICAL_PLAN.md +0 -36
- package/docs/THEMING.md +0 -345
- package/docs/adding-a-new-database-provider.md +0 -642
- package/docs/backlogs/000-PLATFORM_DATA_SYNC_DATABASE.md +0 -360
- package/docs/backlogs/001-INLINE_DATA_EDITING.md +0 -118
- package/docs/backlogs/002-DATA_IMPORT.md +0 -215
- package/docs/backlogs/003-QUERY_TIME_MACHINE.md +0 -183
- package/docs/backlogs/004-AI_DATA_STORYTELLER.md +0 -292
- package/docs/backlogs/005-QUERY_PLAYGROUND.md +0 -352
- package/docs/backlogs/006-DATA_MASKING.md +0 -418
- package/docs/enterprise-features.md +0 -718
- package/docs/kubernetes-helm-chart-artifacthub-plan.md +0 -803
- package/docs/medium-koyeb-article-en.md +0 -215
- package/docs/plans/test-plans.md +0 -445
- package/docs/releases/RELEASE.V0.3.0.md +0 -22
- package/docs/releases/RELEASE.V0.4.0.md +0 -154
- package/docs/releases/RELEASE.V0.5.0.md +0 -252
- package/docs/releases/RELEASE_v0.5.6.md +0 -145
- package/docs/releases/RELEASE_v0.6.1.md +0 -303
- package/docs/releases/RELEASE_v0.6.7.md +0 -292
- package/docs/releases/RELEASE_v0.7.0.md +0 -332
- package/docs/releases/RELEASE_v0.8.0.md +0 -521
- package/docs/sampledb/titanic.sql +0 -1379
- package/docs/superpowers/plans/2026-03-25-seed-connections.md +0 -1362
- package/docs/superpowers/specs/2026-03-25-seed-connections-design.md +0 -590
- package/e2e/admin-dashboard.spec.ts +0 -64
- package/e2e/connection-management.spec.ts +0 -58
- package/e2e/export.spec.ts +0 -34
- package/e2e/login.spec.ts +0 -85
- package/e2e/query-execution.spec.ts +0 -35
- package/e2e/tab-management.spec.ts +0 -64
- package/eslint.config.mjs +0 -28
- package/fly.toml +0 -43
- package/next.config.ts +0 -32
- package/playwright.config.ts +0 -34
- package/postcss.config.mjs +0 -7
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/logo.svg +0 -32
- package/public/next.svg +0 -1
- package/public/screenshots/code-generator.png +0 -0
- package/public/screenshots/connection-modal.png +0 -0
- package/public/screenshots/data-profiler.png +0 -0
- package/public/screenshots/erd-diagram.png +0 -0
- package/public/screenshots/hero-editor.png +0 -0
- package/public/screenshots/nl2sql.png +0 -0
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/render.yaml +0 -58
- package/scripts/merge-lcov.mjs +0 -239
- package/sonar-project.properties +0 -16
- package/src/app/admin/error.tsx +0 -46
- package/src/app/admin/page.tsx +0 -10
- package/src/app/api/admin/audit/route.ts +0 -52
- package/src/app/api/admin/fleet-health/route.ts +0 -81
- package/src/app/api/ai/autopilot/route.ts +0 -105
- package/src/app/api/ai/chat/route.ts +0 -132
- package/src/app/api/ai/describe-schema/route.ts +0 -52
- package/src/app/api/ai/explain/route.ts +0 -86
- package/src/app/api/ai/impact/route.ts +0 -97
- package/src/app/api/ai/index-advisor/route.ts +0 -98
- package/src/app/api/ai/nl2sql/route.ts +0 -87
- package/src/app/api/ai/query-safety/route.ts +0 -87
- package/src/app/api/auth/login/route.ts +0 -62
- package/src/app/api/auth/logout/route.ts +0 -25
- package/src/app/api/auth/me/route.ts +0 -10
- package/src/app/api/auth/oidc/callback/route.ts +0 -82
- package/src/app/api/auth/oidc/login/route.ts +0 -43
- package/src/app/api/connections/managed/route.ts +0 -35
- package/src/app/api/db/cancel/route.ts +0 -42
- package/src/app/api/db/disconnect/route.ts +0 -28
- package/src/app/api/db/health/route.ts +0 -49
- package/src/app/api/db/maintenance/route.ts +0 -72
- package/src/app/api/db/monitoring/route.ts +0 -62
- package/src/app/api/db/multi-query/route.ts +0 -116
- package/src/app/api/db/pool-stats/route.ts +0 -37
- package/src/app/api/db/profile/route.ts +0 -144
- package/src/app/api/db/provider-meta/route.ts +0 -49
- package/src/app/api/db/query/route.ts +0 -50
- package/src/app/api/db/schema/route.ts +0 -47
- package/src/app/api/db/schema-snapshot/route.ts +0 -42
- package/src/app/api/db/test-connection/route.ts +0 -55
- package/src/app/api/db/transaction/route.ts +0 -111
- package/src/app/api/storage/[collection]/route.ts +0 -67
- package/src/app/api/storage/config/route.ts +0 -17
- package/src/app/api/storage/migrate/route.ts +0 -45
- package/src/app/api/storage/route.ts +0 -32
- package/src/app/error.tsx +0 -49
- package/src/app/global-error.tsx +0 -55
- package/src/app/globals.css +0 -146
- package/src/app/icon.svg +0 -42
- package/src/app/layout.tsx +0 -34
- package/src/app/login/login-form.tsx +0 -301
- package/src/app/login/page.tsx +0 -11
- package/src/app/monitoring/page.tsx +0 -8
- package/src/app/not-found.tsx +0 -29
- package/src/app/page.tsx +0 -5
- package/src/components/AIAutopilotPanel.tsx +0 -238
- package/src/components/CodeGenerator.tsx +0 -271
- package/src/components/CommandPalette.tsx +0 -227
- package/src/components/ConnectionModal.tsx +0 -759
- package/src/components/CreateTableModal.tsx +0 -281
- package/src/components/DataCharts.tsx +0 -962
- package/src/components/DataImportModal.tsx +0 -582
- package/src/components/DataProfiler.tsx +0 -335
- package/src/components/DatabaseDocs.tsx +0 -251
- package/src/components/MaskingSettings.tsx +0 -414
- package/src/components/MobileNav.tsx +0 -50
- package/src/components/NL2SQLPanel.tsx +0 -281
- package/src/components/PivotTable.tsx +0 -257
- package/src/components/QueryEditor.tsx +0 -760
- package/src/components/QueryHistory.tsx +0 -344
- package/src/components/QuerySafetyDialog.tsx +0 -290
- package/src/components/ResultsGrid.tsx +0 -644
- package/src/components/SaveQueryModal.tsx +0 -104
- package/src/components/SavedQueries.tsx +0 -128
- package/src/components/SchemaDiagram.tsx +0 -473
- package/src/components/SchemaDiff.tsx +0 -473
- package/src/components/SnapshotTimeline.tsx +0 -116
- package/src/components/Studio.tsx +0 -639
- package/src/components/TestDataGenerator.tsx +0 -261
- package/src/components/VisualExplain.tsx +0 -820
- package/src/components/admin/AdminDashboard.tsx +0 -163
- package/src/components/admin/tabs/AuditTab.tsx +0 -531
- package/src/components/admin/tabs/MonitoringEmbed.tsx +0 -11
- package/src/components/admin/tabs/OperationsTab.tsx +0 -646
- package/src/components/admin/tabs/OverviewTab.tsx +0 -1328
- package/src/components/admin/tabs/SecurityTab.tsx +0 -284
- package/src/components/community-section.tsx +0 -92
- package/src/components/icons/db-icons.tsx +0 -84
- package/src/components/libredb-logo.tsx +0 -61
- package/src/components/monitoring/MonitoringDashboard.tsx +0 -345
- package/src/components/monitoring/tabs/MetricChart.tsx +0 -82
- package/src/components/monitoring/tabs/OverviewTab.tsx +0 -263
- package/src/components/monitoring/tabs/PerformanceTab.tsx +0 -254
- package/src/components/monitoring/tabs/PoolTab.tsx +0 -174
- package/src/components/monitoring/tabs/QueriesTab.tsx +0 -287
- package/src/components/monitoring/tabs/SessionsTab.tsx +0 -316
- package/src/components/monitoring/tabs/StorageTab.tsx +0 -335
- package/src/components/monitoring/tabs/TablesTab.tsx +0 -300
- package/src/components/results-grid/ResultCard.tsx +0 -111
- package/src/components/results-grid/RowDetailSheet.tsx +0 -178
- package/src/components/results-grid/StatsBar.tsx +0 -201
- package/src/components/results-grid/index.ts +0 -1
- package/src/components/results-grid/utils.ts +0 -23
- package/src/components/schema-explorer/ColumnList.tsx +0 -53
- package/src/components/schema-explorer/SchemaExplorer.tsx +0 -182
- package/src/components/schema-explorer/TableItem.tsx +0 -210
- package/src/components/schema-explorer/index.ts +0 -1
- package/src/components/sidebar/ConnectionItem.tsx +0 -105
- package/src/components/sidebar/ConnectionsList.tsx +0 -62
- package/src/components/sidebar/Sidebar.tsx +0 -130
- package/src/components/sidebar/index.ts +0 -2
- package/src/components/studio/BottomPanel.tsx +0 -286
- package/src/components/studio/QueryToolbar.tsx +0 -180
- package/src/components/studio/StudioDesktopHeader.tsx +0 -114
- package/src/components/studio/StudioMobileHeader.tsx +0 -340
- package/src/components/studio/StudioTabBar.tsx +0 -82
- package/src/components/studio/index.ts +0 -5
- package/src/components/ui/accordion.tsx +0 -66
- package/src/components/ui/alert-dialog.tsx +0 -157
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/aspect-ratio.tsx +0 -11
- package/src/components/ui/avatar.tsx +0 -53
- package/src/components/ui/badge.tsx +0 -46
- package/src/components/ui/breadcrumb.tsx +0 -109
- package/src/components/ui/button-group.tsx +0 -83
- package/src/components/ui/button.tsx +0 -60
- package/src/components/ui/calendar.tsx +0 -216
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/carousel.tsx +0 -241
- package/src/components/ui/chart.tsx +0 -357
- package/src/components/ui/checkbox.tsx +0 -32
- package/src/components/ui/collapsible.tsx +0 -33
- package/src/components/ui/command.tsx +0 -184
- package/src/components/ui/context-menu.tsx +0 -252
- package/src/components/ui/dialog.tsx +0 -143
- package/src/components/ui/drawer.tsx +0 -135
- package/src/components/ui/dropdown-menu.tsx +0 -257
- package/src/components/ui/empty.tsx +0 -104
- package/src/components/ui/field.tsx +0 -248
- package/src/components/ui/form.tsx +0 -167
- package/src/components/ui/hover-card.tsx +0 -44
- package/src/components/ui/input-group.tsx +0 -170
- package/src/components/ui/input-otp.tsx +0 -77
- package/src/components/ui/input.tsx +0 -21
- package/src/components/ui/item.tsx +0 -193
- package/src/components/ui/kbd.tsx +0 -28
- package/src/components/ui/label.tsx +0 -24
- package/src/components/ui/menubar.tsx +0 -276
- package/src/components/ui/navigation-menu.tsx +0 -168
- package/src/components/ui/pagination.tsx +0 -127
- package/src/components/ui/popover.tsx +0 -48
- package/src/components/ui/progress.tsx +0 -31
- package/src/components/ui/radio-group.tsx +0 -45
- package/src/components/ui/resizable.tsx +0 -56
- package/src/components/ui/scroll-area.tsx +0 -58
- package/src/components/ui/select.tsx +0 -187
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/sheet.tsx +0 -139
- package/src/components/ui/sidebar.tsx +0 -726
- package/src/components/ui/skeleton.tsx +0 -13
- package/src/components/ui/slider.tsx +0 -63
- package/src/components/ui/sonner.tsx +0 -40
- package/src/components/ui/spinner.tsx +0 -16
- package/src/components/ui/switch.tsx +0 -31
- package/src/components/ui/table.tsx +0 -116
- package/src/components/ui/tabs.tsx +0 -66
- package/src/components/ui/textarea.tsx +0 -18
- package/src/components/ui/toggle-group.tsx +0 -83
- package/src/components/ui/toggle.tsx +0 -47
- package/src/components/ui/tooltip.tsx +0 -61
- package/src/exports/components.ts +0 -15
- package/src/exports/index.ts +0 -4
- package/src/exports/providers.ts +0 -4
- package/src/exports/types.ts +0 -26
- package/src/hooks/use-ai-chat.ts +0 -182
- package/src/hooks/use-all-connections.ts +0 -66
- package/src/hooks/use-api-call.ts +0 -71
- package/src/hooks/use-auth.ts +0 -51
- package/src/hooks/use-connection-form.ts +0 -349
- package/src/hooks/use-connection-manager.ts +0 -169
- package/src/hooks/use-connection-payload.ts +0 -15
- package/src/hooks/use-inline-editing.ts +0 -109
- package/src/hooks/use-mobile.ts +0 -20
- package/src/hooks/use-monitoring-data.ts +0 -270
- package/src/hooks/use-provider-metadata.ts +0 -62
- package/src/hooks/use-query-execution.ts +0 -478
- package/src/hooks/use-storage-sync.ts +0 -259
- package/src/hooks/use-tab-manager.ts +0 -231
- package/src/hooks/use-toast.ts +0 -20
- package/src/hooks/use-transaction-control.ts +0 -64
- package/src/lib/api/error-codes.ts +0 -30
- package/src/lib/api/errors.ts +0 -236
- package/src/lib/api/with-error-handler.ts +0 -41
- package/src/lib/audit.ts +0 -105
- package/src/lib/auth.ts +0 -87
- package/src/lib/connection-string-parser.ts +0 -172
- package/src/lib/data-masking.ts +0 -385
- package/src/lib/db/base-provider.ts +0 -325
- package/src/lib/db/errors.ts +0 -317
- package/src/lib/db/factory.ts +0 -324
- package/src/lib/db/index.ts +0 -123
- package/src/lib/db/providers/document/index.ts +0 -6
- package/src/lib/db/providers/document/mongodb.ts +0 -992
- package/src/lib/db/providers/keyvalue/redis.ts +0 -554
- package/src/lib/db/providers/sql/index.ts +0 -11
- package/src/lib/db/providers/sql/sql-base.ts +0 -174
- package/src/lib/db/providers/sql/sqlite.ts +0 -721
- package/src/lib/db/types.ts +0 -437
- package/src/lib/db/utils/pool-manager.ts +0 -287
- package/src/lib/db/utils/query-limiter.ts +0 -239
- package/src/lib/db-ui-config.ts +0 -86
- package/src/lib/editor/mongodb-completions.ts +0 -172
- package/src/lib/editor/sql-completions.ts +0 -280
- package/src/lib/llm/base-provider.ts +0 -117
- package/src/lib/llm/factory.ts +0 -102
- package/src/lib/llm/index.ts +0 -90
- package/src/lib/llm/providers/custom.ts +0 -181
- package/src/lib/llm/providers/gemini.ts +0 -126
- package/src/lib/llm/providers/ollama.ts +0 -154
- package/src/lib/llm/providers/openai.ts +0 -146
- package/src/lib/llm/types.ts +0 -173
- package/src/lib/llm/utils/config.ts +0 -187
- package/src/lib/llm/utils/retry.ts +0 -119
- package/src/lib/llm/utils/streaming.ts +0 -202
- package/src/lib/logger.ts +0 -127
- package/src/lib/monitoring-thresholds.ts +0 -44
- package/src/lib/oidc.ts +0 -262
- package/src/lib/query-generators.ts +0 -61
- package/src/lib/schema-diff/diff-engine.ts +0 -273
- package/src/lib/schema-diff/migration-generator.ts +0 -208
- package/src/lib/schema-diff/types.ts +0 -55
- package/src/lib/seed/config-loader.ts +0 -79
- package/src/lib/seed/connection-filter.ts +0 -49
- package/src/lib/seed/credential-resolver.ts +0 -62
- package/src/lib/seed/index.ts +0 -40
- package/src/lib/seed/resolve-connection.ts +0 -57
- package/src/lib/seed/types.ts +0 -69
- package/src/lib/sql/alias-extractor.ts +0 -267
- package/src/lib/sql/index.ts +0 -8
- package/src/lib/sql/statement-splitter.ts +0 -167
- package/src/lib/sql/types.ts +0 -40
- package/src/lib/ssh/tunnel.ts +0 -142
- package/src/lib/storage/factory.ts +0 -84
- package/src/lib/storage/index.ts +0 -14
- package/src/lib/storage/local-storage.ts +0 -99
- package/src/lib/storage/providers/postgres.ts +0 -225
- package/src/lib/storage/providers/sqlite.ts +0 -153
- package/src/lib/storage/storage-facade.ts +0 -272
- package/src/lib/storage/types.ts +0 -75
- package/src/lib/time-series-buffer.ts +0 -58
- package/src/lib/types.ts +0 -173
- package/src/lib/utils.ts +0 -6
- package/src/proxy.ts +0 -104
- package/src/types/db-drivers.d.ts +0 -23
- package/src/types/html2canvas.d.ts +0 -9
- package/tests/api/admin/audit.test.ts +0 -178
- package/tests/api/admin/fleet-health.test.ts +0 -183
- package/tests/api/ai/autopilot.test.ts +0 -174
- package/tests/api/ai/chat.test.ts +0 -250
- package/tests/api/ai/describe-schema.test.ts +0 -266
- package/tests/api/ai/explain.test.ts +0 -199
- package/tests/api/ai/impact.test.ts +0 -168
- package/tests/api/ai/index-advisor.test.ts +0 -171
- package/tests/api/ai/nl2sql.test.ts +0 -202
- package/tests/api/ai/query-safety.test.ts +0 -196
- package/tests/api/auth/login.test.ts +0 -170
- package/tests/api/auth/logout.test.ts +0 -140
- package/tests/api/auth/me.test.ts +0 -73
- package/tests/api/auth/oidc-callback.test.ts +0 -215
- package/tests/api/auth/oidc-login.test.ts +0 -127
- package/tests/api/db/cancel.test.ts +0 -198
- package/tests/api/db/disconnect.test.ts +0 -124
- package/tests/api/db/health.test.ts +0 -222
- package/tests/api/db/maintenance.test.ts +0 -263
- package/tests/api/db/monitoring.test.ts +0 -221
- package/tests/api/db/multi-query.test.ts +0 -316
- package/tests/api/db/pool-stats.test.ts +0 -135
- package/tests/api/db/profile.test.ts +0 -330
- package/tests/api/db/provider-meta.test.ts +0 -193
- package/tests/api/db/query.test.ts +0 -314
- package/tests/api/db/schema-snapshot.test.ts +0 -170
- package/tests/api/db/schema.test.ts +0 -191
- package/tests/api/db/test-connection.test.ts +0 -185
- package/tests/api/db/transaction.test.ts +0 -314
- package/tests/api/proxy.test.ts +0 -191
- package/tests/api/seed/managed-route.test.ts +0 -113
- package/tests/api/storage/config.test.ts +0 -42
- package/tests/api/storage/storage-routes.test.ts +0 -309
- package/tests/components/AIAutopilotPanel.test.tsx +0 -756
- package/tests/components/AdminPage.test.tsx +0 -33
- package/tests/components/CodeGenerator.test.tsx +0 -182
- package/tests/components/CommandPalette.test.tsx +0 -428
- package/tests/components/CommunitySection.test.tsx +0 -91
- package/tests/components/ConnectionModal.mobile.test.tsx +0 -284
- package/tests/components/ConnectionModal.test.tsx +0 -570
- package/tests/components/CreateTableModal.test.tsx +0 -383
- package/tests/components/DataCharts.test.tsx +0 -739
- package/tests/components/DataImportModal.test.tsx +0 -751
- package/tests/components/DataProfiler.test.tsx +0 -589
- package/tests/components/DatabaseDocs.test.tsx +0 -353
- package/tests/components/LoginPage.test.tsx +0 -163
- package/tests/components/LoginPageOIDC.test.tsx +0 -92
- package/tests/components/MaskingSettings.test.tsx +0 -498
- package/tests/components/MobileNav.test.tsx +0 -30
- package/tests/components/MonitoringPage.test.tsx +0 -32
- package/tests/components/NL2SQLPanel.test.tsx +0 -621
- package/tests/components/Page.test.tsx +0 -33
- package/tests/components/PivotTable.test.tsx +0 -350
- package/tests/components/QueryEditor.test.tsx +0 -1730
- package/tests/components/QueryHistory.test.tsx +0 -572
- package/tests/components/QuerySafetyDialog.test.tsx +0 -586
- package/tests/components/ResultsGrid.test.tsx +0 -804
- package/tests/components/RootLayout.test.tsx +0 -83
- package/tests/components/SaveQueryModal.test.tsx +0 -25
- package/tests/components/SavedQueries.test.tsx +0 -43
- package/tests/components/SchemaDiagram.test.tsx +0 -1034
- package/tests/components/SchemaDiff.test.tsx +0 -906
- package/tests/components/SnapshotTimeline.test.tsx +0 -174
- package/tests/components/Studio.test.tsx +0 -1030
- package/tests/components/TestDataGenerator.test.tsx +0 -291
- package/tests/components/VisualExplain.test.tsx +0 -704
- package/tests/components/admin/AdminDashboard.test.tsx +0 -205
- package/tests/components/admin/AuditTab.test.tsx +0 -220
- package/tests/components/admin/MonitoringEmbed.test.tsx +0 -58
- package/tests/components/admin/OperationsTab.test.tsx +0 -975
- package/tests/components/admin/OverviewTab.test.tsx +0 -254
- package/tests/components/admin/SecurityTab.test.tsx +0 -467
- package/tests/components/monitoring/MetricChart.test.tsx +0 -111
- package/tests/components/monitoring/MonitoringDashboard.test.tsx +0 -259
- package/tests/components/monitoring/OverviewTab.test.tsx +0 -78
- package/tests/components/monitoring/PerformanceTab.test.tsx +0 -87
- package/tests/components/monitoring/PoolTab.test.tsx +0 -42
- package/tests/components/monitoring/QueriesTab.test.tsx +0 -80
- package/tests/components/monitoring/SessionsTab.test.tsx +0 -154
- package/tests/components/monitoring/StorageTab.test.tsx +0 -127
- package/tests/components/monitoring/TablesTab.test.tsx +0 -153
- package/tests/components/results-grid/ResultCard.test.tsx +0 -105
- package/tests/components/results-grid/RowDetailSheet.test.tsx +0 -308
- package/tests/components/results-grid/StatsBar.test.tsx +0 -162
- package/tests/components/schema-explorer/ColumnList.test.tsx +0 -151
- package/tests/components/schema-explorer/SchemaExplorer.test.tsx +0 -461
- package/tests/components/schema-explorer/TableItem.test.tsx +0 -415
- package/tests/components/sidebar/ConnectionItem.test.tsx +0 -201
- package/tests/components/sidebar/ConnectionsList.test.tsx +0 -176
- package/tests/components/sidebar/Sidebar.test.tsx +0 -187
- package/tests/components/studio/BottomPanel.test.tsx +0 -383
- package/tests/components/studio/QueryToolbar.test.tsx +0 -321
- package/tests/components/studio/StudioDesktopHeader.test.tsx +0 -377
- package/tests/components/studio/StudioMobileHeader.test.tsx +0 -198
- package/tests/components/studio/StudioTabBar.test.tsx +0 -331
- package/tests/fixtures/connections.ts +0 -96
- package/tests/fixtures/masking-configs.ts +0 -86
- package/tests/fixtures/query-results.ts +0 -71
- package/tests/fixtures/schemas.ts +0 -64
- package/tests/fixtures/seed-connections/invalid-config.yaml +0 -7
- package/tests/fixtures/seed-connections/minimal-config.yaml +0 -8
- package/tests/fixtures/seed-connections/mixed-credentials.yaml +0 -23
- package/tests/fixtures/seed-connections/multi-role-config.yaml +0 -30
- package/tests/fixtures/seed-connections/valid-config.json +0 -15
- package/tests/fixtures/seed-connections/valid-config.yaml +0 -51
- package/tests/helpers/mock-fetch.ts +0 -59
- package/tests/helpers/mock-monaco.ts +0 -112
- package/tests/helpers/mock-navigation.ts +0 -28
- package/tests/helpers/mock-next.ts +0 -80
- package/tests/helpers/mock-provider.ts +0 -133
- package/tests/helpers/mock-sonner.ts +0 -29
- package/tests/helpers/render-with-providers.tsx +0 -19
- package/tests/hooks/use-ai-chat.test.ts +0 -600
- package/tests/hooks/use-auth.test.ts +0 -371
- package/tests/hooks/use-connection-form.test.ts +0 -743
- package/tests/hooks/use-connection-manager.test.ts +0 -466
- package/tests/hooks/use-inline-editing.test.ts +0 -321
- package/tests/hooks/use-mobile.test.ts +0 -177
- package/tests/hooks/use-monitoring-data.test.ts +0 -819
- package/tests/hooks/use-provider-metadata.test.ts +0 -228
- package/tests/hooks/use-query-execution.test.ts +0 -1212
- package/tests/hooks/use-tab-manager.test.ts +0 -756
- package/tests/hooks/use-toast.test.ts +0 -74
- package/tests/hooks/use-transaction-control.test.ts +0 -211
- package/tests/integration/db/mongodb-provider.test.ts +0 -698
- package/tests/integration/db/mssql-provider.test.ts +0 -840
- package/tests/integration/db/mysql-provider.test.ts +0 -872
- package/tests/integration/db/oracle-provider.test.ts +0 -843
- package/tests/integration/db/postgres-provider.test.ts +0 -1382
- package/tests/integration/db/redis-provider.test.ts +0 -526
- package/tests/integration/db/sqlite-provider.test.ts +0 -480
- package/tests/integration/seed/seed-pipeline.test.ts +0 -102
- package/tests/isolated/factory-singleton.test.ts +0 -150
- package/tests/isolated/use-storage-sync.test.ts +0 -389
- package/tests/run-components.sh +0 -196
- package/tests/setup-dom.ts +0 -58
- package/tests/setup.ts +0 -40
- package/tests/unit/api-errors.test.ts +0 -210
- package/tests/unit/code-generator-functions.test.ts +0 -271
- package/tests/unit/components/column-list.test.tsx +0 -190
- package/tests/unit/components/data-import-modal.test.tsx +0 -441
- package/tests/unit/components/studio-mobile-header.test.tsx +0 -327
- package/tests/unit/data-charts-functions.test.ts +0 -496
- package/tests/unit/data-import-functions.test.ts +0 -320
- package/tests/unit/data-import-utils.test.ts +0 -125
- package/tests/unit/db/base-provider.test.ts +0 -517
- package/tests/unit/db/errors.test.ts +0 -403
- package/tests/unit/db/factory.test.ts +0 -436
- package/tests/unit/db/pool-manager.test.ts +0 -440
- package/tests/unit/db/query-limiter.test.ts +0 -387
- package/tests/unit/db/sql-base.test.ts +0 -438
- package/tests/unit/lib/api/error-codes.test.ts +0 -39
- package/tests/unit/lib/audit.test.ts +0 -326
- package/tests/unit/lib/auth.test.ts +0 -146
- package/tests/unit/lib/connection-string-parser.test.ts +0 -424
- package/tests/unit/lib/data-masking.test.ts +0 -583
- package/tests/unit/lib/db-icons.test.tsx +0 -41
- package/tests/unit/lib/monitoring-thresholds.test.ts +0 -133
- package/tests/unit/lib/oidc.test.ts +0 -509
- package/tests/unit/lib/query-generators.test.ts +0 -127
- package/tests/unit/lib/storage/factory.test.ts +0 -71
- package/tests/unit/lib/storage/local-storage.test.ts +0 -114
- package/tests/unit/lib/storage/providers/postgres.test.ts +0 -312
- package/tests/unit/lib/storage/providers/sqlite.test.ts +0 -232
- package/tests/unit/lib/storage/storage-facade-extended.test.ts +0 -331
- package/tests/unit/lib/storage/storage-facade.test.ts +0 -184
- package/tests/unit/lib/storage.test.ts +0 -317
- package/tests/unit/lib/time-series-buffer.test.ts +0 -212
- package/tests/unit/lib/utils.test.ts +0 -24
- package/tests/unit/llm/base-provider.test.ts +0 -238
- package/tests/unit/llm/config.test.ts +0 -262
- package/tests/unit/llm/custom-provider.test.ts +0 -281
- package/tests/unit/llm/gemini-provider.test.ts +0 -248
- package/tests/unit/llm/llm-factory.test.ts +0 -155
- package/tests/unit/llm/ollama-provider.test.ts +0 -288
- package/tests/unit/llm/openai-provider.test.ts +0 -324
- package/tests/unit/llm/retry.test.ts +0 -180
- package/tests/unit/llm/streaming.test.ts +0 -355
- package/tests/unit/logger.test.ts +0 -198
- package/tests/unit/mongodb-completions.test.ts +0 -516
- package/tests/unit/pivot-table-functions.test.ts +0 -76
- package/tests/unit/query-cancelled-error.test.ts +0 -81
- package/tests/unit/schema-diff/diff-engine.test.ts +0 -367
- package/tests/unit/schema-diff/migration-generator.test.ts +0 -513
- package/tests/unit/seed/config-loader.test.ts +0 -73
- package/tests/unit/seed/connection-filter.test.ts +0 -91
- package/tests/unit/seed/credential-resolver.test.ts +0 -85
- package/tests/unit/seed/index.test.ts +0 -72
- package/tests/unit/seed/resolve-connection.test.ts +0 -74
- package/tests/unit/seed/types.test.ts +0 -129
- package/tests/unit/sql/alias-extractor.test.ts +0 -444
- package/tests/unit/sql/statement-splitter.test.ts +0 -348
- package/tests/unit/sql-completions.test.ts +0 -463
- package/tests/unit/ssh-tunnel.test.ts +0 -465
- package/tsconfig.json +0 -42
|
@@ -0,0 +1,4155 @@
|
|
|
1
|
+
import { getDBIcon, cn, ENVIRONMENT_LABELS, Button, SchemaDiagram, SchemaExplorer, QueryEditor, QuerySafetyDialog, DataProfiler, CodeGenerator, TestDataGenerator, isDangerousQuery, ScrollArea, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, NL2SQLPanel, DataCharts, VisualExplain, ResultsGrid, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Label, Input, DialogFooter, buttonVariants, storage, Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from './chunk-DZ2UB3C6.mjs';
|
|
2
|
+
import './chunk-6DRZXXNT.mjs';
|
|
3
|
+
import { __spreadValues, __spreadProps, __objRest } from './chunk-4LVB3K53.mjs';
|
|
4
|
+
import React, { useRef, useMemo, useEffect, useState, useCallback } from 'react';
|
|
5
|
+
import { Lock, Pencil, Trash2, Database, AlertTriangle, Zap, Layers, Plus, GripVerticalIcon, Hash, FileJson, X, FlaskConical, Terminal, Save, Square, Play, Upload, Download, Bookmark, Tag, Check, ArrowRight, FileSpreadsheet, FileText, Table2, Loader2, LayoutGrid, Clock, BarChart3, Sparkles, Columns3, GitCompare, LayoutDashboard, RefreshCw, GripVertical, Search, History, ArrowUpDown, CheckCircle2, AlertCircle, RotateCcw, Edit3, Calendar, Camera, FileCode, ChevronDown, ChevronRight, Copy, Minus } from 'lucide-react';
|
|
6
|
+
import { motion, AnimatePresence } from 'framer-motion';
|
|
7
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
import 'next/navigation';
|
|
9
|
+
import { format } from 'date-fns';
|
|
10
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
11
|
+
import { cva } from 'class-variance-authority';
|
|
12
|
+
import { toast } from 'sonner';
|
|
13
|
+
import * as ResizablePrimitive from 'react-resizable-panels';
|
|
14
|
+
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
|
|
15
|
+
|
|
16
|
+
var ConnectionItem = React.memo(function ConnectionItem2({
|
|
17
|
+
connection: conn,
|
|
18
|
+
isActive,
|
|
19
|
+
onSelect,
|
|
20
|
+
onDelete,
|
|
21
|
+
onEdit
|
|
22
|
+
}) {
|
|
23
|
+
return /* @__PURE__ */ jsxs(
|
|
24
|
+
motion.div,
|
|
25
|
+
{
|
|
26
|
+
initial: false,
|
|
27
|
+
className: cn(
|
|
28
|
+
"group flex items-center gap-2.5 px-3 py-2 rounded-lg cursor-pointer transition-all duration-200 text-sm relative overflow-hidden",
|
|
29
|
+
isActive ? "bg-blue-600/10 text-blue-400" : "hover:bg-accent/50 text-muted-foreground hover:text-foreground"
|
|
30
|
+
),
|
|
31
|
+
onClick: () => onSelect(conn),
|
|
32
|
+
children: [
|
|
33
|
+
isActive && /* @__PURE__ */ jsx(
|
|
34
|
+
motion.div,
|
|
35
|
+
{
|
|
36
|
+
layoutId: "active-indicator",
|
|
37
|
+
className: "absolute left-0 w-1 h-4 rounded-r-full",
|
|
38
|
+
style: { backgroundColor: conn.color || "#3b82f6" }
|
|
39
|
+
}
|
|
40
|
+
),
|
|
41
|
+
/* @__PURE__ */ jsx(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
className: cn(
|
|
45
|
+
"p-1 rounded transition-colors",
|
|
46
|
+
isActive ? "bg-blue-500/20" : "bg-muted group-hover:bg-accent"
|
|
47
|
+
),
|
|
48
|
+
children: React.createElement(getDBIcon(conn.type), { className: "w-3 h-3" })
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
52
|
+
/* @__PURE__ */ jsx("span", { className: "truncate block font-medium text-body", children: conn.name }),
|
|
53
|
+
conn.environment && conn.environment !== "other" && /* @__PURE__ */ jsx(
|
|
54
|
+
"span",
|
|
55
|
+
{
|
|
56
|
+
className: "text-micro uppercase tracking-wider font-bold px-1.5 py-0.5 rounded-sm shrink-0",
|
|
57
|
+
style: {
|
|
58
|
+
color: conn.color || "#6b7280",
|
|
59
|
+
backgroundColor: `${conn.color || "#6b7280"}15`
|
|
60
|
+
},
|
|
61
|
+
children: ENVIRONMENT_LABELS[conn.environment]
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
] }) }),
|
|
65
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
66
|
+
conn.managed && /* @__PURE__ */ jsx(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
"data-testid": `managed-lock-${conn.seedId || conn.id}`,
|
|
70
|
+
className: "w-6 h-6 flex items-center justify-center text-amber-500/60",
|
|
71
|
+
title: "Managed by administrator",
|
|
72
|
+
children: /* @__PURE__ */ jsx(Lock, { className: "w-3 h-3" })
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
!conn.managed && onEdit && /* @__PURE__ */ jsx(
|
|
76
|
+
Button,
|
|
77
|
+
{
|
|
78
|
+
variant: "ghost",
|
|
79
|
+
size: "icon",
|
|
80
|
+
className: "w-6 h-6 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-blue-500/20 hover:text-blue-400",
|
|
81
|
+
onClick: (e) => {
|
|
82
|
+
e.stopPropagation();
|
|
83
|
+
onEdit(conn);
|
|
84
|
+
},
|
|
85
|
+
children: /* @__PURE__ */ jsx(Pencil, { className: "w-3 h-3" })
|
|
86
|
+
}
|
|
87
|
+
),
|
|
88
|
+
!conn.managed && /* @__PURE__ */ jsx(
|
|
89
|
+
Button,
|
|
90
|
+
{
|
|
91
|
+
variant: "ghost",
|
|
92
|
+
size: "icon",
|
|
93
|
+
className: "w-6 h-6 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/20 hover:text-red-400",
|
|
94
|
+
onClick: (e) => {
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
onDelete(conn.id);
|
|
97
|
+
},
|
|
98
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "w-3 h-3" })
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
] })
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
function ConnectionsList({
|
|
107
|
+
connections,
|
|
108
|
+
activeConnection,
|
|
109
|
+
onSelectConnection,
|
|
110
|
+
onDeleteConnection,
|
|
111
|
+
onEditConnection,
|
|
112
|
+
onAddConnection
|
|
113
|
+
}) {
|
|
114
|
+
return /* @__PURE__ */ jsxs("section", { children: [
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "px-3 mb-2 flex items-center justify-between", children: [
|
|
116
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold uppercase tracking-[0.15em] text-muted-foreground", children: "Connections" }),
|
|
117
|
+
/* @__PURE__ */ jsx("div", { className: "h-[1px] flex-1 bg-border/30 ml-3" })
|
|
118
|
+
] }),
|
|
119
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-0.5", children: connections.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "px-3 py-6 text-center border border-dashed border-border/50 rounded-lg mx-2", children: [
|
|
120
|
+
/* @__PURE__ */ jsx("p", { className: "text-body text-muted-foreground mb-3 leading-relaxed", children: "No database connections established yet." }),
|
|
121
|
+
/* @__PURE__ */ jsx(
|
|
122
|
+
Button,
|
|
123
|
+
{
|
|
124
|
+
variant: "outline",
|
|
125
|
+
size: "sm",
|
|
126
|
+
className: "h-7 text-xs",
|
|
127
|
+
onClick: onAddConnection,
|
|
128
|
+
children: "Add Connection"
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] }) : connections.map((conn) => /* @__PURE__ */ jsx(
|
|
132
|
+
ConnectionItem,
|
|
133
|
+
{
|
|
134
|
+
connection: conn,
|
|
135
|
+
isActive: (activeConnection == null ? void 0 : activeConnection.id) === conn.id,
|
|
136
|
+
onSelect: onSelectConnection,
|
|
137
|
+
onDelete: onDeleteConnection,
|
|
138
|
+
onEdit: onEditConnection
|
|
139
|
+
},
|
|
140
|
+
conn.id
|
|
141
|
+
)) })
|
|
142
|
+
] });
|
|
143
|
+
}
|
|
144
|
+
function Sidebar({
|
|
145
|
+
connections,
|
|
146
|
+
activeConnection,
|
|
147
|
+
schema,
|
|
148
|
+
isLoadingSchema,
|
|
149
|
+
onSelectConnection,
|
|
150
|
+
onDeleteConnection,
|
|
151
|
+
onEditConnection,
|
|
152
|
+
onAddConnection,
|
|
153
|
+
onTableClick,
|
|
154
|
+
onGenerateSelect,
|
|
155
|
+
onCreateTableClick,
|
|
156
|
+
onShowDiagram,
|
|
157
|
+
isAdmin = false,
|
|
158
|
+
onOpenMaintenance,
|
|
159
|
+
databaseType,
|
|
160
|
+
metadata,
|
|
161
|
+
onProfileTable,
|
|
162
|
+
onGenerateCode,
|
|
163
|
+
onGenerateTestData
|
|
164
|
+
}) {
|
|
165
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex w-full h-full border-r border-border flex-col bg-background select-none", children: [
|
|
166
|
+
/* @__PURE__ */ jsxs("div", { className: "h-14 px-4 flex items-center justify-between border-b border-border", children: [
|
|
167
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
168
|
+
/* @__PURE__ */ jsx("div", { className: "w-6 h-6 bg-blue-600 rounded-md flex items-center justify-center", children: /* @__PURE__ */ jsx(Zap, { className: "w-3.5 h-3.5 text-white fill-current" }) }),
|
|
169
|
+
/* @__PURE__ */ jsx("span", { className: "font-bold text-sm tracking-tight bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent", children: "LibreDB Studio" })
|
|
170
|
+
] }),
|
|
171
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
172
|
+
activeConnection && /* @__PURE__ */ jsx(
|
|
173
|
+
Button,
|
|
174
|
+
{
|
|
175
|
+
variant: "ghost",
|
|
176
|
+
size: "icon",
|
|
177
|
+
className: "h-8 w-8 hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",
|
|
178
|
+
onClick: onShowDiagram,
|
|
179
|
+
title: "Show ERD Diagram",
|
|
180
|
+
children: /* @__PURE__ */ jsx(Layers, { className: "w-4 h-4" })
|
|
181
|
+
}
|
|
182
|
+
),
|
|
183
|
+
/* @__PURE__ */ jsx(
|
|
184
|
+
Button,
|
|
185
|
+
{
|
|
186
|
+
variant: "ghost",
|
|
187
|
+
size: "icon",
|
|
188
|
+
className: "h-8 w-8 hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",
|
|
189
|
+
onClick: onAddConnection,
|
|
190
|
+
children: /* @__PURE__ */ jsx(Plus, { className: "w-4 h-4" })
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
] })
|
|
194
|
+
] }),
|
|
195
|
+
/* @__PURE__ */ jsx(ScrollArea, { className: "flex-1 min-h-0 px-2 py-4", children: /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
ConnectionsList,
|
|
198
|
+
{
|
|
199
|
+
connections,
|
|
200
|
+
activeConnection,
|
|
201
|
+
onSelectConnection,
|
|
202
|
+
onDeleteConnection,
|
|
203
|
+
onEditConnection,
|
|
204
|
+
onAddConnection
|
|
205
|
+
}
|
|
206
|
+
),
|
|
207
|
+
activeConnection && /* @__PURE__ */ jsx(
|
|
208
|
+
SchemaExplorer,
|
|
209
|
+
{
|
|
210
|
+
schema,
|
|
211
|
+
isLoadingSchema,
|
|
212
|
+
onTableClick,
|
|
213
|
+
onGenerateSelect,
|
|
214
|
+
onCreateTableClick,
|
|
215
|
+
isAdmin,
|
|
216
|
+
onOpenMaintenance,
|
|
217
|
+
databaseType,
|
|
218
|
+
metadata,
|
|
219
|
+
onProfileTable,
|
|
220
|
+
onGenerateCode,
|
|
221
|
+
onGenerateTestData
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] }) }),
|
|
225
|
+
/* @__PURE__ */ jsx("div", { className: "p-3 border-t border-border bg-card/50 backdrop-blur-md", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-2 py-1.5 rounded-lg bg-muted/30 border border-border/50", children: [
|
|
226
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
227
|
+
/* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse" }),
|
|
228
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Connected" })
|
|
229
|
+
] }),
|
|
230
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-mono text-muted-foreground/70", children: "v1.2.5" })
|
|
231
|
+
] }) })
|
|
232
|
+
] });
|
|
233
|
+
}
|
|
234
|
+
function parseCSV(text) {
|
|
235
|
+
const lines = text.split(/\r?\n/).filter((line) => line.trim());
|
|
236
|
+
if (lines.length === 0) return { headers: [], rows: [], totalRows: 0 };
|
|
237
|
+
const parseLine = (line) => {
|
|
238
|
+
const result = [];
|
|
239
|
+
let current = "";
|
|
240
|
+
let inQuotes = false;
|
|
241
|
+
for (let i = 0; i < line.length; i++) {
|
|
242
|
+
const ch = line[i];
|
|
243
|
+
if (ch === '"' && !inQuotes) {
|
|
244
|
+
inQuotes = true;
|
|
245
|
+
} else if (ch === '"' && inQuotes) {
|
|
246
|
+
if (i + 1 < line.length && line[i + 1] === '"') {
|
|
247
|
+
current += '"';
|
|
248
|
+
i++;
|
|
249
|
+
} else {
|
|
250
|
+
inQuotes = false;
|
|
251
|
+
}
|
|
252
|
+
} else if (ch === "," && !inQuotes) {
|
|
253
|
+
result.push(current.trim());
|
|
254
|
+
current = "";
|
|
255
|
+
} else {
|
|
256
|
+
current += ch;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
result.push(current.trim());
|
|
260
|
+
return result;
|
|
261
|
+
};
|
|
262
|
+
const headers = parseLine(lines[0]);
|
|
263
|
+
const rows = lines.slice(1).map((line) => parseLine(line));
|
|
264
|
+
return { headers, rows, totalRows: rows.length };
|
|
265
|
+
}
|
|
266
|
+
function parseJSON(text) {
|
|
267
|
+
const data = JSON.parse(text);
|
|
268
|
+
const arr = Array.isArray(data) ? data : [data];
|
|
269
|
+
if (arr.length === 0) return { headers: [], rows: [], totalRows: 0 };
|
|
270
|
+
const headers = [...new Set(arr.flatMap((obj) => Object.keys(obj)))];
|
|
271
|
+
const rows = arr.map((obj) => headers.map((h) => {
|
|
272
|
+
const val = obj[h];
|
|
273
|
+
if (val === null || val === void 0) return "";
|
|
274
|
+
if (typeof val === "object") return JSON.stringify(val);
|
|
275
|
+
return String(val);
|
|
276
|
+
}));
|
|
277
|
+
return { headers, rows, totalRows: rows.length };
|
|
278
|
+
}
|
|
279
|
+
function inferSqlType(values) {
|
|
280
|
+
const nonEmpty = values.filter((v) => v !== "" && v !== null);
|
|
281
|
+
if (nonEmpty.length === 0) return "TEXT";
|
|
282
|
+
const allIntegers = nonEmpty.every((v) => /^-?\d+$/.test(v));
|
|
283
|
+
if (allIntegers) return "INTEGER";
|
|
284
|
+
const allNumbers = nonEmpty.every((v) => /^-?\d+(\.\d+)?$/.test(v));
|
|
285
|
+
if (allNumbers) return "NUMERIC";
|
|
286
|
+
const allBooleans = nonEmpty.every((v) => /^(true|false|0|1)$/i.test(v));
|
|
287
|
+
if (allBooleans) return "BOOLEAN";
|
|
288
|
+
return "TEXT";
|
|
289
|
+
}
|
|
290
|
+
function escapeSQL(value) {
|
|
291
|
+
if (value === "" || value === "null" || value === "NULL") return "NULL";
|
|
292
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
293
|
+
}
|
|
294
|
+
function generateImportSQL(parsedData, targetTable, createNewTable, newTableName, columnMapping) {
|
|
295
|
+
if (!parsedData) return "";
|
|
296
|
+
const tableName = createNewTable ? newTableName || "imported_data" : targetTable;
|
|
297
|
+
if (!tableName) return "";
|
|
298
|
+
const statements = [];
|
|
299
|
+
if (createNewTable) {
|
|
300
|
+
const colDefs = parsedData.headers.map((h) => {
|
|
301
|
+
const colValues = parsedData.rows.slice(0, 100).map((r) => r[parsedData.headers.indexOf(h)]);
|
|
302
|
+
const sqlType = inferSqlType(colValues);
|
|
303
|
+
const colName = columnMapping[h] || h;
|
|
304
|
+
return ` ${colName} ${sqlType}`;
|
|
305
|
+
});
|
|
306
|
+
statements.push(`CREATE TABLE ${tableName} (
|
|
307
|
+
${colDefs.join(",\n")}
|
|
308
|
+
);`);
|
|
309
|
+
}
|
|
310
|
+
const mappedHeaders = parsedData.headers.map((h) => columnMapping[h] || h);
|
|
311
|
+
const batchSize = 100;
|
|
312
|
+
for (let i = 0; i < parsedData.rows.length; i += batchSize) {
|
|
313
|
+
const batch = parsedData.rows.slice(i, i + batchSize);
|
|
314
|
+
const valueRows = batch.map((row) => {
|
|
315
|
+
const values = row.map((val, idx) => {
|
|
316
|
+
const sqlType = inferSqlType(parsedData.rows.slice(0, 100).map((r) => r[idx]));
|
|
317
|
+
if (val === "" || val === "NULL" || val === "null") return "NULL";
|
|
318
|
+
if (sqlType === "INTEGER" || sqlType === "NUMERIC" || sqlType === "BOOLEAN") {
|
|
319
|
+
if (sqlType === "BOOLEAN") return val.toLowerCase() === "true" || val === "1" ? "TRUE" : "FALSE";
|
|
320
|
+
return val;
|
|
321
|
+
}
|
|
322
|
+
return escapeSQL(val);
|
|
323
|
+
});
|
|
324
|
+
return ` (${values.join(", ")})`;
|
|
325
|
+
});
|
|
326
|
+
statements.push(
|
|
327
|
+
`INSERT INTO ${tableName} (${mappedHeaders.join(", ")})
|
|
328
|
+
VALUES
|
|
329
|
+
${valueRows.join(",\n")};`
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
return statements.join("\n\n");
|
|
333
|
+
}
|
|
334
|
+
function DataImportModal({ isOpen, onClose, onImport, tables, databaseType }) {
|
|
335
|
+
const [step, setStep] = useState("upload");
|
|
336
|
+
const [parsedData, setParsedData] = useState(null);
|
|
337
|
+
const [fileName, setFileName] = useState("");
|
|
338
|
+
const [fileType, setFileType] = useState("csv");
|
|
339
|
+
const [targetTable, setTargetTable] = useState("");
|
|
340
|
+
const [createNewTable, setCreateNewTable] = useState(false);
|
|
341
|
+
const [newTableName, setNewTableName] = useState("");
|
|
342
|
+
const [columnMapping, setColumnMapping] = useState({});
|
|
343
|
+
const [error, setError] = useState(null);
|
|
344
|
+
const [isImporting, setIsImporting] = useState(false);
|
|
345
|
+
const fileInputRef = useRef(null);
|
|
346
|
+
const resetState = useCallback(() => {
|
|
347
|
+
setStep("upload");
|
|
348
|
+
setParsedData(null);
|
|
349
|
+
setFileName("");
|
|
350
|
+
setTargetTable("");
|
|
351
|
+
setCreateNewTable(false);
|
|
352
|
+
setNewTableName("");
|
|
353
|
+
setColumnMapping({});
|
|
354
|
+
setError(null);
|
|
355
|
+
setIsImporting(false);
|
|
356
|
+
}, []);
|
|
357
|
+
const handleClose = () => {
|
|
358
|
+
resetState();
|
|
359
|
+
onClose();
|
|
360
|
+
};
|
|
361
|
+
const handleFileSelect = useCallback((file) => {
|
|
362
|
+
var _a;
|
|
363
|
+
setError(null);
|
|
364
|
+
setFileName(file.name);
|
|
365
|
+
const ext = (_a = file.name.split(".").pop()) == null ? void 0 : _a.toLowerCase();
|
|
366
|
+
const isJSON = ext === "json";
|
|
367
|
+
setFileType(isJSON ? "json" : "csv");
|
|
368
|
+
const reader = new FileReader();
|
|
369
|
+
reader.onload = (e) => {
|
|
370
|
+
var _a2;
|
|
371
|
+
try {
|
|
372
|
+
const text = (_a2 = e.target) == null ? void 0 : _a2.result;
|
|
373
|
+
const data = isJSON ? parseJSON(text) : parseCSV(text);
|
|
374
|
+
if (data.headers.length === 0) {
|
|
375
|
+
setError("No data found in file");
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
setParsedData(data);
|
|
379
|
+
const mapping = {};
|
|
380
|
+
data.headers.forEach((h) => {
|
|
381
|
+
mapping[h] = h;
|
|
382
|
+
});
|
|
383
|
+
setColumnMapping(mapping);
|
|
384
|
+
setStep("preview");
|
|
385
|
+
} catch (err) {
|
|
386
|
+
setError(`Failed to parse file: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
reader.readAsText(file);
|
|
390
|
+
}, []);
|
|
391
|
+
const handleDrop = useCallback((e) => {
|
|
392
|
+
e.preventDefault();
|
|
393
|
+
const file = e.dataTransfer.files[0];
|
|
394
|
+
if (file) handleFileSelect(file);
|
|
395
|
+
}, [handleFileSelect]);
|
|
396
|
+
const handleDragOver = useCallback((e) => {
|
|
397
|
+
e.preventDefault();
|
|
398
|
+
}, []);
|
|
399
|
+
const generatedSQL = useMemo(
|
|
400
|
+
() => generateImportSQL(parsedData, targetTable, createNewTable, newTableName, columnMapping),
|
|
401
|
+
[parsedData, targetTable, createNewTable, newTableName, columnMapping]
|
|
402
|
+
);
|
|
403
|
+
const handleImport = () => {
|
|
404
|
+
if (!generatedSQL) return;
|
|
405
|
+
setIsImporting(true);
|
|
406
|
+
onImport(generatedSQL);
|
|
407
|
+
setTimeout(() => {
|
|
408
|
+
handleClose();
|
|
409
|
+
}, 200);
|
|
410
|
+
};
|
|
411
|
+
return /* @__PURE__ */ jsx(Dialog, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(DialogContent, { className: "bg-[#0a0a0a] border-white/10 text-zinc-100 max-w-2xl max-h-[85vh] overflow-hidden flex flex-col", children: [
|
|
412
|
+
/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
|
|
413
|
+
/* @__PURE__ */ jsx(Upload, { className: "w-5 h-5 text-blue-400" }),
|
|
414
|
+
"Import Data",
|
|
415
|
+
fileName && /* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500 font-normal ml-2", children: fileName })
|
|
416
|
+
] }) }),
|
|
417
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 px-1 py-2", children: ["upload", "preview", "configure", "ready"].map((s, idx) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
418
|
+
/* @__PURE__ */ jsxs("div", { className: cn(
|
|
419
|
+
"flex items-center gap-1.5 text-xs font-bold uppercase tracking-wider",
|
|
420
|
+
step === s ? "text-blue-400" : idx < ["upload", "preview", "configure", "ready"].indexOf(step) ? "text-emerald-400" : "text-zinc-600"
|
|
421
|
+
), children: [
|
|
422
|
+
/* @__PURE__ */ jsx("div", { className: cn(
|
|
423
|
+
"w-5 h-5 rounded-full flex items-center justify-center text-label",
|
|
424
|
+
step === s ? "bg-blue-500/20 border border-blue-500/40" : idx < ["upload", "preview", "configure", "ready"].indexOf(step) ? "bg-emerald-500/20 border border-emerald-500/40" : "bg-white/5 border border-white/10"
|
|
425
|
+
), children: idx < ["upload", "preview", "configure", "ready"].indexOf(step) ? /* @__PURE__ */ jsx(Check, { className: "w-3 h-3" }) : idx + 1 }),
|
|
426
|
+
/* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: s === "upload" ? "Upload" : s === "preview" ? "Preview" : s === "configure" ? "Configure" : "Import" })
|
|
427
|
+
] }),
|
|
428
|
+
idx < 3 && /* @__PURE__ */ jsx(ArrowRight, { className: "w-3 h-3 text-zinc-700" })
|
|
429
|
+
] }, s)) }),
|
|
430
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-auto min-h-0", children: [
|
|
431
|
+
step === "upload" && /* @__PURE__ */ jsxs("div", { className: "p-4", children: [
|
|
432
|
+
/* @__PURE__ */ jsxs(
|
|
433
|
+
"div",
|
|
434
|
+
{
|
|
435
|
+
onDrop: handleDrop,
|
|
436
|
+
onDragOver: handleDragOver,
|
|
437
|
+
onClick: () => {
|
|
438
|
+
var _a;
|
|
439
|
+
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
440
|
+
},
|
|
441
|
+
className: "border-2 border-dashed border-white/10 rounded-xl p-12 text-center cursor-pointer hover:border-blue-500/30 hover:bg-blue-500/5 transition-all",
|
|
442
|
+
children: [
|
|
443
|
+
/* @__PURE__ */ jsx(Upload, { className: "w-10 h-10 text-zinc-600 mx-auto mb-4" }),
|
|
444
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-zinc-400 mb-1", children: "Drop a file here or click to browse" }),
|
|
445
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-600", children: "Supports CSV and JSON files" }),
|
|
446
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-4 mt-4", children: [
|
|
447
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-zinc-500", children: [
|
|
448
|
+
/* @__PURE__ */ jsx(FileSpreadsheet, { className: "w-4 h-4" }),
|
|
449
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs", children: "CSV" })
|
|
450
|
+
] }),
|
|
451
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-zinc-500", children: [
|
|
452
|
+
/* @__PURE__ */ jsx(FileJson, { className: "w-4 h-4" }),
|
|
453
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs", children: "JSON" })
|
|
454
|
+
] })
|
|
455
|
+
] })
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
),
|
|
459
|
+
/* @__PURE__ */ jsx(
|
|
460
|
+
"input",
|
|
461
|
+
{
|
|
462
|
+
ref: fileInputRef,
|
|
463
|
+
type: "file",
|
|
464
|
+
accept: ".csv,.json,.tsv",
|
|
465
|
+
className: "hidden",
|
|
466
|
+
onChange: (e) => {
|
|
467
|
+
var _a;
|
|
468
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
469
|
+
if (file) handleFileSelect(file);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
),
|
|
473
|
+
error && /* @__PURE__ */ jsxs("div", { className: "mt-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 flex items-center gap-2", children: [
|
|
474
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "w-4 h-4 text-red-400 shrink-0" }),
|
|
475
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-red-400", children: error })
|
|
476
|
+
] })
|
|
477
|
+
] }),
|
|
478
|
+
step === "preview" && parsedData && /* @__PURE__ */ jsxs("div", { className: "p-4 space-y-4", children: [
|
|
479
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
480
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
481
|
+
fileType === "json" ? /* @__PURE__ */ jsx(FileJson, { className: "w-5 h-5 text-amber-400" }) : /* @__PURE__ */ jsx(FileText, { className: "w-5 h-5 text-emerald-400" }),
|
|
482
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
483
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: fileName }),
|
|
484
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs text-zinc-500", children: [
|
|
485
|
+
parsedData.totalRows,
|
|
486
|
+
" rows, ",
|
|
487
|
+
parsedData.headers.length,
|
|
488
|
+
" columns"
|
|
489
|
+
] })
|
|
490
|
+
] })
|
|
491
|
+
] }),
|
|
492
|
+
/* @__PURE__ */ jsxs(
|
|
493
|
+
Button,
|
|
494
|
+
{
|
|
495
|
+
variant: "ghost",
|
|
496
|
+
size: "sm",
|
|
497
|
+
className: "h-7 text-xs text-zinc-500",
|
|
498
|
+
onClick: () => {
|
|
499
|
+
resetState();
|
|
500
|
+
},
|
|
501
|
+
children: [
|
|
502
|
+
/* @__PURE__ */ jsx(X, { className: "w-3 h-3 mr-1" }),
|
|
503
|
+
" Reset"
|
|
504
|
+
]
|
|
505
|
+
}
|
|
506
|
+
)
|
|
507
|
+
] }),
|
|
508
|
+
/* @__PURE__ */ jsxs("div", { className: "border border-white/5 rounded-lg overflow-auto max-h-60", children: [
|
|
509
|
+
/* @__PURE__ */ jsxs("table", { className: "w-full text-xs", children: [
|
|
510
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { className: "bg-[#0d0d0d]", children: parsedData.headers.map((h) => /* @__PURE__ */ jsx("th", { className: "px-3 py-2 text-left text-xs uppercase tracking-wider text-zinc-500 font-mono border-b border-white/5 whitespace-nowrap", children: h }, h)) }) }),
|
|
511
|
+
/* @__PURE__ */ jsx("tbody", { children: parsedData.rows.slice(0, 10).map((row, idx) => /* @__PURE__ */ jsx("tr", { className: "border-b border-white/5 hover:bg-white/[0.02]", children: row.map((cell, cidx) => /* @__PURE__ */ jsx("td", { className: "px-3 py-1.5 text-zinc-300 font-mono whitespace-nowrap max-w-[200px] truncate", children: cell || /* @__PURE__ */ jsx("span", { className: "text-zinc-600 italic", children: "NULL" }) }, cidx)) }, idx)) })
|
|
512
|
+
] }),
|
|
513
|
+
parsedData.totalRows > 10 && /* @__PURE__ */ jsxs("div", { className: "text-center py-2 text-xs text-zinc-600 bg-[#0d0d0d]", children: [
|
|
514
|
+
"... and ",
|
|
515
|
+
parsedData.totalRows - 10,
|
|
516
|
+
" more rows"
|
|
517
|
+
] })
|
|
518
|
+
] }),
|
|
519
|
+
/* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsxs(
|
|
520
|
+
Button,
|
|
521
|
+
{
|
|
522
|
+
size: "sm",
|
|
523
|
+
className: "bg-blue-600 hover:bg-blue-500 h-8 text-xs gap-1",
|
|
524
|
+
onClick: () => setStep("configure"),
|
|
525
|
+
children: [
|
|
526
|
+
"Configure Import ",
|
|
527
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "w-3 h-3" })
|
|
528
|
+
]
|
|
529
|
+
}
|
|
530
|
+
) })
|
|
531
|
+
] }),
|
|
532
|
+
step === "configure" && parsedData && /* @__PURE__ */ jsxs("div", { className: "p-4 space-y-4", children: [
|
|
533
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
534
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs text-zinc-400 font-medium", children: "Target Table" }),
|
|
535
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
536
|
+
/* @__PURE__ */ jsxs(
|
|
537
|
+
"button",
|
|
538
|
+
{
|
|
539
|
+
className: cn(
|
|
540
|
+
"flex-1 px-3 py-2 rounded-lg border text-xs text-left transition-all",
|
|
541
|
+
!createNewTable ? "border-blue-500/40 bg-blue-500/10 text-blue-400" : "border-white/10 text-zinc-500 hover:bg-white/5"
|
|
542
|
+
),
|
|
543
|
+
onClick: () => setCreateNewTable(false),
|
|
544
|
+
children: [
|
|
545
|
+
/* @__PURE__ */ jsx(Table2, { className: "w-4 h-4 mb-1" }),
|
|
546
|
+
"Existing Table"
|
|
547
|
+
]
|
|
548
|
+
}
|
|
549
|
+
),
|
|
550
|
+
/* @__PURE__ */ jsxs(
|
|
551
|
+
"button",
|
|
552
|
+
{
|
|
553
|
+
className: cn(
|
|
554
|
+
"flex-1 px-3 py-2 rounded-lg border text-xs text-left transition-all",
|
|
555
|
+
createNewTable ? "border-emerald-500/40 bg-emerald-500/10 text-emerald-400" : "border-white/10 text-zinc-500 hover:bg-white/5"
|
|
556
|
+
),
|
|
557
|
+
onClick: () => setCreateNewTable(true),
|
|
558
|
+
children: [
|
|
559
|
+
/* @__PURE__ */ jsx(FileSpreadsheet, { className: "w-4 h-4 mb-1" }),
|
|
560
|
+
"New Table"
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
)
|
|
564
|
+
] })
|
|
565
|
+
] }),
|
|
566
|
+
createNewTable ? /* @__PURE__ */ jsxs("div", { children: [
|
|
567
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs text-zinc-400", children: "New Table Name" }),
|
|
568
|
+
/* @__PURE__ */ jsx(
|
|
569
|
+
Input,
|
|
570
|
+
{
|
|
571
|
+
value: newTableName,
|
|
572
|
+
onChange: (e) => setNewTableName(e.target.value),
|
|
573
|
+
placeholder: "imported_data",
|
|
574
|
+
className: "mt-1 bg-[#111] border-white/10 text-sm h-9"
|
|
575
|
+
}
|
|
576
|
+
)
|
|
577
|
+
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
578
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs text-zinc-400", children: "Select Table" }),
|
|
579
|
+
/* @__PURE__ */ jsxs(
|
|
580
|
+
"select",
|
|
581
|
+
{
|
|
582
|
+
value: targetTable,
|
|
583
|
+
onChange: (e) => setTargetTable(e.target.value),
|
|
584
|
+
className: "w-full mt-1 bg-[#111] border border-white/10 rounded-md px-3 py-2 text-sm text-zinc-300 outline-none focus:border-blue-500/40",
|
|
585
|
+
children: [
|
|
586
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "-- Select a table --" }),
|
|
587
|
+
tables.map((t) => /* @__PURE__ */ jsx("option", { value: t.name, children: t.name }, t.name))
|
|
588
|
+
]
|
|
589
|
+
}
|
|
590
|
+
)
|
|
591
|
+
] }),
|
|
592
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
593
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs text-zinc-400 font-medium", children: "Column Mapping" }),
|
|
594
|
+
/* @__PURE__ */ jsxs("div", { className: "border border-white/5 rounded-lg overflow-hidden", children: [
|
|
595
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-[#0d0d0d] grid grid-cols-[1fr,auto,1fr] gap-2 px-3 py-1.5 text-xs uppercase tracking-wider text-zinc-500 border-b border-white/5", children: [
|
|
596
|
+
/* @__PURE__ */ jsx("span", { children: "Source Column" }),
|
|
597
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
598
|
+
/* @__PURE__ */ jsx("span", { children: "Target Column" })
|
|
599
|
+
] }),
|
|
600
|
+
/* @__PURE__ */ jsx("div", { className: "max-h-40 overflow-auto", children: parsedData.headers.map((header) => /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr,auto,1fr] gap-2 items-center px-3 py-1.5 border-b border-white/5", children: [
|
|
601
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-300 font-mono truncate", children: header }),
|
|
602
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "w-3 h-3 text-zinc-600" }),
|
|
603
|
+
/* @__PURE__ */ jsx(
|
|
604
|
+
Input,
|
|
605
|
+
{
|
|
606
|
+
value: columnMapping[header] || "",
|
|
607
|
+
onChange: (e) => setColumnMapping((prev) => __spreadProps(__spreadValues({}, prev), { [header]: e.target.value })),
|
|
608
|
+
className: "h-7 text-xs bg-[#111] border-white/10",
|
|
609
|
+
placeholder: header
|
|
610
|
+
}
|
|
611
|
+
)
|
|
612
|
+
] }, header)) })
|
|
613
|
+
] })
|
|
614
|
+
] }),
|
|
615
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between", children: [
|
|
616
|
+
/* @__PURE__ */ jsx(
|
|
617
|
+
Button,
|
|
618
|
+
{
|
|
619
|
+
variant: "ghost",
|
|
620
|
+
size: "sm",
|
|
621
|
+
className: "h-8 text-xs text-zinc-500",
|
|
622
|
+
onClick: () => setStep("preview"),
|
|
623
|
+
children: "Back"
|
|
624
|
+
}
|
|
625
|
+
),
|
|
626
|
+
/* @__PURE__ */ jsxs(
|
|
627
|
+
Button,
|
|
628
|
+
{
|
|
629
|
+
size: "sm",
|
|
630
|
+
className: "bg-blue-600 hover:bg-blue-500 h-8 text-xs gap-1",
|
|
631
|
+
onClick: () => setStep("ready"),
|
|
632
|
+
disabled: !createNewTable && !targetTable,
|
|
633
|
+
children: [
|
|
634
|
+
"Review SQL ",
|
|
635
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "w-3 h-3" })
|
|
636
|
+
]
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
] })
|
|
640
|
+
] }),
|
|
641
|
+
step === "ready" && /* @__PURE__ */ jsxs("div", { className: "p-4 space-y-4", children: [
|
|
642
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
643
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
644
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Ready to Import" }),
|
|
645
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs text-zinc-500 mt-0.5", children: [
|
|
646
|
+
parsedData == null ? void 0 : parsedData.totalRows,
|
|
647
|
+
" rows into ",
|
|
648
|
+
createNewTable ? newTableName || "imported_data" : targetTable
|
|
649
|
+
] })
|
|
650
|
+
] }),
|
|
651
|
+
databaseType && /* @__PURE__ */ jsx("span", { className: "text-xs uppercase tracking-wider text-zinc-500 bg-white/5 px-2 py-1 rounded", children: databaseType })
|
|
652
|
+
] }),
|
|
653
|
+
/* @__PURE__ */ jsx("div", { className: "border border-white/5 rounded-lg bg-[#0d0d0d] overflow-auto max-h-60", children: /* @__PURE__ */ jsxs("pre", { className: "p-3 text-xs text-zinc-400 font-mono whitespace-pre-wrap", children: [
|
|
654
|
+
generatedSQL.substring(0, 3e3),
|
|
655
|
+
generatedSQL.length > 3e3 && "\n\n... (truncated for preview)"
|
|
656
|
+
] }) }),
|
|
657
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between", children: [
|
|
658
|
+
/* @__PURE__ */ jsx(
|
|
659
|
+
Button,
|
|
660
|
+
{
|
|
661
|
+
variant: "ghost",
|
|
662
|
+
size: "sm",
|
|
663
|
+
className: "h-8 text-xs text-zinc-500",
|
|
664
|
+
onClick: () => setStep("configure"),
|
|
665
|
+
children: "Back"
|
|
666
|
+
}
|
|
667
|
+
),
|
|
668
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
669
|
+
/* @__PURE__ */ jsx(
|
|
670
|
+
Button,
|
|
671
|
+
{
|
|
672
|
+
variant: "outline",
|
|
673
|
+
size: "sm",
|
|
674
|
+
className: "h-8 text-xs border-white/10",
|
|
675
|
+
onClick: () => {
|
|
676
|
+
navigator.clipboard.writeText(generatedSQL);
|
|
677
|
+
},
|
|
678
|
+
children: "Copy SQL"
|
|
679
|
+
}
|
|
680
|
+
),
|
|
681
|
+
/* @__PURE__ */ jsx(
|
|
682
|
+
Button,
|
|
683
|
+
{
|
|
684
|
+
size: "sm",
|
|
685
|
+
className: "bg-emerald-600 hover:bg-emerald-500 h-8 text-xs gap-1",
|
|
686
|
+
onClick: handleImport,
|
|
687
|
+
disabled: isImporting,
|
|
688
|
+
children: isImporting ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
689
|
+
/* @__PURE__ */ jsx(Loader2, { className: "w-3 h-3 animate-spin" }),
|
|
690
|
+
" Importing..."
|
|
691
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
692
|
+
/* @__PURE__ */ jsx(Upload, { className: "w-3 h-3" }),
|
|
693
|
+
" Execute Import"
|
|
694
|
+
] })
|
|
695
|
+
}
|
|
696
|
+
)
|
|
697
|
+
] })
|
|
698
|
+
] })
|
|
699
|
+
] })
|
|
700
|
+
] })
|
|
701
|
+
] }) });
|
|
702
|
+
}
|
|
703
|
+
function Textarea(_a) {
|
|
704
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
705
|
+
return /* @__PURE__ */ jsx(
|
|
706
|
+
"textarea",
|
|
707
|
+
__spreadValues({
|
|
708
|
+
"data-slot": "textarea",
|
|
709
|
+
className: cn(
|
|
710
|
+
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
711
|
+
className
|
|
712
|
+
)
|
|
713
|
+
}, props)
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
function SaveQueryModal({ isOpen, onClose, onSave, defaultQuery }) {
|
|
717
|
+
const [name, setName] = useState("");
|
|
718
|
+
const [description, setDescription] = useState("");
|
|
719
|
+
const [tagsInput, setTagsInput] = useState("");
|
|
720
|
+
const handleSave = () => {
|
|
721
|
+
if (!name) return;
|
|
722
|
+
const tags = tagsInput.split(",").map((t) => t.trim()).filter((t) => t);
|
|
723
|
+
onSave(name, description, tags);
|
|
724
|
+
setName("");
|
|
725
|
+
setDescription("");
|
|
726
|
+
setTagsInput("");
|
|
727
|
+
onClose();
|
|
728
|
+
};
|
|
729
|
+
return /* @__PURE__ */ jsx(Dialog, { open: isOpen, onOpenChange: onClose, children: /* @__PURE__ */ jsxs(DialogContent, { className: "bg-[#0d0d0d] border-white/10 text-zinc-300 sm:max-w-[425px]", children: [
|
|
730
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
731
|
+
/* @__PURE__ */ jsxs(DialogTitle, { className: "text-white flex items-center gap-2", children: [
|
|
732
|
+
/* @__PURE__ */ jsx(Bookmark, { className: "w-5 h-5 text-blue-500" }),
|
|
733
|
+
" Save Query"
|
|
734
|
+
] }),
|
|
735
|
+
/* @__PURE__ */ jsx(DialogDescription, { className: "text-zinc-500", children: "Give your query a name and description to find it easily later." })
|
|
736
|
+
] }),
|
|
737
|
+
/* @__PURE__ */ jsxs("div", { className: "grid gap-4 py-4", children: [
|
|
738
|
+
/* @__PURE__ */ jsxs("div", { className: "grid gap-2", children: [
|
|
739
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "name", className: "text-xs font-bold uppercase tracking-widest text-zinc-500", children: "Name" }),
|
|
740
|
+
/* @__PURE__ */ jsx(
|
|
741
|
+
Input,
|
|
742
|
+
{
|
|
743
|
+
id: "name",
|
|
744
|
+
value: name,
|
|
745
|
+
onChange: (e) => setName(e.target.value),
|
|
746
|
+
placeholder: "e.g. Monthly Active Users",
|
|
747
|
+
className: "bg-white/5 border-white/10 focus:ring-blue-500/20"
|
|
748
|
+
}
|
|
749
|
+
)
|
|
750
|
+
] }),
|
|
751
|
+
/* @__PURE__ */ jsxs("div", { className: "grid gap-2", children: [
|
|
752
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "description", className: "text-xs font-bold uppercase tracking-widest text-zinc-500", children: "Description" }),
|
|
753
|
+
/* @__PURE__ */ jsx(
|
|
754
|
+
Textarea,
|
|
755
|
+
{
|
|
756
|
+
id: "description",
|
|
757
|
+
value: description,
|
|
758
|
+
onChange: (e) => setDescription(e.target.value),
|
|
759
|
+
placeholder: "What does this query do?",
|
|
760
|
+
className: "bg-white/5 border-white/10 focus:ring-blue-500/20 min-h-[80px]"
|
|
761
|
+
}
|
|
762
|
+
)
|
|
763
|
+
] }),
|
|
764
|
+
/* @__PURE__ */ jsxs("div", { className: "grid gap-2", children: [
|
|
765
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: "tags", className: "text-xs font-bold uppercase tracking-widest text-zinc-500 flex items-center gap-2", children: [
|
|
766
|
+
/* @__PURE__ */ jsx(Tag, { className: "w-3 h-3" }),
|
|
767
|
+
" Tags (comma separated)"
|
|
768
|
+
] }),
|
|
769
|
+
/* @__PURE__ */ jsx(
|
|
770
|
+
Input,
|
|
771
|
+
{
|
|
772
|
+
id: "tags",
|
|
773
|
+
value: tagsInput,
|
|
774
|
+
onChange: (e) => setTagsInput(e.target.value),
|
|
775
|
+
placeholder: "reports, analytics, users",
|
|
776
|
+
className: "bg-white/5 border-white/10 focus:ring-blue-500/20"
|
|
777
|
+
}
|
|
778
|
+
)
|
|
779
|
+
] }),
|
|
780
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-2", children: [
|
|
781
|
+
/* @__PURE__ */ jsx(Label, { className: "text-xs font-bold uppercase tracking-widest text-zinc-500 mb-2 block", children: "Preview" }),
|
|
782
|
+
/* @__PURE__ */ jsx("div", { className: "bg-[#050505] p-3 rounded-md border border-white/5 max-h-[100px] overflow-y-auto", children: /* @__PURE__ */ jsx("pre", { className: "text-xs font-mono text-zinc-500 italic whitespace-pre-wrap break-words", children: defaultQuery }) })
|
|
783
|
+
] })
|
|
784
|
+
] }),
|
|
785
|
+
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
786
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: onClose, className: "text-zinc-400", children: "Cancel" }),
|
|
787
|
+
/* @__PURE__ */ jsx(
|
|
788
|
+
Button,
|
|
789
|
+
{
|
|
790
|
+
onClick: handleSave,
|
|
791
|
+
disabled: !name,
|
|
792
|
+
className: "bg-blue-600 hover:bg-blue-500 text-white font-bold",
|
|
793
|
+
children: "Save Query"
|
|
794
|
+
}
|
|
795
|
+
)
|
|
796
|
+
] })
|
|
797
|
+
] }) });
|
|
798
|
+
}
|
|
799
|
+
function StudioTabBar({
|
|
800
|
+
tabs,
|
|
801
|
+
activeTabId,
|
|
802
|
+
editingTabId,
|
|
803
|
+
editingTabName,
|
|
804
|
+
onSetActiveTabId,
|
|
805
|
+
onSetEditingTabId,
|
|
806
|
+
onSetEditingTabName,
|
|
807
|
+
onSetTabs,
|
|
808
|
+
onCloseTab,
|
|
809
|
+
onAddTab
|
|
810
|
+
}) {
|
|
811
|
+
return /* @__PURE__ */ jsxs("div", { className: "hidden md:flex h-10 bg-[#0d0d0d] border-b border-white/5 items-center px-2 gap-1 overflow-x-auto no-scrollbar", children: [
|
|
812
|
+
tabs.map((tab) => /* @__PURE__ */ jsxs(
|
|
813
|
+
"div",
|
|
814
|
+
{
|
|
815
|
+
onClick: () => onSetActiveTabId(tab.id),
|
|
816
|
+
onDoubleClick: () => {
|
|
817
|
+
onSetEditingTabId(tab.id);
|
|
818
|
+
onSetEditingTabName(tab.name);
|
|
819
|
+
},
|
|
820
|
+
className: cn(
|
|
821
|
+
"h-8 flex items-center px-3 gap-2 rounded-t-md transition-all cursor-pointer min-w-[120px] max-w-[200px] group relative border-t-2",
|
|
822
|
+
activeTabId === tab.id ? "bg-[#141414] text-zinc-100 border-blue-500" : "text-zinc-500 hover:bg-white/5 border-transparent"
|
|
823
|
+
),
|
|
824
|
+
children: [
|
|
825
|
+
tab.type === "sql" ? /* @__PURE__ */ jsx(Hash, { className: "w-3 h-3" }) : /* @__PURE__ */ jsx(FileJson, { className: "w-3 h-3" }),
|
|
826
|
+
editingTabId === tab.id ? /* @__PURE__ */ jsx(
|
|
827
|
+
"input",
|
|
828
|
+
{
|
|
829
|
+
autoFocus: true,
|
|
830
|
+
value: editingTabName,
|
|
831
|
+
onChange: (e) => onSetEditingTabName(e.target.value),
|
|
832
|
+
onBlur: () => {
|
|
833
|
+
if (editingTabName.trim()) {
|
|
834
|
+
onSetTabs((prev) => prev.map((t) => t.id === tab.id ? __spreadProps(__spreadValues({}, t), { name: editingTabName.trim() }) : t));
|
|
835
|
+
}
|
|
836
|
+
onSetEditingTabId(null);
|
|
837
|
+
},
|
|
838
|
+
onKeyDown: (e) => {
|
|
839
|
+
if (e.key === "Enter") {
|
|
840
|
+
if (editingTabName.trim()) {
|
|
841
|
+
onSetTabs((prev) => prev.map((t) => t.id === tab.id ? __spreadProps(__spreadValues({}, t), { name: editingTabName.trim() }) : t));
|
|
842
|
+
}
|
|
843
|
+
onSetEditingTabId(null);
|
|
844
|
+
} else if (e.key === "Escape") {
|
|
845
|
+
onSetEditingTabId(null);
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
onClick: (e) => e.stopPropagation(),
|
|
849
|
+
className: "text-xs font-medium bg-transparent border-b border-blue-500 outline-none w-full text-zinc-100"
|
|
850
|
+
}
|
|
851
|
+
) : /* @__PURE__ */ jsx("span", { className: "text-xs truncate font-medium", children: tab.name }),
|
|
852
|
+
tabs.length > 1 && /* @__PURE__ */ jsx(X, { className: "w-3 h-3 ml-auto opacity-0 group-hover:opacity-100 hover:text-white shrink-0", onClick: (e) => onCloseTab(tab.id, e) })
|
|
853
|
+
]
|
|
854
|
+
},
|
|
855
|
+
tab.id
|
|
856
|
+
)),
|
|
857
|
+
/* @__PURE__ */ jsx(Plus, { className: "w-4 h-4 text-zinc-500 cursor-pointer hover:text-white mx-2", onClick: onAddTab })
|
|
858
|
+
] });
|
|
859
|
+
}
|
|
860
|
+
function QueryToolbar({
|
|
861
|
+
activeConnection,
|
|
862
|
+
metadata,
|
|
863
|
+
isExecuting,
|
|
864
|
+
playgroundMode,
|
|
865
|
+
transactionActive,
|
|
866
|
+
editingEnabled,
|
|
867
|
+
onSaveQuery,
|
|
868
|
+
onExecuteQuery,
|
|
869
|
+
onCancelQuery,
|
|
870
|
+
onBeginTransaction,
|
|
871
|
+
onCommitTransaction,
|
|
872
|
+
onRollbackTransaction,
|
|
873
|
+
onTogglePlayground,
|
|
874
|
+
onToggleEditing,
|
|
875
|
+
onImport
|
|
876
|
+
}) {
|
|
877
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
878
|
+
playgroundMode && /* @__PURE__ */ jsxs("div", { className: "hidden md:flex items-center justify-center gap-2 px-4 py-1 bg-emerald-500/10 border-b border-emerald-500/20 text-emerald-400", children: [
|
|
879
|
+
/* @__PURE__ */ jsx(FlaskConical, { className: "w-3 h-3" }),
|
|
880
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold uppercase tracking-widest", children: "Sandbox Mode \u2014 All changes will be auto-rolled back" })
|
|
881
|
+
] }),
|
|
882
|
+
/* @__PURE__ */ jsxs("div", { className: "hidden md:flex items-center justify-between px-4 py-1.5 bg-[#0a0a0a] border-b border-white/5", children: [
|
|
883
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
884
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-2 py-0.5 rounded bg-blue-500/5 border border-blue-500/10", children: [
|
|
885
|
+
/* @__PURE__ */ jsx(Terminal, { className: "w-3 h-3 text-blue-400" }),
|
|
886
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-blue-400 uppercase tracking-widest", children: "Query" })
|
|
887
|
+
] }),
|
|
888
|
+
/* @__PURE__ */ jsx("div", { className: "h-4 w-px bg-white/5" }),
|
|
889
|
+
/* @__PURE__ */ jsxs(
|
|
890
|
+
Button,
|
|
891
|
+
{
|
|
892
|
+
variant: "ghost",
|
|
893
|
+
size: "sm",
|
|
894
|
+
className: "h-7 text-xs font-bold uppercase tracking-widest text-zinc-500 hover:text-white gap-2",
|
|
895
|
+
onClick: onSaveQuery,
|
|
896
|
+
children: [
|
|
897
|
+
/* @__PURE__ */ jsx(Save, { className: "w-3 h-3" }),
|
|
898
|
+
" Save"
|
|
899
|
+
]
|
|
900
|
+
}
|
|
901
|
+
)
|
|
902
|
+
] }),
|
|
903
|
+
isExecuting ? /* @__PURE__ */ jsxs(
|
|
904
|
+
Button,
|
|
905
|
+
{
|
|
906
|
+
size: "sm",
|
|
907
|
+
className: "bg-red-600 hover:bg-red-500 text-white font-bold text-body h-7 px-4 gap-2",
|
|
908
|
+
onClick: onCancelQuery,
|
|
909
|
+
children: [
|
|
910
|
+
/* @__PURE__ */ jsx(Square, { className: "w-3 h-3 fill-current" }),
|
|
911
|
+
"CANCEL"
|
|
912
|
+
]
|
|
913
|
+
}
|
|
914
|
+
) : /* @__PURE__ */ jsxs(
|
|
915
|
+
Button,
|
|
916
|
+
{
|
|
917
|
+
size: "sm",
|
|
918
|
+
className: "bg-blue-600 hover:bg-blue-500 text-white font-bold text-body h-7 px-4 gap-2",
|
|
919
|
+
onClick: onExecuteQuery,
|
|
920
|
+
disabled: !activeConnection,
|
|
921
|
+
children: [
|
|
922
|
+
/* @__PURE__ */ jsx(Play, { className: "w-3 h-3 fill-current" }),
|
|
923
|
+
"RUN"
|
|
924
|
+
]
|
|
925
|
+
}
|
|
926
|
+
),
|
|
927
|
+
activeConnection && (metadata == null ? void 0 : metadata.capabilities.queryLanguage) === "sql" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 ml-2 pl-2 border-l border-white/10", children: [
|
|
928
|
+
transactionActive ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
929
|
+
/* @__PURE__ */ jsx("span", { className: "text-label font-bold text-amber-400 uppercase tracking-wider px-1.5 py-0.5 bg-amber-500/10 rounded border border-amber-500/20 mr-1", children: "TXN" }),
|
|
930
|
+
/* @__PURE__ */ jsx(
|
|
931
|
+
Button,
|
|
932
|
+
{
|
|
933
|
+
size: "sm",
|
|
934
|
+
variant: "ghost",
|
|
935
|
+
className: "h-7 text-xs font-bold text-emerald-400 hover:text-emerald-300 hover:bg-emerald-500/10 gap-1",
|
|
936
|
+
onClick: onCommitTransaction,
|
|
937
|
+
children: "COMMIT"
|
|
938
|
+
}
|
|
939
|
+
),
|
|
940
|
+
/* @__PURE__ */ jsx(
|
|
941
|
+
Button,
|
|
942
|
+
{
|
|
943
|
+
size: "sm",
|
|
944
|
+
variant: "ghost",
|
|
945
|
+
className: "h-7 text-xs font-bold text-red-400 hover:text-red-300 hover:bg-red-500/10 gap-1",
|
|
946
|
+
onClick: onRollbackTransaction,
|
|
947
|
+
children: "ROLLBACK"
|
|
948
|
+
}
|
|
949
|
+
)
|
|
950
|
+
] }) : /* @__PURE__ */ jsx(
|
|
951
|
+
Button,
|
|
952
|
+
{
|
|
953
|
+
size: "sm",
|
|
954
|
+
variant: "ghost",
|
|
955
|
+
className: "h-7 text-xs font-bold uppercase tracking-widest text-zinc-500 hover:text-white gap-1",
|
|
956
|
+
onClick: onBeginTransaction,
|
|
957
|
+
disabled: playgroundMode,
|
|
958
|
+
children: "BEGIN"
|
|
959
|
+
}
|
|
960
|
+
),
|
|
961
|
+
/* @__PURE__ */ jsxs(
|
|
962
|
+
Button,
|
|
963
|
+
{
|
|
964
|
+
size: "sm",
|
|
965
|
+
variant: "ghost",
|
|
966
|
+
className: cn(
|
|
967
|
+
"h-7 text-xs font-bold uppercase tracking-widest gap-1",
|
|
968
|
+
playgroundMode ? "text-emerald-400 bg-emerald-500/10 hover:bg-emerald-500/20" : "text-zinc-500 hover:text-white"
|
|
969
|
+
),
|
|
970
|
+
onClick: onTogglePlayground,
|
|
971
|
+
disabled: transactionActive,
|
|
972
|
+
title: "Playground mode: queries are auto-rolled back",
|
|
973
|
+
children: [
|
|
974
|
+
/* @__PURE__ */ jsx(FlaskConical, { className: "w-3 h-3" }),
|
|
975
|
+
"SANDBOX"
|
|
976
|
+
]
|
|
977
|
+
}
|
|
978
|
+
),
|
|
979
|
+
/* @__PURE__ */ jsxs(
|
|
980
|
+
Button,
|
|
981
|
+
{
|
|
982
|
+
size: "sm",
|
|
983
|
+
variant: "ghost",
|
|
984
|
+
className: cn(
|
|
985
|
+
"h-7 text-xs font-bold uppercase tracking-widest gap-1",
|
|
986
|
+
editingEnabled ? "text-amber-400 bg-amber-500/10 hover:bg-amber-500/20" : "text-zinc-500 hover:text-white"
|
|
987
|
+
),
|
|
988
|
+
onClick: onToggleEditing,
|
|
989
|
+
title: "Enable inline data editing",
|
|
990
|
+
children: [
|
|
991
|
+
/* @__PURE__ */ jsx(Pencil, { className: "w-3 h-3" }),
|
|
992
|
+
"EDIT"
|
|
993
|
+
]
|
|
994
|
+
}
|
|
995
|
+
),
|
|
996
|
+
/* @__PURE__ */ jsxs(
|
|
997
|
+
Button,
|
|
998
|
+
{
|
|
999
|
+
size: "sm",
|
|
1000
|
+
variant: "ghost",
|
|
1001
|
+
className: "h-7 text-xs font-bold uppercase tracking-widest text-zinc-500 hover:text-white gap-1",
|
|
1002
|
+
onClick: onImport,
|
|
1003
|
+
title: "Import data from CSV/JSON",
|
|
1004
|
+
children: [
|
|
1005
|
+
/* @__PURE__ */ jsx(Upload, { className: "w-3 h-3" }),
|
|
1006
|
+
"IMPORT"
|
|
1007
|
+
]
|
|
1008
|
+
}
|
|
1009
|
+
)
|
|
1010
|
+
] })
|
|
1011
|
+
] })
|
|
1012
|
+
] });
|
|
1013
|
+
}
|
|
1014
|
+
function AIAutopilotPanel({ connection, schemaContext, onExecuteQuery }) {
|
|
1015
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
1016
|
+
const [report, setReport] = useState("");
|
|
1017
|
+
const [error, setError] = useState(null);
|
|
1018
|
+
const [copiedIndex, setCopiedIndex] = useState(null);
|
|
1019
|
+
const reportRef = useRef(null);
|
|
1020
|
+
const runAutopilot = async () => {
|
|
1021
|
+
var _a;
|
|
1022
|
+
if (!connection) return;
|
|
1023
|
+
setIsLoading(true);
|
|
1024
|
+
setError(null);
|
|
1025
|
+
setReport("");
|
|
1026
|
+
try {
|
|
1027
|
+
const [monitoringRes] = await Promise.all([
|
|
1028
|
+
fetch("/api/db/monitoring", {
|
|
1029
|
+
method: "POST",
|
|
1030
|
+
headers: { "Content-Type": "application/json" },
|
|
1031
|
+
body: JSON.stringify({
|
|
1032
|
+
connection,
|
|
1033
|
+
options: {
|
|
1034
|
+
includeTables: true,
|
|
1035
|
+
includeIndexes: true,
|
|
1036
|
+
slowQueryLimit: 20
|
|
1037
|
+
}
|
|
1038
|
+
})
|
|
1039
|
+
})
|
|
1040
|
+
]);
|
|
1041
|
+
let monitoringData = null;
|
|
1042
|
+
if (monitoringRes.ok) {
|
|
1043
|
+
monitoringData = await monitoringRes.json();
|
|
1044
|
+
}
|
|
1045
|
+
let filteredSchema = "";
|
|
1046
|
+
if (schemaContext) {
|
|
1047
|
+
try {
|
|
1048
|
+
const tables = JSON.parse(schemaContext);
|
|
1049
|
+
filteredSchema = tables.slice(0, 30).map((t) => {
|
|
1050
|
+
var _a2;
|
|
1051
|
+
const cols = ((_a2 = t.columns) == null ? void 0 : _a2.slice(0, 6).map((c) => `${c.name} (${c.type})`).join(", ")) || "";
|
|
1052
|
+
return `${t.name} (${t.rowCount || 0} rows): ${cols}`;
|
|
1053
|
+
}).join("\n");
|
|
1054
|
+
} catch (e) {
|
|
1055
|
+
filteredSchema = schemaContext.substring(0, 2e3);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
const response = await fetch("/api/ai/autopilot", {
|
|
1059
|
+
method: "POST",
|
|
1060
|
+
headers: { "Content-Type": "application/json" },
|
|
1061
|
+
body: JSON.stringify({
|
|
1062
|
+
slowQueries: monitoringData == null ? void 0 : monitoringData.slowQueries,
|
|
1063
|
+
indexStats: monitoringData == null ? void 0 : monitoringData.indexes,
|
|
1064
|
+
tableStats: monitoringData == null ? void 0 : monitoringData.tables,
|
|
1065
|
+
performanceMetrics: monitoringData == null ? void 0 : monitoringData.performance,
|
|
1066
|
+
overview: monitoringData == null ? void 0 : monitoringData.overview,
|
|
1067
|
+
schemaContext: filteredSchema,
|
|
1068
|
+
databaseType: connection.type
|
|
1069
|
+
})
|
|
1070
|
+
});
|
|
1071
|
+
if (!response.ok) {
|
|
1072
|
+
const errData = await response.json();
|
|
1073
|
+
throw new Error(errData.error || "Autopilot analysis failed");
|
|
1074
|
+
}
|
|
1075
|
+
const reader = (_a = response.body) == null ? void 0 : _a.getReader();
|
|
1076
|
+
if (!reader) throw new Error("No reader");
|
|
1077
|
+
let fullResponse = "";
|
|
1078
|
+
while (true) {
|
|
1079
|
+
const { done, value } = await reader.read();
|
|
1080
|
+
if (done) break;
|
|
1081
|
+
fullResponse += new TextDecoder().decode(value);
|
|
1082
|
+
setReport(fullResponse);
|
|
1083
|
+
}
|
|
1084
|
+
} catch (err) {
|
|
1085
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
1086
|
+
} finally {
|
|
1087
|
+
setIsLoading(false);
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
const copyToClipboard = (text, index) => {
|
|
1091
|
+
navigator.clipboard.writeText(text);
|
|
1092
|
+
setCopiedIndex(index);
|
|
1093
|
+
setTimeout(() => setCopiedIndex(null), 2e3);
|
|
1094
|
+
};
|
|
1095
|
+
const renderMarkdown = (text) => {
|
|
1096
|
+
const lines = text.split("\n");
|
|
1097
|
+
const elements = [];
|
|
1098
|
+
let inCodeBlock = false;
|
|
1099
|
+
let codeContent = "";
|
|
1100
|
+
let codeBlockIdx = 0;
|
|
1101
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1102
|
+
const line = lines[i];
|
|
1103
|
+
if (line.startsWith("```")) {
|
|
1104
|
+
if (inCodeBlock) {
|
|
1105
|
+
const blockIndex = codeBlockIdx++;
|
|
1106
|
+
const sql = codeContent.trim();
|
|
1107
|
+
elements.push(
|
|
1108
|
+
/* @__PURE__ */ jsxs("div", { className: "relative group my-2", children: [
|
|
1109
|
+
/* @__PURE__ */ jsx("pre", { className: "bg-[#050505] rounded-lg p-3 text-body font-mono text-blue-300 overflow-x-auto whitespace-pre-wrap border border-white/5", children: sql }),
|
|
1110
|
+
/* @__PURE__ */ jsxs("div", { className: "absolute top-1.5 right-1.5 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity", children: [
|
|
1111
|
+
/* @__PURE__ */ jsx(
|
|
1112
|
+
"button",
|
|
1113
|
+
{
|
|
1114
|
+
onClick: () => copyToClipboard(sql, blockIndex),
|
|
1115
|
+
className: "p-1 rounded bg-white/10 hover:bg-white/20 text-zinc-400",
|
|
1116
|
+
title: "Copy",
|
|
1117
|
+
children: copiedIndex === blockIndex ? /* @__PURE__ */ jsx(Check, { className: "w-3 h-3 text-emerald-400" }) : /* @__PURE__ */ jsx(Copy, { className: "w-3 h-3" })
|
|
1118
|
+
}
|
|
1119
|
+
),
|
|
1120
|
+
onExecuteQuery && /* @__PURE__ */ jsx(
|
|
1121
|
+
"button",
|
|
1122
|
+
{
|
|
1123
|
+
onClick: () => onExecuteQuery(sql),
|
|
1124
|
+
className: "p-1 rounded bg-blue-600/20 hover:bg-blue-600/30 text-blue-400",
|
|
1125
|
+
title: "Execute",
|
|
1126
|
+
children: /* @__PURE__ */ jsx(Play, { className: "w-3 h-3 fill-current" })
|
|
1127
|
+
}
|
|
1128
|
+
)
|
|
1129
|
+
] })
|
|
1130
|
+
] }, `code-${i}`)
|
|
1131
|
+
);
|
|
1132
|
+
codeContent = "";
|
|
1133
|
+
inCodeBlock = false;
|
|
1134
|
+
} else {
|
|
1135
|
+
inCodeBlock = true;
|
|
1136
|
+
}
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
if (inCodeBlock) {
|
|
1140
|
+
codeContent += line + "\n";
|
|
1141
|
+
continue;
|
|
1142
|
+
}
|
|
1143
|
+
if (line.startsWith("## ")) {
|
|
1144
|
+
elements.push(/* @__PURE__ */ jsx("h2", { className: "text-sm font-bold text-zinc-200 mt-4 mb-2", children: line.slice(3) }, i));
|
|
1145
|
+
} else if (line.startsWith("### ")) {
|
|
1146
|
+
elements.push(/* @__PURE__ */ jsx("h3", { className: "text-xs font-bold text-zinc-300 mt-3 mb-1", children: line.slice(4) }, i));
|
|
1147
|
+
} else if (line.startsWith("- ")) {
|
|
1148
|
+
const content = line.slice(2).replace(/\*\*(.*?)\*\*/g, '<strong class="text-zinc-200">$1</strong>');
|
|
1149
|
+
elements.push(/* @__PURE__ */ jsx("li", { className: "text-xs text-zinc-400 ml-4 leading-relaxed", dangerouslySetInnerHTML: { __html: content } }, i));
|
|
1150
|
+
} else if (line.match(/^\d+\.\s/)) {
|
|
1151
|
+
const content = line.replace(/\*\*(.*?)\*\*/g, '<strong class="text-zinc-200">$1</strong>');
|
|
1152
|
+
elements.push(/* @__PURE__ */ jsx("li", { className: "text-xs text-zinc-400 ml-4 leading-relaxed list-decimal", dangerouslySetInnerHTML: { __html: content } }, i));
|
|
1153
|
+
} else if (line.trim()) {
|
|
1154
|
+
const content = line.replace(/\*\*(.*?)\*\*/g, '<strong class="text-zinc-200">$1</strong>');
|
|
1155
|
+
elements.push(/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-400 leading-relaxed", dangerouslySetInnerHTML: { __html: content } }, i));
|
|
1156
|
+
} else {
|
|
1157
|
+
elements.push(/* @__PURE__ */ jsx("div", { className: "h-2" }, i));
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return elements;
|
|
1161
|
+
};
|
|
1162
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#080808]", children: [
|
|
1163
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2 border-b border-white/5 bg-[#0a0a0a]", children: [
|
|
1164
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1165
|
+
/* @__PURE__ */ jsx("div", { className: "p-1 rounded bg-cyan-500/10", children: /* @__PURE__ */ jsx(Sparkles, { className: "w-3.5 h-3.5 text-cyan-400" }) }),
|
|
1166
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-cyan-400 uppercase tracking-widest", children: "AI Performance Autopilot" })
|
|
1167
|
+
] }),
|
|
1168
|
+
/* @__PURE__ */ jsx(
|
|
1169
|
+
"button",
|
|
1170
|
+
{
|
|
1171
|
+
onClick: runAutopilot,
|
|
1172
|
+
disabled: isLoading || !connection,
|
|
1173
|
+
className: cn(
|
|
1174
|
+
"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors",
|
|
1175
|
+
isLoading ? "bg-cyan-600/20 text-cyan-400 cursor-wait" : "bg-cyan-600 hover:bg-cyan-500 text-white"
|
|
1176
|
+
),
|
|
1177
|
+
children: isLoading ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1178
|
+
/* @__PURE__ */ jsx(Loader2, { className: "w-3 h-3 animate-spin" }),
|
|
1179
|
+
" Analyzing..."
|
|
1180
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1181
|
+
/* @__PURE__ */ jsx(RefreshCw, { className: "w-3 h-3" }),
|
|
1182
|
+
" ",
|
|
1183
|
+
report ? "Re-analyze" : "Run Analysis"
|
|
1184
|
+
] })
|
|
1185
|
+
}
|
|
1186
|
+
)
|
|
1187
|
+
] }),
|
|
1188
|
+
/* @__PURE__ */ jsxs("div", { ref: reportRef, className: "flex-1 overflow-auto p-4", children: [
|
|
1189
|
+
!report && !isLoading && !error && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full opacity-40", children: [
|
|
1190
|
+
/* @__PURE__ */ jsx(Sparkles, { className: "w-8 h-8 mb-3" }),
|
|
1191
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "AI Performance Autopilot" }),
|
|
1192
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-500 mt-1", children: 'Click "Run Analysis" to get AI-powered optimization recommendations' })
|
|
1193
|
+
] }),
|
|
1194
|
+
error && /* @__PURE__ */ jsx("div", { className: "bg-red-500/10 border border-red-500/20 rounded-lg p-3 text-xs text-red-400", children: error }),
|
|
1195
|
+
report && /* @__PURE__ */ jsx("div", { className: "prose prose-invert prose-xs max-w-none", children: renderMarkdown(report) })
|
|
1196
|
+
] })
|
|
1197
|
+
] });
|
|
1198
|
+
}
|
|
1199
|
+
var AGG_LABELS = {
|
|
1200
|
+
count: "COUNT",
|
|
1201
|
+
sum: "SUM",
|
|
1202
|
+
avg: "AVG",
|
|
1203
|
+
min: "MIN",
|
|
1204
|
+
max: "MAX"
|
|
1205
|
+
};
|
|
1206
|
+
function aggregate(values, fn) {
|
|
1207
|
+
const nums = values.map((v) => Number(v)).filter((n) => !isNaN(n));
|
|
1208
|
+
switch (fn) {
|
|
1209
|
+
case "count":
|
|
1210
|
+
return String(values.length);
|
|
1211
|
+
case "sum":
|
|
1212
|
+
return nums.length ? nums.reduce((a, b) => a + b, 0).toFixed(2) : "0";
|
|
1213
|
+
case "avg":
|
|
1214
|
+
return nums.length ? (nums.reduce((a, b) => a + b, 0) / nums.length).toFixed(2) : "0";
|
|
1215
|
+
case "min":
|
|
1216
|
+
return nums.length ? String(Math.min(...nums)) : "-";
|
|
1217
|
+
case "max":
|
|
1218
|
+
return nums.length ? String(Math.max(...nums)) : "-";
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
function PivotTable({ result, onLoadQuery }) {
|
|
1222
|
+
const [rowField, setRowField] = useState(null);
|
|
1223
|
+
const [colField, setColField] = useState(null);
|
|
1224
|
+
const [valueField, setValueField] = useState(null);
|
|
1225
|
+
const [aggFunction, setAggFunction] = useState("count");
|
|
1226
|
+
const fields = (result == null ? void 0 : result.fields) || [];
|
|
1227
|
+
const rows = useMemo(() => (result == null ? void 0 : result.rows) || [], [result == null ? void 0 : result.rows]);
|
|
1228
|
+
useEffect(() => {
|
|
1229
|
+
if (fields.length >= 2 && !rowField) {
|
|
1230
|
+
const strCol = fields.find((f) => {
|
|
1231
|
+
var _a;
|
|
1232
|
+
const sample = (_a = rows[0]) == null ? void 0 : _a[f];
|
|
1233
|
+
return typeof sample === "string";
|
|
1234
|
+
});
|
|
1235
|
+
if (strCol) setRowField(strCol);
|
|
1236
|
+
const numCol = fields.find((f) => {
|
|
1237
|
+
var _a;
|
|
1238
|
+
const sample = (_a = rows[0]) == null ? void 0 : _a[f];
|
|
1239
|
+
return typeof sample === "number";
|
|
1240
|
+
});
|
|
1241
|
+
if (numCol) setValueField(numCol);
|
|
1242
|
+
}
|
|
1243
|
+
}, [fields.length]);
|
|
1244
|
+
const pivotData = useMemo(() => {
|
|
1245
|
+
var _a, _b;
|
|
1246
|
+
if (!rowField || !rows.length) return null;
|
|
1247
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1248
|
+
const colValues = /* @__PURE__ */ new Set();
|
|
1249
|
+
for (const row of rows) {
|
|
1250
|
+
const rowKey = String((_a = row[rowField]) != null ? _a : "NULL");
|
|
1251
|
+
const colKey = colField ? String((_b = row[colField]) != null ? _b : "NULL") : "__all__";
|
|
1252
|
+
const value = valueField ? row[valueField] : 1;
|
|
1253
|
+
if (colField) colValues.add(colKey);
|
|
1254
|
+
if (!groups.has(rowKey)) groups.set(rowKey, /* @__PURE__ */ new Map());
|
|
1255
|
+
const colMap = groups.get(rowKey);
|
|
1256
|
+
if (!colMap.has(colKey)) colMap.set(colKey, []);
|
|
1257
|
+
colMap.get(colKey).push(value);
|
|
1258
|
+
}
|
|
1259
|
+
const colKeys = colField ? Array.from(colValues).sort() : ["__all__"];
|
|
1260
|
+
const pivotRows = [];
|
|
1261
|
+
for (const [rowKey, colMap] of groups) {
|
|
1262
|
+
const values = /* @__PURE__ */ new Map();
|
|
1263
|
+
for (const ck of colKeys) {
|
|
1264
|
+
const vals = colMap.get(ck) || [];
|
|
1265
|
+
values.set(ck, aggregate(vals, aggFunction));
|
|
1266
|
+
}
|
|
1267
|
+
pivotRows.push({ rowKey, values });
|
|
1268
|
+
}
|
|
1269
|
+
pivotRows.sort((a, b) => a.rowKey.localeCompare(b.rowKey));
|
|
1270
|
+
return { colKeys, pivotRows };
|
|
1271
|
+
}, [rows, rowField, colField, valueField, aggFunction]);
|
|
1272
|
+
const generateSQL = useCallback(() => {
|
|
1273
|
+
if (!rowField) return "";
|
|
1274
|
+
const select = [`"${rowField}"`];
|
|
1275
|
+
const groupBy = [`"${rowField}"`];
|
|
1276
|
+
if (colField) {
|
|
1277
|
+
const colKeys = (pivotData == null ? void 0 : pivotData.colKeys) || [];
|
|
1278
|
+
for (const ck of colKeys) {
|
|
1279
|
+
if (ck === "__all__") continue;
|
|
1280
|
+
const valExpr = valueField ? `"${valueField}"` : "1";
|
|
1281
|
+
select.push(
|
|
1282
|
+
`${AGG_LABELS[aggFunction]}(CASE WHEN "${colField}" = '${ck.replace(/'/g, "''")}' THEN ${valExpr} END) AS "${ck}"`
|
|
1283
|
+
);
|
|
1284
|
+
}
|
|
1285
|
+
} else {
|
|
1286
|
+
const valExpr = valueField ? `"${valueField}"` : "*";
|
|
1287
|
+
select.push(`${AGG_LABELS[aggFunction]}(${valExpr}) AS "${aggFunction}_value"`);
|
|
1288
|
+
}
|
|
1289
|
+
return `SELECT
|
|
1290
|
+
${select.join(",\n ")}
|
|
1291
|
+
FROM your_table
|
|
1292
|
+
GROUP BY ${groupBy.join(", ")}
|
|
1293
|
+
ORDER BY ${groupBy.join(", ")};`;
|
|
1294
|
+
}, [rowField, colField, valueField, aggFunction, pivotData]);
|
|
1295
|
+
if (!result || rows.length === 0) {
|
|
1296
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col items-center justify-center opacity-30", children: [
|
|
1297
|
+
/* @__PURE__ */ jsx(Columns3, { className: "w-8 h-8 mb-3" }),
|
|
1298
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Pivot Table" }),
|
|
1299
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-500 mt-1", children: "Execute a query to create pivot tables" })
|
|
1300
|
+
] });
|
|
1301
|
+
}
|
|
1302
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#080808]", children: [
|
|
1303
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-4 py-2 border-b border-white/5 bg-[#0a0a0a] flex-wrap", children: [
|
|
1304
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1305
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500 font-bold uppercase", children: "Rows:" }),
|
|
1306
|
+
/* @__PURE__ */ jsxs(
|
|
1307
|
+
"select",
|
|
1308
|
+
{
|
|
1309
|
+
value: rowField || "",
|
|
1310
|
+
onChange: (e) => setRowField(e.target.value || null),
|
|
1311
|
+
className: "bg-[#111] border border-white/10 rounded px-2 py-1 text-body text-zinc-300 outline-none",
|
|
1312
|
+
children: [
|
|
1313
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "Select..." }),
|
|
1314
|
+
fields.map((f) => /* @__PURE__ */ jsx("option", { value: f, children: f }, f))
|
|
1315
|
+
]
|
|
1316
|
+
}
|
|
1317
|
+
)
|
|
1318
|
+
] }),
|
|
1319
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1320
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500 font-bold uppercase", children: "Columns:" }),
|
|
1321
|
+
/* @__PURE__ */ jsxs(
|
|
1322
|
+
"select",
|
|
1323
|
+
{
|
|
1324
|
+
value: colField || "",
|
|
1325
|
+
onChange: (e) => setColField(e.target.value || null),
|
|
1326
|
+
className: "bg-[#111] border border-white/10 rounded px-2 py-1 text-body text-zinc-300 outline-none",
|
|
1327
|
+
children: [
|
|
1328
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "None" }),
|
|
1329
|
+
fields.filter((f) => f !== rowField).map((f) => /* @__PURE__ */ jsx("option", { value: f, children: f }, f))
|
|
1330
|
+
]
|
|
1331
|
+
}
|
|
1332
|
+
)
|
|
1333
|
+
] }),
|
|
1334
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1335
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500 font-bold uppercase", children: "Values:" }),
|
|
1336
|
+
/* @__PURE__ */ jsxs(
|
|
1337
|
+
"select",
|
|
1338
|
+
{
|
|
1339
|
+
value: valueField || "",
|
|
1340
|
+
onChange: (e) => setValueField(e.target.value || null),
|
|
1341
|
+
className: "bg-[#111] border border-white/10 rounded px-2 py-1 text-body text-zinc-300 outline-none",
|
|
1342
|
+
children: [
|
|
1343
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "Count" }),
|
|
1344
|
+
fields.filter((f) => f !== rowField && f !== colField).map((f) => /* @__PURE__ */ jsx("option", { value: f, children: f }, f))
|
|
1345
|
+
]
|
|
1346
|
+
}
|
|
1347
|
+
)
|
|
1348
|
+
] }),
|
|
1349
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: Object.keys(AGG_LABELS).map((fn) => /* @__PURE__ */ jsx(
|
|
1350
|
+
"button",
|
|
1351
|
+
{
|
|
1352
|
+
onClick: () => setAggFunction(fn),
|
|
1353
|
+
className: cn(
|
|
1354
|
+
"px-1.5 py-0.5 rounded text-xs font-bold transition-colors",
|
|
1355
|
+
aggFunction === fn ? "bg-blue-500/20 text-blue-400 border border-blue-500/20" : "text-zinc-600 hover:text-zinc-400"
|
|
1356
|
+
),
|
|
1357
|
+
children: AGG_LABELS[fn]
|
|
1358
|
+
},
|
|
1359
|
+
fn
|
|
1360
|
+
)) }),
|
|
1361
|
+
onLoadQuery && rowField && /* @__PURE__ */ jsxs(
|
|
1362
|
+
"button",
|
|
1363
|
+
{
|
|
1364
|
+
onClick: () => {
|
|
1365
|
+
const sql = generateSQL();
|
|
1366
|
+
if (sql) onLoadQuery(sql);
|
|
1367
|
+
},
|
|
1368
|
+
className: "ml-auto flex items-center gap-1 px-2 py-1 rounded text-xs font-bold text-zinc-500 hover:text-blue-400 hover:bg-blue-500/10 transition-colors",
|
|
1369
|
+
children: [
|
|
1370
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "w-3 h-3" }),
|
|
1371
|
+
" Generate SQL"
|
|
1372
|
+
]
|
|
1373
|
+
}
|
|
1374
|
+
)
|
|
1375
|
+
] }),
|
|
1376
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-auto", children: pivotData && pivotData.pivotRows.length > 0 ? /* @__PURE__ */ jsxs("table", { className: "w-full text-body font-mono", children: [
|
|
1377
|
+
/* @__PURE__ */ jsx("thead", { className: "sticky top-0 z-10 bg-[#0d0d0d]", children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
1378
|
+
/* @__PURE__ */ jsx("th", { className: "text-left px-3 py-2 text-zinc-500 border-b border-r border-white/5 font-bold uppercase tracking-wider", children: rowField }),
|
|
1379
|
+
pivotData.colKeys.map((ck) => /* @__PURE__ */ jsx("th", { className: "text-right px-3 py-2 text-zinc-500 border-b border-r border-white/5 font-bold", children: ck === "__all__" ? `${AGG_LABELS[aggFunction]}(${valueField || "*"})` : ck }, ck))
|
|
1380
|
+
] }) }),
|
|
1381
|
+
/* @__PURE__ */ jsx("tbody", { children: pivotData.pivotRows.map((row, i) => /* @__PURE__ */ jsxs("tr", { className: "hover:bg-blue-500/[0.03] border-b border-white/5", children: [
|
|
1382
|
+
/* @__PURE__ */ jsx("td", { className: "px-3 py-1.5 text-zinc-300 border-r border-white/5 font-medium", children: row.rowKey }),
|
|
1383
|
+
pivotData.colKeys.map((ck) => /* @__PURE__ */ jsx("td", { className: "px-3 py-1.5 text-right text-amber-500/90 border-r border-white/5", children: row.values.get(ck) || "0" }, ck))
|
|
1384
|
+
] }, i)) })
|
|
1385
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full opacity-30", children: [
|
|
1386
|
+
/* @__PURE__ */ jsx(GripVertical, { className: "w-6 h-6 mb-2" }),
|
|
1387
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs", children: "Select row and value fields to build pivot" })
|
|
1388
|
+
] }) }),
|
|
1389
|
+
pivotData && /* @__PURE__ */ jsxs("div", { className: "px-4 py-1.5 border-t border-white/5 bg-[#0a0a0a] text-xs text-zinc-500 font-mono", children: [
|
|
1390
|
+
pivotData.pivotRows.length,
|
|
1391
|
+
" groups \u2022 ",
|
|
1392
|
+
pivotData.colKeys.length,
|
|
1393
|
+
" columns \u2022 ",
|
|
1394
|
+
AGG_LABELS[aggFunction],
|
|
1395
|
+
" aggregation"
|
|
1396
|
+
] })
|
|
1397
|
+
] });
|
|
1398
|
+
}
|
|
1399
|
+
function DatabaseDocs({ schema, schemaContext, databaseType }) {
|
|
1400
|
+
const [search, setSearch] = useState("");
|
|
1401
|
+
const [aiDocs, setAiDocs] = useState("");
|
|
1402
|
+
const [isAiLoading, setIsAiLoading] = useState(false);
|
|
1403
|
+
const [error, setError] = useState(null);
|
|
1404
|
+
const filteredSchema = schema.filter(
|
|
1405
|
+
(t) => {
|
|
1406
|
+
var _a;
|
|
1407
|
+
return t.name.toLowerCase().includes(search.toLowerCase()) || ((_a = t.columns) == null ? void 0 : _a.some((c) => c.name.toLowerCase().includes(search.toLowerCase())));
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1410
|
+
const generateAiDocs = async () => {
|
|
1411
|
+
var _a;
|
|
1412
|
+
setIsAiLoading(true);
|
|
1413
|
+
setError(null);
|
|
1414
|
+
setAiDocs("");
|
|
1415
|
+
try {
|
|
1416
|
+
let filteredSchemaStr = "";
|
|
1417
|
+
if (schemaContext) {
|
|
1418
|
+
try {
|
|
1419
|
+
const tables = JSON.parse(schemaContext);
|
|
1420
|
+
filteredSchemaStr = tables.slice(0, 50).map((t) => {
|
|
1421
|
+
var _a2;
|
|
1422
|
+
const cols = ((_a2 = t.columns) == null ? void 0 : _a2.map(
|
|
1423
|
+
(c) => `${c.name} (${c.type}${c.isPrimary ? ", PK" : ""}${c.isNullable === false ? ", NOT NULL" : ""})`
|
|
1424
|
+
).join(", ")) || "";
|
|
1425
|
+
return `Table: ${t.name} (${t.rowCount || 0} rows)
|
|
1426
|
+
Columns: ${cols}`;
|
|
1427
|
+
}).join("\n\n");
|
|
1428
|
+
} catch (e) {
|
|
1429
|
+
filteredSchemaStr = schemaContext.substring(0, 5e3);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
const response = await fetch("/api/ai/describe-schema", {
|
|
1433
|
+
method: "POST",
|
|
1434
|
+
headers: { "Content-Type": "application/json" },
|
|
1435
|
+
body: JSON.stringify({
|
|
1436
|
+
schemaContext: filteredSchemaStr,
|
|
1437
|
+
databaseType,
|
|
1438
|
+
mode: "full"
|
|
1439
|
+
})
|
|
1440
|
+
});
|
|
1441
|
+
if (!response.ok) {
|
|
1442
|
+
const err = await response.json();
|
|
1443
|
+
throw new Error(err.error || "Documentation generation failed");
|
|
1444
|
+
}
|
|
1445
|
+
const reader = (_a = response.body) == null ? void 0 : _a.getReader();
|
|
1446
|
+
if (!reader) throw new Error("No reader");
|
|
1447
|
+
let full = "";
|
|
1448
|
+
while (true) {
|
|
1449
|
+
const { done, value } = await reader.read();
|
|
1450
|
+
if (done) break;
|
|
1451
|
+
full += new TextDecoder().decode(value);
|
|
1452
|
+
setAiDocs(full);
|
|
1453
|
+
}
|
|
1454
|
+
} catch (err) {
|
|
1455
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
1456
|
+
} finally {
|
|
1457
|
+
setIsAiLoading(false);
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
const exportMarkdown = () => {
|
|
1461
|
+
let md = `# Database Documentation
|
|
1462
|
+
|
|
1463
|
+
`;
|
|
1464
|
+
md += `**Type:** ${databaseType || "Unknown"}
|
|
1465
|
+
`;
|
|
1466
|
+
md += `**Tables:** ${schema.length}
|
|
1467
|
+
|
|
1468
|
+
`;
|
|
1469
|
+
if (aiDocs) {
|
|
1470
|
+
md += `## AI Analysis
|
|
1471
|
+
|
|
1472
|
+
${aiDocs}
|
|
1473
|
+
|
|
1474
|
+
---
|
|
1475
|
+
|
|
1476
|
+
`;
|
|
1477
|
+
}
|
|
1478
|
+
md += `## Table Reference
|
|
1479
|
+
|
|
1480
|
+
`;
|
|
1481
|
+
for (const table of schema) {
|
|
1482
|
+
md += `### ${table.name}
|
|
1483
|
+
|
|
1484
|
+
`;
|
|
1485
|
+
if (table.rowCount !== void 0) md += `Rows: ${table.rowCount.toLocaleString()}
|
|
1486
|
+
|
|
1487
|
+
`;
|
|
1488
|
+
if (table.columns && table.columns.length > 0) {
|
|
1489
|
+
md += `| Column | Type | Primary | Nullable |
|
|
1490
|
+
|--------|------|---------|----------|
|
|
1491
|
+
`;
|
|
1492
|
+
for (const col of table.columns) {
|
|
1493
|
+
md += `| ${col.name} | ${col.type} | ${col.isPrimary ? "Yes" : ""} | ${col.nullable !== false ? "Yes" : "No"} |
|
|
1494
|
+
`;
|
|
1495
|
+
}
|
|
1496
|
+
md += "\n";
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
const blob = new Blob([md], { type: "text/markdown" });
|
|
1500
|
+
const url = URL.createObjectURL(blob);
|
|
1501
|
+
const a = document.createElement("a");
|
|
1502
|
+
a.href = url;
|
|
1503
|
+
a.download = "database-docs.md";
|
|
1504
|
+
a.click();
|
|
1505
|
+
URL.revokeObjectURL(url);
|
|
1506
|
+
};
|
|
1507
|
+
const renderMarkdown = (text) => {
|
|
1508
|
+
return text.split("\n").map((line, i) => {
|
|
1509
|
+
if (line.startsWith("## ")) return /* @__PURE__ */ jsx("h2", { className: "text-sm font-bold text-zinc-200 mt-4 mb-2", children: line.slice(3) }, i);
|
|
1510
|
+
if (line.startsWith("### ")) return /* @__PURE__ */ jsx("h3", { className: "text-xs font-bold text-zinc-300 mt-3 mb-1", children: line.slice(4) }, i);
|
|
1511
|
+
if (line.startsWith("- ")) {
|
|
1512
|
+
const content = line.slice(2).replace(/\*\*(.*?)\*\*/g, '<strong class="text-zinc-200">$1</strong>');
|
|
1513
|
+
return /* @__PURE__ */ jsx("li", { className: "text-xs text-zinc-400 ml-4 leading-relaxed", dangerouslySetInnerHTML: { __html: content } }, i);
|
|
1514
|
+
}
|
|
1515
|
+
if (line.match(/^\d+\.\s/)) {
|
|
1516
|
+
const content = line.replace(/\*\*(.*?)\*\*/g, '<strong class="text-zinc-200">$1</strong>');
|
|
1517
|
+
return /* @__PURE__ */ jsx("li", { className: "text-xs text-zinc-400 ml-4 leading-relaxed list-decimal", dangerouslySetInnerHTML: { __html: content } }, i);
|
|
1518
|
+
}
|
|
1519
|
+
if (line.trim()) {
|
|
1520
|
+
const content = line.replace(/\*\*(.*?)\*\*/g, '<strong class="text-zinc-200">$1</strong>');
|
|
1521
|
+
return /* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-400 leading-relaxed", dangerouslySetInnerHTML: { __html: content } }, i);
|
|
1522
|
+
}
|
|
1523
|
+
return /* @__PURE__ */ jsx("div", { className: "h-1.5" }, i);
|
|
1524
|
+
});
|
|
1525
|
+
};
|
|
1526
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#080808]", children: [
|
|
1527
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2 border-b border-white/5 bg-[#0a0a0a]", children: [
|
|
1528
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1529
|
+
/* @__PURE__ */ jsx("div", { className: "p-1 rounded bg-teal-500/10", children: /* @__PURE__ */ jsx(FileText, { className: "w-3.5 h-3.5 text-teal-400" }) }),
|
|
1530
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-teal-400 uppercase tracking-widest", children: "Database Docs" }),
|
|
1531
|
+
/* @__PURE__ */ jsxs("span", { className: "text-label text-zinc-500 font-mono", children: [
|
|
1532
|
+
schema.length,
|
|
1533
|
+
" tables"
|
|
1534
|
+
] })
|
|
1535
|
+
] }),
|
|
1536
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1537
|
+
/* @__PURE__ */ jsxs(
|
|
1538
|
+
"button",
|
|
1539
|
+
{
|
|
1540
|
+
onClick: generateAiDocs,
|
|
1541
|
+
disabled: isAiLoading,
|
|
1542
|
+
className: cn(
|
|
1543
|
+
"flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-bold transition-colors",
|
|
1544
|
+
isAiLoading ? "bg-teal-600/20 text-teal-400 cursor-wait" : "bg-teal-600 hover:bg-teal-500 text-white"
|
|
1545
|
+
),
|
|
1546
|
+
children: [
|
|
1547
|
+
isAiLoading ? /* @__PURE__ */ jsx(Loader2, { className: "w-3 h-3 animate-spin" }) : /* @__PURE__ */ jsx(Sparkles, { className: "w-3 h-3" }),
|
|
1548
|
+
aiDocs ? "Regenerate" : "AI Describe"
|
|
1549
|
+
]
|
|
1550
|
+
}
|
|
1551
|
+
),
|
|
1552
|
+
/* @__PURE__ */ jsxs(
|
|
1553
|
+
"button",
|
|
1554
|
+
{
|
|
1555
|
+
onClick: exportMarkdown,
|
|
1556
|
+
className: "flex items-center gap-1 px-2.5 py-1 rounded-lg bg-white/5 text-zinc-400 text-xs font-bold hover:bg-white/10 transition-colors",
|
|
1557
|
+
children: [
|
|
1558
|
+
/* @__PURE__ */ jsx(Download, { className: "w-3 h-3" }),
|
|
1559
|
+
" Export MD"
|
|
1560
|
+
]
|
|
1561
|
+
}
|
|
1562
|
+
)
|
|
1563
|
+
] })
|
|
1564
|
+
] }),
|
|
1565
|
+
/* @__PURE__ */ jsx("div", { className: "px-4 py-2 border-b border-white/5 bg-[#0a0a0a]", children: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
1566
|
+
/* @__PURE__ */ jsx(Search, { className: "absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-zinc-500" }),
|
|
1567
|
+
/* @__PURE__ */ jsx(
|
|
1568
|
+
"input",
|
|
1569
|
+
{
|
|
1570
|
+
value: search,
|
|
1571
|
+
onChange: (e) => setSearch(e.target.value),
|
|
1572
|
+
placeholder: "Search tables or columns...",
|
|
1573
|
+
className: "w-full bg-[#111] border border-white/10 rounded-lg pl-7 pr-3 py-1.5 text-xs text-zinc-200 placeholder:text-zinc-600 outline-none focus:border-teal-500/30"
|
|
1574
|
+
}
|
|
1575
|
+
)
|
|
1576
|
+
] }) }),
|
|
1577
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-auto p-4 space-y-3", children: [
|
|
1578
|
+
error && /* @__PURE__ */ jsx("div", { className: "bg-red-500/10 border border-red-500/20 rounded-lg p-3 text-xs text-red-400", children: error }),
|
|
1579
|
+
(aiDocs || isAiLoading) && /* @__PURE__ */ jsxs("div", { className: "bg-teal-500/5 border border-teal-500/10 rounded-lg p-4 mb-4", children: [
|
|
1580
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-3", children: [
|
|
1581
|
+
/* @__PURE__ */ jsx(Sparkles, { className: "w-3.5 h-3.5 text-teal-400" }),
|
|
1582
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-teal-400 uppercase tracking-wider", children: "AI-Generated Documentation" }),
|
|
1583
|
+
isAiLoading && /* @__PURE__ */ jsx(Loader2, { className: "w-3 h-3 animate-spin text-teal-400" })
|
|
1584
|
+
] }),
|
|
1585
|
+
aiDocs && /* @__PURE__ */ jsx("div", { className: "prose prose-invert prose-xs max-w-none", children: renderMarkdown(aiDocs) })
|
|
1586
|
+
] }),
|
|
1587
|
+
/* @__PURE__ */ jsx("h3", { className: "text-xs font-bold text-zinc-400 uppercase tracking-wider", children: "Table Reference" }),
|
|
1588
|
+
filteredSchema.map((table) => {
|
|
1589
|
+
var _a;
|
|
1590
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-[#0a0a0a] border border-white/5 rounded-lg overflow-hidden", children: [
|
|
1591
|
+
/* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between", children: [
|
|
1592
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1593
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-zinc-200", children: table.name }),
|
|
1594
|
+
table.rowCount !== void 0 && /* @__PURE__ */ jsxs("span", { className: "text-xs text-zinc-500 font-mono", children: [
|
|
1595
|
+
table.rowCount.toLocaleString(),
|
|
1596
|
+
" rows"
|
|
1597
|
+
] })
|
|
1598
|
+
] }),
|
|
1599
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-zinc-600", children: [
|
|
1600
|
+
((_a = table.columns) == null ? void 0 : _a.length) || 0,
|
|
1601
|
+
" columns"
|
|
1602
|
+
] })
|
|
1603
|
+
] }),
|
|
1604
|
+
table.columns && table.columns.length > 0 && /* @__PURE__ */ jsx("div", { className: "border-t border-white/5", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-body", children: [
|
|
1605
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "text-zinc-500", children: [
|
|
1606
|
+
/* @__PURE__ */ jsx("th", { className: "text-left px-3 py-1 font-normal", children: "Column" }),
|
|
1607
|
+
/* @__PURE__ */ jsx("th", { className: "text-left px-3 py-1 font-normal", children: "Type" }),
|
|
1608
|
+
/* @__PURE__ */ jsx("th", { className: "text-left px-3 py-1 font-normal", children: "PK" }),
|
|
1609
|
+
/* @__PURE__ */ jsx("th", { className: "text-left px-3 py-1 font-normal", children: "Nullable" })
|
|
1610
|
+
] }) }),
|
|
1611
|
+
/* @__PURE__ */ jsx("tbody", { children: table.columns.map((col) => /* @__PURE__ */ jsxs("tr", { className: "border-t border-white/[0.03] hover:bg-white/[0.02]", children: [
|
|
1612
|
+
/* @__PURE__ */ jsx("td", { className: "px-3 py-1 text-zinc-300 font-mono", children: col.name }),
|
|
1613
|
+
/* @__PURE__ */ jsx("td", { className: "px-3 py-1 text-zinc-500 font-mono", children: col.type }),
|
|
1614
|
+
/* @__PURE__ */ jsx("td", { className: "px-3 py-1", children: col.isPrimary && /* @__PURE__ */ jsx("span", { className: "text-amber-400 text-label font-bold", children: "PK" }) }),
|
|
1615
|
+
/* @__PURE__ */ jsx("td", { className: "px-3 py-1 text-zinc-600", children: col.nullable !== false ? "Yes" : "No" })
|
|
1616
|
+
] }, col.name)) })
|
|
1617
|
+
] }) })
|
|
1618
|
+
] }, table.name);
|
|
1619
|
+
})
|
|
1620
|
+
] })
|
|
1621
|
+
] });
|
|
1622
|
+
}
|
|
1623
|
+
function QueryHistory({ onSelectQuery, activeConnectionId, refreshTrigger }) {
|
|
1624
|
+
const [history, setHistory] = useState([]);
|
|
1625
|
+
const [search, setSearch] = useState("");
|
|
1626
|
+
const [filterStatus, setFilterStatus] = useState("all");
|
|
1627
|
+
const [isGlobal, setIsGlobal] = useState(false);
|
|
1628
|
+
const [sortField, setSortField] = useState("executedAt");
|
|
1629
|
+
const [sortOrder, setSortOrder] = useState("desc");
|
|
1630
|
+
useEffect(() => {
|
|
1631
|
+
setHistory(storage.getHistory());
|
|
1632
|
+
}, [refreshTrigger]);
|
|
1633
|
+
const filteredHistory = useMemo(() => {
|
|
1634
|
+
return history.filter((item) => {
|
|
1635
|
+
var _a, _b;
|
|
1636
|
+
const matchesSearch = item.query.toLowerCase().includes(search.toLowerCase()) || ((_a = item.connectionName) == null ? void 0 : _a.toLowerCase().includes(search.toLowerCase())) || ((_b = item.tabName) == null ? void 0 : _b.toLowerCase().includes(search.toLowerCase()));
|
|
1637
|
+
const matchesStatus = filterStatus === "all" || item.status === filterStatus;
|
|
1638
|
+
const matchesConnection = isGlobal || !activeConnectionId || item.connectionId === activeConnectionId;
|
|
1639
|
+
return matchesSearch && matchesStatus && matchesConnection;
|
|
1640
|
+
}).sort((a, b) => {
|
|
1641
|
+
let valA = 0;
|
|
1642
|
+
let valB = 0;
|
|
1643
|
+
if (sortField === "executedAt") {
|
|
1644
|
+
valA = a.executedAt ? new Date(a.executedAt).getTime() : 0;
|
|
1645
|
+
valB = b.executedAt ? new Date(b.executedAt).getTime() : 0;
|
|
1646
|
+
} else {
|
|
1647
|
+
valA = a[sortField] || 0;
|
|
1648
|
+
valB = b[sortField] || 0;
|
|
1649
|
+
}
|
|
1650
|
+
if (sortOrder === "asc") return valA > valB ? 1 : -1;
|
|
1651
|
+
return valA < valB ? 1 : -1;
|
|
1652
|
+
});
|
|
1653
|
+
}, [history, search, filterStatus, isGlobal, activeConnectionId, sortField, sortOrder]);
|
|
1654
|
+
const handleClearHistory = () => {
|
|
1655
|
+
if (confirm("Are you sure you want to clear all history?")) {
|
|
1656
|
+
storage.clearHistory();
|
|
1657
|
+
setHistory([]);
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
const handleSort = (field) => {
|
|
1661
|
+
if (sortField === field) {
|
|
1662
|
+
setSortOrder(sortOrder === "asc" ? "desc" : "asc");
|
|
1663
|
+
} else {
|
|
1664
|
+
setSortField(field);
|
|
1665
|
+
setSortOrder("desc");
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
const exportHistory = (format3) => {
|
|
1669
|
+
let content = "";
|
|
1670
|
+
let mimeType = "";
|
|
1671
|
+
const fileName = `query_history_${(/* @__PURE__ */ new Date()).getTime()}.${format3}`;
|
|
1672
|
+
if (format3 === "csv") {
|
|
1673
|
+
const headers = ["Executed At", "Status", "Connection", "Tab", "Execution Time (ms)", "Rows", "Query", "Error"];
|
|
1674
|
+
const rows = filteredHistory.map((item) => [
|
|
1675
|
+
item.executedAt,
|
|
1676
|
+
item.status,
|
|
1677
|
+
item.connectionName || item.connectionId,
|
|
1678
|
+
item.tabName || "",
|
|
1679
|
+
item.executionTime,
|
|
1680
|
+
item.rowCount || 0,
|
|
1681
|
+
`"${item.query.replace(/"/g, '""')}"`,
|
|
1682
|
+
`"${(item.errorMessage || "").replace(/"/g, '""')}"`
|
|
1683
|
+
].join(","));
|
|
1684
|
+
content = [headers.join(","), ...rows].join("\n");
|
|
1685
|
+
mimeType = "text/csv";
|
|
1686
|
+
} else {
|
|
1687
|
+
content = JSON.stringify(filteredHistory, null, 2);
|
|
1688
|
+
mimeType = "application/json";
|
|
1689
|
+
}
|
|
1690
|
+
const blob = new Blob([content], { type: mimeType });
|
|
1691
|
+
const url = URL.createObjectURL(blob);
|
|
1692
|
+
const link = document.createElement("a");
|
|
1693
|
+
link.href = url;
|
|
1694
|
+
link.download = fileName;
|
|
1695
|
+
link.click();
|
|
1696
|
+
URL.revokeObjectURL(url);
|
|
1697
|
+
};
|
|
1698
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#080808]", children: [
|
|
1699
|
+
/* @__PURE__ */ jsxs("div", { className: "p-4 border-b border-white/5 bg-[#0a0a0a]/50 backdrop-blur-sm sticky top-0 z-10 space-y-4", children: [
|
|
1700
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1701
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1702
|
+
/* @__PURE__ */ jsx("div", { className: "p-2 rounded-lg bg-emerald-500/10 border border-emerald-500/20", children: /* @__PURE__ */ jsx(History, { className: "w-4 h-4 text-emerald-400" }) }),
|
|
1703
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1704
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-bold text-zinc-100 uppercase tracking-widest flex items-center gap-2", children: "Query History" }),
|
|
1705
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs text-zinc-500 font-medium", children: [
|
|
1706
|
+
"Showing ",
|
|
1707
|
+
filteredHistory.length,
|
|
1708
|
+
" executions"
|
|
1709
|
+
] })
|
|
1710
|
+
] })
|
|
1711
|
+
] }),
|
|
1712
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1713
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
1714
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "h-8 text-xs font-bold uppercase tracking-widest text-zinc-400 hover:text-white gap-2", children: [
|
|
1715
|
+
/* @__PURE__ */ jsx(Download, { className: "w-3.5 h-3.5" }),
|
|
1716
|
+
" Export"
|
|
1717
|
+
] }) }),
|
|
1718
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "bg-[#0d0d0d] border-white/10 text-zinc-300", children: [
|
|
1719
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => exportHistory("csv"), className: "text-xs cursor-pointer", children: "Export as CSV" }),
|
|
1720
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => exportHistory("json"), className: "text-xs cursor-pointer", children: "Export as JSON" })
|
|
1721
|
+
] })
|
|
1722
|
+
] }),
|
|
1723
|
+
/* @__PURE__ */ jsxs(
|
|
1724
|
+
Button,
|
|
1725
|
+
{
|
|
1726
|
+
variant: "ghost",
|
|
1727
|
+
size: "sm",
|
|
1728
|
+
onClick: handleClearHistory,
|
|
1729
|
+
className: "h-8 text-xs font-bold uppercase tracking-widest text-red-400/70 hover:text-red-400 hover:bg-red-400/10",
|
|
1730
|
+
children: [
|
|
1731
|
+
/* @__PURE__ */ jsx(Trash2, { className: "w-3.5 h-3.5 mr-2" }),
|
|
1732
|
+
" Clear"
|
|
1733
|
+
]
|
|
1734
|
+
}
|
|
1735
|
+
)
|
|
1736
|
+
] })
|
|
1737
|
+
] }),
|
|
1738
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
1739
|
+
/* @__PURE__ */ jsxs("div", { className: "relative flex-1 min-w-[240px]", children: [
|
|
1740
|
+
/* @__PURE__ */ jsx(Search, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-zinc-500" }),
|
|
1741
|
+
/* @__PURE__ */ jsx(
|
|
1742
|
+
Input,
|
|
1743
|
+
{
|
|
1744
|
+
placeholder: "Search by query, connection or tab...",
|
|
1745
|
+
value: search,
|
|
1746
|
+
onChange: (e) => setSearch(e.target.value),
|
|
1747
|
+
className: "pl-9 h-9 bg-white/5 border-white/10 text-xs focus:ring-emerald-500/20 rounded-lg"
|
|
1748
|
+
}
|
|
1749
|
+
),
|
|
1750
|
+
search && /* @__PURE__ */ jsx(
|
|
1751
|
+
"button",
|
|
1752
|
+
{
|
|
1753
|
+
onClick: () => setSearch(""),
|
|
1754
|
+
className: "absolute right-3 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-white",
|
|
1755
|
+
children: /* @__PURE__ */ jsx(X, { className: "w-3 h-3" })
|
|
1756
|
+
}
|
|
1757
|
+
)
|
|
1758
|
+
] }),
|
|
1759
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 bg-white/5 rounded-lg p-1 border border-white/10", children: [
|
|
1760
|
+
/* @__PURE__ */ jsx(
|
|
1761
|
+
"button",
|
|
1762
|
+
{
|
|
1763
|
+
onClick: () => setIsGlobal(false),
|
|
1764
|
+
className: cn(
|
|
1765
|
+
"px-3 py-1.5 text-xs font-bold uppercase rounded-md transition-all",
|
|
1766
|
+
!isGlobal ? "bg-emerald-600 text-white shadow-lg shadow-emerald-600/20" : "text-zinc-500 hover:text-zinc-300"
|
|
1767
|
+
),
|
|
1768
|
+
children: "Active Conn"
|
|
1769
|
+
}
|
|
1770
|
+
),
|
|
1771
|
+
/* @__PURE__ */ jsx(
|
|
1772
|
+
"button",
|
|
1773
|
+
{
|
|
1774
|
+
onClick: () => setIsGlobal(true),
|
|
1775
|
+
className: cn(
|
|
1776
|
+
"px-3 py-1.5 text-xs font-bold uppercase rounded-md transition-all",
|
|
1777
|
+
isGlobal ? "bg-emerald-600 text-white shadow-lg shadow-emerald-600/20" : "text-zinc-500 hover:text-zinc-300"
|
|
1778
|
+
),
|
|
1779
|
+
children: "All Connections"
|
|
1780
|
+
}
|
|
1781
|
+
)
|
|
1782
|
+
] }),
|
|
1783
|
+
/* @__PURE__ */ jsx("div", { className: "flex bg-white/5 rounded-lg p-1 border border-white/10", children: ["all", "success", "error"].map((status) => /* @__PURE__ */ jsx(
|
|
1784
|
+
"button",
|
|
1785
|
+
{
|
|
1786
|
+
onClick: () => setFilterStatus(status),
|
|
1787
|
+
className: cn(
|
|
1788
|
+
"px-3 py-1.5 text-xs font-bold uppercase rounded-md transition-all",
|
|
1789
|
+
filterStatus === status ? "bg-white/10 text-white" : "text-zinc-500 hover:text-zinc-300"
|
|
1790
|
+
),
|
|
1791
|
+
children: status
|
|
1792
|
+
},
|
|
1793
|
+
status
|
|
1794
|
+
)) })
|
|
1795
|
+
] })
|
|
1796
|
+
] }),
|
|
1797
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-auto custom-scrollbar", children: filteredHistory.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col items-center justify-center opacity-20 p-8 text-center", children: [
|
|
1798
|
+
/* @__PURE__ */ jsx(History, { className: "w-16 h-16 mb-4 text-zinc-600" }),
|
|
1799
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "No history items found" }),
|
|
1800
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-500 mt-1 uppercase tracking-widest", children: "Run some queries to see them here" })
|
|
1801
|
+
] }) : /* @__PURE__ */ jsx("div", { className: "min-w-[800px]", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-left border-collapse", children: [
|
|
1802
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "bg-white/[0.02] border-b border-white/5 text-xs font-bold uppercase tracking-wider text-zinc-500", children: [
|
|
1803
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3 w-10 text-center", children: "Status" }),
|
|
1804
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3 cursor-pointer hover:text-zinc-300 transition-colors group", onClick: () => handleSort("executedAt"), children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1805
|
+
"Executed At",
|
|
1806
|
+
/* @__PURE__ */ jsx(ArrowUpDown, { className: cn("w-3 h-3 transition-opacity", sortField === "executedAt" ? "opacity-100 text-emerald-500" : "opacity-0 group-hover:opacity-100") })
|
|
1807
|
+
] }) }),
|
|
1808
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3", children: "Source" }),
|
|
1809
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3", children: "SQL Query" }),
|
|
1810
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3 cursor-pointer hover:text-zinc-300 transition-colors group", onClick: () => handleSort("executionTime"), children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1811
|
+
"Duration",
|
|
1812
|
+
/* @__PURE__ */ jsx(ArrowUpDown, { className: cn("w-3 h-3 transition-opacity", sortField === "executionTime" ? "opacity-100 text-emerald-500" : "opacity-0 group-hover:opacity-100") })
|
|
1813
|
+
] }) }),
|
|
1814
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3 cursor-pointer hover:text-zinc-300 transition-colors group", onClick: () => handleSort("rowCount"), children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1815
|
+
"Rows",
|
|
1816
|
+
/* @__PURE__ */ jsx(ArrowUpDown, { className: cn("w-3 h-3 transition-opacity", sortField === "rowCount" ? "opacity-100 text-emerald-500" : "opacity-0 group-hover:opacity-100") })
|
|
1817
|
+
] }) }),
|
|
1818
|
+
/* @__PURE__ */ jsx("th", { className: "px-4 py-3 w-20" })
|
|
1819
|
+
] }) }),
|
|
1820
|
+
/* @__PURE__ */ jsx("tbody", { className: "divide-y divide-white/5", children: filteredHistory.map((item) => /* @__PURE__ */ jsxs(
|
|
1821
|
+
"tr",
|
|
1822
|
+
{
|
|
1823
|
+
className: "hover:bg-white/[0.03] transition-colors group text-xs border-b border-white/5",
|
|
1824
|
+
children: [
|
|
1825
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-center", children: /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: item.status === "success" ? /* @__PURE__ */ jsx("div", { className: "w-5 h-5 rounded-full bg-emerald-500/10 flex items-center justify-center border border-emerald-500/20", children: /* @__PURE__ */ jsx(CheckCircle2, { className: "w-3 h-3 text-emerald-500" }) }) : /* @__PURE__ */ jsx("div", { className: "w-5 h-5 rounded-full bg-red-500/10 flex items-center justify-center border border-red-500/20", children: /* @__PURE__ */ jsx(AlertCircle, { className: "w-3 h-3 text-red-500" }) }) }) }),
|
|
1826
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 whitespace-nowrap", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
1827
|
+
/* @__PURE__ */ jsx("span", { className: "text-zinc-200 font-medium", children: item.executedAt ? format(new Date(item.executedAt), "MMM d, HH:mm:ss") : "-" }),
|
|
1828
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500 font-mono mt-0.5", children: item.executedAt ? format(new Date(item.executedAt), "yyyy") : "" })
|
|
1829
|
+
] }) }),
|
|
1830
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 whitespace-nowrap", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
1831
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-zinc-300", children: [
|
|
1832
|
+
/* @__PURE__ */ jsx(Database, { className: "w-3 h-3 text-blue-400" }),
|
|
1833
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold", children: item.connectionName || "Unknown" })
|
|
1834
|
+
] }),
|
|
1835
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-zinc-500 text-xs", children: [
|
|
1836
|
+
/* @__PURE__ */ jsx(Hash, { className: "w-2.5 h-2.5" }),
|
|
1837
|
+
/* @__PURE__ */ jsx("span", { children: item.tabName || "Default Tab" })
|
|
1838
|
+
] })
|
|
1839
|
+
] }) }),
|
|
1840
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 max-w-md", children: /* @__PURE__ */ jsxs("div", { className: "bg-[#050505] border border-white/5 rounded-md p-2 relative group-hover:border-white/10 transition-colors", children: [
|
|
1841
|
+
/* @__PURE__ */ jsx("pre", { className: "text-body font-mono text-zinc-400 line-clamp-2 break-all whitespace-pre-wrap leading-relaxed", children: item.query }),
|
|
1842
|
+
item.errorMessage && /* @__PURE__ */ jsx("div", { className: "mt-2 pt-2 border-t border-red-500/10 text-xs text-red-400/80 font-mono italic", children: item.errorMessage })
|
|
1843
|
+
] }) }),
|
|
1844
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 whitespace-nowrap", children: /* @__PURE__ */ jsxs("span", { className: cn(
|
|
1845
|
+
"px-2 py-0.5 rounded text-xs font-mono font-bold",
|
|
1846
|
+
item.executionTime > 500 ? "text-amber-400 bg-amber-400/10" : "text-zinc-400 bg-white/5"
|
|
1847
|
+
), children: [
|
|
1848
|
+
item.executionTime,
|
|
1849
|
+
"ms"
|
|
1850
|
+
] }) }),
|
|
1851
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 whitespace-nowrap", children: /* @__PURE__ */ jsx("span", { className: "text-zinc-400 font-mono text-xs", children: item.rowCount != null ? item.rowCount.toLocaleString() : "-" }) }),
|
|
1852
|
+
/* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-right", children: /* @__PURE__ */ jsx(
|
|
1853
|
+
Button,
|
|
1854
|
+
{
|
|
1855
|
+
variant: "ghost",
|
|
1856
|
+
size: "sm",
|
|
1857
|
+
className: "h-8 w-8 p-0 hover:bg-emerald-500/10 hover:text-emerald-400",
|
|
1858
|
+
onClick: () => onSelectQuery(item.query),
|
|
1859
|
+
title: "Restore Query",
|
|
1860
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { className: "w-3.5 h-3.5" })
|
|
1861
|
+
}
|
|
1862
|
+
) })
|
|
1863
|
+
]
|
|
1864
|
+
},
|
|
1865
|
+
item.id
|
|
1866
|
+
)) })
|
|
1867
|
+
] }) }) })
|
|
1868
|
+
] });
|
|
1869
|
+
}
|
|
1870
|
+
function SavedQueries({ onSelectQuery, connectionType, refreshTrigger }) {
|
|
1871
|
+
const [queries, setQueries] = useState([]);
|
|
1872
|
+
const [search, setSearch] = useState("");
|
|
1873
|
+
useEffect(() => {
|
|
1874
|
+
setQueries(storage.getSavedQueries());
|
|
1875
|
+
}, [refreshTrigger]);
|
|
1876
|
+
const filteredQueries = queries.filter((q) => {
|
|
1877
|
+
const matchesSearch = q.name.toLowerCase().includes(search.toLowerCase()) || q.query.toLowerCase().includes(search.toLowerCase());
|
|
1878
|
+
const matchesType = !connectionType || q.connectionType === connectionType;
|
|
1879
|
+
return matchesSearch && matchesType;
|
|
1880
|
+
});
|
|
1881
|
+
const handleDelete = (id, e) => {
|
|
1882
|
+
e.stopPropagation();
|
|
1883
|
+
if (confirm("Are you sure you want to delete this saved query?")) {
|
|
1884
|
+
storage.deleteSavedQuery(id);
|
|
1885
|
+
setQueries(storage.getSavedQueries());
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#0a0a0a]", children: [
|
|
1889
|
+
/* @__PURE__ */ jsxs("div", { className: "p-4 border-b border-white/5 flex flex-col gap-4", children: [
|
|
1890
|
+
/* @__PURE__ */ jsxs("h3", { className: "text-sm font-bold text-zinc-400 uppercase tracking-widest flex items-center gap-2", children: [
|
|
1891
|
+
/* @__PURE__ */ jsx(Bookmark, { className: "w-4 h-4" }),
|
|
1892
|
+
" Saved Queries"
|
|
1893
|
+
] }),
|
|
1894
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
1895
|
+
/* @__PURE__ */ jsx(Search, { className: "absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-zinc-500" }),
|
|
1896
|
+
/* @__PURE__ */ jsx(
|
|
1897
|
+
Input,
|
|
1898
|
+
{
|
|
1899
|
+
placeholder: "Search saved queries...",
|
|
1900
|
+
value: search,
|
|
1901
|
+
onChange: (e) => setSearch(e.target.value),
|
|
1902
|
+
className: "pl-8 h-8 bg-white/5 border-white/10 text-xs focus:ring-blue-500/20"
|
|
1903
|
+
}
|
|
1904
|
+
)
|
|
1905
|
+
] })
|
|
1906
|
+
] }),
|
|
1907
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto custom-scrollbar", children: filteredQueries.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col items-center justify-center opacity-20 p-8 text-center", children: [
|
|
1908
|
+
/* @__PURE__ */ jsx(Bookmark, { className: "w-12 h-12 mb-4" }),
|
|
1909
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm italic", children: "No saved queries found" })
|
|
1910
|
+
] }) : /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-px bg-white/5", children: filteredQueries.map((q) => {
|
|
1911
|
+
var _a;
|
|
1912
|
+
return /* @__PURE__ */ jsxs(
|
|
1913
|
+
"div",
|
|
1914
|
+
{
|
|
1915
|
+
className: "bg-[#0a0a0a] p-4 hover:bg-white/[0.02] transition-colors group cursor-pointer",
|
|
1916
|
+
onClick: () => onSelectQuery(q.query),
|
|
1917
|
+
children: [
|
|
1918
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between mb-2", children: [
|
|
1919
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1920
|
+
/* @__PURE__ */ jsx("h4", { className: "text-xs font-bold text-blue-400 mb-1 group-hover:text-blue-300 transition-colors", children: q.name }),
|
|
1921
|
+
q.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-500 line-clamp-1", children: q.description })
|
|
1922
|
+
] }),
|
|
1923
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity", children: [
|
|
1924
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-6 w-6 text-zinc-500 hover:text-white", children: /* @__PURE__ */ jsx(Edit3, { className: "w-3 h-3" }) }),
|
|
1925
|
+
/* @__PURE__ */ jsx(
|
|
1926
|
+
Button,
|
|
1927
|
+
{
|
|
1928
|
+
variant: "ghost",
|
|
1929
|
+
size: "icon",
|
|
1930
|
+
className: "h-6 w-6 text-zinc-500 hover:text-red-400",
|
|
1931
|
+
onClick: (e) => handleDelete(q.id, e),
|
|
1932
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "w-3 h-3" })
|
|
1933
|
+
}
|
|
1934
|
+
)
|
|
1935
|
+
] })
|
|
1936
|
+
] }),
|
|
1937
|
+
/* @__PURE__ */ jsx("div", { className: "bg-[#050505] border border-white/5 rounded-md p-2 mb-3", children: /* @__PURE__ */ jsx("pre", { className: "text-xs font-mono text-zinc-400 line-clamp-3", children: q.query }) }),
|
|
1938
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1939
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1940
|
+
/* @__PURE__ */ jsx("span", { className: "px-1.5 py-0.5 rounded bg-blue-500/10 border border-blue-500/20 text-label font-bold text-blue-400 uppercase tracking-tighter", children: q.connectionType }),
|
|
1941
|
+
(_a = q.tags) == null ? void 0 : _a.map((tag) => /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1 text-label text-zinc-500", children: [
|
|
1942
|
+
/* @__PURE__ */ jsx(Tag, { className: "w-2.5 h-2.5" }),
|
|
1943
|
+
" ",
|
|
1944
|
+
tag
|
|
1945
|
+
] }, tag))
|
|
1946
|
+
] }),
|
|
1947
|
+
/* @__PURE__ */ jsxs("span", { className: "text-label text-zinc-600 flex items-center gap-1 font-mono", children: [
|
|
1948
|
+
/* @__PURE__ */ jsx(Calendar, { className: "w-2.5 h-2.5" }),
|
|
1949
|
+
" ",
|
|
1950
|
+
format(q.updatedAt, "MMM d, yyyy")
|
|
1951
|
+
] })
|
|
1952
|
+
] })
|
|
1953
|
+
]
|
|
1954
|
+
},
|
|
1955
|
+
q.id
|
|
1956
|
+
);
|
|
1957
|
+
}) }) })
|
|
1958
|
+
] });
|
|
1959
|
+
}
|
|
1960
|
+
var badgeVariants = cva(
|
|
1961
|
+
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
1962
|
+
{
|
|
1963
|
+
variants: {
|
|
1964
|
+
variant: {
|
|
1965
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
1966
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
1967
|
+
destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
1968
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
1969
|
+
}
|
|
1970
|
+
},
|
|
1971
|
+
defaultVariants: {
|
|
1972
|
+
variant: "default"
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
);
|
|
1976
|
+
function Badge(_a) {
|
|
1977
|
+
var _b = _a, {
|
|
1978
|
+
className,
|
|
1979
|
+
variant,
|
|
1980
|
+
asChild = false
|
|
1981
|
+
} = _b, props = __objRest(_b, [
|
|
1982
|
+
"className",
|
|
1983
|
+
"variant",
|
|
1984
|
+
"asChild"
|
|
1985
|
+
]);
|
|
1986
|
+
const Comp = asChild ? Slot : "span";
|
|
1987
|
+
return /* @__PURE__ */ jsx(
|
|
1988
|
+
Comp,
|
|
1989
|
+
__spreadValues({
|
|
1990
|
+
"data-slot": "badge",
|
|
1991
|
+
className: cn(badgeVariants({ variant }), className)
|
|
1992
|
+
}, props)
|
|
1993
|
+
);
|
|
1994
|
+
}
|
|
1995
|
+
function useAllConnections() {
|
|
1996
|
+
const [connections, setConnections] = useState([]);
|
|
1997
|
+
const [loading, setLoading] = useState(true);
|
|
1998
|
+
useEffect(() => {
|
|
1999
|
+
let cancelled = false;
|
|
2000
|
+
async function load() {
|
|
2001
|
+
const userConns = storage.getConnections();
|
|
2002
|
+
try {
|
|
2003
|
+
const res = await fetch("/api/connections/managed");
|
|
2004
|
+
if (res.ok) {
|
|
2005
|
+
const { connections: managedConns } = await res.json();
|
|
2006
|
+
if ((managedConns == null ? void 0 : managedConns.length) > 0 && !cancelled) {
|
|
2007
|
+
const merged = [];
|
|
2008
|
+
const addedIds = /* @__PURE__ */ new Set();
|
|
2009
|
+
for (const mc of managedConns) {
|
|
2010
|
+
merged.push(__spreadProps(__spreadValues({}, mc), { createdAt: new Date(mc.createdAt) }));
|
|
2011
|
+
addedIds.add(mc.id);
|
|
2012
|
+
if (mc.seedId) addedIds.add(`seed:${mc.seedId}`);
|
|
2013
|
+
}
|
|
2014
|
+
for (const uc of userConns) {
|
|
2015
|
+
if (addedIds.has(uc.id)) continue;
|
|
2016
|
+
if (uc.seedId && managedConns.some((mc) => mc.seedId === uc.seedId)) continue;
|
|
2017
|
+
merged.push(uc);
|
|
2018
|
+
}
|
|
2019
|
+
setConnections(merged);
|
|
2020
|
+
setLoading(false);
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
} catch (e) {
|
|
2025
|
+
}
|
|
2026
|
+
if (!cancelled) {
|
|
2027
|
+
setConnections(userConns);
|
|
2028
|
+
setLoading(false);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
load();
|
|
2032
|
+
return () => {
|
|
2033
|
+
cancelled = true;
|
|
2034
|
+
};
|
|
2035
|
+
}, []);
|
|
2036
|
+
return { connections, loading };
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
// src/lib/schema-diff/diff-engine.ts
|
|
2040
|
+
function diffColumns(sourceCols, targetCols) {
|
|
2041
|
+
const diffs = [];
|
|
2042
|
+
const sourceMap = new Map(sourceCols.map((c) => [c.name, c]));
|
|
2043
|
+
const targetMap = new Map(targetCols.map((c) => [c.name, c]));
|
|
2044
|
+
for (const [name, col] of targetMap) {
|
|
2045
|
+
if (!sourceMap.has(name)) {
|
|
2046
|
+
diffs.push({
|
|
2047
|
+
action: "added",
|
|
2048
|
+
columnName: name,
|
|
2049
|
+
targetType: col.type,
|
|
2050
|
+
targetNullable: col.nullable,
|
|
2051
|
+
targetDefault: col.defaultValue,
|
|
2052
|
+
targetIsPrimary: col.isPrimary,
|
|
2053
|
+
changes: [`Added column "${name}" (${col.type})`]
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
for (const [name, col] of sourceMap) {
|
|
2058
|
+
if (!targetMap.has(name)) {
|
|
2059
|
+
diffs.push({
|
|
2060
|
+
action: "removed",
|
|
2061
|
+
columnName: name,
|
|
2062
|
+
sourceType: col.type,
|
|
2063
|
+
sourceNullable: col.nullable,
|
|
2064
|
+
sourceDefault: col.defaultValue,
|
|
2065
|
+
sourceIsPrimary: col.isPrimary,
|
|
2066
|
+
changes: [`Removed column "${name}" (${col.type})`]
|
|
2067
|
+
});
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
for (const [name, sourceCol] of sourceMap) {
|
|
2071
|
+
const targetCol = targetMap.get(name);
|
|
2072
|
+
if (!targetCol) continue;
|
|
2073
|
+
const changes = [];
|
|
2074
|
+
if (sourceCol.type.toLowerCase() !== targetCol.type.toLowerCase()) {
|
|
2075
|
+
changes.push(`Type changed: ${sourceCol.type} \u2192 ${targetCol.type}`);
|
|
2076
|
+
}
|
|
2077
|
+
if (sourceCol.nullable !== targetCol.nullable) {
|
|
2078
|
+
changes.push(`Nullable changed: ${sourceCol.nullable} \u2192 ${targetCol.nullable}`);
|
|
2079
|
+
}
|
|
2080
|
+
if ((sourceCol.defaultValue || "") !== (targetCol.defaultValue || "")) {
|
|
2081
|
+
changes.push(`Default changed: ${sourceCol.defaultValue || "none"} \u2192 ${targetCol.defaultValue || "none"}`);
|
|
2082
|
+
}
|
|
2083
|
+
if (sourceCol.isPrimary !== targetCol.isPrimary) {
|
|
2084
|
+
changes.push(`Primary key changed: ${sourceCol.isPrimary} \u2192 ${targetCol.isPrimary}`);
|
|
2085
|
+
}
|
|
2086
|
+
if (changes.length > 0) {
|
|
2087
|
+
diffs.push({
|
|
2088
|
+
action: "modified",
|
|
2089
|
+
columnName: name,
|
|
2090
|
+
sourceType: sourceCol.type,
|
|
2091
|
+
targetType: targetCol.type,
|
|
2092
|
+
sourceNullable: sourceCol.nullable,
|
|
2093
|
+
targetNullable: targetCol.nullable,
|
|
2094
|
+
sourceDefault: sourceCol.defaultValue,
|
|
2095
|
+
targetDefault: targetCol.defaultValue,
|
|
2096
|
+
sourceIsPrimary: sourceCol.isPrimary,
|
|
2097
|
+
targetIsPrimary: targetCol.isPrimary,
|
|
2098
|
+
changes
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
return diffs;
|
|
2103
|
+
}
|
|
2104
|
+
function diffIndexes(sourceIndexes, targetIndexes) {
|
|
2105
|
+
const diffs = [];
|
|
2106
|
+
const sourceMap = /* @__PURE__ */ new Map();
|
|
2107
|
+
sourceIndexes.forEach((idx) => {
|
|
2108
|
+
const key = idx.name || idx.columns.sort().join(",");
|
|
2109
|
+
sourceMap.set(key, idx);
|
|
2110
|
+
});
|
|
2111
|
+
const targetMap = /* @__PURE__ */ new Map();
|
|
2112
|
+
targetIndexes.forEach((idx) => {
|
|
2113
|
+
const key = idx.name || idx.columns.sort().join(",");
|
|
2114
|
+
targetMap.set(key, idx);
|
|
2115
|
+
});
|
|
2116
|
+
for (const [key, idx] of targetMap) {
|
|
2117
|
+
if (!sourceMap.has(key)) {
|
|
2118
|
+
diffs.push({
|
|
2119
|
+
action: "added",
|
|
2120
|
+
indexName: idx.name || key,
|
|
2121
|
+
targetColumns: idx.columns,
|
|
2122
|
+
targetUnique: idx.unique,
|
|
2123
|
+
changes: [`Added index "${idx.name || key}" on (${idx.columns.join(", ")})`]
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
for (const [key, idx] of sourceMap) {
|
|
2128
|
+
if (!targetMap.has(key)) {
|
|
2129
|
+
diffs.push({
|
|
2130
|
+
action: "removed",
|
|
2131
|
+
indexName: idx.name || key,
|
|
2132
|
+
sourceColumns: idx.columns,
|
|
2133
|
+
sourceUnique: idx.unique,
|
|
2134
|
+
changes: [`Removed index "${idx.name || key}"`]
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
for (const [key, sourceIdx] of sourceMap) {
|
|
2139
|
+
const targetIdx = targetMap.get(key);
|
|
2140
|
+
if (!targetIdx) continue;
|
|
2141
|
+
const changes = [];
|
|
2142
|
+
const sourceColStr = sourceIdx.columns.sort().join(",");
|
|
2143
|
+
const targetColStr = targetIdx.columns.sort().join(",");
|
|
2144
|
+
if (sourceColStr !== targetColStr) {
|
|
2145
|
+
changes.push(`Columns changed: (${sourceIdx.columns.join(", ")}) \u2192 (${targetIdx.columns.join(", ")})`);
|
|
2146
|
+
}
|
|
2147
|
+
if (sourceIdx.unique !== targetIdx.unique) {
|
|
2148
|
+
changes.push(`Unique changed: ${sourceIdx.unique} \u2192 ${targetIdx.unique}`);
|
|
2149
|
+
}
|
|
2150
|
+
if (changes.length > 0) {
|
|
2151
|
+
diffs.push({
|
|
2152
|
+
action: "modified",
|
|
2153
|
+
indexName: sourceIdx.name || key,
|
|
2154
|
+
sourceColumns: sourceIdx.columns,
|
|
2155
|
+
targetColumns: targetIdx.columns,
|
|
2156
|
+
sourceUnique: sourceIdx.unique,
|
|
2157
|
+
targetUnique: targetIdx.unique,
|
|
2158
|
+
changes
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
return diffs;
|
|
2163
|
+
}
|
|
2164
|
+
function diffForeignKeys(sourceFKs, targetFKs) {
|
|
2165
|
+
const diffs = [];
|
|
2166
|
+
const makeKey = (fk) => `${fk.columnName}\u2192${fk.referencedTable}.${fk.referencedColumn}`;
|
|
2167
|
+
const sourceMap = new Map(sourceFKs.map((fk) => [makeKey(fk), fk]));
|
|
2168
|
+
const targetMap = new Map(targetFKs.map((fk) => [makeKey(fk), fk]));
|
|
2169
|
+
for (const [key, fk] of targetMap) {
|
|
2170
|
+
if (!sourceMap.has(key)) {
|
|
2171
|
+
diffs.push({
|
|
2172
|
+
action: "added",
|
|
2173
|
+
columnName: fk.columnName,
|
|
2174
|
+
targetReferencedTable: fk.referencedTable,
|
|
2175
|
+
targetReferencedColumn: fk.referencedColumn,
|
|
2176
|
+
changes: [`Added FK: ${fk.columnName} \u2192 ${fk.referencedTable}(${fk.referencedColumn})`]
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
for (const [key, fk] of sourceMap) {
|
|
2181
|
+
if (!targetMap.has(key)) {
|
|
2182
|
+
diffs.push({
|
|
2183
|
+
action: "removed",
|
|
2184
|
+
columnName: fk.columnName,
|
|
2185
|
+
sourceReferencedTable: fk.referencedTable,
|
|
2186
|
+
sourceReferencedColumn: fk.referencedColumn,
|
|
2187
|
+
changes: [`Removed FK: ${fk.columnName} \u2192 ${fk.referencedTable}(${fk.referencedColumn})`]
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return diffs;
|
|
2192
|
+
}
|
|
2193
|
+
function diffSchemas(source, target) {
|
|
2194
|
+
const sourceMap = new Map(source.map((t) => [t.name, t]));
|
|
2195
|
+
const targetMap = new Map(target.map((t) => [t.name, t]));
|
|
2196
|
+
const tables = [];
|
|
2197
|
+
let added = 0, removed = 0, modified = 0;
|
|
2198
|
+
for (const [name, table] of targetMap) {
|
|
2199
|
+
if (!sourceMap.has(name)) {
|
|
2200
|
+
tables.push({
|
|
2201
|
+
action: "added",
|
|
2202
|
+
tableName: name,
|
|
2203
|
+
columns: table.columns.map((c) => ({
|
|
2204
|
+
action: "added",
|
|
2205
|
+
columnName: c.name,
|
|
2206
|
+
targetType: c.type,
|
|
2207
|
+
targetNullable: c.nullable,
|
|
2208
|
+
targetDefault: c.defaultValue,
|
|
2209
|
+
targetIsPrimary: c.isPrimary,
|
|
2210
|
+
changes: [`Added column "${c.name}" (${c.type})`]
|
|
2211
|
+
})),
|
|
2212
|
+
indexes: table.indexes.map((idx) => ({
|
|
2213
|
+
action: "added",
|
|
2214
|
+
indexName: idx.name,
|
|
2215
|
+
targetColumns: idx.columns,
|
|
2216
|
+
targetUnique: idx.unique,
|
|
2217
|
+
changes: [`Added index "${idx.name}"`]
|
|
2218
|
+
})),
|
|
2219
|
+
foreignKeys: (table.foreignKeys || []).map((fk) => ({
|
|
2220
|
+
action: "added",
|
|
2221
|
+
columnName: fk.columnName,
|
|
2222
|
+
targetReferencedTable: fk.referencedTable,
|
|
2223
|
+
targetReferencedColumn: fk.referencedColumn,
|
|
2224
|
+
changes: [`Added FK: ${fk.columnName} \u2192 ${fk.referencedTable}(${fk.referencedColumn})`]
|
|
2225
|
+
}))
|
|
2226
|
+
});
|
|
2227
|
+
added++;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
for (const [name, table] of sourceMap) {
|
|
2231
|
+
if (!targetMap.has(name)) {
|
|
2232
|
+
tables.push({
|
|
2233
|
+
action: "removed",
|
|
2234
|
+
tableName: name,
|
|
2235
|
+
columns: table.columns.map((c) => ({
|
|
2236
|
+
action: "removed",
|
|
2237
|
+
columnName: c.name,
|
|
2238
|
+
sourceType: c.type,
|
|
2239
|
+
sourceNullable: c.nullable,
|
|
2240
|
+
sourceDefault: c.defaultValue,
|
|
2241
|
+
sourceIsPrimary: c.isPrimary,
|
|
2242
|
+
changes: [`Removed column "${c.name}"`]
|
|
2243
|
+
})),
|
|
2244
|
+
indexes: [],
|
|
2245
|
+
foreignKeys: []
|
|
2246
|
+
});
|
|
2247
|
+
removed++;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
for (const [name, sourceTable] of sourceMap) {
|
|
2251
|
+
const targetTable = targetMap.get(name);
|
|
2252
|
+
if (!targetTable) continue;
|
|
2253
|
+
const columns = diffColumns(sourceTable.columns, targetTable.columns);
|
|
2254
|
+
const indexes = diffIndexes(sourceTable.indexes, targetTable.indexes);
|
|
2255
|
+
const foreignKeys = diffForeignKeys(sourceTable.foreignKeys || [], targetTable.foreignKeys || []);
|
|
2256
|
+
if (columns.length > 0 || indexes.length > 0 || foreignKeys.length > 0) {
|
|
2257
|
+
tables.push({
|
|
2258
|
+
action: "modified",
|
|
2259
|
+
tableName: name,
|
|
2260
|
+
columns,
|
|
2261
|
+
indexes,
|
|
2262
|
+
foreignKeys
|
|
2263
|
+
});
|
|
2264
|
+
modified++;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
return {
|
|
2268
|
+
tables,
|
|
2269
|
+
summary: { added, removed, modified },
|
|
2270
|
+
hasChanges: tables.length > 0
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
// src/lib/schema-diff/migration-generator.ts
|
|
2275
|
+
function escapeIdentifier(name, dialect) {
|
|
2276
|
+
switch (dialect) {
|
|
2277
|
+
case "mysql":
|
|
2278
|
+
return `\`${name}\``;
|
|
2279
|
+
case "mssql":
|
|
2280
|
+
return `[${name.replace(/\]/g, "]]")}]`;
|
|
2281
|
+
case "oracle":
|
|
2282
|
+
case "postgres":
|
|
2283
|
+
case "sqlite":
|
|
2284
|
+
default:
|
|
2285
|
+
return `"${name}"`;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
function generateColumnDef(col, dialect) {
|
|
2289
|
+
const type = col.targetType || col.sourceType || "TEXT";
|
|
2290
|
+
const nullable = col.targetNullable === false ? " NOT NULL" : "";
|
|
2291
|
+
const defaultVal = col.targetDefault ? ` DEFAULT ${col.targetDefault}` : "";
|
|
2292
|
+
return `${escapeIdentifier(col.columnName, dialect)} ${type}${nullable}${defaultVal}`;
|
|
2293
|
+
}
|
|
2294
|
+
function generateCreateTable(table, dialect) {
|
|
2295
|
+
const lines = [];
|
|
2296
|
+
const id = escapeIdentifier(table.tableName, dialect);
|
|
2297
|
+
const colDefs = table.columns.filter((c) => c.action === "added").map((c) => ` ${generateColumnDef(c, dialect)}`);
|
|
2298
|
+
const pkCols = table.columns.filter((c) => c.targetIsPrimary).map((c) => escapeIdentifier(c.columnName, dialect));
|
|
2299
|
+
lines.push(`CREATE TABLE ${id} (`);
|
|
2300
|
+
lines.push(colDefs.join(",\n"));
|
|
2301
|
+
if (pkCols.length > 0) {
|
|
2302
|
+
lines.push(`, PRIMARY KEY (${pkCols.join(", ")})`);
|
|
2303
|
+
}
|
|
2304
|
+
lines.push(");");
|
|
2305
|
+
table.indexes.filter((i) => i.action === "added").forEach((idx) => {
|
|
2306
|
+
const unique = idx.targetUnique ? "UNIQUE " : "";
|
|
2307
|
+
const cols = (idx.targetColumns || []).map((c) => escapeIdentifier(c, dialect)).join(", ");
|
|
2308
|
+
lines.push(`CREATE ${unique}INDEX ${escapeIdentifier(idx.indexName, dialect)} ON ${id} (${cols});`);
|
|
2309
|
+
});
|
|
2310
|
+
table.foreignKeys.filter((fk) => fk.action === "added").forEach((fk) => {
|
|
2311
|
+
lines.push(`ALTER TABLE ${id} ADD CONSTRAINT ${escapeIdentifier(`fk_${table.tableName}_${fk.columnName}`, dialect)} FOREIGN KEY (${escapeIdentifier(fk.columnName, dialect)}) REFERENCES ${escapeIdentifier(fk.targetReferencedTable || "", dialect)}(${escapeIdentifier(fk.targetReferencedColumn || "", dialect)});`);
|
|
2312
|
+
});
|
|
2313
|
+
return lines.join("\n");
|
|
2314
|
+
}
|
|
2315
|
+
function generateDropTable(table, dialect) {
|
|
2316
|
+
return `DROP TABLE IF EXISTS ${escapeIdentifier(table.tableName, dialect)};`;
|
|
2317
|
+
}
|
|
2318
|
+
function generateAlterTable(table, dialect) {
|
|
2319
|
+
const lines = [];
|
|
2320
|
+
const id = escapeIdentifier(table.tableName, dialect);
|
|
2321
|
+
lines.push(`-- Alter table: ${table.tableName}`);
|
|
2322
|
+
table.columns.filter((c) => c.action === "added").forEach((col) => {
|
|
2323
|
+
lines.push(`ALTER TABLE ${id} ADD COLUMN ${generateColumnDef(col, dialect)};`);
|
|
2324
|
+
});
|
|
2325
|
+
table.columns.filter((c) => c.action === "removed").forEach((col) => {
|
|
2326
|
+
if (dialect === "sqlite") {
|
|
2327
|
+
lines.push(`-- SQLite: Cannot drop column "${col.columnName}" directly. Requires table recreation.`);
|
|
2328
|
+
} else {
|
|
2329
|
+
lines.push(`ALTER TABLE ${id} DROP COLUMN ${escapeIdentifier(col.columnName, dialect)};`);
|
|
2330
|
+
}
|
|
2331
|
+
});
|
|
2332
|
+
table.columns.filter((c) => c.action === "modified").forEach((col) => {
|
|
2333
|
+
if (dialect === "sqlite") {
|
|
2334
|
+
lines.push(`-- SQLite: Cannot alter column "${col.columnName}" type directly. Requires table recreation.`);
|
|
2335
|
+
} else if (dialect === "mysql") {
|
|
2336
|
+
const type = col.targetType || col.sourceType || "TEXT";
|
|
2337
|
+
const nullable = col.targetNullable === false ? " NOT NULL" : " NULL";
|
|
2338
|
+
const defaultVal = col.targetDefault ? ` DEFAULT ${col.targetDefault}` : "";
|
|
2339
|
+
lines.push(`ALTER TABLE ${id} MODIFY COLUMN ${escapeIdentifier(col.columnName, dialect)} ${type}${nullable}${defaultVal};`);
|
|
2340
|
+
} else if (dialect === "oracle") {
|
|
2341
|
+
const type = col.targetType || col.sourceType || "VARCHAR2(255)";
|
|
2342
|
+
const nullable = col.targetNullable === false ? " NOT NULL" : " NULL";
|
|
2343
|
+
const defaultVal = col.targetDefault ? ` DEFAULT ${col.targetDefault}` : "";
|
|
2344
|
+
lines.push(`ALTER TABLE ${id} MODIFY (${escapeIdentifier(col.columnName, dialect)} ${type}${defaultVal}${nullable});`);
|
|
2345
|
+
} else if (dialect === "mssql") {
|
|
2346
|
+
const type = col.targetType || col.sourceType || "NVARCHAR(MAX)";
|
|
2347
|
+
const nullable = col.targetNullable === false ? " NOT NULL" : " NULL";
|
|
2348
|
+
lines.push(`ALTER TABLE ${id} ALTER COLUMN ${escapeIdentifier(col.columnName, dialect)} ${type}${nullable};`);
|
|
2349
|
+
if (col.sourceDefault !== col.targetDefault && col.targetDefault) {
|
|
2350
|
+
lines.push(`ALTER TABLE ${id} ADD DEFAULT ${col.targetDefault} FOR ${escapeIdentifier(col.columnName, dialect)};`);
|
|
2351
|
+
}
|
|
2352
|
+
} else {
|
|
2353
|
+
if (col.sourceType !== col.targetType) {
|
|
2354
|
+
lines.push(`ALTER TABLE ${id} ALTER COLUMN ${escapeIdentifier(col.columnName, dialect)} TYPE ${col.targetType};`);
|
|
2355
|
+
}
|
|
2356
|
+
if (col.sourceNullable !== col.targetNullable) {
|
|
2357
|
+
if (col.targetNullable) {
|
|
2358
|
+
lines.push(`ALTER TABLE ${id} ALTER COLUMN ${escapeIdentifier(col.columnName, dialect)} DROP NOT NULL;`);
|
|
2359
|
+
} else {
|
|
2360
|
+
lines.push(`ALTER TABLE ${id} ALTER COLUMN ${escapeIdentifier(col.columnName, dialect)} SET NOT NULL;`);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
if (col.sourceDefault !== col.targetDefault) {
|
|
2364
|
+
if (col.targetDefault) {
|
|
2365
|
+
lines.push(`ALTER TABLE ${id} ALTER COLUMN ${escapeIdentifier(col.columnName, dialect)} SET DEFAULT ${col.targetDefault};`);
|
|
2366
|
+
} else {
|
|
2367
|
+
lines.push(`ALTER TABLE ${id} ALTER COLUMN ${escapeIdentifier(col.columnName, dialect)} DROP DEFAULT;`);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
});
|
|
2372
|
+
table.indexes.filter((i) => i.action === "added").forEach((idx) => {
|
|
2373
|
+
const unique = idx.targetUnique ? "UNIQUE " : "";
|
|
2374
|
+
const cols = (idx.targetColumns || []).map((c) => escapeIdentifier(c, dialect)).join(", ");
|
|
2375
|
+
lines.push(`CREATE ${unique}INDEX ${escapeIdentifier(idx.indexName, dialect)} ON ${id} (${cols});`);
|
|
2376
|
+
});
|
|
2377
|
+
table.indexes.filter((i) => i.action === "removed").forEach((idx) => {
|
|
2378
|
+
if (dialect === "mysql") {
|
|
2379
|
+
lines.push(`DROP INDEX ${escapeIdentifier(idx.indexName, dialect)} ON ${id};`);
|
|
2380
|
+
} else {
|
|
2381
|
+
lines.push(`DROP INDEX IF EXISTS ${escapeIdentifier(idx.indexName, dialect)};`);
|
|
2382
|
+
}
|
|
2383
|
+
});
|
|
2384
|
+
table.foreignKeys.filter((fk) => fk.action === "added").forEach((fk) => {
|
|
2385
|
+
const constraintName = escapeIdentifier(`fk_${table.tableName}_${fk.columnName}`, dialect);
|
|
2386
|
+
lines.push(`ALTER TABLE ${id} ADD CONSTRAINT ${constraintName} FOREIGN KEY (${escapeIdentifier(fk.columnName, dialect)}) REFERENCES ${escapeIdentifier(fk.targetReferencedTable || "", dialect)}(${escapeIdentifier(fk.targetReferencedColumn || "", dialect)});`);
|
|
2387
|
+
});
|
|
2388
|
+
table.foreignKeys.filter((fk) => fk.action === "removed").forEach((fk) => {
|
|
2389
|
+
const constraintName = escapeIdentifier(`fk_${table.tableName}_${fk.columnName}`, dialect);
|
|
2390
|
+
if (dialect === "mysql") {
|
|
2391
|
+
lines.push(`ALTER TABLE ${id} DROP FOREIGN KEY ${constraintName};`);
|
|
2392
|
+
} else if (dialect === "sqlite") {
|
|
2393
|
+
lines.push(`-- SQLite: Cannot drop foreign key directly. Requires table recreation.`);
|
|
2394
|
+
} else {
|
|
2395
|
+
lines.push(`ALTER TABLE ${id} DROP CONSTRAINT IF EXISTS ${constraintName};`);
|
|
2396
|
+
}
|
|
2397
|
+
});
|
|
2398
|
+
return lines.join("\n");
|
|
2399
|
+
}
|
|
2400
|
+
function generateMigrationSQL(diff, dialect) {
|
|
2401
|
+
if (!diff.hasChanges) {
|
|
2402
|
+
return "-- No schema changes detected.";
|
|
2403
|
+
}
|
|
2404
|
+
const sections = [];
|
|
2405
|
+
sections.push(`-- Migration generated at ${(/* @__PURE__ */ new Date()).toISOString()}`);
|
|
2406
|
+
sections.push(`-- Dialect: ${dialect}`);
|
|
2407
|
+
sections.push(`-- Changes: ${diff.summary.added} added, ${diff.summary.removed} removed, ${diff.summary.modified} modified`);
|
|
2408
|
+
sections.push("");
|
|
2409
|
+
if (dialect !== "sqlite") {
|
|
2410
|
+
sections.push("BEGIN;");
|
|
2411
|
+
sections.push("");
|
|
2412
|
+
}
|
|
2413
|
+
const droppedTables = diff.tables.filter((t) => t.action === "removed");
|
|
2414
|
+
if (droppedTables.length > 0) {
|
|
2415
|
+
sections.push("-- Drop removed tables");
|
|
2416
|
+
droppedTables.forEach((t) => sections.push(generateDropTable(t, dialect)));
|
|
2417
|
+
sections.push("");
|
|
2418
|
+
}
|
|
2419
|
+
const addedTables = diff.tables.filter((t) => t.action === "added");
|
|
2420
|
+
if (addedTables.length > 0) {
|
|
2421
|
+
sections.push("-- Create new tables");
|
|
2422
|
+
addedTables.forEach((t) => {
|
|
2423
|
+
sections.push(generateCreateTable(t, dialect));
|
|
2424
|
+
sections.push("");
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2427
|
+
const modifiedTables = diff.tables.filter((t) => t.action === "modified");
|
|
2428
|
+
if (modifiedTables.length > 0) {
|
|
2429
|
+
sections.push("-- Modify existing tables");
|
|
2430
|
+
modifiedTables.forEach((t) => {
|
|
2431
|
+
sections.push(generateAlterTable(t, dialect));
|
|
2432
|
+
sections.push("");
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
if (dialect !== "sqlite") {
|
|
2436
|
+
sections.push("COMMIT;");
|
|
2437
|
+
}
|
|
2438
|
+
return sections.join("\n");
|
|
2439
|
+
}
|
|
2440
|
+
function SnapshotTimeline({ snapshots, onCompare, onDelete }) {
|
|
2441
|
+
const [selected, setSelected] = useState([]);
|
|
2442
|
+
const handleClick = (id) => {
|
|
2443
|
+
setSelected((prev) => {
|
|
2444
|
+
if (prev.includes(id)) {
|
|
2445
|
+
return prev.filter((s) => s !== id);
|
|
2446
|
+
}
|
|
2447
|
+
if (prev.length >= 2) {
|
|
2448
|
+
return [prev[1], id];
|
|
2449
|
+
}
|
|
2450
|
+
return [...prev, id];
|
|
2451
|
+
});
|
|
2452
|
+
};
|
|
2453
|
+
const canCompare = selected.length === 2;
|
|
2454
|
+
useEffect(() => {
|
|
2455
|
+
if (canCompare) {
|
|
2456
|
+
onCompare(selected[0], selected[1]);
|
|
2457
|
+
}
|
|
2458
|
+
}, [selected, canCompare, onCompare]);
|
|
2459
|
+
if (snapshots.length === 0) {
|
|
2460
|
+
return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-4 text-zinc-600 text-xs", children: "No snapshots taken yet. Take a snapshot to start tracking schema changes." });
|
|
2461
|
+
}
|
|
2462
|
+
const sorted = [...snapshots].sort(
|
|
2463
|
+
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
|
|
2464
|
+
);
|
|
2465
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2466
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-2", children: [
|
|
2467
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs uppercase text-zinc-500 font-bold", children: "Timeline" }),
|
|
2468
|
+
canCompare && /* @__PURE__ */ jsx("span", { className: "text-xs text-blue-400", children: "Comparing 2 snapshots" })
|
|
2469
|
+
] }),
|
|
2470
|
+
/* @__PURE__ */ jsxs("div", { className: "relative flex items-center overflow-x-auto pb-2 px-2 gap-0", children: [
|
|
2471
|
+
/* @__PURE__ */ jsx("div", { className: "absolute top-[18px] left-4 right-4 h-[2px] bg-white/10" }),
|
|
2472
|
+
sorted.map((snapshot, idx) => {
|
|
2473
|
+
const isSelected = selected.includes(snapshot.id);
|
|
2474
|
+
const date = new Date(snapshot.createdAt);
|
|
2475
|
+
return /* @__PURE__ */ jsxs(
|
|
2476
|
+
"div",
|
|
2477
|
+
{
|
|
2478
|
+
className: "relative flex flex-col items-center min-w-[100px] cursor-pointer group",
|
|
2479
|
+
onClick: () => handleClick(snapshot.id),
|
|
2480
|
+
children: [
|
|
2481
|
+
/* @__PURE__ */ jsx("div", { className: cn(
|
|
2482
|
+
"w-4 h-4 rounded-full border-2 z-10 transition-all",
|
|
2483
|
+
isSelected ? "bg-blue-500 border-blue-400 scale-125" : "bg-[#0d0d0d] border-white/20 hover:border-white/40"
|
|
2484
|
+
) }),
|
|
2485
|
+
idx < sorted.length - 1 && /* @__PURE__ */ jsx("div", { className: "absolute top-[7px] left-[50%] w-full h-[2px] bg-white/10" }),
|
|
2486
|
+
/* @__PURE__ */ jsxs("div", { className: cn(
|
|
2487
|
+
"mt-2 text-center transition-colors",
|
|
2488
|
+
isSelected ? "text-blue-400" : "text-zinc-500 group-hover:text-zinc-300"
|
|
2489
|
+
), children: [
|
|
2490
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs font-medium truncate max-w-[90px]", children: snapshot.label || snapshot.connectionName }),
|
|
2491
|
+
/* @__PURE__ */ jsxs("div", { className: "text-label text-zinc-600", children: [
|
|
2492
|
+
date.toLocaleDateString(),
|
|
2493
|
+
" ",
|
|
2494
|
+
date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })
|
|
2495
|
+
] }),
|
|
2496
|
+
/* @__PURE__ */ jsxs(Badge, { variant: "secondary", className: "text-label mt-1", children: [
|
|
2497
|
+
snapshot.schema.length,
|
|
2498
|
+
" tables"
|
|
2499
|
+
] })
|
|
2500
|
+
] }),
|
|
2501
|
+
/* @__PURE__ */ jsx(
|
|
2502
|
+
"button",
|
|
2503
|
+
{
|
|
2504
|
+
onClick: (e) => {
|
|
2505
|
+
e.stopPropagation();
|
|
2506
|
+
onDelete(snapshot.id);
|
|
2507
|
+
},
|
|
2508
|
+
className: "absolute -top-2 -right-1 p-0.5 text-zinc-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-opacity",
|
|
2509
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "w-2.5 h-2.5" })
|
|
2510
|
+
}
|
|
2511
|
+
)
|
|
2512
|
+
]
|
|
2513
|
+
},
|
|
2514
|
+
snapshot.id
|
|
2515
|
+
);
|
|
2516
|
+
})
|
|
2517
|
+
] })
|
|
2518
|
+
] });
|
|
2519
|
+
}
|
|
2520
|
+
function SchemaDiff({ schema, connection }) {
|
|
2521
|
+
const [snapshots, setSnapshots] = useState(
|
|
2522
|
+
() => storage.getSchemaSnapshots()
|
|
2523
|
+
);
|
|
2524
|
+
const [sourceId, setSourceId] = useState("current");
|
|
2525
|
+
const [targetId, setTargetId] = useState("");
|
|
2526
|
+
const [selectedTable, setSelectedTable] = useState(null);
|
|
2527
|
+
const [showMigration, setShowMigration] = useState(false);
|
|
2528
|
+
const [snapshotLabel, setSnapshotLabel] = useState("");
|
|
2529
|
+
const [showLabelInput, setShowLabelInput] = useState(false);
|
|
2530
|
+
const takeSnapshot = useCallback(() => {
|
|
2531
|
+
if (!connection) return;
|
|
2532
|
+
const snapshot = {
|
|
2533
|
+
id: Date.now().toString(),
|
|
2534
|
+
connectionId: connection.id,
|
|
2535
|
+
connectionName: connection.name,
|
|
2536
|
+
databaseType: connection.type,
|
|
2537
|
+
schema: JSON.parse(JSON.stringify(schema)),
|
|
2538
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2539
|
+
label: snapshotLabel.trim() || void 0
|
|
2540
|
+
};
|
|
2541
|
+
storage.saveSchemaSnapshot(snapshot);
|
|
2542
|
+
setSnapshots(storage.getSchemaSnapshots());
|
|
2543
|
+
setSnapshotLabel("");
|
|
2544
|
+
setShowLabelInput(false);
|
|
2545
|
+
}, [schema, connection, snapshotLabel]);
|
|
2546
|
+
const deleteSnapshot = useCallback((id) => {
|
|
2547
|
+
storage.deleteSchemaSnapshot(id);
|
|
2548
|
+
setSnapshots(storage.getSchemaSnapshots());
|
|
2549
|
+
if (sourceId === id) setSourceId("current");
|
|
2550
|
+
if (targetId === id) setTargetId("");
|
|
2551
|
+
}, [sourceId, targetId]);
|
|
2552
|
+
const diff = useMemo(() => {
|
|
2553
|
+
var _a, _b;
|
|
2554
|
+
if (!targetId) return null;
|
|
2555
|
+
const sourceSchema = sourceId === "current" ? schema : ((_a = snapshots.find((s) => s.id === sourceId)) == null ? void 0 : _a.schema) || [];
|
|
2556
|
+
const targetSchema = targetId === "current" ? schema : ((_b = snapshots.find((s) => s.id === targetId)) == null ? void 0 : _b.schema) || [];
|
|
2557
|
+
if (sourceId === targetId) return null;
|
|
2558
|
+
return diffSchemas(sourceSchema, targetSchema);
|
|
2559
|
+
}, [sourceId, targetId, schema, snapshots]);
|
|
2560
|
+
const migrationSQL = useMemo(() => {
|
|
2561
|
+
if (!diff || !diff.hasChanges) return "";
|
|
2562
|
+
const dialect = (connection == null ? void 0 : connection.type) || "postgres";
|
|
2563
|
+
return generateMigrationSQL(diff, dialect);
|
|
2564
|
+
}, [diff, connection]);
|
|
2565
|
+
const { connections: allConnections } = useAllConnections();
|
|
2566
|
+
const [fetchingRemote, setFetchingRemote] = useState(false);
|
|
2567
|
+
const fetchRemoteSchema = useCallback(async (connId) => {
|
|
2568
|
+
const conn = allConnections.find((c) => c.id === connId);
|
|
2569
|
+
if (!conn) return;
|
|
2570
|
+
setFetchingRemote(true);
|
|
2571
|
+
try {
|
|
2572
|
+
const res = await fetch("/api/db/schema-snapshot", {
|
|
2573
|
+
method: "POST",
|
|
2574
|
+
headers: { "Content-Type": "application/json" },
|
|
2575
|
+
body: JSON.stringify(
|
|
2576
|
+
conn.managed && conn.seedId ? { connectionId: `seed:${conn.seedId}` } : { connection: conn }
|
|
2577
|
+
)
|
|
2578
|
+
});
|
|
2579
|
+
const data = await res.json();
|
|
2580
|
+
if (!res.ok) throw new Error(data.error);
|
|
2581
|
+
const snapshot = {
|
|
2582
|
+
id: `remote-${Date.now()}`,
|
|
2583
|
+
connectionId: conn.id,
|
|
2584
|
+
connectionName: conn.name,
|
|
2585
|
+
databaseType: conn.type,
|
|
2586
|
+
schema: data.schema,
|
|
2587
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2588
|
+
label: `Live: ${conn.name}`
|
|
2589
|
+
};
|
|
2590
|
+
storage.saveSchemaSnapshot(snapshot);
|
|
2591
|
+
setSnapshots(storage.getSchemaSnapshots());
|
|
2592
|
+
setTargetId(snapshot.id);
|
|
2593
|
+
} catch (err) {
|
|
2594
|
+
console.error("Failed to fetch remote schema:", err);
|
|
2595
|
+
} finally {
|
|
2596
|
+
setFetchingRemote(false);
|
|
2597
|
+
}
|
|
2598
|
+
}, [allConnections]);
|
|
2599
|
+
const getActionBadge = (action) => {
|
|
2600
|
+
switch (action) {
|
|
2601
|
+
case "added":
|
|
2602
|
+
return /* @__PURE__ */ jsxs(Badge, { className: "bg-green-500/20 text-green-400 border-green-500/30 text-xs", children: [
|
|
2603
|
+
/* @__PURE__ */ jsx(Plus, { className: "w-2.5 h-2.5 mr-0.5" }),
|
|
2604
|
+
"Added"
|
|
2605
|
+
] });
|
|
2606
|
+
case "removed":
|
|
2607
|
+
return /* @__PURE__ */ jsxs(Badge, { className: "bg-red-500/20 text-red-400 border-red-500/30 text-xs", children: [
|
|
2608
|
+
/* @__PURE__ */ jsx(Minus, { className: "w-2.5 h-2.5 mr-0.5" }),
|
|
2609
|
+
"Removed"
|
|
2610
|
+
] });
|
|
2611
|
+
case "modified":
|
|
2612
|
+
return /* @__PURE__ */ jsxs(Badge, { className: "bg-yellow-500/20 text-yellow-400 border-yellow-500/30 text-xs", children: [
|
|
2613
|
+
/* @__PURE__ */ jsx(Edit3, { className: "w-2.5 h-2.5 mr-0.5" }),
|
|
2614
|
+
"Modified"
|
|
2615
|
+
] });
|
|
2616
|
+
default:
|
|
2617
|
+
return null;
|
|
2618
|
+
}
|
|
2619
|
+
};
|
|
2620
|
+
const formatSnapshotLabel = (s) => {
|
|
2621
|
+
const date = new Date(s.createdAt).toLocaleString();
|
|
2622
|
+
return `${s.label || s.connectionName} (${date})`;
|
|
2623
|
+
};
|
|
2624
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#080808]", children: [
|
|
2625
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2 border-b border-white/5 bg-[#0a0a0a] flex-wrap", children: [
|
|
2626
|
+
/* @__PURE__ */ jsx(GitCompare, { className: "w-4 h-4 text-rose-400" }),
|
|
2627
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold uppercase text-zinc-400 tracking-wider", children: "Schema Diff" }),
|
|
2628
|
+
/* @__PURE__ */ jsx("div", { className: "h-4 w-px bg-white/10" }),
|
|
2629
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2630
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-600 uppercase", children: "Source" }),
|
|
2631
|
+
/* @__PURE__ */ jsxs(Select, { value: sourceId, onValueChange: setSourceId, children: [
|
|
2632
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: "h-7 w-[180px] text-xs bg-white/5 border-white/10", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select source" }) }),
|
|
2633
|
+
/* @__PURE__ */ jsxs(SelectContent, { className: "bg-[#111] border-white/10", children: [
|
|
2634
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "current", className: "text-xs", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2635
|
+
/* @__PURE__ */ jsx(Database, { className: "w-3 h-3" }),
|
|
2636
|
+
" Current Schema"
|
|
2637
|
+
] }) }),
|
|
2638
|
+
snapshots.map((s) => /* @__PURE__ */ jsx(SelectItem, { value: s.id, className: "text-xs", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2639
|
+
/* @__PURE__ */ jsx(Clock, { className: "w-3 h-3" }),
|
|
2640
|
+
" ",
|
|
2641
|
+
formatSnapshotLabel(s)
|
|
2642
|
+
] }) }, s.id))
|
|
2643
|
+
] })
|
|
2644
|
+
] })
|
|
2645
|
+
] }),
|
|
2646
|
+
/* @__PURE__ */ jsx("span", { className: "text-zinc-600 text-xs", children: "vs" }),
|
|
2647
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2648
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-600 uppercase", children: "Target" }),
|
|
2649
|
+
/* @__PURE__ */ jsxs(Select, { value: targetId, onValueChange: (v) => {
|
|
2650
|
+
if (v.startsWith("conn:")) {
|
|
2651
|
+
fetchRemoteSchema(v.replace("conn:", ""));
|
|
2652
|
+
} else {
|
|
2653
|
+
setTargetId(v);
|
|
2654
|
+
}
|
|
2655
|
+
}, children: [
|
|
2656
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: "h-7 w-[180px] text-xs bg-white/5 border-white/10", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select target" }) }),
|
|
2657
|
+
/* @__PURE__ */ jsxs(SelectContent, { className: "bg-[#111] border-white/10", children: [
|
|
2658
|
+
/* @__PURE__ */ jsx(SelectItem, { value: "current", className: "text-xs", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2659
|
+
/* @__PURE__ */ jsx(Database, { className: "w-3 h-3" }),
|
|
2660
|
+
" Current Schema"
|
|
2661
|
+
] }) }),
|
|
2662
|
+
snapshots.map((s) => /* @__PURE__ */ jsx(SelectItem, { value: s.id, className: "text-xs", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2663
|
+
/* @__PURE__ */ jsx(Clock, { className: "w-3 h-3" }),
|
|
2664
|
+
" ",
|
|
2665
|
+
formatSnapshotLabel(s)
|
|
2666
|
+
] }) }, s.id)),
|
|
2667
|
+
allConnections.filter((c) => c.id !== (connection == null ? void 0 : connection.id)).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2668
|
+
/* @__PURE__ */ jsx("div", { className: "px-2 py-1 text-label text-zinc-600 uppercase border-t border-white/5 mt-1", children: "Fetch from connection" }),
|
|
2669
|
+
allConnections.filter((c) => c.id !== (connection == null ? void 0 : connection.id)).map((c) => /* @__PURE__ */ jsx(SelectItem, { value: `conn:${c.id}`, className: "text-xs", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2670
|
+
/* @__PURE__ */ jsx(Database, { className: "w-3 h-3 text-blue-400" }),
|
|
2671
|
+
" ",
|
|
2672
|
+
c.name,
|
|
2673
|
+
c.environment === "production" && /* @__PURE__ */ jsx(AlertTriangle, { className: "w-3 h-3 text-red-400" })
|
|
2674
|
+
] }) }, `conn:${c.id}`))
|
|
2675
|
+
] })
|
|
2676
|
+
] })
|
|
2677
|
+
] }),
|
|
2678
|
+
fetchingRemote && /* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500 animate-pulse", children: "Fetching..." })
|
|
2679
|
+
] }),
|
|
2680
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1" }),
|
|
2681
|
+
showLabelInput ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2682
|
+
/* @__PURE__ */ jsx(
|
|
2683
|
+
"input",
|
|
2684
|
+
{
|
|
2685
|
+
type: "text",
|
|
2686
|
+
placeholder: "Label (optional)...",
|
|
2687
|
+
value: snapshotLabel,
|
|
2688
|
+
onChange: (e) => setSnapshotLabel(e.target.value),
|
|
2689
|
+
onKeyDown: (e) => e.key === "Enter" && takeSnapshot(),
|
|
2690
|
+
className: "h-7 px-2 text-xs bg-white/5 border border-white/10 rounded text-zinc-300 focus:outline-none focus:border-blue-500 w-32",
|
|
2691
|
+
autoFocus: true
|
|
2692
|
+
}
|
|
2693
|
+
),
|
|
2694
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", className: "h-7 text-xs text-blue-400", onClick: takeSnapshot, children: "Save" }),
|
|
2695
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", className: "h-7 text-xs text-zinc-500", onClick: () => setShowLabelInput(false), children: "Cancel" })
|
|
2696
|
+
] }) : /* @__PURE__ */ jsxs(
|
|
2697
|
+
Button,
|
|
2698
|
+
{
|
|
2699
|
+
variant: "ghost",
|
|
2700
|
+
size: "sm",
|
|
2701
|
+
className: "h-7 text-xs font-bold uppercase text-zinc-500 hover:text-white gap-1",
|
|
2702
|
+
onClick: () => setShowLabelInput(true),
|
|
2703
|
+
disabled: !connection,
|
|
2704
|
+
children: [
|
|
2705
|
+
/* @__PURE__ */ jsx(Camera, { className: "w-3 h-3" }),
|
|
2706
|
+
" Snapshot"
|
|
2707
|
+
]
|
|
2708
|
+
}
|
|
2709
|
+
),
|
|
2710
|
+
(diff == null ? void 0 : diff.hasChanges) && /* @__PURE__ */ jsxs(
|
|
2711
|
+
Button,
|
|
2712
|
+
{
|
|
2713
|
+
variant: "ghost",
|
|
2714
|
+
size: "sm",
|
|
2715
|
+
className: "h-7 text-xs font-bold uppercase text-zinc-500 hover:text-white gap-1",
|
|
2716
|
+
onClick: () => setShowMigration(!showMigration),
|
|
2717
|
+
children: [
|
|
2718
|
+
/* @__PURE__ */ jsx(FileCode, { className: "w-3 h-3" }),
|
|
2719
|
+
" ",
|
|
2720
|
+
showMigration ? "Diff View" : "SQL Migration"
|
|
2721
|
+
]
|
|
2722
|
+
}
|
|
2723
|
+
)
|
|
2724
|
+
] }),
|
|
2725
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden flex", children: !targetId ? /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center text-zinc-600 gap-3", children: [
|
|
2726
|
+
/* @__PURE__ */ jsx(GitCompare, { className: "w-10 h-10 opacity-30" }),
|
|
2727
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "Select source and target to compare schemas" }),
|
|
2728
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-700", children: "Take a snapshot first, then compare with the current schema" }),
|
|
2729
|
+
snapshots.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-4 w-full max-w-2xl px-4", children: /* @__PURE__ */ jsx(
|
|
2730
|
+
SnapshotTimeline,
|
|
2731
|
+
{
|
|
2732
|
+
snapshots,
|
|
2733
|
+
onCompare: (sourceId2, targetId2) => {
|
|
2734
|
+
setSourceId(sourceId2);
|
|
2735
|
+
setTargetId(targetId2);
|
|
2736
|
+
},
|
|
2737
|
+
onDelete: deleteSnapshot
|
|
2738
|
+
}
|
|
2739
|
+
) })
|
|
2740
|
+
] }) : showMigration && migrationSQL ? /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-auto p-4", children: /* @__PURE__ */ jsx("pre", { className: "text-xs font-mono text-zinc-300 bg-[#0d0d0d] border border-white/10 rounded-lg p-4 overflow-auto whitespace-pre-wrap", children: migrationSQL }) }) : diff && diff.hasChanges ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2741
|
+
/* @__PURE__ */ jsxs("div", { className: "w-64 border-r border-white/5 overflow-auto", children: [
|
|
2742
|
+
/* @__PURE__ */ jsx("div", { className: "p-2 border-b border-white/5", children: /* @__PURE__ */ jsxs("div", { className: "text-xs text-zinc-500 uppercase px-2 mb-1", children: [
|
|
2743
|
+
diff.summary.added,
|
|
2744
|
+
" added, ",
|
|
2745
|
+
diff.summary.removed,
|
|
2746
|
+
" removed, ",
|
|
2747
|
+
diff.summary.modified,
|
|
2748
|
+
" modified"
|
|
2749
|
+
] }) }),
|
|
2750
|
+
diff.tables.map((table) => /* @__PURE__ */ jsxs(
|
|
2751
|
+
"button",
|
|
2752
|
+
{
|
|
2753
|
+
onClick: () => setSelectedTable(table.tableName),
|
|
2754
|
+
className: cn(
|
|
2755
|
+
"w-full text-left px-3 py-2 text-xs flex items-center gap-2 hover:bg-white/5 transition-colors",
|
|
2756
|
+
selectedTable === table.tableName && "bg-white/10"
|
|
2757
|
+
),
|
|
2758
|
+
children: [
|
|
2759
|
+
selectedTable === table.tableName ? /* @__PURE__ */ jsx(ChevronDown, { className: "w-3 h-3 text-zinc-500" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "w-3 h-3 text-zinc-500" }),
|
|
2760
|
+
/* @__PURE__ */ jsx("span", { className: "text-zinc-300", children: table.tableName }),
|
|
2761
|
+
/* @__PURE__ */ jsx("span", { className: "ml-auto", children: getActionBadge(table.action) })
|
|
2762
|
+
]
|
|
2763
|
+
},
|
|
2764
|
+
table.tableName
|
|
2765
|
+
))
|
|
2766
|
+
] }),
|
|
2767
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-auto p-4", children: selectedTable ? /* @__PURE__ */ jsx(TableDiffDetail, { diff: diff.tables.find((t) => t.tableName === selectedTable) }) : /* @__PURE__ */ jsx("div", { className: "h-full flex items-center justify-center text-zinc-600 text-sm", children: "Select a table to view diff details" }) })
|
|
2768
|
+
] }) : diff && !diff.hasChanges ? /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-center text-zinc-600 gap-2", children: /* @__PURE__ */ jsx("span", { className: "text-sm", children: "No differences found between source and target" }) }) : /* @__PURE__ */ jsxs("div", { className: "flex-1 flex items-center justify-center text-zinc-600 gap-2", children: [
|
|
2769
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "w-4 h-4" }),
|
|
2770
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm", children: "Cannot compare same schema with itself" })
|
|
2771
|
+
] }) })
|
|
2772
|
+
] });
|
|
2773
|
+
}
|
|
2774
|
+
function TableDiffDetail({ diff }) {
|
|
2775
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
2776
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2777
|
+
/* @__PURE__ */ jsx(Database, { className: "w-4 h-4 text-zinc-400" }),
|
|
2778
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-bold text-zinc-200", children: diff.tableName }),
|
|
2779
|
+
/* @__PURE__ */ jsx(Badge, { className: cn(
|
|
2780
|
+
"text-xs",
|
|
2781
|
+
diff.action === "added" && "bg-green-500/20 text-green-400",
|
|
2782
|
+
diff.action === "removed" && "bg-red-500/20 text-red-400",
|
|
2783
|
+
diff.action === "modified" && "bg-yellow-500/20 text-yellow-400"
|
|
2784
|
+
), children: diff.action })
|
|
2785
|
+
] }),
|
|
2786
|
+
diff.columns.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
2787
|
+
/* @__PURE__ */ jsx("h4", { className: "text-xs uppercase text-zinc-500 mb-2 font-bold", children: "Columns" }),
|
|
2788
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-1", children: diff.columns.map((col, i) => /* @__PURE__ */ jsxs("div", { className: cn(
|
|
2789
|
+
"px-3 py-2 rounded text-xs flex items-center gap-2",
|
|
2790
|
+
col.action === "added" && "bg-green-500/5 border border-green-500/10",
|
|
2791
|
+
col.action === "removed" && "bg-red-500/5 border border-red-500/10",
|
|
2792
|
+
col.action === "modified" && "bg-yellow-500/5 border border-yellow-500/10"
|
|
2793
|
+
), children: [
|
|
2794
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono text-zinc-300 min-w-[120px]", children: col.columnName }),
|
|
2795
|
+
col.action === "modified" && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-0.5", children: col.changes.map((change, j) => /* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500", children: change }, j)) }),
|
|
2796
|
+
col.action === "added" && /* @__PURE__ */ jsx("span", { className: "text-xs text-green-400 font-mono", children: col.targetType }),
|
|
2797
|
+
col.action === "removed" && /* @__PURE__ */ jsx("span", { className: "text-xs text-red-400 font-mono", children: col.sourceType }),
|
|
2798
|
+
/* @__PURE__ */ jsx("span", { className: "ml-auto", children: getActionIcon(col.action) })
|
|
2799
|
+
] }, i)) })
|
|
2800
|
+
] }),
|
|
2801
|
+
diff.indexes.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
2802
|
+
/* @__PURE__ */ jsx("h4", { className: "text-xs uppercase text-zinc-500 mb-2 font-bold", children: "Indexes" }),
|
|
2803
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-1", children: diff.indexes.map((idx, i) => /* @__PURE__ */ jsxs("div", { className: cn(
|
|
2804
|
+
"px-3 py-2 rounded text-xs flex items-center gap-2",
|
|
2805
|
+
idx.action === "added" && "bg-green-500/5 border border-green-500/10",
|
|
2806
|
+
idx.action === "removed" && "bg-red-500/5 border border-red-500/10",
|
|
2807
|
+
idx.action === "modified" && "bg-yellow-500/5 border border-yellow-500/10"
|
|
2808
|
+
), children: [
|
|
2809
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono text-zinc-300", children: idx.indexName }),
|
|
2810
|
+
idx.changes.map((change, j) => /* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500", children: change }, j)),
|
|
2811
|
+
/* @__PURE__ */ jsx("span", { className: "ml-auto", children: getActionIcon(idx.action) })
|
|
2812
|
+
] }, i)) })
|
|
2813
|
+
] }),
|
|
2814
|
+
diff.foreignKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
2815
|
+
/* @__PURE__ */ jsx("h4", { className: "text-xs uppercase text-zinc-500 mb-2 font-bold", children: "Foreign Keys" }),
|
|
2816
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-1", children: diff.foreignKeys.map((fk, i) => /* @__PURE__ */ jsxs("div", { className: cn(
|
|
2817
|
+
"px-3 py-2 rounded text-xs flex items-center gap-2",
|
|
2818
|
+
fk.action === "added" && "bg-green-500/5 border border-green-500/10",
|
|
2819
|
+
fk.action === "removed" && "bg-red-500/5 border border-red-500/10"
|
|
2820
|
+
), children: [
|
|
2821
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono text-zinc-300", children: fk.columnName }),
|
|
2822
|
+
fk.changes.map((change, j) => /* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-500", children: change }, j)),
|
|
2823
|
+
/* @__PURE__ */ jsx("span", { className: "ml-auto", children: getActionIcon(fk.action) })
|
|
2824
|
+
] }, i)) })
|
|
2825
|
+
] })
|
|
2826
|
+
] });
|
|
2827
|
+
}
|
|
2828
|
+
function getActionIcon(action) {
|
|
2829
|
+
switch (action) {
|
|
2830
|
+
case "added":
|
|
2831
|
+
return /* @__PURE__ */ jsx(Plus, { className: "w-3 h-3 text-green-400" });
|
|
2832
|
+
case "removed":
|
|
2833
|
+
return /* @__PURE__ */ jsx(Minus, { className: "w-3 h-3 text-red-400" });
|
|
2834
|
+
case "modified":
|
|
2835
|
+
return /* @__PURE__ */ jsx(Edit3, { className: "w-3 h-3 text-yellow-400" });
|
|
2836
|
+
default:
|
|
2837
|
+
return null;
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
function ChartDashboardLazy({ result }) {
|
|
2841
|
+
const [savedCharts, setSavedCharts] = React.useState([]);
|
|
2842
|
+
React.useEffect(() => {
|
|
2843
|
+
const charts = storage.getSavedCharts();
|
|
2844
|
+
if (charts.length > 0) setSavedCharts(charts);
|
|
2845
|
+
}, []);
|
|
2846
|
+
if (savedCharts.length === 0) {
|
|
2847
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col items-center justify-center bg-[#080808] text-zinc-500 gap-2", children: [
|
|
2848
|
+
/* @__PURE__ */ jsx(LayoutDashboard, { className: "w-10 h-10 opacity-30" }),
|
|
2849
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "No saved charts yet" }),
|
|
2850
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-zinc-600", children: "Save charts from the Charts tab to display them here" })
|
|
2851
|
+
] });
|
|
2852
|
+
}
|
|
2853
|
+
return /* @__PURE__ */ jsx("div", { className: "h-full overflow-auto bg-[#080808] p-4", children: /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4", children: savedCharts.map((chart) => {
|
|
2854
|
+
var _a;
|
|
2855
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-[#0d0d0d] border border-white/10 rounded-lg p-3", children: [
|
|
2856
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-2", children: [
|
|
2857
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-bold text-zinc-300", children: chart.name }),
|
|
2858
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-zinc-600 uppercase", children: chart.chartType })
|
|
2859
|
+
] }),
|
|
2860
|
+
/* @__PURE__ */ jsxs("div", { className: "text-xs text-zinc-500", children: [
|
|
2861
|
+
chart.xAxis && /* @__PURE__ */ jsxs("span", { children: [
|
|
2862
|
+
"X: ",
|
|
2863
|
+
chart.xAxis
|
|
2864
|
+
] }),
|
|
2865
|
+
((_a = chart.yAxis) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */ jsxs("span", { className: "ml-2", children: [
|
|
2866
|
+
"Y: ",
|
|
2867
|
+
chart.yAxis.join(", ")
|
|
2868
|
+
] })
|
|
2869
|
+
] }),
|
|
2870
|
+
result ? /* @__PURE__ */ jsx("div", { className: "mt-2 h-[160px]", children: /* @__PURE__ */ jsx(DataCharts, { result }) }) : /* @__PURE__ */ jsx("div", { className: "mt-2 h-[100px] flex items-center justify-center text-zinc-600 text-xs", children: "Execute a query to see chart" })
|
|
2871
|
+
] }, chart.id);
|
|
2872
|
+
}) }) });
|
|
2873
|
+
}
|
|
2874
|
+
function BottomPanel({
|
|
2875
|
+
mode,
|
|
2876
|
+
onSetMode,
|
|
2877
|
+
currentTab,
|
|
2878
|
+
schema,
|
|
2879
|
+
schemaContext,
|
|
2880
|
+
activeConnection,
|
|
2881
|
+
metadata,
|
|
2882
|
+
historyKey,
|
|
2883
|
+
savedKey,
|
|
2884
|
+
isNL2SQLOpen,
|
|
2885
|
+
onSetIsNL2SQLOpen,
|
|
2886
|
+
maskingEnabled,
|
|
2887
|
+
onToggleMasking,
|
|
2888
|
+
userRole,
|
|
2889
|
+
maskingConfig,
|
|
2890
|
+
editingEnabled,
|
|
2891
|
+
pendingChanges,
|
|
2892
|
+
onCellChange,
|
|
2893
|
+
onApplyChanges,
|
|
2894
|
+
onDiscardChanges,
|
|
2895
|
+
onExecuteQuery,
|
|
2896
|
+
onLoadQuery,
|
|
2897
|
+
onLoadMore,
|
|
2898
|
+
isLoadingMore,
|
|
2899
|
+
onExportResults
|
|
2900
|
+
}) {
|
|
2901
|
+
const tabs = [
|
|
2902
|
+
{ key: "results", label: "Results", icon: /* @__PURE__ */ jsx(LayoutGrid, { className: "w-3 h-3" }), activeClass: "text-blue-400 border-blue-500 bg-white/5" },
|
|
2903
|
+
{ key: "explain", label: "Explain", icon: /* @__PURE__ */ jsx(Zap, { className: "w-3 h-3" }), activeClass: "text-amber-400 border-amber-500 bg-white/5" },
|
|
2904
|
+
{ key: "history", label: "History", icon: /* @__PURE__ */ jsx(Clock, { className: "w-3 h-3" }), activeClass: "text-emerald-400 border-emerald-500 bg-white/5" },
|
|
2905
|
+
{ key: "saved", label: "Saved", icon: /* @__PURE__ */ jsx(Bookmark, { className: "w-3 h-3" }), activeClass: "text-purple-400 border-purple-500 bg-white/5" },
|
|
2906
|
+
{ key: "charts", label: "Charts", icon: /* @__PURE__ */ jsx(BarChart3, { className: "w-3 h-3" }), activeClass: "text-cyan-400 border-cyan-500 bg-white/5" },
|
|
2907
|
+
{ key: "nl2sql", label: "NL2SQL", icon: /* @__PURE__ */ jsx(Sparkles, { className: "w-3 h-3" }), activeClass: "text-violet-400 border-violet-500 bg-white/5" },
|
|
2908
|
+
{ key: "autopilot", label: "Autopilot", icon: /* @__PURE__ */ jsx(Zap, { className: "w-3 h-3" }), activeClass: "text-cyan-400 border-cyan-500 bg-white/5" },
|
|
2909
|
+
{ key: "pivot", label: "Pivot", icon: /* @__PURE__ */ jsx(Columns3, { className: "w-3 h-3" }), activeClass: "text-orange-400 border-orange-500 bg-white/5" },
|
|
2910
|
+
{ key: "docs", label: "Docs", icon: /* @__PURE__ */ jsx(FileText, { className: "w-3 h-3" }), activeClass: "text-teal-400 border-teal-500 bg-white/5" },
|
|
2911
|
+
{ key: "schemadiff", label: "Diff", icon: /* @__PURE__ */ jsx(GitCompare, { className: "w-3 h-3" }), activeClass: "text-rose-400 border-rose-500 bg-white/5" },
|
|
2912
|
+
{ key: "dashboard", label: "Dashboard", icon: /* @__PURE__ */ jsx(LayoutDashboard, { className: "w-3 h-3" }), activeClass: "text-indigo-400 border-indigo-500 bg-white/5" }
|
|
2913
|
+
];
|
|
2914
|
+
return /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col bg-[#080808]", children: [
|
|
2915
|
+
/* @__PURE__ */ jsxs("div", { className: "h-9 bg-[#0a0a0a] border-b border-white/5 flex items-center justify-between px-2", children: [
|
|
2916
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center h-full gap-1", children: tabs.map((tab) => /* @__PURE__ */ jsxs(
|
|
2917
|
+
"button",
|
|
2918
|
+
{
|
|
2919
|
+
onClick: () => {
|
|
2920
|
+
onSetMode(tab.key);
|
|
2921
|
+
if (tab.key === "nl2sql") onSetIsNL2SQLOpen(true);
|
|
2922
|
+
},
|
|
2923
|
+
className: cn(
|
|
2924
|
+
"h-full px-3 text-xs font-bold uppercase transition-all border-b-2 flex items-center gap-2",
|
|
2925
|
+
mode === tab.key ? tab.activeClass : "text-zinc-500 border-transparent hover:text-zinc-300"
|
|
2926
|
+
),
|
|
2927
|
+
children: [
|
|
2928
|
+
tab.icon,
|
|
2929
|
+
" ",
|
|
2930
|
+
tab.label
|
|
2931
|
+
]
|
|
2932
|
+
},
|
|
2933
|
+
tab.key
|
|
2934
|
+
)) }),
|
|
2935
|
+
currentTab.result && mode === "results" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
2936
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs font-mono text-zinc-500 mr-2", children: [
|
|
2937
|
+
currentTab.result.rowCount,
|
|
2938
|
+
" rows \u2022 ",
|
|
2939
|
+
currentTab.result.executionTime,
|
|
2940
|
+
"ms"
|
|
2941
|
+
] }),
|
|
2942
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
2943
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "h-7 text-xs font-bold uppercase text-zinc-500 hover:text-white gap-2", children: [
|
|
2944
|
+
/* @__PURE__ */ jsx(Download, { className: "w-3 h-3" }),
|
|
2945
|
+
" Export"
|
|
2946
|
+
] }) }),
|
|
2947
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "bg-[#0d0d0d] border-white/10 text-zinc-300", children: [
|
|
2948
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => onExportResults("csv"), className: "text-xs cursor-pointer", children: "Export as CSV" }),
|
|
2949
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => onExportResults("json"), className: "text-xs cursor-pointer", children: "Export as JSON" }),
|
|
2950
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => onExportResults("sql-insert"), className: "text-xs cursor-pointer", children: "Export as SQL INSERT" }),
|
|
2951
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => onExportResults("sql-ddl"), className: "text-xs cursor-pointer", children: "Export as DDL (CREATE TABLE)" })
|
|
2952
|
+
] })
|
|
2953
|
+
] })
|
|
2954
|
+
] })
|
|
2955
|
+
] }),
|
|
2956
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden relative", children: mode === "nl2sql" ? /* @__PURE__ */ jsx(
|
|
2957
|
+
NL2SQLPanel,
|
|
2958
|
+
{
|
|
2959
|
+
isOpen: isNL2SQLOpen,
|
|
2960
|
+
onClose: () => {
|
|
2961
|
+
onSetIsNL2SQLOpen(false);
|
|
2962
|
+
onSetMode("results");
|
|
2963
|
+
},
|
|
2964
|
+
onExecuteQuery,
|
|
2965
|
+
onLoadQuery: (q) => {
|
|
2966
|
+
onLoadQuery(q);
|
|
2967
|
+
onSetMode("results");
|
|
2968
|
+
},
|
|
2969
|
+
schemaContext,
|
|
2970
|
+
databaseType: activeConnection == null ? void 0 : activeConnection.type,
|
|
2971
|
+
queryLanguage: metadata == null ? void 0 : metadata.capabilities.queryLanguage
|
|
2972
|
+
}
|
|
2973
|
+
) : mode === "autopilot" ? /* @__PURE__ */ jsx(
|
|
2974
|
+
AIAutopilotPanel,
|
|
2975
|
+
{
|
|
2976
|
+
connection: activeConnection,
|
|
2977
|
+
schemaContext,
|
|
2978
|
+
onExecuteQuery
|
|
2979
|
+
}
|
|
2980
|
+
) : mode === "pivot" ? /* @__PURE__ */ jsx(
|
|
2981
|
+
PivotTable,
|
|
2982
|
+
{
|
|
2983
|
+
result: currentTab.result,
|
|
2984
|
+
onLoadQuery: (q) => {
|
|
2985
|
+
onLoadQuery(q);
|
|
2986
|
+
onSetMode("results");
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
) : mode === "docs" ? /* @__PURE__ */ jsx(
|
|
2990
|
+
DatabaseDocs,
|
|
2991
|
+
{
|
|
2992
|
+
schema,
|
|
2993
|
+
schemaContext,
|
|
2994
|
+
databaseType: activeConnection == null ? void 0 : activeConnection.type
|
|
2995
|
+
}
|
|
2996
|
+
) : mode === "history" ? /* @__PURE__ */ jsx(
|
|
2997
|
+
QueryHistory,
|
|
2998
|
+
{
|
|
2999
|
+
refreshTrigger: historyKey,
|
|
3000
|
+
activeConnectionId: activeConnection == null ? void 0 : activeConnection.id,
|
|
3001
|
+
onSelectQuery: (q) => {
|
|
3002
|
+
onLoadQuery(q);
|
|
3003
|
+
onSetMode("results");
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
) : mode === "saved" ? /* @__PURE__ */ jsx(
|
|
3007
|
+
SavedQueries,
|
|
3008
|
+
{
|
|
3009
|
+
refreshTrigger: savedKey,
|
|
3010
|
+
connectionType: activeConnection == null ? void 0 : activeConnection.type,
|
|
3011
|
+
onSelectQuery: (q) => {
|
|
3012
|
+
onLoadQuery(q);
|
|
3013
|
+
onSetMode("results");
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
) : mode === "charts" ? /* @__PURE__ */ jsx(DataCharts, { result: currentTab.result }) : mode === "schemadiff" ? /* @__PURE__ */ jsx(SchemaDiff, { schema, connection: activeConnection }) : mode === "dashboard" ? /* @__PURE__ */ jsx(ChartDashboardLazy, { result: currentTab.result }) : currentTab.result ? mode === "explain" ? /* @__PURE__ */ jsx(
|
|
3017
|
+
VisualExplain,
|
|
3018
|
+
{
|
|
3019
|
+
plan: currentTab.explainPlan,
|
|
3020
|
+
query: currentTab.query,
|
|
3021
|
+
schemaContext,
|
|
3022
|
+
databaseType: activeConnection == null ? void 0 : activeConnection.type,
|
|
3023
|
+
onLoadQuery: (q) => {
|
|
3024
|
+
onLoadQuery(q);
|
|
3025
|
+
onSetMode("results");
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
) : /* @__PURE__ */ jsx(
|
|
3029
|
+
ResultsGrid,
|
|
3030
|
+
{
|
|
3031
|
+
result: currentTab.result,
|
|
3032
|
+
onLoadMore,
|
|
3033
|
+
isLoadingMore,
|
|
3034
|
+
maskingEnabled,
|
|
3035
|
+
onToggleMasking,
|
|
3036
|
+
userRole,
|
|
3037
|
+
maskingConfig,
|
|
3038
|
+
editingEnabled,
|
|
3039
|
+
pendingChanges,
|
|
3040
|
+
onCellChange,
|
|
3041
|
+
onApplyChanges,
|
|
3042
|
+
onDiscardChanges
|
|
3043
|
+
}
|
|
3044
|
+
) : /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col items-center justify-center opacity-20 bg-[#0a0a0a]", children: [
|
|
3045
|
+
/* @__PURE__ */ jsx(Terminal, { className: "w-12 h-12 mb-4" }),
|
|
3046
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Execute a query or check history" }),
|
|
3047
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-widest mt-2", children: "Ready to query" })
|
|
3048
|
+
] }) })
|
|
3049
|
+
] });
|
|
3050
|
+
}
|
|
3051
|
+
function useToast() {
|
|
3052
|
+
const toast$1 = useCallback(({ title, description, variant }) => {
|
|
3053
|
+
if (variant === "destructive") {
|
|
3054
|
+
toast.error(title, { description });
|
|
3055
|
+
} else {
|
|
3056
|
+
toast.success(title, { description });
|
|
3057
|
+
}
|
|
3058
|
+
}, []);
|
|
3059
|
+
return { toast: toast$1 };
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
// src/hooks/use-tab-manager.ts
|
|
3063
|
+
var DEFAULT_TAB = {
|
|
3064
|
+
id: "default",
|
|
3065
|
+
name: "Query 1",
|
|
3066
|
+
query: "",
|
|
3067
|
+
result: null,
|
|
3068
|
+
isExecuting: false,
|
|
3069
|
+
type: "sql"
|
|
3070
|
+
};
|
|
3071
|
+
var WORKSPACE_STORAGE_PREFIX = "libredb_workspace_tabs_v1";
|
|
3072
|
+
function useTabManager({
|
|
3073
|
+
activeConnection,
|
|
3074
|
+
metadata,
|
|
3075
|
+
schema,
|
|
3076
|
+
persistWorkspace
|
|
3077
|
+
}) {
|
|
3078
|
+
const [tabs, setTabs] = useState([DEFAULT_TAB]);
|
|
3079
|
+
const [activeTabId, setActiveTabId] = useState("default");
|
|
3080
|
+
const [editingTabId, setEditingTabId] = useState(null);
|
|
3081
|
+
const [editingTabName, setEditingTabName] = useState("");
|
|
3082
|
+
const [isWorkspaceHydrated, setIsWorkspaceHydrated] = useState(false);
|
|
3083
|
+
const workspaceKey = useMemo(
|
|
3084
|
+
() => {
|
|
3085
|
+
var _a;
|
|
3086
|
+
return `${WORKSPACE_STORAGE_PREFIX}:${(_a = activeConnection == null ? void 0 : activeConnection.id) != null ? _a : "default"}`;
|
|
3087
|
+
},
|
|
3088
|
+
[activeConnection == null ? void 0 : activeConnection.id]
|
|
3089
|
+
);
|
|
3090
|
+
const shouldPersistWorkspace = persistWorkspace != null ? persistWorkspace : process.env.NODE_ENV !== "test";
|
|
3091
|
+
const currentTab = tabs.find((t) => t.id === activeTabId) || tabs[0];
|
|
3092
|
+
useEffect(() => {
|
|
3093
|
+
setIsWorkspaceHydrated(false);
|
|
3094
|
+
if (!shouldPersistWorkspace) return;
|
|
3095
|
+
const storage2 = typeof globalThis !== "undefined" && "localStorage" in globalThis ? globalThis.localStorage : null;
|
|
3096
|
+
if (!storage2) return;
|
|
3097
|
+
try {
|
|
3098
|
+
const raw = storage2.getItem(workspaceKey);
|
|
3099
|
+
if (!raw) {
|
|
3100
|
+
setTabs([DEFAULT_TAB]);
|
|
3101
|
+
setActiveTabId(DEFAULT_TAB.id);
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
const parsed = JSON.parse(raw);
|
|
3105
|
+
if (!parsed || !Array.isArray(parsed.tabs) || parsed.tabs.length === 0) {
|
|
3106
|
+
setTabs([DEFAULT_TAB]);
|
|
3107
|
+
setActiveTabId(DEFAULT_TAB.id);
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3110
|
+
const restoredTabs = parsed.tabs.map((tab) => ({
|
|
3111
|
+
id: tab.id,
|
|
3112
|
+
name: tab.name,
|
|
3113
|
+
query: tab.query,
|
|
3114
|
+
type: tab.type,
|
|
3115
|
+
result: null,
|
|
3116
|
+
isExecuting: false
|
|
3117
|
+
}));
|
|
3118
|
+
const hasActiveTab = restoredTabs.some((tab) => tab.id === parsed.activeTabId);
|
|
3119
|
+
setTabs(restoredTabs);
|
|
3120
|
+
setActiveTabId(hasActiveTab ? parsed.activeTabId : restoredTabs[0].id);
|
|
3121
|
+
} catch (error) {
|
|
3122
|
+
console.error("[useTabManager] Failed to restore workspace tabs:", error);
|
|
3123
|
+
setTabs([DEFAULT_TAB]);
|
|
3124
|
+
setActiveTabId(DEFAULT_TAB.id);
|
|
3125
|
+
}
|
|
3126
|
+
}, [workspaceKey, shouldPersistWorkspace]);
|
|
3127
|
+
useEffect(() => {
|
|
3128
|
+
if (!shouldPersistWorkspace || isWorkspaceHydrated) return;
|
|
3129
|
+
setIsWorkspaceHydrated(true);
|
|
3130
|
+
}, [tabs, activeTabId, shouldPersistWorkspace, isWorkspaceHydrated]);
|
|
3131
|
+
useEffect(() => {
|
|
3132
|
+
if (!shouldPersistWorkspace) return;
|
|
3133
|
+
const storage2 = typeof globalThis !== "undefined" && "localStorage" in globalThis ? globalThis.localStorage : null;
|
|
3134
|
+
if (!isWorkspaceHydrated || !storage2) return;
|
|
3135
|
+
const timer = setTimeout(() => {
|
|
3136
|
+
const serialized = {
|
|
3137
|
+
activeTabId,
|
|
3138
|
+
tabs: tabs.map((tab) => ({
|
|
3139
|
+
id: tab.id,
|
|
3140
|
+
name: tab.name,
|
|
3141
|
+
query: tab.query,
|
|
3142
|
+
type: tab.type
|
|
3143
|
+
}))
|
|
3144
|
+
};
|
|
3145
|
+
storage2.setItem(workspaceKey, JSON.stringify(serialized));
|
|
3146
|
+
}, 500);
|
|
3147
|
+
return () => clearTimeout(timer);
|
|
3148
|
+
}, [tabs, activeTabId, workspaceKey, shouldPersistWorkspace, isWorkspaceHydrated]);
|
|
3149
|
+
const updateTabById = useCallback((tabId, updates) => {
|
|
3150
|
+
setTabs((prev) => prev.map((t) => t.id === tabId ? __spreadValues(__spreadValues({}, t), updates) : t));
|
|
3151
|
+
}, []);
|
|
3152
|
+
const updateCurrentTab = useCallback((updates) => {
|
|
3153
|
+
updateTabById(activeTabId, updates);
|
|
3154
|
+
}, [activeTabId, updateTabById]);
|
|
3155
|
+
const addTab = useCallback(() => {
|
|
3156
|
+
const newId = Math.random().toString(36).substring(7);
|
|
3157
|
+
setTabs((prev) => [...prev, {
|
|
3158
|
+
id: newId,
|
|
3159
|
+
name: `Query ${prev.length + 1}`,
|
|
3160
|
+
query: "",
|
|
3161
|
+
result: null,
|
|
3162
|
+
isExecuting: false,
|
|
3163
|
+
type: "sql"
|
|
3164
|
+
}]);
|
|
3165
|
+
setActiveTabId(newId);
|
|
3166
|
+
}, [activeConnection, metadata]);
|
|
3167
|
+
const closeTab = useCallback((id, e) => {
|
|
3168
|
+
e.stopPropagation();
|
|
3169
|
+
setTabs((prev) => {
|
|
3170
|
+
if (prev.length === 1) return prev;
|
|
3171
|
+
const newTabs = prev.filter((t) => t.id !== id);
|
|
3172
|
+
if (activeTabId === id && newTabs.length > 0) {
|
|
3173
|
+
setActiveTabId(newTabs[newTabs.length - 1].id);
|
|
3174
|
+
}
|
|
3175
|
+
return newTabs;
|
|
3176
|
+
});
|
|
3177
|
+
}, [activeTabId]);
|
|
3178
|
+
const handleTableClick = useCallback((tableName, executeQueryFn) => {
|
|
3179
|
+
const newQuery = `SELECT * FROM ${tableName} LIMIT 50;`;
|
|
3180
|
+
const newId = Math.random().toString(36).substring(7);
|
|
3181
|
+
const newTab = {
|
|
3182
|
+
id: newId,
|
|
3183
|
+
name: tableName,
|
|
3184
|
+
query: newQuery,
|
|
3185
|
+
result: null,
|
|
3186
|
+
isExecuting: false,
|
|
3187
|
+
type: "sql"
|
|
3188
|
+
};
|
|
3189
|
+
setTabs((prev) => [...prev, newTab]);
|
|
3190
|
+
setActiveTabId(newId);
|
|
3191
|
+
setTimeout(() => executeQueryFn(newQuery, newId), 100);
|
|
3192
|
+
}, [metadata]);
|
|
3193
|
+
const handleGenerateSelect = useCallback((tableName) => {
|
|
3194
|
+
const table = schema.find((t) => t.name === tableName);
|
|
3195
|
+
const columns = (table == null ? void 0 : table.columns) || [];
|
|
3196
|
+
const newQuery = `SELECT
|
|
3197
|
+
${columns.map((c) => ` ${c.name}`).join(",\n") || " *"}
|
|
3198
|
+
FROM ${tableName}
|
|
3199
|
+
WHERE 1=1
|
|
3200
|
+
LIMIT 100;`;
|
|
3201
|
+
const tabType = "sql";
|
|
3202
|
+
const newId = Math.random().toString(36).substring(7);
|
|
3203
|
+
setTabs((prev) => [...prev, {
|
|
3204
|
+
id: newId,
|
|
3205
|
+
name: `Query: ${tableName}`,
|
|
3206
|
+
query: newQuery,
|
|
3207
|
+
result: null,
|
|
3208
|
+
isExecuting: false,
|
|
3209
|
+
type: tabType
|
|
3210
|
+
}]);
|
|
3211
|
+
setActiveTabId(newId);
|
|
3212
|
+
}, [metadata, schema]);
|
|
3213
|
+
return {
|
|
3214
|
+
tabs,
|
|
3215
|
+
setTabs,
|
|
3216
|
+
activeTabId,
|
|
3217
|
+
setActiveTabId,
|
|
3218
|
+
currentTab,
|
|
3219
|
+
editingTabId,
|
|
3220
|
+
setEditingTabId,
|
|
3221
|
+
editingTabName,
|
|
3222
|
+
setEditingTabName,
|
|
3223
|
+
addTab,
|
|
3224
|
+
closeTab,
|
|
3225
|
+
updateCurrentTab,
|
|
3226
|
+
updateTabById,
|
|
3227
|
+
handleTableClick,
|
|
3228
|
+
handleGenerateSelect
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
3231
|
+
function useConnectionAdapter({
|
|
3232
|
+
connections: externalConnections,
|
|
3233
|
+
onSchemaFetch
|
|
3234
|
+
}) {
|
|
3235
|
+
var _a;
|
|
3236
|
+
const connections = useMemo(
|
|
3237
|
+
() => externalConnections.map((c) => ({
|
|
3238
|
+
id: c.id,
|
|
3239
|
+
name: c.name,
|
|
3240
|
+
type: c.type,
|
|
3241
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
3242
|
+
managed: true
|
|
3243
|
+
})),
|
|
3244
|
+
[externalConnections]
|
|
3245
|
+
);
|
|
3246
|
+
const [activeConnection, setActiveConnection] = useState(
|
|
3247
|
+
(_a = connections[0]) != null ? _a : null
|
|
3248
|
+
);
|
|
3249
|
+
const [schema, setSchema] = useState([]);
|
|
3250
|
+
const [isLoadingSchema, setIsLoadingSchema] = useState(false);
|
|
3251
|
+
useEffect(() => {
|
|
3252
|
+
if (connections.length === 0) {
|
|
3253
|
+
setActiveConnection(null);
|
|
3254
|
+
return;
|
|
3255
|
+
}
|
|
3256
|
+
if (activeConnection && connections.some((c) => c.id === activeConnection.id)) {
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
setActiveConnection(connections[0]);
|
|
3260
|
+
}, [connections]);
|
|
3261
|
+
const fetchSchema = useCallback(
|
|
3262
|
+
async (conn) => {
|
|
3263
|
+
setIsLoadingSchema(true);
|
|
3264
|
+
try {
|
|
3265
|
+
const result = await onSchemaFetch(conn.id);
|
|
3266
|
+
setSchema(result);
|
|
3267
|
+
} catch (e) {
|
|
3268
|
+
setSchema([]);
|
|
3269
|
+
} finally {
|
|
3270
|
+
setIsLoadingSchema(false);
|
|
3271
|
+
}
|
|
3272
|
+
},
|
|
3273
|
+
[onSchemaFetch]
|
|
3274
|
+
);
|
|
3275
|
+
const tableNames = useMemo(() => schema.map((s) => s.name), [schema]);
|
|
3276
|
+
const schemaContext = useMemo(() => JSON.stringify(schema), [schema]);
|
|
3277
|
+
return {
|
|
3278
|
+
connections,
|
|
3279
|
+
setConnections: (() => {
|
|
3280
|
+
}),
|
|
3281
|
+
activeConnection,
|
|
3282
|
+
setActiveConnection,
|
|
3283
|
+
schema,
|
|
3284
|
+
setSchema,
|
|
3285
|
+
isLoadingSchema,
|
|
3286
|
+
connectionPulse: null,
|
|
3287
|
+
fetchSchema,
|
|
3288
|
+
tableNames,
|
|
3289
|
+
schemaContext
|
|
3290
|
+
};
|
|
3291
|
+
}
|
|
3292
|
+
function useQueryAdapter({
|
|
3293
|
+
activeConnection,
|
|
3294
|
+
onQueryExecute,
|
|
3295
|
+
tabs,
|
|
3296
|
+
activeTabId,
|
|
3297
|
+
currentTab,
|
|
3298
|
+
setTabs,
|
|
3299
|
+
fetchSchema: _fetchSchema,
|
|
3300
|
+
features: _features
|
|
3301
|
+
}) {
|
|
3302
|
+
const cancelledRef = useRef(false);
|
|
3303
|
+
const [safetyCheckQuery, setSafetyCheckQuery] = useState(null);
|
|
3304
|
+
const [unlimitedWarningOpen, setUnlimitedWarningOpen] = useState(false);
|
|
3305
|
+
const [pendingUnlimitedQuery, setPendingUnlimitedQuery] = useState(null);
|
|
3306
|
+
const [historyKey, setHistoryKey] = useState(0);
|
|
3307
|
+
const [bottomPanelMode, setBottomPanelMode] = useState("results");
|
|
3308
|
+
const { toast } = useToast();
|
|
3309
|
+
const executeQuery = useCallback(async (overrideQuery, tabId, _isExplain = false) => {
|
|
3310
|
+
const targetTabId = tabId || activeTabId;
|
|
3311
|
+
const tabToExec = tabs.find((t) => t.id === targetTabId) || currentTab;
|
|
3312
|
+
const queryToExecute = overrideQuery || tabToExec.query;
|
|
3313
|
+
if (!activeConnection) {
|
|
3314
|
+
toast({ title: "No Connection", description: "Select a connection first.", variant: "destructive" });
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
if (!queryToExecute || queryToExecute.trim() === "") {
|
|
3318
|
+
toast({ title: "Empty Query", description: "Enter a query to execute.", variant: "destructive" });
|
|
3319
|
+
return;
|
|
3320
|
+
}
|
|
3321
|
+
if (isDangerousQuery(queryToExecute)) {
|
|
3322
|
+
setSafetyCheckQuery(queryToExecute);
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
cancelledRef.current = false;
|
|
3326
|
+
setTabs((prev) => prev.map((t) => t.id === targetTabId ? __spreadProps(__spreadValues({}, t), {
|
|
3327
|
+
isExecuting: true
|
|
3328
|
+
}) : t));
|
|
3329
|
+
setBottomPanelMode("results");
|
|
3330
|
+
const startTime = Date.now();
|
|
3331
|
+
try {
|
|
3332
|
+
const result = await onQueryExecute(activeConnection.id, queryToExecute);
|
|
3333
|
+
if (cancelledRef.current) return;
|
|
3334
|
+
const executionTime = result.executionTime || Date.now() - startTime;
|
|
3335
|
+
setTabs((prev) => prev.map((t) => {
|
|
3336
|
+
if (t.id !== targetTabId) return t;
|
|
3337
|
+
return __spreadProps(__spreadValues({}, t), {
|
|
3338
|
+
result: {
|
|
3339
|
+
rows: result.rows,
|
|
3340
|
+
fields: result.fields,
|
|
3341
|
+
rowCount: result.rowCount,
|
|
3342
|
+
executionTime,
|
|
3343
|
+
pagination: result.pagination
|
|
3344
|
+
},
|
|
3345
|
+
allRows: result.rows,
|
|
3346
|
+
currentOffset: result.rows.length,
|
|
3347
|
+
isExecuting: false,
|
|
3348
|
+
isLoadingMore: false
|
|
3349
|
+
});
|
|
3350
|
+
}));
|
|
3351
|
+
setHistoryKey((prev) => prev + 1);
|
|
3352
|
+
} catch (error) {
|
|
3353
|
+
if (cancelledRef.current) return;
|
|
3354
|
+
setTabs((prev) => prev.map((t) => t.id === targetTabId ? __spreadProps(__spreadValues({}, t), {
|
|
3355
|
+
isExecuting: false,
|
|
3356
|
+
isLoadingMore: false
|
|
3357
|
+
}) : t));
|
|
3358
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
3359
|
+
toast({ title: "Query Error", description: errorMessage, variant: "destructive" });
|
|
3360
|
+
}
|
|
3361
|
+
}, [activeConnection, tabs, currentTab, activeTabId, toast, onQueryExecute, setTabs]);
|
|
3362
|
+
const forceExecuteQuery = useCallback((query) => {
|
|
3363
|
+
setSafetyCheckQuery(null);
|
|
3364
|
+
if (!activeConnection) {
|
|
3365
|
+
toast({ title: "No Connection", description: "Select a connection first.", variant: "destructive" });
|
|
3366
|
+
return;
|
|
3367
|
+
}
|
|
3368
|
+
if (!query || query.trim() === "") {
|
|
3369
|
+
toast({ title: "Empty Query", description: "Enter a query to execute.", variant: "destructive" });
|
|
3370
|
+
return;
|
|
3371
|
+
}
|
|
3372
|
+
cancelledRef.current = false;
|
|
3373
|
+
setTabs((prev) => prev.map((t) => t.id === activeTabId ? __spreadProps(__spreadValues({}, t), {
|
|
3374
|
+
isExecuting: true
|
|
3375
|
+
}) : t));
|
|
3376
|
+
setBottomPanelMode("results");
|
|
3377
|
+
const startTime = Date.now();
|
|
3378
|
+
onQueryExecute(activeConnection.id, query).then((result) => {
|
|
3379
|
+
if (cancelledRef.current) return;
|
|
3380
|
+
const executionTime = result.executionTime || Date.now() - startTime;
|
|
3381
|
+
setTabs((prev) => prev.map((t) => {
|
|
3382
|
+
if (t.id !== activeTabId) return t;
|
|
3383
|
+
return __spreadProps(__spreadValues({}, t), {
|
|
3384
|
+
result: {
|
|
3385
|
+
rows: result.rows,
|
|
3386
|
+
fields: result.fields,
|
|
3387
|
+
rowCount: result.rowCount,
|
|
3388
|
+
executionTime,
|
|
3389
|
+
pagination: result.pagination
|
|
3390
|
+
},
|
|
3391
|
+
allRows: result.rows,
|
|
3392
|
+
currentOffset: result.rows.length,
|
|
3393
|
+
isExecuting: false,
|
|
3394
|
+
isLoadingMore: false
|
|
3395
|
+
});
|
|
3396
|
+
}));
|
|
3397
|
+
setHistoryKey((prev) => prev + 1);
|
|
3398
|
+
}).catch((error) => {
|
|
3399
|
+
if (cancelledRef.current) return;
|
|
3400
|
+
setTabs((prev) => prev.map((t) => t.id === activeTabId ? __spreadProps(__spreadValues({}, t), {
|
|
3401
|
+
isExecuting: false,
|
|
3402
|
+
isLoadingMore: false
|
|
3403
|
+
}) : t));
|
|
3404
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
3405
|
+
toast({ title: "Query Error", description: errorMessage, variant: "destructive" });
|
|
3406
|
+
});
|
|
3407
|
+
}, [activeConnection, activeTabId, toast, onQueryExecute, setTabs]);
|
|
3408
|
+
const cancelQuery = useCallback(() => {
|
|
3409
|
+
cancelledRef.current = true;
|
|
3410
|
+
setTabs((prev) => prev.map((t) => t.isExecuting ? __spreadProps(__spreadValues({}, t), {
|
|
3411
|
+
isExecuting: false,
|
|
3412
|
+
isLoadingMore: false
|
|
3413
|
+
}) : t));
|
|
3414
|
+
toast({ title: "Query Cancelled", description: "Query execution was cancelled." });
|
|
3415
|
+
}, [setTabs, toast]);
|
|
3416
|
+
const handleLoadMore = useCallback(() => {
|
|
3417
|
+
var _a, _b;
|
|
3418
|
+
if (!((_b = (_a = currentTab.result) == null ? void 0 : _a.pagination) == null ? void 0 : _b.hasMore)) return;
|
|
3419
|
+
if (!activeConnection) return;
|
|
3420
|
+
const currentOffset = currentTab.currentOffset || currentTab.result.rows.length;
|
|
3421
|
+
setTabs((prev) => prev.map((t) => t.id === currentTab.id ? __spreadProps(__spreadValues({}, t), {
|
|
3422
|
+
isLoadingMore: true
|
|
3423
|
+
}) : t));
|
|
3424
|
+
onQueryExecute(activeConnection.id, currentTab.query, {
|
|
3425
|
+
limit: 500,
|
|
3426
|
+
offset: currentOffset
|
|
3427
|
+
}).then((result) => {
|
|
3428
|
+
if (cancelledRef.current) return;
|
|
3429
|
+
setTabs((prev) => prev.map((t) => {
|
|
3430
|
+
var _a2, _b2;
|
|
3431
|
+
if (t.id !== currentTab.id) return t;
|
|
3432
|
+
const existingRows = t.allRows || ((_a2 = t.result) == null ? void 0 : _a2.rows) || [];
|
|
3433
|
+
const newAllRows = [...existingRows, ...result.rows];
|
|
3434
|
+
return __spreadProps(__spreadValues({}, t), {
|
|
3435
|
+
result: {
|
|
3436
|
+
rows: newAllRows,
|
|
3437
|
+
fields: result.fields,
|
|
3438
|
+
rowCount: newAllRows.length,
|
|
3439
|
+
executionTime: ((_b2 = t.result) == null ? void 0 : _b2.executionTime) || 0,
|
|
3440
|
+
pagination: result.pagination
|
|
3441
|
+
},
|
|
3442
|
+
allRows: newAllRows,
|
|
3443
|
+
currentOffset: currentOffset + result.rows.length,
|
|
3444
|
+
isExecuting: false,
|
|
3445
|
+
isLoadingMore: false
|
|
3446
|
+
});
|
|
3447
|
+
}));
|
|
3448
|
+
}).catch((error) => {
|
|
3449
|
+
if (cancelledRef.current) return;
|
|
3450
|
+
setTabs((prev) => prev.map((t) => t.id === currentTab.id ? __spreadProps(__spreadValues({}, t), {
|
|
3451
|
+
isExecuting: false,
|
|
3452
|
+
isLoadingMore: false
|
|
3453
|
+
}) : t));
|
|
3454
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
3455
|
+
toast({ title: "Load More Error", description: errorMessage, variant: "destructive" });
|
|
3456
|
+
});
|
|
3457
|
+
}, [currentTab, activeConnection, onQueryExecute, setTabs, toast]);
|
|
3458
|
+
const handleUnlimitedQuery = useCallback(() => {
|
|
3459
|
+
if (!pendingUnlimitedQuery) return;
|
|
3460
|
+
if (!activeConnection) return;
|
|
3461
|
+
const { query, tabId } = pendingUnlimitedQuery;
|
|
3462
|
+
cancelledRef.current = false;
|
|
3463
|
+
setTabs((prev) => prev.map((t) => t.id === tabId ? __spreadProps(__spreadValues({}, t), {
|
|
3464
|
+
isExecuting: true
|
|
3465
|
+
}) : t));
|
|
3466
|
+
onQueryExecute(activeConnection.id, query, { unlimited: true }).then((result) => {
|
|
3467
|
+
if (cancelledRef.current) return;
|
|
3468
|
+
setTabs((prev) => prev.map((t) => {
|
|
3469
|
+
if (t.id !== tabId) return t;
|
|
3470
|
+
return __spreadProps(__spreadValues({}, t), {
|
|
3471
|
+
result: {
|
|
3472
|
+
rows: result.rows,
|
|
3473
|
+
fields: result.fields,
|
|
3474
|
+
rowCount: result.rowCount,
|
|
3475
|
+
executionTime: result.executionTime,
|
|
3476
|
+
pagination: result.pagination
|
|
3477
|
+
},
|
|
3478
|
+
allRows: result.rows,
|
|
3479
|
+
currentOffset: result.rows.length,
|
|
3480
|
+
isExecuting: false,
|
|
3481
|
+
isLoadingMore: false
|
|
3482
|
+
});
|
|
3483
|
+
}));
|
|
3484
|
+
setHistoryKey((prev) => prev + 1);
|
|
3485
|
+
}).catch((error) => {
|
|
3486
|
+
if (cancelledRef.current) return;
|
|
3487
|
+
setTabs((prev) => prev.map((t) => t.id === tabId ? __spreadProps(__spreadValues({}, t), {
|
|
3488
|
+
isExecuting: false,
|
|
3489
|
+
isLoadingMore: false
|
|
3490
|
+
}) : t));
|
|
3491
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
3492
|
+
toast({ title: "Query Error", description: errorMessage, variant: "destructive" });
|
|
3493
|
+
});
|
|
3494
|
+
setUnlimitedWarningOpen(false);
|
|
3495
|
+
setPendingUnlimitedQuery(null);
|
|
3496
|
+
}, [pendingUnlimitedQuery, activeConnection, onQueryExecute, setTabs, toast]);
|
|
3497
|
+
return {
|
|
3498
|
+
executeQuery,
|
|
3499
|
+
forceExecuteQuery,
|
|
3500
|
+
cancelQuery,
|
|
3501
|
+
handleLoadMore,
|
|
3502
|
+
handleUnlimitedQuery,
|
|
3503
|
+
safetyCheckQuery,
|
|
3504
|
+
setSafetyCheckQuery,
|
|
3505
|
+
unlimitedWarningOpen,
|
|
3506
|
+
setUnlimitedWarningOpen,
|
|
3507
|
+
pendingUnlimitedQuery,
|
|
3508
|
+
setPendingUnlimitedQuery,
|
|
3509
|
+
historyKey,
|
|
3510
|
+
bottomPanelMode,
|
|
3511
|
+
setBottomPanelMode
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3515
|
+
// src/workspace/types.ts
|
|
3516
|
+
var DEFAULT_WORKSPACE_FEATURES = {
|
|
3517
|
+
ai: false,
|
|
3518
|
+
charts: true,
|
|
3519
|
+
codeGenerator: true,
|
|
3520
|
+
testDataGenerator: true,
|
|
3521
|
+
schemaDiagram: true,
|
|
3522
|
+
dataImport: true,
|
|
3523
|
+
inlineEditing: false,
|
|
3524
|
+
transactions: false,
|
|
3525
|
+
connectionManagement: false,
|
|
3526
|
+
dataMasking: false
|
|
3527
|
+
};
|
|
3528
|
+
function ResizablePanelGroup(_a) {
|
|
3529
|
+
var _b = _a, {
|
|
3530
|
+
className
|
|
3531
|
+
} = _b, props = __objRest(_b, [
|
|
3532
|
+
"className"
|
|
3533
|
+
]);
|
|
3534
|
+
return /* @__PURE__ */ jsx(
|
|
3535
|
+
ResizablePrimitive.PanelGroup,
|
|
3536
|
+
__spreadValues({
|
|
3537
|
+
"data-slot": "resizable-panel-group",
|
|
3538
|
+
className: cn(
|
|
3539
|
+
"flex h-full w-full data-[panel-group-direction=vertical]:flex-col",
|
|
3540
|
+
className
|
|
3541
|
+
)
|
|
3542
|
+
}, props)
|
|
3543
|
+
);
|
|
3544
|
+
}
|
|
3545
|
+
function ResizablePanel(_a) {
|
|
3546
|
+
var props = __objRest(_a, []);
|
|
3547
|
+
return /* @__PURE__ */ jsx(ResizablePrimitive.Panel, __spreadValues({ "data-slot": "resizable-panel" }, props));
|
|
3548
|
+
}
|
|
3549
|
+
function ResizableHandle(_a) {
|
|
3550
|
+
var _b = _a, {
|
|
3551
|
+
withHandle,
|
|
3552
|
+
className
|
|
3553
|
+
} = _b, props = __objRest(_b, [
|
|
3554
|
+
"withHandle",
|
|
3555
|
+
"className"
|
|
3556
|
+
]);
|
|
3557
|
+
return /* @__PURE__ */ jsx(
|
|
3558
|
+
ResizablePrimitive.PanelResizeHandle,
|
|
3559
|
+
__spreadProps(__spreadValues({
|
|
3560
|
+
"data-slot": "resizable-handle",
|
|
3561
|
+
className: cn(
|
|
3562
|
+
"bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:translate-x-0 data-[panel-group-direction=vertical]:after:-translate-y-1/2 [&[data-panel-group-direction=vertical]>div]:rotate-90",
|
|
3563
|
+
className
|
|
3564
|
+
)
|
|
3565
|
+
}, props), {
|
|
3566
|
+
children: withHandle && /* @__PURE__ */ jsx("div", { className: "bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border", children: /* @__PURE__ */ jsx(GripVerticalIcon, { className: "size-2.5" }) })
|
|
3567
|
+
})
|
|
3568
|
+
);
|
|
3569
|
+
}
|
|
3570
|
+
function AlertDialog(_a) {
|
|
3571
|
+
var props = __objRest(_a, []);
|
|
3572
|
+
return /* @__PURE__ */ jsx(AlertDialogPrimitive.Root, __spreadValues({ "data-slot": "alert-dialog" }, props));
|
|
3573
|
+
}
|
|
3574
|
+
function AlertDialogPortal(_a) {
|
|
3575
|
+
var props = __objRest(_a, []);
|
|
3576
|
+
return /* @__PURE__ */ jsx(AlertDialogPrimitive.Portal, __spreadValues({ "data-slot": "alert-dialog-portal" }, props));
|
|
3577
|
+
}
|
|
3578
|
+
function AlertDialogOverlay(_a) {
|
|
3579
|
+
var _b = _a, {
|
|
3580
|
+
className
|
|
3581
|
+
} = _b, props = __objRest(_b, [
|
|
3582
|
+
"className"
|
|
3583
|
+
]);
|
|
3584
|
+
return /* @__PURE__ */ jsx(
|
|
3585
|
+
AlertDialogPrimitive.Overlay,
|
|
3586
|
+
__spreadValues({
|
|
3587
|
+
"data-slot": "alert-dialog-overlay",
|
|
3588
|
+
className: cn(
|
|
3589
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
|
3590
|
+
className
|
|
3591
|
+
)
|
|
3592
|
+
}, props)
|
|
3593
|
+
);
|
|
3594
|
+
}
|
|
3595
|
+
function AlertDialogContent(_a) {
|
|
3596
|
+
var _b = _a, {
|
|
3597
|
+
className
|
|
3598
|
+
} = _b, props = __objRest(_b, [
|
|
3599
|
+
"className"
|
|
3600
|
+
]);
|
|
3601
|
+
return /* @__PURE__ */ jsxs(AlertDialogPortal, { children: [
|
|
3602
|
+
/* @__PURE__ */ jsx(AlertDialogOverlay, {}),
|
|
3603
|
+
/* @__PURE__ */ jsx(
|
|
3604
|
+
AlertDialogPrimitive.Content,
|
|
3605
|
+
__spreadValues({
|
|
3606
|
+
"data-slot": "alert-dialog-content",
|
|
3607
|
+
className: cn(
|
|
3608
|
+
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
|
3609
|
+
className
|
|
3610
|
+
)
|
|
3611
|
+
}, props)
|
|
3612
|
+
)
|
|
3613
|
+
] });
|
|
3614
|
+
}
|
|
3615
|
+
function AlertDialogTitle(_a) {
|
|
3616
|
+
var _b = _a, {
|
|
3617
|
+
className
|
|
3618
|
+
} = _b, props = __objRest(_b, [
|
|
3619
|
+
"className"
|
|
3620
|
+
]);
|
|
3621
|
+
return /* @__PURE__ */ jsx(
|
|
3622
|
+
AlertDialogPrimitive.Title,
|
|
3623
|
+
__spreadValues({
|
|
3624
|
+
"data-slot": "alert-dialog-title",
|
|
3625
|
+
className: cn("text-lg font-semibold", className)
|
|
3626
|
+
}, props)
|
|
3627
|
+
);
|
|
3628
|
+
}
|
|
3629
|
+
function AlertDialogDescription(_a) {
|
|
3630
|
+
var _b = _a, {
|
|
3631
|
+
className
|
|
3632
|
+
} = _b, props = __objRest(_b, [
|
|
3633
|
+
"className"
|
|
3634
|
+
]);
|
|
3635
|
+
return /* @__PURE__ */ jsx(
|
|
3636
|
+
AlertDialogPrimitive.Description,
|
|
3637
|
+
__spreadValues({
|
|
3638
|
+
"data-slot": "alert-dialog-description",
|
|
3639
|
+
className: cn("text-muted-foreground text-sm", className)
|
|
3640
|
+
}, props)
|
|
3641
|
+
);
|
|
3642
|
+
}
|
|
3643
|
+
function AlertDialogAction(_a) {
|
|
3644
|
+
var _b = _a, {
|
|
3645
|
+
className
|
|
3646
|
+
} = _b, props = __objRest(_b, [
|
|
3647
|
+
"className"
|
|
3648
|
+
]);
|
|
3649
|
+
return /* @__PURE__ */ jsx(
|
|
3650
|
+
AlertDialogPrimitive.Action,
|
|
3651
|
+
__spreadValues({
|
|
3652
|
+
className: cn(buttonVariants(), className)
|
|
3653
|
+
}, props)
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
function AlertDialogCancel(_a) {
|
|
3657
|
+
var _b = _a, {
|
|
3658
|
+
className
|
|
3659
|
+
} = _b, props = __objRest(_b, [
|
|
3660
|
+
"className"
|
|
3661
|
+
]);
|
|
3662
|
+
return /* @__PURE__ */ jsx(
|
|
3663
|
+
AlertDialogPrimitive.Cancel,
|
|
3664
|
+
__spreadValues({
|
|
3665
|
+
className: cn(buttonVariants({ variant: "outline" }), className)
|
|
3666
|
+
}, props)
|
|
3667
|
+
);
|
|
3668
|
+
}
|
|
3669
|
+
var STUDIO_SCOPED_CSS = `
|
|
3670
|
+
[data-studio-workspace] {
|
|
3671
|
+
/* Dark theme \u2014 monochrome (black/white/gray) */
|
|
3672
|
+
--background: #09090b;
|
|
3673
|
+
--foreground: #fafafa;
|
|
3674
|
+
--card: #09090b;
|
|
3675
|
+
--card-foreground: #fafafa;
|
|
3676
|
+
--popover: #09090b;
|
|
3677
|
+
--popover-foreground: #fafafa;
|
|
3678
|
+
--primary: #fafafa;
|
|
3679
|
+
--primary-foreground: #09090b;
|
|
3680
|
+
--secondary: #27272a;
|
|
3681
|
+
--secondary-foreground: #fafafa;
|
|
3682
|
+
--muted: #27272a;
|
|
3683
|
+
--muted-foreground: #a1a1aa;
|
|
3684
|
+
--accent: #27272a;
|
|
3685
|
+
--accent-foreground: #fafafa;
|
|
3686
|
+
--destructive: #dc2626;
|
|
3687
|
+
--destructive-foreground: #fafafa;
|
|
3688
|
+
--border: #27272a;
|
|
3689
|
+
--input: #27272a;
|
|
3690
|
+
--ring: #d4d4d8;
|
|
3691
|
+
--radius: 0.5rem;
|
|
3692
|
+
--chart-1: #e4e4e7;
|
|
3693
|
+
--chart-2: #a1a1aa;
|
|
3694
|
+
--chart-3: #71717a;
|
|
3695
|
+
--chart-4: #52525b;
|
|
3696
|
+
--chart-5: #3f3f46;
|
|
3697
|
+
|
|
3698
|
+
/* Font \u2014 Geist (inherited from host or fallback to system) */
|
|
3699
|
+
font-family: var(--font-geist-sans, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
|
|
3700
|
+
-webkit-font-smoothing: antialiased;
|
|
3701
|
+
-moz-osx-font-smoothing: grayscale;
|
|
3702
|
+
font-feature-settings: "rlig" 1, "calt" 1;
|
|
3703
|
+
letter-spacing: -0.011em;
|
|
3704
|
+
}
|
|
3705
|
+
[data-studio-workspace] *,
|
|
3706
|
+
[data-studio-workspace] *::before,
|
|
3707
|
+
[data-studio-workspace] *::after {
|
|
3708
|
+
font-family: inherit;
|
|
3709
|
+
}
|
|
3710
|
+
[data-studio-workspace] code,
|
|
3711
|
+
[data-studio-workspace] pre,
|
|
3712
|
+
[data-studio-workspace] kbd,
|
|
3713
|
+
[data-studio-workspace] .font-mono {
|
|
3714
|
+
font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace);
|
|
3715
|
+
}
|
|
3716
|
+
`;
|
|
3717
|
+
function useStudioTheme() {
|
|
3718
|
+
useEffect(() => {
|
|
3719
|
+
const id = "studio-workspace-theme";
|
|
3720
|
+
if (document.getElementById(id)) return;
|
|
3721
|
+
const style = document.createElement("style");
|
|
3722
|
+
style.id = id;
|
|
3723
|
+
style.textContent = STUDIO_SCOPED_CSS;
|
|
3724
|
+
document.head.appendChild(style);
|
|
3725
|
+
return () => {
|
|
3726
|
+
var _a;
|
|
3727
|
+
(_a = document.getElementById(id)) == null ? void 0 : _a.remove();
|
|
3728
|
+
};
|
|
3729
|
+
}, []);
|
|
3730
|
+
}
|
|
3731
|
+
var NOOP_MASKING_CONFIG = {
|
|
3732
|
+
enabled: false,
|
|
3733
|
+
patterns: [],
|
|
3734
|
+
roleSettings: {
|
|
3735
|
+
admin: { canToggle: false, canReveal: false },
|
|
3736
|
+
user: { canToggle: false, canReveal: false }
|
|
3737
|
+
}
|
|
3738
|
+
};
|
|
3739
|
+
function StudioWorkspace({
|
|
3740
|
+
connections: externalConnections,
|
|
3741
|
+
currentUser,
|
|
3742
|
+
onQueryExecute,
|
|
3743
|
+
onSchemaFetch,
|
|
3744
|
+
onSaveQuery: onSaveQueryProp,
|
|
3745
|
+
// onLoadSavedQueries — reserved for future saved-queries panel integration
|
|
3746
|
+
features: featuresProp,
|
|
3747
|
+
className
|
|
3748
|
+
}) {
|
|
3749
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3750
|
+
const queryEditorRef = useRef(null);
|
|
3751
|
+
const { toast } = useToast();
|
|
3752
|
+
const features = useMemo(
|
|
3753
|
+
() => __spreadValues(__spreadValues({}, DEFAULT_WORKSPACE_FEATURES), featuresProp),
|
|
3754
|
+
[featuresProp]
|
|
3755
|
+
);
|
|
3756
|
+
const conn = useConnectionAdapter({
|
|
3757
|
+
connections: externalConnections,
|
|
3758
|
+
onSchemaFetch
|
|
3759
|
+
});
|
|
3760
|
+
const tabMgr = useTabManager({
|
|
3761
|
+
activeConnection: conn.activeConnection,
|
|
3762
|
+
metadata: null,
|
|
3763
|
+
schema: conn.schema
|
|
3764
|
+
});
|
|
3765
|
+
const queryExec = useQueryAdapter({
|
|
3766
|
+
activeConnection: conn.activeConnection,
|
|
3767
|
+
onQueryExecute,
|
|
3768
|
+
tabs: tabMgr.tabs,
|
|
3769
|
+
activeTabId: tabMgr.activeTabId,
|
|
3770
|
+
currentTab: tabMgr.currentTab,
|
|
3771
|
+
setTabs: tabMgr.setTabs,
|
|
3772
|
+
fetchSchema: conn.fetchSchema,
|
|
3773
|
+
features
|
|
3774
|
+
});
|
|
3775
|
+
useStudioTheme();
|
|
3776
|
+
useEffect(() => {
|
|
3777
|
+
if (conn.activeConnection) {
|
|
3778
|
+
conn.fetchSchema(conn.activeConnection);
|
|
3779
|
+
} else {
|
|
3780
|
+
conn.setSchema([]);
|
|
3781
|
+
}
|
|
3782
|
+
}, [conn.activeConnection]);
|
|
3783
|
+
const [showDiagram, setShowDiagram] = useState(false);
|
|
3784
|
+
const [isSaveQueryModalOpen, setIsSaveQueryModalOpen] = useState(false);
|
|
3785
|
+
const [savedKey, setSavedKey] = useState(0);
|
|
3786
|
+
const [activeMobileTab, setActiveMobileTab] = useState("editor");
|
|
3787
|
+
const [isImportModalOpen, setIsImportModalOpen] = useState(false);
|
|
3788
|
+
const [isNL2SQLOpen, setIsNL2SQLOpen] = useState(false);
|
|
3789
|
+
const [profilerTable, setProfilerTable] = useState(null);
|
|
3790
|
+
const [codeGenTable, setCodeGenTable] = useState(null);
|
|
3791
|
+
const [testDataTable, setTestDataTable] = useState(null);
|
|
3792
|
+
const handleSaveQuery = useCallback(async (name, description, tags) => {
|
|
3793
|
+
if (!conn.activeConnection) return;
|
|
3794
|
+
if (onSaveQueryProp) {
|
|
3795
|
+
try {
|
|
3796
|
+
await onSaveQueryProp({
|
|
3797
|
+
name,
|
|
3798
|
+
query: tabMgr.currentTab.query,
|
|
3799
|
+
description,
|
|
3800
|
+
connectionType: conn.activeConnection.type,
|
|
3801
|
+
tags
|
|
3802
|
+
});
|
|
3803
|
+
setSavedKey((prev) => prev + 1);
|
|
3804
|
+
toast({ title: "Query Saved", description: `"${name}" has been added to your saved queries.` });
|
|
3805
|
+
} catch (error) {
|
|
3806
|
+
const msg = error instanceof Error ? error.message : "Failed to save query";
|
|
3807
|
+
toast({ title: "Save Failed", description: msg, variant: "destructive" });
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
}, [conn.activeConnection, tabMgr.currentTab.query, onSaveQueryProp, toast]);
|
|
3811
|
+
const exportResults = useCallback((format3) => {
|
|
3812
|
+
if (!tabMgr.currentTab.result) return;
|
|
3813
|
+
const data = tabMgr.currentTab.result.rows;
|
|
3814
|
+
let content = "";
|
|
3815
|
+
let mimeType = "text/plain";
|
|
3816
|
+
let ext = format3;
|
|
3817
|
+
if (format3 === "csv") {
|
|
3818
|
+
const headers = Object.keys(data[0] || {}).join(",");
|
|
3819
|
+
const rows = data.map((row) => Object.values(row).map((val) => `"${val}"`).join(",")).join("\n");
|
|
3820
|
+
content = `${headers}
|
|
3821
|
+
${rows}`;
|
|
3822
|
+
mimeType = "text/csv";
|
|
3823
|
+
ext = "csv";
|
|
3824
|
+
} else if (format3 === "json") {
|
|
3825
|
+
content = JSON.stringify(data, null, 2);
|
|
3826
|
+
mimeType = "application/json";
|
|
3827
|
+
ext = "json";
|
|
3828
|
+
} else if (format3 === "sql-insert") {
|
|
3829
|
+
const tableName = tabMgr.currentTab.name.replace(/^Query[: ]*/, "") || "table_name";
|
|
3830
|
+
const columns = Object.keys(data[0] || {});
|
|
3831
|
+
const lines = data.map((row) => {
|
|
3832
|
+
const values = columns.map((col) => {
|
|
3833
|
+
const val = row[col];
|
|
3834
|
+
if (val === null || val === void 0) return "NULL";
|
|
3835
|
+
if (typeof val === "number" || typeof val === "boolean") return String(val);
|
|
3836
|
+
return `'${String(val).replace(/'/g, "''")}'`;
|
|
3837
|
+
});
|
|
3838
|
+
return `INSERT INTO ${tableName} (${columns.join(", ")}) VALUES (${values.join(", ")});`;
|
|
3839
|
+
});
|
|
3840
|
+
content = lines.join("\n");
|
|
3841
|
+
mimeType = "text/sql";
|
|
3842
|
+
ext = "sql";
|
|
3843
|
+
} else if (format3 === "sql-ddl") {
|
|
3844
|
+
const tableName = tabMgr.currentTab.name.replace(/^Query[: ]*/, "") || "table_name";
|
|
3845
|
+
const columns = Object.keys(data[0] || {});
|
|
3846
|
+
const colDefs = columns.map((col) => {
|
|
3847
|
+
var _a2;
|
|
3848
|
+
const sampleVal = (_a2 = data[0]) == null ? void 0 : _a2[col];
|
|
3849
|
+
let sqlType = "TEXT";
|
|
3850
|
+
if (typeof sampleVal === "number") {
|
|
3851
|
+
sqlType = Number.isInteger(sampleVal) ? "INTEGER" : "NUMERIC";
|
|
3852
|
+
} else if (typeof sampleVal === "boolean") {
|
|
3853
|
+
sqlType = "BOOLEAN";
|
|
3854
|
+
} else if (sampleVal instanceof Date) {
|
|
3855
|
+
sqlType = "TIMESTAMP";
|
|
3856
|
+
}
|
|
3857
|
+
return ` ${col} ${sqlType}`;
|
|
3858
|
+
});
|
|
3859
|
+
content = `CREATE TABLE ${tableName} (
|
|
3860
|
+
${colDefs.join(",\n")}
|
|
3861
|
+
);`;
|
|
3862
|
+
mimeType = "text/sql";
|
|
3863
|
+
ext = "sql";
|
|
3864
|
+
}
|
|
3865
|
+
const fileName = `query_result_export.${ext}`;
|
|
3866
|
+
const blob = new Blob([content], { type: mimeType });
|
|
3867
|
+
const url = URL.createObjectURL(blob);
|
|
3868
|
+
const link = document.createElement("a");
|
|
3869
|
+
link.href = url;
|
|
3870
|
+
link.download = fileName;
|
|
3871
|
+
link.click();
|
|
3872
|
+
URL.revokeObjectURL(url);
|
|
3873
|
+
}, [tabMgr.currentTab]);
|
|
3874
|
+
const onTableClick = useCallback((tableName) => {
|
|
3875
|
+
tabMgr.handleTableClick(tableName, queryExec.executeQuery);
|
|
3876
|
+
}, [tabMgr, queryExec.executeQuery]);
|
|
3877
|
+
const noop = useCallback(() => {
|
|
3878
|
+
}, []);
|
|
3879
|
+
return /* @__PURE__ */ jsxs(
|
|
3880
|
+
"div",
|
|
3881
|
+
{
|
|
3882
|
+
"data-studio-workspace": "",
|
|
3883
|
+
className: cn("dark flex h-full w-full bg-[#050505] text-zinc-100 overflow-hidden font-sans select-none", className),
|
|
3884
|
+
children: [
|
|
3885
|
+
/* @__PURE__ */ jsxs(ResizablePanelGroup, { id: "workspace-main", direction: "horizontal", className: "h-full", children: [
|
|
3886
|
+
/* @__PURE__ */ jsx(ResizablePanel, { defaultSize: 22, minSize: 15, maxSize: 35, className: "hidden md:block", children: /* @__PURE__ */ jsx(
|
|
3887
|
+
Sidebar,
|
|
3888
|
+
{
|
|
3889
|
+
connections: conn.connections,
|
|
3890
|
+
activeConnection: conn.activeConnection,
|
|
3891
|
+
schema: conn.schema,
|
|
3892
|
+
isLoadingSchema: conn.isLoadingSchema,
|
|
3893
|
+
onSelectConnection: conn.setActiveConnection,
|
|
3894
|
+
onDeleteConnection: noop,
|
|
3895
|
+
onEditConnection: noop,
|
|
3896
|
+
onAddConnection: noop,
|
|
3897
|
+
onTableClick,
|
|
3898
|
+
onGenerateSelect: tabMgr.handleGenerateSelect,
|
|
3899
|
+
onCreateTableClick: void 0,
|
|
3900
|
+
onShowDiagram: features.schemaDiagram ? () => setShowDiagram(true) : void 0,
|
|
3901
|
+
isAdmin: false,
|
|
3902
|
+
onOpenMaintenance: noop,
|
|
3903
|
+
databaseType: (_a = conn.activeConnection) == null ? void 0 : _a.type,
|
|
3904
|
+
metadata: null,
|
|
3905
|
+
onProfileTable: features.codeGenerator ? (name) => setProfilerTable(name) : void 0,
|
|
3906
|
+
onGenerateCode: features.codeGenerator ? (name) => setCodeGenTable(name) : void 0,
|
|
3907
|
+
onGenerateTestData: features.testDataGenerator ? (name) => setTestDataTable(name) : void 0
|
|
3908
|
+
}
|
|
3909
|
+
) }),
|
|
3910
|
+
/* @__PURE__ */ jsx(ResizableHandle, { className: "hidden md:flex w-1 bg-transparent hover:bg-blue-500/30 transition-colors" }),
|
|
3911
|
+
/* @__PURE__ */ jsx(ResizablePanel, { defaultSize: 78, children: /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col min-w-0 h-full bg-[#0a0a0a]", children: [
|
|
3912
|
+
/* @__PURE__ */ jsx(
|
|
3913
|
+
StudioTabBar,
|
|
3914
|
+
{
|
|
3915
|
+
tabs: tabMgr.tabs,
|
|
3916
|
+
activeTabId: tabMgr.activeTabId,
|
|
3917
|
+
editingTabId: tabMgr.editingTabId,
|
|
3918
|
+
editingTabName: tabMgr.editingTabName,
|
|
3919
|
+
onSetActiveTabId: tabMgr.setActiveTabId,
|
|
3920
|
+
onSetEditingTabId: tabMgr.setEditingTabId,
|
|
3921
|
+
onSetEditingTabName: tabMgr.setEditingTabName,
|
|
3922
|
+
onSetTabs: tabMgr.setTabs,
|
|
3923
|
+
onCloseTab: tabMgr.closeTab,
|
|
3924
|
+
onAddTab: tabMgr.addTab
|
|
3925
|
+
}
|
|
3926
|
+
),
|
|
3927
|
+
/* @__PURE__ */ jsxs("main", { className: "flex-1 overflow-hidden relative", children: [
|
|
3928
|
+
features.schemaDiagram && /* @__PURE__ */ jsx(AnimatePresence, { children: showDiagram && /* @__PURE__ */ jsx(SchemaDiagram, { schema: conn.schema, onClose: () => setShowDiagram(false) }) }),
|
|
3929
|
+
activeMobileTab === "database" && /* @__PURE__ */ jsxs("div", { className: "md:hidden h-full bg-[#080808] overflow-auto p-4", children: [
|
|
3930
|
+
/* @__PURE__ */ jsx("div", { className: "mb-4 flex items-center justify-between", children: /* @__PURE__ */ jsx("h2", { className: "text-sm font-bold text-zinc-300 uppercase tracking-widest", children: "Connections" }) }),
|
|
3931
|
+
/* @__PURE__ */ jsx(
|
|
3932
|
+
ConnectionsList,
|
|
3933
|
+
{
|
|
3934
|
+
connections: conn.connections,
|
|
3935
|
+
activeConnection: conn.activeConnection,
|
|
3936
|
+
onSelectConnection: (c) => {
|
|
3937
|
+
conn.setActiveConnection(c);
|
|
3938
|
+
setActiveMobileTab("editor");
|
|
3939
|
+
},
|
|
3940
|
+
onDeleteConnection: noop,
|
|
3941
|
+
onAddConnection: noop
|
|
3942
|
+
}
|
|
3943
|
+
)
|
|
3944
|
+
] }),
|
|
3945
|
+
activeMobileTab === "schema" && /* @__PURE__ */ jsx("div", { className: "md:hidden h-full bg-[#080808] overflow-auto p-4", children: conn.activeConnection ? /* @__PURE__ */ jsx(
|
|
3946
|
+
SchemaExplorer,
|
|
3947
|
+
{
|
|
3948
|
+
schema: conn.schema,
|
|
3949
|
+
isLoadingSchema: conn.isLoadingSchema,
|
|
3950
|
+
onTableClick: (tableName) => {
|
|
3951
|
+
onTableClick(tableName);
|
|
3952
|
+
setActiveMobileTab("editor");
|
|
3953
|
+
},
|
|
3954
|
+
onGenerateSelect: (tableName) => {
|
|
3955
|
+
tabMgr.handleGenerateSelect(tableName);
|
|
3956
|
+
setActiveMobileTab("editor");
|
|
3957
|
+
},
|
|
3958
|
+
onCreateTableClick: void 0,
|
|
3959
|
+
isAdmin: false,
|
|
3960
|
+
onOpenMaintenance: noop,
|
|
3961
|
+
databaseType: (_b = conn.activeConnection) == null ? void 0 : _b.type,
|
|
3962
|
+
metadata: null,
|
|
3963
|
+
onProfileTable: features.codeGenerator ? (name) => setProfilerTable(name) : void 0,
|
|
3964
|
+
onGenerateCode: features.codeGenerator ? (name) => setCodeGenTable(name) : void 0,
|
|
3965
|
+
onGenerateTestData: features.testDataGenerator ? (name) => setTestDataTable(name) : void 0
|
|
3966
|
+
}
|
|
3967
|
+
) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full text-zinc-500", children: [
|
|
3968
|
+
/* @__PURE__ */ jsx(Database, { className: "w-12 h-12 mb-4 opacity-30" }),
|
|
3969
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "Select a connection first" })
|
|
3970
|
+
] }) }),
|
|
3971
|
+
/* @__PURE__ */ jsx("div", { className: cn(
|
|
3972
|
+
"h-full",
|
|
3973
|
+
activeMobileTab !== "editor" && "hidden md:block"
|
|
3974
|
+
), children: /* @__PURE__ */ jsx("div", { className: "h-full", children: /* @__PURE__ */ jsxs(ResizablePanelGroup, { id: "workspace-editor", direction: "vertical", children: [
|
|
3975
|
+
/* @__PURE__ */ jsx(ResizablePanel, { defaultSize: 40, minSize: 20, children: /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col", children: [
|
|
3976
|
+
/* @__PURE__ */ jsx(
|
|
3977
|
+
QueryToolbar,
|
|
3978
|
+
{
|
|
3979
|
+
activeConnection: conn.activeConnection,
|
|
3980
|
+
metadata: null,
|
|
3981
|
+
isExecuting: tabMgr.currentTab.isExecuting,
|
|
3982
|
+
playgroundMode: false,
|
|
3983
|
+
transactionActive: false,
|
|
3984
|
+
editingEnabled: false,
|
|
3985
|
+
onSaveQuery: onSaveQueryProp ? () => setIsSaveQueryModalOpen(true) : noop,
|
|
3986
|
+
onExecuteQuery: () => queryExec.executeQuery(),
|
|
3987
|
+
onCancelQuery: queryExec.cancelQuery,
|
|
3988
|
+
onBeginTransaction: noop,
|
|
3989
|
+
onCommitTransaction: noop,
|
|
3990
|
+
onRollbackTransaction: noop,
|
|
3991
|
+
onTogglePlayground: noop,
|
|
3992
|
+
onToggleEditing: noop,
|
|
3993
|
+
onImport: features.dataImport ? () => setIsImportModalOpen(true) : noop
|
|
3994
|
+
}
|
|
3995
|
+
),
|
|
3996
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 relative", children: /* @__PURE__ */ jsx(
|
|
3997
|
+
QueryEditor,
|
|
3998
|
+
{
|
|
3999
|
+
ref: queryEditorRef,
|
|
4000
|
+
value: tabMgr.currentTab.query,
|
|
4001
|
+
onContentChange: (val) => tabMgr.updateTabById(tabMgr.currentTab.id, { query: val }),
|
|
4002
|
+
language: tabMgr.currentTab.type === "mongodb" ? "json" : "sql",
|
|
4003
|
+
tables: conn.tableNames,
|
|
4004
|
+
databaseType: (_c = conn.activeConnection) == null ? void 0 : _c.type,
|
|
4005
|
+
schemaContext: conn.schemaContext,
|
|
4006
|
+
capabilities: void 0
|
|
4007
|
+
}
|
|
4008
|
+
) })
|
|
4009
|
+
] }) }),
|
|
4010
|
+
/* @__PURE__ */ jsx(ResizableHandle, { className: "h-1 bg-white/5 hover:bg-blue-500/20" }),
|
|
4011
|
+
/* @__PURE__ */ jsx(ResizablePanel, { defaultSize: 60, minSize: 20, children: /* @__PURE__ */ jsx(
|
|
4012
|
+
BottomPanel,
|
|
4013
|
+
{
|
|
4014
|
+
mode: queryExec.bottomPanelMode,
|
|
4015
|
+
onSetMode: queryExec.setBottomPanelMode,
|
|
4016
|
+
currentTab: tabMgr.currentTab,
|
|
4017
|
+
schema: conn.schema,
|
|
4018
|
+
schemaContext: conn.schemaContext,
|
|
4019
|
+
activeConnection: conn.activeConnection,
|
|
4020
|
+
metadata: null,
|
|
4021
|
+
historyKey: queryExec.historyKey,
|
|
4022
|
+
savedKey,
|
|
4023
|
+
isNL2SQLOpen: features.ai ? isNL2SQLOpen : false,
|
|
4024
|
+
onSetIsNL2SQLOpen: features.ai ? setIsNL2SQLOpen : noop,
|
|
4025
|
+
maskingEnabled: false,
|
|
4026
|
+
onToggleMasking: void 0,
|
|
4027
|
+
userRole: currentUser == null ? void 0 : currentUser.role,
|
|
4028
|
+
maskingConfig: NOOP_MASKING_CONFIG,
|
|
4029
|
+
editingEnabled: false,
|
|
4030
|
+
pendingChanges: [],
|
|
4031
|
+
onCellChange: noop,
|
|
4032
|
+
onApplyChanges: noop,
|
|
4033
|
+
onDiscardChanges: noop,
|
|
4034
|
+
onExecuteQuery: (q) => queryExec.executeQuery(q),
|
|
4035
|
+
onLoadQuery: (q) => tabMgr.updateCurrentTab({ query: q }),
|
|
4036
|
+
onLoadMore: ((_e = (_d = tabMgr.currentTab.result) == null ? void 0 : _d.pagination) == null ? void 0 : _e.hasMore) ? queryExec.handleLoadMore : void 0,
|
|
4037
|
+
isLoadingMore: tabMgr.currentTab.isLoadingMore,
|
|
4038
|
+
onExportResults: exportResults
|
|
4039
|
+
}
|
|
4040
|
+
) })
|
|
4041
|
+
] }) }) })
|
|
4042
|
+
] })
|
|
4043
|
+
] }) })
|
|
4044
|
+
] }),
|
|
4045
|
+
onSaveQueryProp && /* @__PURE__ */ jsx(
|
|
4046
|
+
SaveQueryModal,
|
|
4047
|
+
{
|
|
4048
|
+
isOpen: isSaveQueryModalOpen,
|
|
4049
|
+
onClose: () => setIsSaveQueryModalOpen(false),
|
|
4050
|
+
onSave: handleSaveQuery,
|
|
4051
|
+
defaultQuery: tabMgr.currentTab.query
|
|
4052
|
+
}
|
|
4053
|
+
),
|
|
4054
|
+
features.dataImport && /* @__PURE__ */ jsx(
|
|
4055
|
+
DataImportModal,
|
|
4056
|
+
{
|
|
4057
|
+
isOpen: isImportModalOpen,
|
|
4058
|
+
onClose: () => setIsImportModalOpen(false),
|
|
4059
|
+
onImport: (sql) => queryExec.executeQuery(sql),
|
|
4060
|
+
tables: conn.schema,
|
|
4061
|
+
databaseType: (_f = conn.activeConnection) == null ? void 0 : _f.type
|
|
4062
|
+
}
|
|
4063
|
+
),
|
|
4064
|
+
/* @__PURE__ */ jsx(
|
|
4065
|
+
QuerySafetyDialog,
|
|
4066
|
+
{
|
|
4067
|
+
isOpen: !!queryExec.safetyCheckQuery,
|
|
4068
|
+
query: queryExec.safetyCheckQuery || "",
|
|
4069
|
+
schemaContext: conn.schemaContext,
|
|
4070
|
+
databaseType: (_g = conn.activeConnection) == null ? void 0 : _g.type,
|
|
4071
|
+
onClose: () => queryExec.setSafetyCheckQuery(null),
|
|
4072
|
+
onProceed: () => {
|
|
4073
|
+
if (queryExec.safetyCheckQuery) queryExec.forceExecuteQuery(queryExec.safetyCheckQuery);
|
|
4074
|
+
},
|
|
4075
|
+
onAnalyzeSafety: async () => ({
|
|
4076
|
+
riskLevel: "high",
|
|
4077
|
+
summary: "Potentially dangerous query detected",
|
|
4078
|
+
warnings: [{
|
|
4079
|
+
type: "destructive",
|
|
4080
|
+
severity: "high",
|
|
4081
|
+
message: "This query may modify or delete data",
|
|
4082
|
+
detail: "Review carefully before proceeding."
|
|
4083
|
+
}],
|
|
4084
|
+
affectedRows: "unknown",
|
|
4085
|
+
cascadeEffects: "unknown",
|
|
4086
|
+
recommendation: "Review this query carefully before proceeding."
|
|
4087
|
+
})
|
|
4088
|
+
}
|
|
4089
|
+
),
|
|
4090
|
+
features.codeGenerator && /* @__PURE__ */ jsx(
|
|
4091
|
+
DataProfiler,
|
|
4092
|
+
{
|
|
4093
|
+
isOpen: !!profilerTable,
|
|
4094
|
+
onClose: () => setProfilerTable(null),
|
|
4095
|
+
tableName: profilerTable || "",
|
|
4096
|
+
tableSchema: conn.schema.find((t) => t.name === profilerTable) || null,
|
|
4097
|
+
connection: conn.activeConnection,
|
|
4098
|
+
schemaContext: conn.schemaContext,
|
|
4099
|
+
databaseType: (_h = conn.activeConnection) == null ? void 0 : _h.type
|
|
4100
|
+
}
|
|
4101
|
+
),
|
|
4102
|
+
features.codeGenerator && /* @__PURE__ */ jsx(
|
|
4103
|
+
CodeGenerator,
|
|
4104
|
+
{
|
|
4105
|
+
isOpen: !!codeGenTable,
|
|
4106
|
+
onClose: () => setCodeGenTable(null),
|
|
4107
|
+
tableName: codeGenTable || "",
|
|
4108
|
+
tableSchema: conn.schema.find((t) => t.name === codeGenTable) || null,
|
|
4109
|
+
databaseType: (_i = conn.activeConnection) == null ? void 0 : _i.type
|
|
4110
|
+
}
|
|
4111
|
+
),
|
|
4112
|
+
features.testDataGenerator && /* @__PURE__ */ jsx(
|
|
4113
|
+
TestDataGenerator,
|
|
4114
|
+
{
|
|
4115
|
+
isOpen: !!testDataTable,
|
|
4116
|
+
onClose: () => setTestDataTable(null),
|
|
4117
|
+
tableName: testDataTable || "",
|
|
4118
|
+
tableSchema: conn.schema.find((t) => t.name === testDataTable) || null,
|
|
4119
|
+
databaseType: (_j = conn.activeConnection) == null ? void 0 : _j.type,
|
|
4120
|
+
queryLanguage: void 0,
|
|
4121
|
+
onExecuteQuery: (q) => queryExec.executeQuery(q)
|
|
4122
|
+
}
|
|
4123
|
+
),
|
|
4124
|
+
/* @__PURE__ */ jsx(AlertDialog, { open: queryExec.unlimitedWarningOpen, onOpenChange: queryExec.setUnlimitedWarningOpen, children: /* @__PURE__ */ jsxs(AlertDialogContent, { className: "bg-[#111] border-white/5 max-w-sm p-0 gap-0 overflow-hidden", children: [
|
|
4125
|
+
/* @__PURE__ */ jsx("div", { className: "px-6 pt-6 pb-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
4126
|
+
/* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-xl bg-gradient-to-br from-amber-500/20 to-red-500/10 flex items-center justify-center shrink-0", children: /* @__PURE__ */ jsx(AlertTriangle, { className: "w-5 h-5 text-amber-400" }) }),
|
|
4127
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
4128
|
+
/* @__PURE__ */ jsx(AlertDialogTitle, { className: "text-[15px] font-semibold text-zinc-100 mb-1", children: "Load all results?" }),
|
|
4129
|
+
/* @__PURE__ */ jsxs(AlertDialogDescription, { className: "text-[13px] text-zinc-500 leading-relaxed", children: [
|
|
4130
|
+
"This may slow down your browser. Max ",
|
|
4131
|
+
/* @__PURE__ */ jsx("span", { className: "text-zinc-400", children: "100K" }),
|
|
4132
|
+
" rows will be loaded."
|
|
4133
|
+
] })
|
|
4134
|
+
] })
|
|
4135
|
+
] }) }),
|
|
4136
|
+
/* @__PURE__ */ jsxs("div", { className: "px-6 pb-6 flex gap-2", children: [
|
|
4137
|
+
/* @__PURE__ */ jsx(AlertDialogCancel, { className: "flex-1 h-9 bg-white/5 border-0 text-zinc-400 text-[13px] font-medium hover:bg-white/10 hover:text-zinc-200", children: "Cancel" }),
|
|
4138
|
+
/* @__PURE__ */ jsx(
|
|
4139
|
+
AlertDialogAction,
|
|
4140
|
+
{
|
|
4141
|
+
onClick: queryExec.handleUnlimitedQuery,
|
|
4142
|
+
className: "flex-1 h-9 bg-amber-600 border-0 text-white text-[13px] font-medium hover:bg-amber-500",
|
|
4143
|
+
children: "Load All"
|
|
4144
|
+
}
|
|
4145
|
+
)
|
|
4146
|
+
] })
|
|
4147
|
+
] }) })
|
|
4148
|
+
]
|
|
4149
|
+
}
|
|
4150
|
+
);
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4153
|
+
export { DEFAULT_WORKSPACE_FEATURES, StudioWorkspace };
|
|
4154
|
+
//# sourceMappingURL=workspace.mjs.map
|
|
4155
|
+
//# sourceMappingURL=workspace.mjs.map
|