mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 01:11:25 +00:00
fix: Update grid after uploading documents (#2131)
- Refactor UploadItemsPane to support onUpload callback - Enhance bulk insert result type - Insert uploaded documents to the grid
This commit is contained in:
@@ -21,7 +21,7 @@ import { readTriggers } from "../../Common/dataAccess/readTriggers";
|
||||
import { readUserDefinedFunctions } from "../../Common/dataAccess/readUserDefinedFunctions";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { UploadDetailsRecord } from "../../Contracts/ViewModels";
|
||||
import { BulkInsertResult, UploadDetailsRecord } from "../../Contracts/ViewModels";
|
||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { userContext } from "../../UserContext";
|
||||
@@ -1092,17 +1092,13 @@ export default class Collection implements ViewModels.Collection {
|
||||
});
|
||||
}
|
||||
|
||||
public async bulkInsertDocuments(documents: JSONObject[]): Promise<{
|
||||
numSucceeded: number;
|
||||
numFailed: number;
|
||||
numThrottled: number;
|
||||
errors: string[];
|
||||
}> {
|
||||
const stats = {
|
||||
public async bulkInsertDocuments(documents: JSONObject[]): Promise<BulkInsertResult> {
|
||||
const stats: BulkInsertResult = {
|
||||
numSucceeded: 0,
|
||||
numFailed: 0,
|
||||
numThrottled: 0,
|
||||
errors: [] as string[],
|
||||
resources: [],
|
||||
};
|
||||
|
||||
const chunkSize = 100; // 100 is the max # of bulk operations the SDK currently accepts
|
||||
@@ -1120,6 +1116,7 @@ export default class Collection implements ViewModels.Collection {
|
||||
responses.forEach((response, index) => {
|
||||
if (response.statusCode === 201) {
|
||||
stats.numSucceeded++;
|
||||
stats.resources.push(response.resourceBody);
|
||||
} else if (response.statusCode === 429) {
|
||||
documentsToAttempt.push(attemptedDocuments[index]);
|
||||
} else if (response.statusCode === 409) {
|
||||
@@ -1152,18 +1149,22 @@ export default class Collection implements ViewModels.Collection {
|
||||
numFailed: 0,
|
||||
numThrottled: 0,
|
||||
errors: [],
|
||||
resources: [],
|
||||
};
|
||||
|
||||
try {
|
||||
const parsedContent = JSON.parse(documentContent);
|
||||
if (Array.isArray(parsedContent)) {
|
||||
const { numSucceeded, numFailed, numThrottled, errors } = await this.bulkInsertDocuments(parsedContent);
|
||||
const { numSucceeded, numFailed, numThrottled, errors, resources } =
|
||||
await this.bulkInsertDocuments(parsedContent);
|
||||
record.numSucceeded = numSucceeded;
|
||||
record.numFailed = numFailed;
|
||||
record.numThrottled = numThrottled;
|
||||
record.errors = errors;
|
||||
record.resources = record.resources.concat(resources);
|
||||
} else {
|
||||
await createDocument(this, parsedContent);
|
||||
const resource = await createDocument(this, parsedContent);
|
||||
record.resources.push(resource);
|
||||
record.numSucceeded++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user