Skip to content

Commit a268708

Browse files
committed
feat: Replace global Data Explorer button with context-specific explorer buttons and add quick explore options for accounts.
1 parent 943cf44 commit a268708

1 file changed

Lines changed: 76 additions & 41 deletions

File tree

frontend/pages/QueryGeneratorPage.tsx

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,10 @@ interface HeaderUIProps {
138138
onStartTutorial: () => void;
139139
onShowSavedQueries: () => void;
140140
onShowShortcuts: () => void;
141-
onNavigateToExplorer: () => void;
142-
isExplorerNavEnabled: boolean;
143141
isUserMenuForcedOpen?: boolean;
144142
}
145143

146-
const HeaderUI: React.FC<HeaderUIProps> = ({ name, onLogout, onClearCache, isClearingCache, cacheClearStatus, onStartTutorial, onShowSavedQueries, onShowShortcuts, onNavigateToExplorer, isExplorerNavEnabled, isUserMenuForcedOpen }) => {
144+
const HeaderUI: React.FC<HeaderUIProps> = ({ name, onLogout, onClearCache, isClearingCache, cacheClearStatus, onStartTutorial, onShowSavedQueries, onShowShortcuts, isUserMenuForcedOpen }) => {
147145
const { theme, toggleTheme } = useTheme();
148146

149147
return (
@@ -156,15 +154,6 @@ const HeaderUI: React.FC<HeaderUIProps> = ({ name, onLogout, onClearCache, isCle
156154
</div>
157155
</div>
158156
<div className="flex items-center gap-2 flex-wrap">
159-
<button
160-
onClick={onNavigateToExplorer}
161-
disabled={!isExplorerNavEnabled}
162-
className="h-9 flex items-center justify-center gap-2 px-3 border text-sm font-medium rounded-md transition-all duration-300 bg-white dark:bg-slate-800 border-slate-300 dark:border-slate-600 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed"
163-
title="Explore and manage data"
164-
>
165-
<DataGridIcon className="w-5 h-5" />
166-
<span className="hidden md:inline">Data Explorer</span>
167-
</button>
168157
<button
169158
onClick={toggleTheme}
170159
className="h-9 w-9 flex items-center justify-center border border-slate-300 dark:border-slate-600 rounded-md text-slate-600 dark:text-slate-300 bg-white dark:bg-slate-800 hover:bg-slate-100 dark:hover:bg-slate-700 transition-colors"
@@ -977,17 +966,44 @@ const QueryGeneratorPage: React.FC<QueryGeneratorPageProps> = ({ name, email, on
977966
}
978967
};
979968

980-
const handleNavigateToExplorer = () => {
981-
if (connectedResource && connectedDbInfo) {
982-
onNavigateToExplorer({
983-
resource: connectedResource,
984-
dbInfo: connectedDbInfo,
985-
accountName: connectedAccountName,
986-
availableDbs: accountDatabases,
987-
availableAccounts: azureAccounts,
988-
});
969+
const handleLaunchExplorer = useCallback((targetDb: DbInfo, targetAccount: CosmosDBAccount, explicitDbs?: DbInfo[]) => {
970+
// Determine the list of available DBs.
971+
// If explicitDbs is provided (e.g. from quick explore fetch), use it.
972+
// Else if we are launching for the currently selected account (in the list), use the state accountDatabases.
973+
// Otherwise fallback to just the target DB (which limits switching capabilities).
974+
const dbsForExplorer = explicitDbs ||
975+
((selectedAccountId === targetAccount.id && accountDatabases.length > 0)
976+
? accountDatabases
977+
: [targetDb]);
978+
979+
onNavigateToExplorer({
980+
resource: { accountId: targetAccount.id, databaseName: targetDb.name },
981+
dbInfo: targetDb,
982+
accountName: targetAccount.name,
983+
availableDbs: dbsForExplorer,
984+
availableAccounts: azureAccounts,
985+
});
986+
}, [onNavigateToExplorer, selectedAccountId, accountDatabases, azureAccounts]);
987+
988+
const handleQuickExploreAccount = useCallback(async (account: CosmosDBAccount) => {
989+
// If we already have the DBs for this account in state (because it's selected)
990+
if (selectedAccountId === account.id && accountDatabases.length > 0) {
991+
handleLaunchExplorer(accountDatabases[0], account, accountDatabases);
992+
return;
989993
}
990-
};
994+
995+
try {
996+
const dbs = await getDatabasesForAccount(account.id);
997+
if (dbs.length > 0) {
998+
handleLaunchExplorer(dbs[0], account, dbs);
999+
} else {
1000+
setError(`No databases found in '${account.name}'. Cannot launch Data Explorer.`);
1001+
}
1002+
} catch (e) {
1003+
console.error("Quick explorer failed", e);
1004+
setError(`Failed to load databases for '${account.name}'.`);
1005+
}
1006+
}, [selectedAccountId, accountDatabases, handleLaunchExplorer]);
9911007

9921008
// --- Tutorial Demo Mode Logic ---
9931009
const isDemoModeForCollectionStep = isTutorialActive && tutorialStepIndex === 2;
@@ -1188,8 +1204,6 @@ const QueryGeneratorPage: React.FC<QueryGeneratorPageProps> = ({ name, email, on
11881204
onStartTutorial={() => setIsTutorialActive(true)}
11891205
onShowSavedQueries={() => setIsSavedQueriesPanelOpen(true)}
11901206
onShowShortcuts={() => setIsShortcutCheatsheetOpen(true)}
1191-
onNavigateToExplorer={handleNavigateToExplorer}
1192-
isExplorerNavEnabled={!!connectedResource}
11931207
isUserMenuForcedOpen={isUserMenuOpenForTutorial}
11941208
/>
11951209

@@ -1205,13 +1219,23 @@ const QueryGeneratorPage: React.FC<QueryGeneratorPageProps> = ({ name, email, on
12051219
Connected to: {accountNameForRender} / <span className="font-bold">{dbInfoForRender.name}</span>
12061220
</p>
12071221
</div>
1208-
<button
1209-
onClick={handleDisconnect}
1210-
className="px-3 py-1.5 border border-red-300 text-sm font-medium rounded-md text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-500/50 dark:text-red-400 dark:hover:bg-red-900/40 transition-colors"
1211-
title="Disconnect from database"
1212-
>
1213-
Disconnect
1214-
</button>
1222+
<div className="flex items-center gap-2">
1223+
<button
1224+
onClick={() => connectedDbInfo && connectedResource && handleLaunchExplorer(connectedDbInfo, azureAccounts.find(a => a.id === connectedResource.accountId) || azureAccounts[0])}
1225+
className="px-3 py-1.5 border border-slate-300 dark:border-slate-600 text-sm font-medium rounded-md text-slate-700 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700 transition-colors flex items-center gap-2"
1226+
title="Open in Data Explorer"
1227+
>
1228+
<DataGridIcon className="w-4 h-4" />
1229+
Explorer
1230+
</button>
1231+
<button
1232+
onClick={handleDisconnect}
1233+
className="px-3 py-1.5 border border-red-300 text-sm font-medium rounded-md text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-500/50 dark:text-red-400 dark:hover:bg-red-900/40 transition-colors"
1234+
title="Disconnect from database"
1235+
>
1236+
Disconnect
1237+
</button>
1238+
</div>
12151239
</div>
12161240
<div className="mt-4 grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
12171241
<div className="bg-slate-100 dark:bg-slate-700/50 p-3 rounded-lg">
@@ -1354,15 +1378,25 @@ const QueryGeneratorPage: React.FC<QueryGeneratorPageProps> = ({ name, email, on
13541378
<div className="mt-4 space-y-4">
13551379
{azureAccounts.map(account => (
13561380
<div key={account.id} className="bg-slate-50 dark:bg-slate-800/50 p-4 rounded-lg border dark:border-slate-700">
1357-
<button
1358-
onClick={() => handleSelectAccount(account.id)}
1359-
disabled={isLoadingDatabases}
1360-
className="w-full text-left font-bold text-slate-800 dark:text-slate-100 flex items-center gap-2 disabled:cursor-not-allowed disabled:opacity-60"
1361-
title={`Load databases for ${account.name}`}
1362-
>
1363-
<CloudIcon className="w-5 h-5 text-slate-500" />
1364-
{account.name}
1365-
</button>
1381+
<div className="flex items-center justify-between gap-2">
1382+
<button
1383+
onClick={() => handleSelectAccount(account.id)}
1384+
disabled={isLoadingDatabases}
1385+
className="flex-grow text-left font-bold text-slate-800 dark:text-slate-100 flex items-center gap-2 disabled:cursor-not-allowed disabled:opacity-60 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
1386+
title={`Load databases for ${account.name}`}
1387+
>
1388+
<CloudIcon className="w-5 h-5 text-slate-500" />
1389+
{account.name}
1390+
</button>
1391+
<button
1392+
onClick={(e) => { e.stopPropagation(); handleQuickExploreAccount(account); }}
1393+
className="flex items-center gap-1.5 px-2 py-1.5 text-xs font-medium text-blue-600 dark:text-blue-400 bg-white dark:bg-slate-700 hover:bg-blue-50 dark:hover:bg-slate-600 border border-slate-200 dark:border-slate-600 rounded-md transition-colors shadow-sm ml-2"
1394+
title={`Quickly open Data Explorer for ${account.name} (first database)`}
1395+
>
1396+
<DataGridIcon className="w-4 h-4" />
1397+
<span className="hidden sm:inline">Explorer</span>
1398+
</button>
1399+
</div>
13661400
{selectedAccountId === account.id && (
13671401
<div className="mt-3 pl-7 animate-fade-in">
13681402
{isLoadingDatabases ? (
@@ -1376,8 +1410,9 @@ const QueryGeneratorPage: React.FC<QueryGeneratorPageProps> = ({ name, email, on
13761410
{accountDatabases.map(db => (
13771411
<button
13781412
key={db.name}
1413+
type="button"
13791414
onClick={() => handleConnectDatabase(db)}
1380-
className="px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-slate-50 dark:focus:ring-offset-slate-800 focus:ring-blue-500 transition-colors"
1415+
className="px-4 py-2 border border-blue-600 dark:border-blue-500 text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 dark:bg-blue-600 dark:hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-slate-50 dark:focus:ring-offset-slate-800 focus:ring-blue-500 transition-colors"
13811416
title={`Connect to the ${db.name} database`}
13821417
>
13831418
{db.name}

0 commit comments

Comments
 (0)