fixed eslint issue of TableEntityProcessor, DocumentTab and MongoDocumentsTab

This commit is contained in:
sunilyadav840
2021-10-12 19:00:02 +05:30
parent 1c54459708
commit 3c72351040
4 changed files with 43 additions and 43 deletions

View File

@@ -87,20 +87,12 @@ src/Explorer/Tables/DataTable/TableCommands.ts
src/Explorer/Tables/DataTable/TableEntityCache.ts
src/Explorer/Tables/DataTable/TableEntityListViewModel.ts
src/Explorer/Tables/Entities.ts
# src/Explorer/Tables/QueryBuilder/ClauseGroup.ts
# src/Explorer/Tables/QueryBuilder/ClauseGroupViewModel.ts
src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
# src/Explorer/Tables/QueryBuilder/QueryBuilderViewModel.ts
# src/Explorer/Tables/QueryBuilder/QueryClauseViewModel.ts
src/Explorer/Tables/TableDataClient.ts
src/Explorer/Tables/TableEntityProcessor.ts
src/Explorer/Tables/Utilities.ts
src/Explorer/Tabs/ConflictsTab.ts
src/Explorer/Tabs/DatabaseSettingsTab.ts
src/Explorer/Tabs/DocumentsTab.test.ts
src/Explorer/Tabs/DocumentsTab.ts
src/Explorer/Tabs/GraphTab.ts
src/Explorer/Tabs/MongoDocumentsTab.ts
src/Explorer/Tabs/NotebookV2Tab.ts
src/Explorer/Tabs/ScriptTabBase.ts
src/Explorer/Tabs/TabComponents.ts

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as ViewModels from "../../Contracts/ViewModels";
import * as Constants from "./Constants";
import * as Entities from "./Entities";
@@ -16,12 +17,12 @@ enum DataTypes {
Int64 = 18,
}
var tablesIndexers = {
const tablesIndexers = {
Value: "$v",
Type: "$t",
};
export var keyProperties = {
export const keyProperties = {
PartitionKey: "$pk",
Id: "id",
Id2: "$id", // This should always be the same value as Id
@@ -33,14 +34,17 @@ export var keyProperties = {
};
export function convertDocumentsToEntities(documents: any[]): Entities.ITableEntityForTablesAPI[] {
let results: Entities.ITableEntityForTablesAPI[] = [];
const results: Entities.ITableEntityForTablesAPI[] = [];
documents &&
documents.forEach((document) => {
if (!document.hasOwnProperty(keyProperties.PartitionKey) || !document.hasOwnProperty(keyProperties.Id)) {
if (
!Object.prototype.hasOwnProperty.call(document, keyProperties.PartitionKey) ||
Object.prototype.hasOwnProperty.call(document, keyProperties.Id)
) {
//Document does not match the current required format for Tables, so we ignore it
return; // The rest of the key properties should be guaranteed as DocumentDB properties
}
let entity: Entities.ITableEntityForTablesAPI = <Entities.ITableEntityForTablesAPI>{
const entity: Entities.ITableEntityForTablesAPI = <Entities.ITableEntityForTablesAPI>{
PartitionKey: {
_: document[keyProperties.PartitionKey],
$: Constants.TableType.String,
@@ -71,8 +75,8 @@ export function convertDocumentsToEntities(documents: any[]): Entities.ITableEnt
$: Constants.TableType.String,
},
};
for (var property in document) {
if (document.hasOwnProperty(property)) {
for (const property in document) {
if (Object.prototype.hasOwnProperty.call(document, property)) {
if (
property !== keyProperties.PartitionKey &&
property !== keyProperties.Id &&
@@ -83,7 +87,10 @@ export function convertDocumentsToEntities(documents: any[]): Entities.ITableEnt
property !== keyProperties.attachments &&
property !== keyProperties.Id2
) {
if (!document[property].hasOwnProperty("$v") || !document[property].hasOwnProperty("$t")) {
if (
!Object.prototype.hasOwnProperty.call(document[property], "$v") ||
!Object.prototype.hasOwnProperty.call(document[property], "$t")
) {
return; //Document property does not match the current required format for Tables, so we ignore it
}
if (DataTypes[document[property][tablesIndexers.Type]] === DataTypes[DataTypes.DateTime]) {
@@ -111,10 +118,10 @@ export function convertEntitiesToDocuments(
entities: Entities.ITableEntityForTablesAPI[],
collection: ViewModels.Collection
): any[] {
let results: any[] = [];
const results: any[] = [];
entities &&
entities.forEach((entity) => {
let document: any = {
const document: any = {
$id: entity.RowKey._,
id: entity.RowKey._,
ts: DateTimeUtilities.convertJSDateToUnix(entity.Timestamp._), // Convert back to unix time
@@ -129,7 +136,7 @@ export function convertEntitiesToDocuments(
document[collection.partitionKeyProperty] = entity.PartitionKey._;
document["partitionKeyValue"] = entity.PartitionKey._;
}
for (var property in entity) {
for (const property in entity) {
if (
property !== Constants.EntityKeyNames.PartitionKey &&
property !== Constants.EntityKeyNames.RowKey &&
@@ -160,7 +167,7 @@ export function convertEntitiesToDocuments(
}
export function convertEntityToNewDocument(entity: Entities.ITableEntityForTablesAPI): any {
let document: any = {
const document: any = {
$pk: entity.PartitionKey._,
$id: entity.RowKey._,
id: entity.RowKey._,

View File

@@ -92,7 +92,7 @@ export default class DocumentsTab extends TabsBase {
this.partitionKeyPropertyHeader =
(this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader();
this.partitionKeyProperty = !!this.partitionKeyPropertyHeader
this.partitionKeyProperty = this.partitionKeyPropertyHeader
? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "")
: null;
@@ -446,8 +446,8 @@ export default class DocumentsTab extends TabsBase {
this.partitionKey as PartitionKeyDefinition
);
const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0];
let id = new DocumentId(this, savedDocument, partitionKeyValue);
let ids = this.documentIds();
const id = new DocumentId(this, savedDocument, partitionKeyValue);
const ids = this.documentIds();
ids.push(id);
this.selectedDocumentId(id);
@@ -682,10 +682,10 @@ export default class DocumentsTab extends TabsBase {
}
public createIterator(): QueryIterator<ItemDefinition & Resource> {
let filters = this.lastFilterContents();
const filters = this.lastFilterContents();
const filter: string = this.filterContent().trim();
const query: string = this.buildQuery(filter);
let options: any = {};
const options: any = {};
options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey();
if (this._resourceTokenPartitionKey) {
@@ -778,7 +778,7 @@ export default class DocumentsTab extends TabsBase {
protected _onEditorContentChange(newContent: string) {
try {
let parsed: any = JSON.parse(newContent);
const parsed: any = JSON.parse(newContent);
this.onValidDocumentEdit();
} catch (e) {
this.onInvalidDocumentEdit();

View File

@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { extractPartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
import * as ko from "knockout";
import Q from "q";
@@ -44,7 +46,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
super.buildCommandBarOptions();
}
public onSaveNewDocumentClick = (): Promise<any> => {
public onSaveNewDocumentClick = (): Promise<void> => {
const documentContent = JSON.parse(this.selectedDocumentContent());
this.displayedError("");
const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, {
@@ -59,9 +61,8 @@ export default class MongoDocumentsTab extends DocumentsTab {
) {
const message = `The document is lacking the shard property: ${this.partitionKeyProperty}`;
this.displayedError(message);
let that = this;
setTimeout(() => {
that.displayedError("");
this.displayedError("");
}, Constants.ClientDefaults.errorNotificationTimeoutMs);
this.isExecutionError(true);
TelemetryProcessor.traceFailure(
@@ -82,19 +83,19 @@ export default class MongoDocumentsTab extends DocumentsTab {
return createDocument(this.collection.databaseId, this.collection, this.partitionKeyProperty, documentContent)
.then(
(savedDocument: any) => {
let partitionKeyArray = extractPartitionKey(
const partitionKeyArray = extractPartitionKey(
savedDocument,
this._getPartitionKeyDefinition() as PartitionKeyDefinition
);
let partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
let id = new ObjectId(this, savedDocument, partitionKeyValue);
let ids = this.documentIds();
const id = new ObjectId(this, savedDocument, partitionKeyValue);
const ids = this.documentIds();
ids.push(id);
delete savedDocument._self;
let value: string = this.renderObjectForEditor(savedDocument || {}, null, 4);
const value: string = this.renderObjectForEditor(savedDocument || {}, null, 4);
this.selectedDocumentContent.setBaseline(value);
this.selectedDocumentId(id);
@@ -128,7 +129,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
.finally(() => this.isExecuting(false));
};
public onSaveExisitingDocumentClick = (): Promise<any> => {
public onSaveExisitingDocumentClick = (): Promise<void> => {
const selectedDocumentId = this.selectedDocumentId();
const documentContent = this.selectedDocumentContent();
this.isExecutionError(false);
@@ -141,7 +142,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
return updateDocument(this.collection.databaseId, this.collection, selectedDocumentId, documentContent)
.then(
(updatedDocument: any) => {
let value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4);
const value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4);
this.selectedDocumentContent.setBaseline(value);
this.documentIds().forEach((documentId: DocumentId) => {
@@ -151,7 +152,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
this._getPartitionKeyDefinition() as PartitionKeyDefinition
);
let partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
const id = new ObjectId(this, updatedDocument, partitionKeyValue);
documentId.id(id.id());
@@ -196,7 +197,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
this.initDocumentEditor(documentId, content);
}
public loadNextPage(): Q.Promise<any> {
public loadNextPage(): Q.Promise<void> {
this.isExecuting(true);
this.isExecutionError(false);
const filter: string = this.filterContent().trim();
@@ -228,7 +229,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
this.selectedDocumentId(null);
this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected);
}
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceSuccess(
Action.Tab,
{
@@ -243,8 +244,8 @@ export default class MongoDocumentsTab extends DocumentsTab {
this.onLoadStartKey = null;
}
},
(error: any) => {
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
(error: Error) => {
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceFailure(
Action.Tab,
{
@@ -265,13 +266,13 @@ export default class MongoDocumentsTab extends DocumentsTab {
.finally(() => this.isExecuting(false));
}
protected _onEditorContentChange(newContent: string) {
protected _onEditorContentChange(newContent: string): void {
try {
if (
this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid ||
this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid
) {
let parsed: any = JSON.parse(newContent);
const parsed: any = JSON.parse(newContent);
}
// Mongo uses BSON format for _id, trying to parse it as JSON blocks normal flow in an edit