From bc951b4e13d4f26089fe83b8891cfb5a1a9097a9 Mon Sep 17 00:00:00 2001 From: Darko Radivojevic Date: Mon, 19 Jun 2023 13:31:49 +0200 Subject: [PATCH] Add button to route to copilot tab --- images/CopilotQueryTablesTab.svg | 3 +++ src/Explorer/Tabs/DocumentsTab.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 images/CopilotQueryTablesTab.svg diff --git a/images/CopilotQueryTablesTab.svg b/images/CopilotQueryTablesTab.svg new file mode 100644 index 000000000..16cee2a53 --- /dev/null +++ b/images/CopilotQueryTablesTab.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/Explorer/Tabs/DocumentsTab.ts b/src/Explorer/Tabs/DocumentsTab.ts index f75a99fac..a95ed7b2a 100644 --- a/src/Explorer/Tabs/DocumentsTab.ts +++ b/src/Explorer/Tabs/DocumentsTab.ts @@ -1,6 +1,8 @@ import { extractPartitionKey, ItemDefinition, PartitionKeyDefinition, QueryIterator, Resource } from "@azure/cosmos"; +import { ReactTabKind, useTabs } from "hooks/useTabs"; import * as ko from "knockout"; import Q from "q"; +import CopilotQueryTablesTab from "../../../images/CopilotQueryTablesTab.svg"; import DeleteDocumentIcon from "../../../images/DeleteDocument.svg"; import DiscardIcon from "../../../images/discard.svg"; import NewDocumentIcon from "../../../images/NewDocument.svg"; @@ -54,6 +56,7 @@ export default class DocumentsTab extends TabsBase { public discardNewDocumentChangesButton: ViewModels.Button; public discardExisitingDocumentChangesButton: ViewModels.Button; public deleteExisitingDocumentButton: ViewModels.Button; + public copliotEntityButton: ViewModels.Button; public displayedError: ko.Observable; public accessibleDocumentList: AccessibleVerticalList; public dataContentsGridScrollHeight: ko.Observable; @@ -304,6 +307,16 @@ export default class DocumentsTab extends TabsBase { return true; }), }; + + this.copliotEntityButton = { + enabled: ko.computed(() => { + return userContext.features.enableCopilot; + }), + visible: ko.computed(() => { + return userContext.features.enableCopilot; + }) + }; + this.buildCommandBarOptions(); this.shouldShowEditor = ko.computed(() => { const documentHasContent: boolean = @@ -768,6 +781,10 @@ export default class DocumentsTab extends TabsBase { } }; + public onCopilotEntityClick = (): void => { + useTabs.getState().openAndActivateReactTab(ReactTabKind.QueryCopilot) + } + protected _loadNextPageInternal(): Q.Promise { return Q(this._documentsIterator.fetchNext().then((response) => response.resources)); } @@ -884,6 +901,19 @@ export default class DocumentsTab extends TabsBase { buttons.push(DocumentsTab._createUploadButton(this.collection.container)); } + if (this.copliotEntityButton.visible()) { + const label = "Query Copliot"; + buttons.push({ + iconSrc: CopilotQueryTablesTab, + iconAlt: label, + onCommandClick: this.onCopilotEntityClick, + commandButtonLabel: label, + ariaLabel: label, + hasPopup: true, + disabled: !this.copliotEntityButton.enabled(), + }); + } + return buttons; }