mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
Fabric: clean up RPC and support show/hide toolbar message (#1680)
* Use Promise for allResourceToken fabric message. Cleanup token message handling and add debounce. * Improve rpc and update initalization flow * Fix format * Rev up message names for new version * Refactor RPC with Fabric * Build fix * Fix build * Fix format * Update Message types * Fix format * Fix comments * Fabric toolbar style and support to show/hide it (#1720) * Add Fabric specific Toolbar design * Add Fabric message to show/hide the Toolbar * Fix CommandBarUtil formatting * Update zustand state on setToolbarStatus to trigger a redraw of the command bar with updated visibility --------- Co-authored-by: Laurent Nguyen <laurent.nguyen@microsoft.com> * Fix format --------- Co-authored-by: Vsevolod Kukol <sevoku@microsoft.com>
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { createUri } from "Common/UrlUtility";
|
||||
import { FabricDatabaseConnectionInfo, FabricMessage } from "Contracts/FabricContract";
|
||||
import { DATA_EXPLORER_RPC_VERSION } from "Contracts/DataExplorerMessagesContract";
|
||||
import { FABRIC_RPC_VERSION, FabricMessageV2 } from "Contracts/FabricMessagesContract";
|
||||
import Explorer from "Explorer/Explorer";
|
||||
import { useCommandBar } from "Explorer/Menus/CommandBar/CommandBarComponentAdapter";
|
||||
import { useSelectedNode } from "Explorer/useSelectedNode";
|
||||
import {
|
||||
handleRequestDatabaseResourceTokensResponse,
|
||||
scheduleRefreshDatabaseResourceToken,
|
||||
} from "Platform/Fabric/FabricUtil";
|
||||
import { scheduleRefreshDatabaseResourceToken } from "Platform/Fabric/FabricUtil";
|
||||
import { getNetworkSettingsWarningMessage } from "Utils/NetworkUtility";
|
||||
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||
import { ReactTabKind, useTabs } from "hooks/useTabs";
|
||||
@@ -88,6 +87,9 @@ export function useKnockoutExplorer(platform: Platform): Explorer {
|
||||
}
|
||||
|
||||
async function configureFabric(): Promise<Explorer> {
|
||||
// These are the versions of Fabric that Data Explorer supports.
|
||||
const SUPPORTED_FABRIC_VERSIONS = [FABRIC_RPC_VERSION];
|
||||
|
||||
let explorer: Explorer;
|
||||
return new Promise<Explorer>((resolve) => {
|
||||
window.addEventListener(
|
||||
@@ -101,38 +103,37 @@ async function configureFabric(): Promise<Explorer> {
|
||||
return;
|
||||
}
|
||||
|
||||
const data: FabricMessage = event.data?.data;
|
||||
const data: FabricMessageV2 = event.data?.data;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (data.type) {
|
||||
case "initialize": {
|
||||
const fabricDatabaseConnectionInfo: FabricDatabaseConnectionInfo = {
|
||||
endpoint: data.message.endpoint,
|
||||
databaseId: data.message.databaseId,
|
||||
resourceTokens: data.message.resourceTokens as { [resourceId: string]: string },
|
||||
resourceTokensTimestamp: data.message.resourceTokensTimestamp,
|
||||
};
|
||||
explorer = await createExplorerFabric(fabricDatabaseConnectionInfo);
|
||||
resolve(explorer);
|
||||
const fabricVersion = data.version;
|
||||
if (!SUPPORTED_FABRIC_VERSIONS.includes(fabricVersion)) {
|
||||
// TODO Surface error to user
|
||||
console.error(`Unsupported Fabric version: ${fabricVersion}`);
|
||||
return;
|
||||
}
|
||||
|
||||
explorer.refreshAllDatabases().then(() => {
|
||||
openFirstContainer(explorer, fabricDatabaseConnectionInfo.databaseId);
|
||||
});
|
||||
scheduleRefreshDatabaseResourceToken();
|
||||
explorer = createExplorerFabric(data.message);
|
||||
await scheduleRefreshDatabaseResourceToken(true);
|
||||
resolve(explorer);
|
||||
await explorer.refreshAllDatabases();
|
||||
openFirstContainer(explorer, userContext.fabricContext.databaseConnectionInfo.databaseId);
|
||||
break;
|
||||
}
|
||||
case "newContainer":
|
||||
explorer.onNewCollectionClicked();
|
||||
break;
|
||||
case "authorizationToken": {
|
||||
case "authorizationToken":
|
||||
case "allResourceTokens_v2": {
|
||||
handleCachedDataMessage(data);
|
||||
break;
|
||||
}
|
||||
case "allResourceTokens": {
|
||||
// TODO call handleCachedDataMessage when Fabric echoes message id back
|
||||
handleRequestDatabaseResourceTokensResponse(explorer, data.message as FabricDatabaseConnectionInfo);
|
||||
case "setToolbarStatus": {
|
||||
useCommandBar.getState().setIsHidden(data.message.visible === false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -143,7 +144,11 @@ async function configureFabric(): Promise<Explorer> {
|
||||
false,
|
||||
);
|
||||
|
||||
sendReadyMessage();
|
||||
sendMessage({
|
||||
type: MessageTypes.Ready,
|
||||
id: "ready",
|
||||
params: [DATA_EXPLORER_RPC_VERSION],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -319,9 +324,12 @@ function configureHostedWithResourceToken(config: ResourceToken): Explorer {
|
||||
return explorer;
|
||||
}
|
||||
|
||||
function createExplorerFabric(fabricDatabaseConnectionInfo: FabricDatabaseConnectionInfo): Explorer {
|
||||
function createExplorerFabric(params: { connectionId: string }): Explorer {
|
||||
updateUserContext({
|
||||
fabricDatabaseConnectionInfo,
|
||||
fabricContext: {
|
||||
connectionId: params.connectionId,
|
||||
databaseConnectionInfo: undefined,
|
||||
},
|
||||
authType: AuthType.ConnectionString,
|
||||
databaseAccount: {
|
||||
id: "",
|
||||
@@ -330,7 +338,7 @@ function createExplorerFabric(fabricDatabaseConnectionInfo: FabricDatabaseConnec
|
||||
name: "Mounted",
|
||||
kind: AccountKind.Default,
|
||||
properties: {
|
||||
documentEndpoint: fabricDatabaseConnectionInfo.endpoint,
|
||||
documentEndpoint: undefined,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user