Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

feat(windows): gate EE GenerateMockDataAsync hook in WorkspacePage

DangHuynhcd1683e81f19
diff --git a/windows/Gridex/WorkspacePage.cpp b/windows/Gridex/WorkspacePage.cpp
index 7c82e54..4b8843d 100644
--- a/windows/Gridex/WorkspacePage.cpp
+++ b/windows/Gridex/WorkspacePage.cpp
@@ -17,6 +17,13 @@
#include "Models/ERDiagramService.h"
#include "Models/AppSettings.h"
#include "App.xaml.h"
+#ifdef GRIDEX_ENTERPRISE
+#include "row-relationship-graph/EERowRelationshipDialog.h"
+#include "mock-data-generator/EEMockDataConfigDialog.h"
+#include "mock-data-generator/EEMockDataProgressDialog.h"
+#include "mock-data-generator/EEMockDataHeuristics.h"
+#include "mock-data-generator/EEMockDataGeneratorService.h"
+#endif
#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Microsoft.UI.Input.h>
#include <winrt/Microsoft.Web.WebView2.Core.h>
@@ -190,6 +197,12 @@ namespace winrt::Gridex::implementation
OnTableSelected(refTable, currentSchema_);
};
+ // Enterprise "View Relationship" menu item is wired in
+ // InitializeConnection (per-connection) instead of here, so that
+ // switching from a relational DB to Mongo/Redis actually toggles
+ // the menu item's visibility. At constructor time we don't yet
+ // know the real databaseType.
+
// Wire structure view ALTER apply
Structure().as<StructureView>()->OnApplyAlter = [this](const std::vector<std::wstring>& sqls)
{
@@ -820,6 +833,28 @@ namespace winrt::Gridex::implementation
ImportDataAsync(tableName, schema);
};
+#ifdef GRIDEX_ENTERPRISE
+ // EE: right-click table → Generate Data. Wired only on SQL
+ // databases since the feature requires INSERT + transactions.
+ {
+ auto dbType = state_.connection.databaseType;
+ bool isSql =
+ dbType == DBModels::DatabaseType::PostgreSQL ||
+ dbType == DBModels::DatabaseType::MySQL ||
+ dbType == DBModels::DatabaseType::SQLite;
+ if (isSql) {
+ Sidebar().as<SidebarPanel>()->OnGenerateMockData =
+ [this](const std::wstring& tableName,
+ const std::wstring& schema)
+ {
+ GenerateMockDataAsync(tableName, schema);
+ };
+ } else {
+ Sidebar().as<SidebarPanel>()->OnGenerateMockData = nullptr;
+ }
+ }
+#endif
+
// Sidebar ER diagram — right-click Database/Schema group → Show ER Diagram
Sidebar().as<SidebarPanel>()->OnShowERDiagram = [this](const std::wstring& schema)
{
@@ -1350,6 +1385,123 @@ namespace winrt::Gridex::implementation
StatusBar().as<StatusBarControl>()->SetStatus(
L"Disconnected", L"--", 0, 0.0, 0.0);
}
+
+#ifdef GRIDEX_ENTERPRISE
+ // Enterprise: wire "View Relationship" based on the ACTIVE
+ // connection. Runs on every switch so moving from PG to Mongo
+ // clears the callback and DataGridView's Opening handler
+ // collapses the menu item (gate: callback != nullptr).
+ {
+ auto dbType = state_.connection.databaseType;
+ bool isRelational =
+ dbType == DBModels::DatabaseType::PostgreSQL ||
+ dbType == DBModels::DatabaseType::MySQL ||
+ dbType == DBModels::DatabaseType::SQLite ||
+ dbType == DBModels::DatabaseType::MSSQLServer;
+
+ if (isRelational)
+ {
+ DataGrid().as<DataGridView>()->OnViewRelationshipsRequested = [this]()
+ {
+ int rowIdx = DataGrid().as<DataGridView>()->GetSelectedRowIndex();
+ if (rowIdx < 0) return;
+ if (rowIdx >= static_cast<int>(state_.currentData.rows.size())) return;
+ if (!connMgr_.isConnected()) return;
+
+ std::wstring table, schema;
+ for (const auto& t : state_.tabs)
+ {
+ if (t.id == state_.activeTabId
+ && t.type == DBModels::TabType::DataGrid)
+ {
+ table = t.tableName;
+ schema = t.schema.empty() ? currentSchema_ : t.schema;
+ break;
+ }
+ }
+ if (table.empty()) return;
+
+ auto adapter = connMgr_.getActiveAdapter();
+ if (!adapter) return;
+
+ ::Gridex::EE::RowRelationshipGraph::BuildInput input;
+ input.adapter = adapter;
+ input.dbType = state_.connection.databaseType;
+ input.schema = schema;
+ input.table = table;
+ input.columns = state_.currentColumns;
+ input.rowValues = state_.currentData.rows[rowIdx];
+
+ auto projected = winrt::make<
+ winrt::Gridex::implementation::EERowRelationshipDialog>();
+ auto impl = winrt::get_self<
+ winrt::Gridex::implementation::EERowRelationshipDialog>(projected);
+ impl->SetInput(std::move(input));
+
+ // Inline overlay inside ContentArea — feels like a
+ // workspace page rather than a popup. Capture current
+ // visibilities + chrome widths so we can restore them
+ // after the user closes the view.
+ auto contentArea = ContentArea();
+
+ struct LayoutSnapshot
+ {
+ std::vector<std::pair<mux::UIElement, mux::Visibility>> children;
+ double sidebarWidth = 0;
+ double detailsWidth = 0;
+ mux::Visibility tabBarVis = mux::Visibility::Visible;
+ };
+ auto snapshot = std::make_shared<LayoutSnapshot>();
+ for (auto const& child : contentArea.Children())
+ {
+ if (auto fe = child.try_as<mux::UIElement>())
+ snapshot->children.push_back({ fe, fe.Visibility() });
+ }
+ snapshot->sidebarWidth = SidebarColumn().Width().Value;
+ snapshot->detailsWidth = DetailsColumn().Width().Value;
+ snapshot->tabBarVis = TabBar().Visibility();
+
+ // Hide everything else in ContentArea; collapse side
+ // panels so the diagram uses the full width. Keep
+ // TopToolbar + StatusBar so the connection name is
+ // still visible.
+ for (auto& [child, _] : snapshot->children)
+ child.Visibility(mux::Visibility::Collapsed);
+ SidebarColumn().Width(mux::GridLengthHelper::FromPixels(0));
+ DetailsColumn().Width(mux::GridLengthHelper::FromPixels(0));
+ TabBar().Visibility(mux::Visibility::Collapsed);
+
+ // Close handler restores the captured layout and
+ // detaches the UserControl (triggers its Unloaded →
+ // cleanup of the SVG temp file).
+ impl->OnCloseRequested = [this, snapshot, projected]()
+ {
+ auto contentArea = ContentArea();
+ uint32_t idx = 0;
+ if (contentArea.Children().IndexOf(projected, idx))
+ contentArea.Children().RemoveAt(idx);
+
+ for (auto& [child, vis] : snapshot->children)
+ child.Visibility(vis);
+ SidebarColumn().Width(mux::GridLengthHelper::FromPixels(
+ snapshot->sidebarWidth > 0 ? snapshot->sidebarWidth : 280));
+ DetailsColumn().Width(mux::GridLengthHelper::FromPixels(
+ snapshot->detailsWidth > 0 ? snapshot->detailsWidth : 260));
+ TabBar().Visibility(snapshot->tabBarVis);
+ };
+
+ contentArea.Children().Append(projected);
+ };
+ }
+ else
+ {
+ // Mongo / Redis: clear the callback so the menu item
+ // returns to Collapsed after a switch away from a
+ // relational connection.
+ DataGrid().as<DataGridView>()->OnViewRelationshipsRequested = nullptr;
+ }
+ }
+#endif // GRIDEX_ENTERPRISE
}
// ── Sidebar Data Loading ────────────────────────────
@@ -4187,4 +4339,133 @@ g.er-selected > foreignObject > div.er-card{
state_.statusRenderTimeMs);
UpdatePaginationUI();
}
+
+#ifdef GRIDEX_ENTERPRISE
+ // ── EE: Mock Data Generator orchestration ─────────────────
+ // Flow: describeTable → seed heuristic specs → show config dialog →
+ // if Start pressed, run service + show progress dialog → on finish,
+ // show error or reload the grid.
+ winrt::fire_and_forget WorkspacePage::GenerateMockDataAsync(
+ std::wstring tableName, std::wstring schema)
+ {
+ if (!connMgr_.isConnected()) co_return;
+ auto adapter = connMgr_.getActiveAdapter();
+ if (!adapter) co_return;
+
+ // Introspect columns. Skip if the table disappeared or returned empty.
+ std::vector<DBModels::ColumnInfo> columns;
+ std::wstring describeErr;
+ try { columns = adapter->describeTable(tableName, schema); }
+ catch (const std::exception& e) {
+ describeErr = std::wstring(e.what(), e.what() + std::strlen(e.what()));
+ }
+ catch (...) { describeErr = L"Unknown error describing table."; }
+ if (!describeErr.empty()) {
+ muxc::ContentDialog err;
+ err.Title(winrt::box_value(winrt::hstring{L"Can't describe table"}));
+ err.Content(winrt::box_value(winrt::hstring{describeErr}));
+ err.CloseButtonText(L"OK");
+ err.XamlRoot(this->XamlRoot());
+ co_await err.ShowAsync();
+ co_return;
+ }
+ if (columns.empty()) co_return;
+
+ // Heuristic-seed specs.
+ std::vector<::Gridex::EE::MockData::EEColumnSpec> specs;
+ specs.reserve(columns.size());
+ for (const auto& c : columns)
+ specs.push_back(::Gridex::EE::MockData::EEMockDataHeuristics::toSpec(c));
+
+ // Build config dialog.
+ auto configCtrl = winrt::make<
+ winrt::Gridex::implementation::EEMockDataConfigDialog>();
+ auto configImpl = winrt::get_self<
+ winrt::Gridex::implementation::EEMockDataConfigDialog>(configCtrl);
+ configImpl->SetContext(schema, tableName, std::move(specs));
+
+ muxc::ContentDialog cfgDlg;
+ cfgDlg.Title(winrt::box_value(winrt::hstring{L"Generate Mock Data"}));
+ cfgDlg.Content(configCtrl);
+ cfgDlg.PrimaryButtonText(L"Start");
+ cfgDlg.CloseButtonText(L"Cancel");
+ cfgDlg.DefaultButton(muxc::ContentDialogButton::Primary);
+ cfgDlg.XamlRoot(this->XamlRoot());
+
+ // Intercept Primary: validate + stop close if invalid.
+ auto cfgDeferralToken = cfgDlg.PrimaryButtonClick(
+ [configImpl](auto const& sender, auto const& args)
+ {
+ if (!configImpl->BuildConfig().has_value()) {
+ args.Cancel(true); // keep dialog open; error shown inline
+ }
+ });
+
+ auto result = co_await cfgDlg.ShowAsync();
+ cfgDlg.PrimaryButtonClick(cfgDeferralToken);
+ if (result != muxc::ContentDialogResult::Primary) co_return;
+
+ auto cfgOpt = configImpl->BuildConfig();
+ if (!cfgOpt) co_return;
+
+ // Start service.
+ ::Gridex::EE::MockData::EEMockDataGeneratorService service;
+ auto state = service.start(adapter.get(), *cfgOpt);
+
+ // Show progress dialog.
+ auto progCtrl = winrt::make<
+ winrt::Gridex::implementation::EEMockDataProgressDialog>();
+ auto progImpl = winrt::get_self<
+ winrt::Gridex::implementation::EEMockDataProgressDialog>(progCtrl);
+ progImpl->Attach(state);
+
+ muxc::ContentDialog progDlg;
+ progDlg.Title(winrt::box_value(winrt::hstring{L"Generating"}));
+ progDlg.Content(progCtrl);
+ progDlg.PrimaryButtonText(L"Cancel");
+ progDlg.DefaultButton(muxc::ContentDialogButton::Primary);
+ progDlg.XamlRoot(this->XamlRoot());
+
+ // Primary button = Cancel while running; changes to "Close" on finish.
+ auto cancelToken = progDlg.PrimaryButtonClick(
+ [progImpl](auto const&, auto const& args)
+ {
+ if (!progImpl->IsFinished()) {
+ progImpl->RequestCancel();
+ args.Cancel(true); // keep dialog open; worker still draining
+ }
+ });
+
+ progImpl->OnFinished = [&progDlg]()
+ {
+ // Job done: swap Cancel → Close so the dialog can be dismissed.
+ // We deliberately don't auto-Hide; on error the user reads the
+ // inline message first, then clicks Close.
+ progDlg.PrimaryButtonText(L"Close");
+ };
+
+ co_await progDlg.ShowAsync();
+ progDlg.PrimaryButtonClick(cancelToken);
+
+ auto err = state->readError();
+ if (!err.empty()) {
+ muxc::ContentDialog eDlg;
+ eDlg.Title(winrt::box_value(winrt::hstring{L"Generation failed"}));
+ eDlg.Content(winrt::box_value(winrt::hstring{err}));
+ eDlg.CloseButtonText(L"OK");
+ eDlg.XamlRoot(this->XamlRoot());
+ co_await eDlg.ShowAsync();
+ co_return;
+ }
+
+ // Refresh the grid if the user is currently viewing the target table.
+ if (state_.connection.databaseType != DBModels::DatabaseType::Redis &&
+ state_.statusSchema.empty() == false &&
+ state_.statusSchema == schema) {
+ ReloadCurrentTable();
+ } else {
+ ReloadCurrentTable();
+ }
+ }
+#endif
}
diff --git a/windows/Gridex/WorkspacePage.h b/windows/Gridex/WorkspacePage.h
index 947e92e..6090219 100644
--- a/windows/Gridex/WorkspacePage.h
+++ b/windows/Gridex/WorkspacePage.h
@@ -173,6 +173,16 @@ namespace winrt::Gridex::implementation
winrt::fire_and_forget FlushRedisDbAsync();
winrt::fire_and_forget BrowseRedisKeysAsync();
+#ifdef GRIDEX_ENTERPRISE
+ // ── EE Mock Data Generator ────────────────
+ // Opens config dialog, spawns the service, shows progress, and
+ // reloads the grid on success. Gated because it pulls EE-only
+ // headers; the callback itself is never wired in OSS so the
+ // menu entry is hidden there.
+ winrt::fire_and_forget GenerateMockDataAsync(
+ std::wstring tableName, std::wstring schema);
+#endif
+
// Shared progress state for dump/restore background jobs
struct DumpRestoreJobState
{