mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-26 07:26:58 +00:00
Fix bugs with clicking on newly created documents
This commit is contained in:
parent
6b3df52185
commit
570a67c746
@ -282,6 +282,24 @@ const DocumentsTabComponent: React.FunctionComponent<{
|
|||||||
partitionKeyPropertyHeader.replace(/[/]+/g, ".").substring(1).replace(/[']+/g, ""),
|
partitionKeyPropertyHeader.replace(/[/]+/g, ".").substring(1).replace(/[']+/g, ""),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// new DocumentId() requires a DocumentTab which we mock with only the required properties
|
||||||
|
const newDocumentId = (
|
||||||
|
rawDocument: DataModels.DocumentId,
|
||||||
|
partitionKeyProperties: string[],
|
||||||
|
partitionKeyValue: string[],
|
||||||
|
) =>
|
||||||
|
new DocumentId(
|
||||||
|
{
|
||||||
|
partitionKey,
|
||||||
|
partitionKeyProperties,
|
||||||
|
// Fake unused mocks
|
||||||
|
isEditorDirty: () => false,
|
||||||
|
selectDocument: () => Promise.reject(),
|
||||||
|
},
|
||||||
|
rawDocument,
|
||||||
|
partitionKeyValue,
|
||||||
|
);
|
||||||
|
|
||||||
// const isPreferredApiMongoDB = useMemo(
|
// const isPreferredApiMongoDB = useMemo(
|
||||||
// () => userContext.apiType === "Mongo" || props.isPreferredApiMongoDB,
|
// () => userContext.apiType === "Mongo" || props.isPreferredApiMongoDB,
|
||||||
// [props.isPreferredApiMongoDB],
|
// [props.isPreferredApiMongoDB],
|
||||||
@ -395,7 +413,7 @@ const DocumentsTabComponent: React.FunctionComponent<{
|
|||||||
setIsExecuting(true);
|
setIsExecuting(true);
|
||||||
return createDocument(props.collection, document)
|
return createDocument(props.collection, document)
|
||||||
.then(
|
.then(
|
||||||
(savedDocument: unknown) => {
|
(savedDocument: DataModels.DocumentId) => {
|
||||||
const value: string = renderObjectForEditor(savedDocument || {}, null, 4);
|
const value: string = renderObjectForEditor(savedDocument || {}, null, 4);
|
||||||
setSelectedDocumentContentBaseline(value);
|
setSelectedDocumentContentBaseline(value);
|
||||||
setInitialDocumentContent(value);
|
setInitialDocumentContent(value);
|
||||||
@ -403,7 +421,7 @@ const DocumentsTabComponent: React.FunctionComponent<{
|
|||||||
savedDocument,
|
savedDocument,
|
||||||
partitionKey as PartitionKeyDefinition,
|
partitionKey as PartitionKeyDefinition,
|
||||||
);
|
);
|
||||||
const id = new DocumentId(this, savedDocument, partitionKeyValueArray);
|
const id = newDocumentId(savedDocument, partitionKeyProperties, partitionKeyValueArray as string[]);
|
||||||
const ids = documentIds;
|
const ids = documentIds;
|
||||||
ids.push(id);
|
ids.push(id);
|
||||||
|
|
||||||
@ -770,15 +788,7 @@ const DocumentsTabComponent: React.FunctionComponent<{
|
|||||||
partitionKeyPropertyHeader.replace(/[/]+/g, ".").substring(1).replace(/[']+/g, ""),
|
partitionKeyPropertyHeader.replace(/[/]+/g, ".").substring(1).replace(/[']+/g, ""),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new DocumentId(
|
return newDocumentId(rawDocument, partitionKeyProperties, partitionKeyValue);
|
||||||
{
|
|
||||||
partitionKey,
|
|
||||||
partitionKeyPropertyHeaders,
|
|
||||||
partitionKeyProperties,
|
|
||||||
} as DocumentsTab,
|
|
||||||
rawDocument,
|
|
||||||
partitionKeyValue,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const merged = currentDocuments.concat(nextDocumentIds);
|
const merged = currentDocuments.concat(nextDocumentIds);
|
||||||
@ -1370,7 +1380,8 @@ const DocumentsTabComponent: React.FunctionComponent<{
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
.map((rawDocument: any) => {
|
.map((rawDocument: any) => {
|
||||||
const partitionKeyValue = rawDocument._partitionKeyValue;
|
const partitionKeyValue = rawDocument._partitionKeyValue;
|
||||||
return new DocumentId(this, rawDocument, [partitionKeyValue]);
|
return newDocumentId(rawDocument, partitionKeyProperties, [partitionKeyValue]);
|
||||||
|
// return new DocumentId(this, rawDocument, [partitionKeyValue]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const merged = currentDocuments.concat(nextDocumentIds);
|
const merged = currentDocuments.concat(nextDocumentIds);
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
import * as ko from "knockout";
|
import * as ko from "knockout";
|
||||||
import * as DataModels from "../../Contracts/DataModels";
|
import * as DataModels from "../../Contracts/DataModels";
|
||||||
import { useDialog } from "../Controls/Dialog";
|
import { useDialog } from "../Controls/Dialog";
|
||||||
import DocumentsTab from "../Tabs/DocumentsTab";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces DocumentsTab so we can switch container
|
||||||
|
*/
|
||||||
|
export interface IDocumentIdContainer {
|
||||||
|
partitionKeyProperties?: string[];
|
||||||
|
partitionKey: DataModels.PartitionKey;
|
||||||
|
isEditorDirty: () => boolean;
|
||||||
|
selectDocument: (documentId: DocumentId) => Promise<void>;
|
||||||
|
}
|
||||||
export default class DocumentId {
|
export default class DocumentId {
|
||||||
public container: DocumentsTab;
|
public container: IDocumentIdContainer;
|
||||||
public rid: string;
|
public rid: string;
|
||||||
public self: string;
|
public self: string;
|
||||||
public ts: string;
|
public ts: string;
|
||||||
@ -15,7 +23,7 @@ export default class DocumentId {
|
|||||||
public stringPartitionKeyValues: string[];
|
public stringPartitionKeyValues: string[];
|
||||||
public isDirty: ko.Observable<boolean>;
|
public isDirty: ko.Observable<boolean>;
|
||||||
|
|
||||||
constructor(container: DocumentsTab, data: any, partitionKeyValue: any[]) {
|
constructor(container: IDocumentIdContainer, data: any, partitionKeyValue: any[]) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.self = data._self;
|
this.self = data._self;
|
||||||
this.rid = data._rid;
|
this.rid = data._rid;
|
||||||
|
Loading…
Reference in New Issue
Block a user