From cf8533dea6898017814ecf9c10a0cd0033ba0f8d Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Mon, 22 Apr 2024 14:43:57 +0200 Subject: [PATCH] Fix resourceTokenPartitionKey code --- .../Tabs/DocumentsTabV2/DocumentsTabV2.tsx | 19 +++++++++++-------- src/Explorer/Tree/ResourceTokenCollection.ts | 10 +++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx index e3c82da04..45fd726ea 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx @@ -48,6 +48,7 @@ export class DocumentsTabV2 extends TabsBase { public partitionKey: DataModels.PartitionKey; private documentIds: DocumentId[]; private title: string; + private resourceTokenPartitionKey: string; constructor(options: ViewModels.DocumentsTabOptions) { super(options); @@ -55,6 +56,7 @@ export class DocumentsTabV2 extends TabsBase { this.documentIds = options.documentIds(); this.title = options.title; this.partitionKey = options.partitionKey; + this.resourceTokenPartitionKey = options.resourceTokenPartitionKey; } public render(): JSX.Element { @@ -71,6 +73,7 @@ export class DocumentsTabV2 extends TabsBase { partitionKey={this.partitionKey} onLoadStartKey={this.onLoadStartKey} tabTitle={this.title} + resourceTokenPartitionKey={this.resourceTokenPartitionKey} /> ); } @@ -96,6 +99,7 @@ const DocumentsTabComponent: React.FunctionComponent<{ partitionKey: DataModels.PartitionKey; onLoadStartKey: number; tabTitle: string; + resourceTokenPartitionKey?: string; }> = (props) => { const [isFilterCreated, setIsFilterCreated] = useState(true); const [isFilterExpanded, setIsFilterExpanded] = useState(false); @@ -115,7 +119,6 @@ const DocumentsTabComponent: React.FunctionComponent<{ applyFilterButtonPressed: boolean; }>(undefined); const [queryAbortController, setQueryAbortController] = useState(undefined); - const [resourceTokenPartitionKey, setResourceTokenPartitionKey] = useState(undefined); // TODO: Make this a constant is setter getting called const [isQueryCopilotSampleContainer, setIsQueryCopilotSampleContainer] = useState(false); // TODO: Make this a constant is setter getting called const [cancelQueryTimeoutID, setCancelQueryTimeoutID] = useState(undefined); @@ -540,8 +543,8 @@ const DocumentsTabComponent: React.FunctionComponent<{ ? `the selected ${selectedRows.size} items` : "the selected item" : isPlural - ? `the selected ${selectedRows.size} documents` - : "the selected document"; + ? `the selected ${selectedRows.size} documents` + : "the selected document"; const msg = `Are you sure you want to delete ${documentName}?`; useDialog.getState().showOkCancelModalDialog( @@ -648,8 +651,8 @@ const DocumentsTabComponent: React.FunctionComponent<{ // TODO: Property 'enableCrossPartitionQuery' does not exist on type 'FeedOptions'. options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey(); - if (resourceTokenPartitionKey) { - options.partitionKey = resourceTokenPartitionKey; + if (props.resourceTokenPartitionKey) { + options.partitionKey = props.resourceTokenPartitionKey; } // Fixes compile error error TS2741: Property 'throwIfAborted' is missing in type 'AbortSignal' but required in type 'import("/home/runner/work/cosmos-explorer/cosmos-explorer/node_modules/node-abort-controller/index").AbortSignal'. options.abortSignal = _queryAbortController.signal; @@ -1465,7 +1468,7 @@ const DocumentsTabComponent: React.FunctionComponent<{ @@ -1515,7 +1518,7 @@ const DocumentsTabComponent: React.FunctionComponent<{ } value={filterContent} onChange={(e) => setFilterContent(e.target.value)} - /* + /* data-bind=" W attr:{ placeholder:isPreferredApiMongoDB?'Type a query predicate (e.g., {´a´:´foo´}), or choose one from the drop down list, or leave empty to query all documents.':'Type a query predicate (e.g., WHERE c.id=´1´), or choose one from the drop down list, or leave empty to query all documents.' @@ -1568,7 +1571,7 @@ textInput: filterContent" tabIndex={0} onClick={onHideFilterClick} onKeyDown={onCloseButtonKeyDown} - /*data-bind="click: onHideFilterClick, event: { keydown: onCloseButtonKeyDown }"*/ + /*data-bind="click: onHideFilterClick, event: { keydown: onCloseButtonKeyDown }"*/ > Hide filter diff --git a/src/Explorer/Tree/ResourceTokenCollection.ts b/src/Explorer/Tree/ResourceTokenCollection.ts index a5e6ab07f..6212c14a8 100644 --- a/src/Explorer/Tree/ResourceTokenCollection.ts +++ b/src/Explorer/Tree/ResourceTokenCollection.ts @@ -1,3 +1,4 @@ +import { DocumentsTabV2 } from "Explorer/Tabs/DocumentsTabV2/DocumentsTabV2"; import * as ko from "knockout"; import * as Constants from "../../Common/Constants"; import * as DataModels from "../../Contracts/DataModels"; @@ -7,7 +8,6 @@ import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; import { useTabs } from "../../hooks/useTabs"; import Explorer from "../Explorer"; -import DocumentsTab from "../Tabs/DocumentsTab"; import { NewQueryTab } from "../Tabs/QueryTab/QueryTab"; import TabsBase from "../Tabs/TabsBase"; import { useDatabases } from "../useDatabases"; @@ -118,15 +118,15 @@ export default class ResourceTokenCollection implements ViewModels.CollectionBas dataExplorerArea: Constants.Areas.ResourceTree, }); - const documentsTabs: DocumentsTab[] = useTabs + const documentsTabs: DocumentsTabV2[] = useTabs .getState() .getTabs( ViewModels.CollectionTabKind.Documents, (tab: TabsBase) => tab.collection?.id() === this.id() && (tab.collection as ViewModels.CollectionBase).databaseId === this.databaseId, - ) as DocumentsTab[]; - let documentsTab: DocumentsTab = documentsTabs && documentsTabs[0]; + ) as DocumentsTabV2[]; + let documentsTab: DocumentsTabV2 = documentsTabs && documentsTabs[0]; if (documentsTab) { useTabs.getState().activateTab(documentsTab); @@ -139,7 +139,7 @@ export default class ResourceTokenCollection implements ViewModels.CollectionBas tabTitle: "Items", }); - documentsTab = new DocumentsTab({ + documentsTab = new DocumentsTabV2({ partitionKey: this.partitionKey, resourceTokenPartitionKey: userContext.parsedResourceToken?.partitionKey, documentIds: ko.observableArray([]),