From f403b086adf2131c37ed2c349e2582e17ea8c47c Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Fri, 9 Feb 2024 14:10:57 +0000 Subject: [PATCH] Hide buttons for Fabric or when no write access (#1742) --- .../Menus/CommandBar/CommandBarComponentButtonFactory.tsx | 2 +- src/Explorer/Tabs/DocumentsTab.ts | 5 +++++ src/Explorer/Tabs/QueryTab/QueryTabComponent.tsx | 3 ++- src/Platform/Fabric/FabricUtil.ts | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx index 78810e9db..a24c38ce5 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.tsx @@ -135,7 +135,7 @@ export function createStaticCommandBarButtons( buttons.push(newSqlQueryBtn); } - if (isQuerySupported && selectedNodeState.findSelectedCollection()) { + if (isQuerySupported && selectedNodeState.findSelectedCollection() && configContext.platform !== Platform.Fabric) { const openQueryBtn = createOpenQueryButton(container); openQueryBtn.children = [createOpenQueryButton(container), createOpenQueryFromDiskButton()]; buttons.push(openQueryBtn); diff --git a/src/Explorer/Tabs/DocumentsTab.ts b/src/Explorer/Tabs/DocumentsTab.ts index d4e532ca4..e9c6bee4e 100644 --- a/src/Explorer/Tabs/DocumentsTab.ts +++ b/src/Explorer/Tabs/DocumentsTab.ts @@ -881,6 +881,11 @@ export default class DocumentsTab extends TabsBase { } protected getTabsButtons(): CommandButtonComponentProps[] { + if (!userContext.hasWriteAccess) { + // All the following buttons require write access + return []; + } + const buttons: CommandButtonComponentProps[] = []; const label = !this.isPreferredApiMongoDB ? "New Item" : "New Document"; if (this.newDocumentButton.visible()) { diff --git a/src/Explorer/Tabs/QueryTab/QueryTabComponent.tsx b/src/Explorer/Tabs/QueryTab/QueryTabComponent.tsx index 783e24dfa..ff44a4be3 100644 --- a/src/Explorer/Tabs/QueryTab/QueryTabComponent.tsx +++ b/src/Explorer/Tabs/QueryTab/QueryTabComponent.tsx @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable no-console */ import { FeedOptions, QueryOperationOptions } from "@azure/cosmos"; +import { Platform, configContext } from "ConfigContext"; import { useDialog } from "Explorer/Controls/Dialog"; import { QueryCopilotFeedbackModal } from "Explorer/QueryCopilot/Modal/QueryCopilotFeedbackModal"; import { useCopilotStore } from "Explorer/QueryCopilot/QueryCopilotContext"; @@ -402,7 +403,7 @@ export default class QueryTabComponent extends React.Component => { updateUserContext({ fabricContext: { ...userContext.fabricContext, databaseConnectionInfo: fabricDatabaseConnectionInfo }, databaseAccount: { ...userContext.databaseAccount }, + hasWriteAccess: false, // TODO: receive from fabricDatabaseConnectionInfo }); scheduleRefreshDatabaseResourceToken(); } catch (error) {