Fix resourceTokenPartitionKey code

This commit is contained in:
Laurent Nguyen 2024-04-22 14:43:57 +02:00
parent 0de2d6d899
commit cf8533dea6
2 changed files with 16 additions and 13 deletions

View File

@ -48,6 +48,7 @@ export class DocumentsTabV2 extends TabsBase {
public partitionKey: DataModels.PartitionKey; public partitionKey: DataModels.PartitionKey;
private documentIds: DocumentId[]; private documentIds: DocumentId[];
private title: string; private title: string;
private resourceTokenPartitionKey: string;
constructor(options: ViewModels.DocumentsTabOptions) { constructor(options: ViewModels.DocumentsTabOptions) {
super(options); super(options);
@ -55,6 +56,7 @@ export class DocumentsTabV2 extends TabsBase {
this.documentIds = options.documentIds(); this.documentIds = options.documentIds();
this.title = options.title; this.title = options.title;
this.partitionKey = options.partitionKey; this.partitionKey = options.partitionKey;
this.resourceTokenPartitionKey = options.resourceTokenPartitionKey;
} }
public render(): JSX.Element { public render(): JSX.Element {
@ -71,6 +73,7 @@ export class DocumentsTabV2 extends TabsBase {
partitionKey={this.partitionKey} partitionKey={this.partitionKey}
onLoadStartKey={this.onLoadStartKey} onLoadStartKey={this.onLoadStartKey}
tabTitle={this.title} tabTitle={this.title}
resourceTokenPartitionKey={this.resourceTokenPartitionKey}
/> />
); );
} }
@ -96,6 +99,7 @@ const DocumentsTabComponent: React.FunctionComponent<{
partitionKey: DataModels.PartitionKey; partitionKey: DataModels.PartitionKey;
onLoadStartKey: number; onLoadStartKey: number;
tabTitle: string; tabTitle: string;
resourceTokenPartitionKey?: string;
}> = (props) => { }> = (props) => {
const [isFilterCreated, setIsFilterCreated] = useState<boolean>(true); const [isFilterCreated, setIsFilterCreated] = useState<boolean>(true);
const [isFilterExpanded, setIsFilterExpanded] = useState<boolean>(false); const [isFilterExpanded, setIsFilterExpanded] = useState<boolean>(false);
@ -115,7 +119,6 @@ const DocumentsTabComponent: React.FunctionComponent<{
applyFilterButtonPressed: boolean; applyFilterButtonPressed: boolean;
}>(undefined); }>(undefined);
const [queryAbortController, setQueryAbortController] = useState<AbortController>(undefined); const [queryAbortController, setQueryAbortController] = useState<AbortController>(undefined);
const [resourceTokenPartitionKey, setResourceTokenPartitionKey] = useState<string>(undefined); // TODO: Make this a constant is setter getting called
const [isQueryCopilotSampleContainer, setIsQueryCopilotSampleContainer] = useState<boolean>(false); // TODO: Make this a constant is setter getting called const [isQueryCopilotSampleContainer, setIsQueryCopilotSampleContainer] = useState<boolean>(false); // TODO: Make this a constant is setter getting called
const [cancelQueryTimeoutID, setCancelQueryTimeoutID] = useState<NodeJS.Timeout>(undefined); const [cancelQueryTimeoutID, setCancelQueryTimeoutID] = useState<NodeJS.Timeout>(undefined);
@ -648,8 +651,8 @@ const DocumentsTabComponent: React.FunctionComponent<{
// TODO: Property 'enableCrossPartitionQuery' does not exist on type 'FeedOptions'. // TODO: Property 'enableCrossPartitionQuery' does not exist on type 'FeedOptions'.
options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey(); options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey();
if (resourceTokenPartitionKey) { if (props.resourceTokenPartitionKey) {
options.partitionKey = 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'. // 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; options.abortSignal = _queryAbortController.signal;

View File

@ -1,3 +1,4 @@
import { DocumentsTabV2 } from "Explorer/Tabs/DocumentsTabV2/DocumentsTabV2";
import * as ko from "knockout"; import * as ko from "knockout";
import * as Constants from "../../Common/Constants"; import * as Constants from "../../Common/Constants";
import * as DataModels from "../../Contracts/DataModels"; import * as DataModels from "../../Contracts/DataModels";
@ -7,7 +8,6 @@ import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import { userContext } from "../../UserContext"; import { userContext } from "../../UserContext";
import { useTabs } from "../../hooks/useTabs"; import { useTabs } from "../../hooks/useTabs";
import Explorer from "../Explorer"; import Explorer from "../Explorer";
import DocumentsTab from "../Tabs/DocumentsTab";
import { NewQueryTab } from "../Tabs/QueryTab/QueryTab"; import { NewQueryTab } from "../Tabs/QueryTab/QueryTab";
import TabsBase from "../Tabs/TabsBase"; import TabsBase from "../Tabs/TabsBase";
import { useDatabases } from "../useDatabases"; import { useDatabases } from "../useDatabases";
@ -118,15 +118,15 @@ export default class ResourceTokenCollection implements ViewModels.CollectionBas
dataExplorerArea: Constants.Areas.ResourceTree, dataExplorerArea: Constants.Areas.ResourceTree,
}); });
const documentsTabs: DocumentsTab[] = useTabs const documentsTabs: DocumentsTabV2[] = useTabs
.getState() .getState()
.getTabs( .getTabs(
ViewModels.CollectionTabKind.Documents, ViewModels.CollectionTabKind.Documents,
(tab: TabsBase) => (tab: TabsBase) =>
tab.collection?.id() === this.id() && tab.collection?.id() === this.id() &&
(tab.collection as ViewModels.CollectionBase).databaseId === this.databaseId, (tab.collection as ViewModels.CollectionBase).databaseId === this.databaseId,
) as DocumentsTab[]; ) as DocumentsTabV2[];
let documentsTab: DocumentsTab = documentsTabs && documentsTabs[0]; let documentsTab: DocumentsTabV2 = documentsTabs && documentsTabs[0];
if (documentsTab) { if (documentsTab) {
useTabs.getState().activateTab(documentsTab); useTabs.getState().activateTab(documentsTab);
@ -139,7 +139,7 @@ export default class ResourceTokenCollection implements ViewModels.CollectionBas
tabTitle: "Items", tabTitle: "Items",
}); });
documentsTab = new DocumentsTab({ documentsTab = new DocumentsTabV2({
partitionKey: this.partitionKey, partitionKey: this.partitionKey,
resourceTokenPartitionKey: userContext.parsedResourceToken?.partitionKey, resourceTokenPartitionKey: userContext.parsedResourceToken?.partitionKey,
documentIds: ko.observableArray<DocumentId>([]), documentIds: ko.observableArray<DocumentId>([]),