mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 15:06:55 +00:00
Address feedback comments
This commit is contained in:
parent
478467bda5
commit
eb7c737066
@ -68,6 +68,7 @@ import StoredProcedure from "./Tree/StoredProcedure";
|
|||||||
import { useDatabases } from "./useDatabases";
|
import { useDatabases } from "./useDatabases";
|
||||||
import { useSelectedNode } from "./useSelectedNode";
|
import { useSelectedNode } from "./useSelectedNode";
|
||||||
import { update } from "Utils/arm/generatedClients/cosmos/databaseAccounts";
|
import { update } from "Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||||
|
import { useDataPlaneRbac } from "Explorer/Panes/SettingsPane/SettingsPane";
|
||||||
|
|
||||||
BindingHandlersRegisterer.registerBindingHandlers();
|
BindingHandlersRegisterer.registerBindingHandlers();
|
||||||
|
|
||||||
@ -277,21 +278,16 @@ export default class Explorer {
|
|||||||
authority: `${configContext.AAD_ENDPOINT}${localStorage.getItem("cachedTenantId")}`,
|
authority: `${configContext.AAD_ENDPOINT}${localStorage.getItem("cachedTenantId")}`,
|
||||||
});
|
});
|
||||||
updateUserContext({ aadToken: aadToken });
|
updateUserContext({ aadToken: aadToken });
|
||||||
|
useDataPlaneRbac.setState({ aadTokenUpdated: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof msal.AuthError && error.errorCode === msal.BrowserAuthErrorMessage.popUpWindowError.code) {
|
if (error instanceof msal.AuthError && error.errorCode === msal.BrowserAuthErrorMessage.popUpWindowError.code) {
|
||||||
useDialog
|
logConsoleError(
|
||||||
.getState()
|
|
||||||
.showOkModalDialog(
|
|
||||||
"Pop up blocked",
|
|
||||||
"We were unable to establish authorization for this account, due to pop-ups being disabled in the browser.\nPlease enable pop-ups for this site and try again",
|
"We were unable to establish authorization for this account, due to pop-ups being disabled in the browser.\nPlease enable pop-ups for this site and try again",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const errorJson = JSON.stringify(error);
|
const errorJson = JSON.stringify(error);
|
||||||
useDialog
|
logConsoleError(
|
||||||
.getState()
|
`Failed to perform authorization for this account, due to the following error: \n${errorJson}`,
|
||||||
.showOkModalDialog(
|
|
||||||
"Failed to perform authorization",
|
|
||||||
`We were unable to establish authorization for this account, due to the following error: \n${errorJson}`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import { AuthType } from "../../../AuthType";
|
|||||||
import * as Constants from "../../../Common/Constants";
|
import * as Constants from "../../../Common/Constants";
|
||||||
import { Platform, configContext } from "../../../ConfigContext";
|
import { Platform, configContext } from "../../../ConfigContext";
|
||||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||||
import { userContext } from "../../../UserContext";
|
import { updateUserContext, userContext } from "../../../UserContext";
|
||||||
import { getCollectionName, getDatabaseName } from "../../../Utils/APITypeUtils";
|
import { getCollectionName, getDatabaseName } from "../../../Utils/APITypeUtils";
|
||||||
import { isRunningOnNationalCloud } from "../../../Utils/CloudUtils";
|
import { isRunningOnNationalCloud } from "../../../Utils/CloudUtils";
|
||||||
import { useSidePanel } from "../../../hooks/useSidePanel";
|
import { useSidePanel } from "../../../hooks/useSidePanel";
|
||||||
@ -31,9 +31,10 @@ import { OpenFullScreen } from "../../OpenFullScreen";
|
|||||||
import { AddDatabasePanel } from "../../Panes/AddDatabasePanel/AddDatabasePanel";
|
import { AddDatabasePanel } from "../../Panes/AddDatabasePanel/AddDatabasePanel";
|
||||||
import { BrowseQueriesPane } from "../../Panes/BrowseQueriesPane/BrowseQueriesPane";
|
import { BrowseQueriesPane } from "../../Panes/BrowseQueriesPane/BrowseQueriesPane";
|
||||||
import { LoadQueryPane } from "../../Panes/LoadQueryPane/LoadQueryPane";
|
import { LoadQueryPane } from "../../Panes/LoadQueryPane/LoadQueryPane";
|
||||||
import { SettingsPane } from "../../Panes/SettingsPane/SettingsPane";
|
import { SettingsPane, useDataPlaneRbac } from "../../Panes/SettingsPane/SettingsPane";
|
||||||
import { useDatabases } from "../../useDatabases";
|
import { useDatabases } from "../../useDatabases";
|
||||||
import { SelectedNodeState, useSelectedNode } from "../../useSelectedNode";
|
import { SelectedNodeState, useSelectedNode } from "../../useSelectedNode";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
|
||||||
@ -71,11 +72,18 @@ export function createStaticCommandBarButtons(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userContext.apiType === "SQL") {
|
if (userContext.apiType === "SQL") {
|
||||||
const addLoginForEntraIDBtn = createLoginForEntraIDButton(container);
|
const [loginButtonProps, setLoginButtonProps] = useState<CommandButtonComponentProps | undefined>(undefined);
|
||||||
|
const dataPlaneRbacEnabled = useDataPlaneRbac((state) => state.dataPlaneRbacEnabled);
|
||||||
|
const aadTokenUpdated = useDataPlaneRbac((state) => state.aadTokenUpdated);
|
||||||
|
|
||||||
if (addLoginForEntraIDBtn) {
|
useEffect(() => {
|
||||||
|
const buttonProps = createLoginForEntraIDButton(container);
|
||||||
|
setLoginButtonProps(buttonProps);
|
||||||
|
}, [dataPlaneRbacEnabled, aadTokenUpdated, container]);
|
||||||
|
|
||||||
|
if (loginButtonProps) {
|
||||||
addDivider();
|
addDivider();
|
||||||
buttons.push(addLoginForEntraIDBtn);
|
buttons.push(loginButtonProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,11 +298,20 @@ function createLoginForEntraIDButton(container: Explorer): CommandButtonComponen
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleCommandClick = async () => {
|
||||||
|
await container.openLoginForEntraIDPopUp();
|
||||||
|
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!userContext.dataPlaneRbacEnabled || userContext.aadToken) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const label = "Login for Entra ID RBAC";
|
const label = "Login for Entra ID RBAC";
|
||||||
return {
|
return {
|
||||||
iconSrc: EntraIDIcon,
|
iconSrc: EntraIDIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
onCommandClick: () => container.openLoginForEntraIDPopUp(),
|
onCommandClick: handleCommandClick,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
hasPopup: true,
|
hasPopup: true,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
@ -35,6 +35,23 @@ import React, { FunctionComponent, useState } from "react";
|
|||||||
import Explorer from "../../Explorer";
|
import Explorer from "../../Explorer";
|
||||||
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
||||||
import { AuthType } from "AuthType";
|
import { AuthType } from "AuthType";
|
||||||
|
import create, { UseStore } from "zustand";
|
||||||
|
|
||||||
|
export interface DataPlaneRbacState {
|
||||||
|
dataPlaneRbacEnabled: boolean;
|
||||||
|
aadTokenUpdated: boolean;
|
||||||
|
|
||||||
|
getState?: () => DataPlaneRbacState;
|
||||||
|
|
||||||
|
setDataPlaneRbacEnabled: (dataPlaneRbacEnabled: boolean) => void;
|
||||||
|
setAadDataPlaneUpdated: (aadTokenUpdated: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataPlaneRbacStore = UseStore<Partial<DataPlaneRbacState>>;
|
||||||
|
|
||||||
|
export const useDataPlaneRbac: DataPlaneRbacStore = create((set) => ({
|
||||||
|
dataPlaneRbacEnabled: false,
|
||||||
|
}));
|
||||||
|
|
||||||
export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
||||||
explorer,
|
explorer,
|
||||||
@ -144,10 +161,12 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
|||||||
updateUserContext({
|
updateUserContext({
|
||||||
dataPlaneRbacEnabled: true,
|
dataPlaneRbacEnabled: true,
|
||||||
});
|
});
|
||||||
|
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: true });
|
||||||
} else {
|
} else {
|
||||||
updateUserContext({
|
updateUserContext({
|
||||||
dataPlaneRbacEnabled: false,
|
dataPlaneRbacEnabled: false,
|
||||||
});
|
});
|
||||||
|
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled);
|
LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled);
|
||||||
@ -266,9 +285,10 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
|||||||
setEnableDataPlaneRBACOption(option.key);
|
setEnableDataPlaneRBACOption(option.key);
|
||||||
|
|
||||||
const shouldShowWarning =
|
const shouldShowWarning =
|
||||||
option.key === Constants.RBACOptions.setTrueRBACOption ||
|
(option.key === Constants.RBACOptions.setTrueRBACOption ||
|
||||||
(option.key === Constants.RBACOptions.setAutomaticRBACOption &&
|
(option.key === Constants.RBACOptions.setAutomaticRBACOption &&
|
||||||
userContext.databaseAccount.properties.disableLocalAuth === true);
|
userContext.databaseAccount.properties.disableLocalAuth === true)) &&
|
||||||
|
!useDataPlaneRbac.getState().aadTokenUpdated;
|
||||||
setShowDataPlaneRBACWarning(shouldShowWarning);
|
setShowDataPlaneRBACWarning(shouldShowWarning);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ import { isInvalidParentFrameOrigin, shouldProcessMessage } from "../Utils/Messa
|
|||||||
import { listKeys } from "../Utils/arm/generatedClients/cosmos/databaseAccounts";
|
import { listKeys } from "../Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||||
import { DatabaseAccountListKeysResult } from "../Utils/arm/generatedClients/cosmos/types";
|
import { DatabaseAccountListKeysResult } from "../Utils/arm/generatedClients/cosmos/types";
|
||||||
import { applyExplorerBindings } from "../applyExplorerBindings";
|
import { applyExplorerBindings } from "../applyExplorerBindings";
|
||||||
|
import { useDataPlaneRbac } from "Explorer/Panes/SettingsPane/SettingsPane";
|
||||||
|
|
||||||
// This hook will create a new instance of Explorer.ts and bind it to the DOM
|
// This hook will create a new instance of Explorer.ts and bind it to the DOM
|
||||||
// This hook has a LOT of magic, but ideally we can delete it once we have removed KO and switched entirely to React
|
// This hook has a LOT of magic, but ideally we can delete it once we have removed KO and switched entirely to React
|
||||||
@ -485,6 +486,7 @@ async function configurePortal(): Promise<Explorer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateUserContext({ dataPlaneRbacEnabled });
|
updateUserContext({ dataPlaneRbacEnabled });
|
||||||
|
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user