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/TableEntityCache.ts
src/Explorer/Tables/DataTable/TableEntityListViewModel.ts src/Explorer/Tables/DataTable/TableEntityListViewModel.ts
src/Explorer/Tables/Entities.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/CustomTimestampHelper.ts
# src/Explorer/Tables/QueryBuilder/QueryBuilderViewModel.ts
# src/Explorer/Tables/QueryBuilder/QueryClauseViewModel.ts
src/Explorer/Tables/TableDataClient.ts src/Explorer/Tables/TableDataClient.ts
src/Explorer/Tables/TableEntityProcessor.ts
src/Explorer/Tables/Utilities.ts src/Explorer/Tables/Utilities.ts
src/Explorer/Tabs/ConflictsTab.ts src/Explorer/Tabs/ConflictsTab.ts
src/Explorer/Tabs/DatabaseSettingsTab.ts
src/Explorer/Tabs/DocumentsTab.test.ts src/Explorer/Tabs/DocumentsTab.test.ts
src/Explorer/Tabs/DocumentsTab.ts src/Explorer/Tabs/DocumentsTab.ts
src/Explorer/Tabs/GraphTab.ts
src/Explorer/Tabs/MongoDocumentsTab.ts
src/Explorer/Tabs/NotebookV2Tab.ts src/Explorer/Tabs/NotebookV2Tab.ts
src/Explorer/Tabs/ScriptTabBase.ts src/Explorer/Tabs/ScriptTabBase.ts
src/Explorer/Tabs/TabComponents.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 ViewModels from "../../Contracts/ViewModels";
import * as Constants from "./Constants"; import * as Constants from "./Constants";
import * as Entities from "./Entities"; import * as Entities from "./Entities";
@@ -16,12 +17,12 @@ enum DataTypes {
Int64 = 18, Int64 = 18,
} }
var tablesIndexers = { const tablesIndexers = {
Value: "$v", Value: "$v",
Type: "$t", Type: "$t",
}; };
export var keyProperties = { export const keyProperties = {
PartitionKey: "$pk", PartitionKey: "$pk",
Id: "id", Id: "id",
Id2: "$id", // This should always be the same value as 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[] { export function convertDocumentsToEntities(documents: any[]): Entities.ITableEntityForTablesAPI[] {
let results: Entities.ITableEntityForTablesAPI[] = []; const results: Entities.ITableEntityForTablesAPI[] = [];
documents && documents &&
documents.forEach((document) => { 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 //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 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: { PartitionKey: {
_: document[keyProperties.PartitionKey], _: document[keyProperties.PartitionKey],
$: Constants.TableType.String, $: Constants.TableType.String,
@@ -71,8 +75,8 @@ export function convertDocumentsToEntities(documents: any[]): Entities.ITableEnt
$: Constants.TableType.String, $: Constants.TableType.String,
}, },
}; };
for (var property in document) { for (const property in document) {
if (document.hasOwnProperty(property)) { if (Object.prototype.hasOwnProperty.call(document, property)) {
if ( if (
property !== keyProperties.PartitionKey && property !== keyProperties.PartitionKey &&
property !== keyProperties.Id && property !== keyProperties.Id &&
@@ -83,7 +87,10 @@ export function convertDocumentsToEntities(documents: any[]): Entities.ITableEnt
property !== keyProperties.attachments && property !== keyProperties.attachments &&
property !== keyProperties.Id2 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 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]) { if (DataTypes[document[property][tablesIndexers.Type]] === DataTypes[DataTypes.DateTime]) {
@@ -111,10 +118,10 @@ export function convertEntitiesToDocuments(
entities: Entities.ITableEntityForTablesAPI[], entities: Entities.ITableEntityForTablesAPI[],
collection: ViewModels.Collection collection: ViewModels.Collection
): any[] { ): any[] {
let results: any[] = []; const results: any[] = [];
entities && entities &&
entities.forEach((entity) => { entities.forEach((entity) => {
let document: any = { const document: any = {
$id: entity.RowKey._, $id: entity.RowKey._,
id: entity.RowKey._, id: entity.RowKey._,
ts: DateTimeUtilities.convertJSDateToUnix(entity.Timestamp._), // Convert back to unix time ts: DateTimeUtilities.convertJSDateToUnix(entity.Timestamp._), // Convert back to unix time
@@ -129,7 +136,7 @@ export function convertEntitiesToDocuments(
document[collection.partitionKeyProperty] = entity.PartitionKey._; document[collection.partitionKeyProperty] = entity.PartitionKey._;
document["partitionKeyValue"] = entity.PartitionKey._; document["partitionKeyValue"] = entity.PartitionKey._;
} }
for (var property in entity) { for (const property in entity) {
if ( if (
property !== Constants.EntityKeyNames.PartitionKey && property !== Constants.EntityKeyNames.PartitionKey &&
property !== Constants.EntityKeyNames.RowKey && property !== Constants.EntityKeyNames.RowKey &&
@@ -160,7 +167,7 @@ export function convertEntitiesToDocuments(
} }
export function convertEntityToNewDocument(entity: Entities.ITableEntityForTablesAPI): any { export function convertEntityToNewDocument(entity: Entities.ITableEntityForTablesAPI): any {
let document: any = { const document: any = {
$pk: entity.PartitionKey._, $pk: entity.PartitionKey._,
$id: entity.RowKey._, $id: entity.RowKey._,
id: entity.RowKey._, id: entity.RowKey._,

View File

@@ -92,7 +92,7 @@ export default class DocumentsTab extends TabsBase {
this.partitionKeyPropertyHeader = this.partitionKeyPropertyHeader =
(this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader(); (this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader();
this.partitionKeyProperty = !!this.partitionKeyPropertyHeader this.partitionKeyProperty = this.partitionKeyPropertyHeader
? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "") ? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "")
: null; : null;
@@ -446,8 +446,8 @@ export default class DocumentsTab extends TabsBase {
this.partitionKey as PartitionKeyDefinition this.partitionKey as PartitionKeyDefinition
); );
const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0]; const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0];
let id = new DocumentId(this, savedDocument, partitionKeyValue); const id = new DocumentId(this, savedDocument, partitionKeyValue);
let ids = this.documentIds(); const ids = this.documentIds();
ids.push(id); ids.push(id);
this.selectedDocumentId(id); this.selectedDocumentId(id);
@@ -682,10 +682,10 @@ export default class DocumentsTab extends TabsBase {
} }
public createIterator(): QueryIterator<ItemDefinition & Resource> { public createIterator(): QueryIterator<ItemDefinition & Resource> {
let filters = this.lastFilterContents(); const filters = this.lastFilterContents();
const filter: string = this.filterContent().trim(); const filter: string = this.filterContent().trim();
const query: string = this.buildQuery(filter); const query: string = this.buildQuery(filter);
let options: any = {}; const options: any = {};
options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey(); options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey();
if (this._resourceTokenPartitionKey) { if (this._resourceTokenPartitionKey) {
@@ -778,7 +778,7 @@ export default class DocumentsTab extends TabsBase {
protected _onEditorContentChange(newContent: string) { protected _onEditorContentChange(newContent: string) {
try { try {
let parsed: any = JSON.parse(newContent); const parsed: any = JSON.parse(newContent);
this.onValidDocumentEdit(); this.onValidDocumentEdit();
} catch (e) { } catch (e) {
this.onInvalidDocumentEdit(); 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 { extractPartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
import * as ko from "knockout"; import * as ko from "knockout";
import Q from "q"; import Q from "q";
@@ -44,7 +46,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
super.buildCommandBarOptions(); super.buildCommandBarOptions();
} }
public onSaveNewDocumentClick = (): Promise<any> => { public onSaveNewDocumentClick = (): Promise<void> => {
const documentContent = JSON.parse(this.selectedDocumentContent()); const documentContent = JSON.parse(this.selectedDocumentContent());
this.displayedError(""); this.displayedError("");
const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, { 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}`; const message = `The document is lacking the shard property: ${this.partitionKeyProperty}`;
this.displayedError(message); this.displayedError(message);
let that = this;
setTimeout(() => { setTimeout(() => {
that.displayedError(""); this.displayedError("");
}, Constants.ClientDefaults.errorNotificationTimeoutMs); }, Constants.ClientDefaults.errorNotificationTimeoutMs);
this.isExecutionError(true); this.isExecutionError(true);
TelemetryProcessor.traceFailure( TelemetryProcessor.traceFailure(
@@ -82,19 +83,19 @@ export default class MongoDocumentsTab extends DocumentsTab {
return createDocument(this.collection.databaseId, this.collection, this.partitionKeyProperty, documentContent) return createDocument(this.collection.databaseId, this.collection, this.partitionKeyProperty, documentContent)
.then( .then(
(savedDocument: any) => { (savedDocument: any) => {
let partitionKeyArray = extractPartitionKey( const partitionKeyArray = extractPartitionKey(
savedDocument, savedDocument,
this._getPartitionKeyDefinition() as PartitionKeyDefinition this._getPartitionKeyDefinition() as PartitionKeyDefinition
); );
let partitionKeyValue = partitionKeyArray && partitionKeyArray[0]; const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
let id = new ObjectId(this, savedDocument, partitionKeyValue); const id = new ObjectId(this, savedDocument, partitionKeyValue);
let ids = this.documentIds(); const ids = this.documentIds();
ids.push(id); ids.push(id);
delete savedDocument._self; delete savedDocument._self;
let value: string = this.renderObjectForEditor(savedDocument || {}, null, 4); const value: string = this.renderObjectForEditor(savedDocument || {}, null, 4);
this.selectedDocumentContent.setBaseline(value); this.selectedDocumentContent.setBaseline(value);
this.selectedDocumentId(id); this.selectedDocumentId(id);
@@ -128,7 +129,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
.finally(() => this.isExecuting(false)); .finally(() => this.isExecuting(false));
}; };
public onSaveExisitingDocumentClick = (): Promise<any> => { public onSaveExisitingDocumentClick = (): Promise<void> => {
const selectedDocumentId = this.selectedDocumentId(); const selectedDocumentId = this.selectedDocumentId();
const documentContent = this.selectedDocumentContent(); const documentContent = this.selectedDocumentContent();
this.isExecutionError(false); this.isExecutionError(false);
@@ -141,7 +142,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
return updateDocument(this.collection.databaseId, this.collection, selectedDocumentId, documentContent) return updateDocument(this.collection.databaseId, this.collection, selectedDocumentId, documentContent)
.then( .then(
(updatedDocument: any) => { (updatedDocument: any) => {
let value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4); const value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4);
this.selectedDocumentContent.setBaseline(value); this.selectedDocumentContent.setBaseline(value);
this.documentIds().forEach((documentId: DocumentId) => { this.documentIds().forEach((documentId: DocumentId) => {
@@ -151,7 +152,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
this._getPartitionKeyDefinition() as PartitionKeyDefinition this._getPartitionKeyDefinition() as PartitionKeyDefinition
); );
let partitionKeyValue = partitionKeyArray && partitionKeyArray[0]; const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
const id = new ObjectId(this, updatedDocument, partitionKeyValue); const id = new ObjectId(this, updatedDocument, partitionKeyValue);
documentId.id(id.id()); documentId.id(id.id());
@@ -196,7 +197,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
this.initDocumentEditor(documentId, content); this.initDocumentEditor(documentId, content);
} }
public loadNextPage(): Q.Promise<any> { public loadNextPage(): Q.Promise<void> {
this.isExecuting(true); this.isExecuting(true);
this.isExecutionError(false); this.isExecutionError(false);
const filter: string = this.filterContent().trim(); const filter: string = this.filterContent().trim();
@@ -228,7 +229,7 @@ export default class MongoDocumentsTab extends DocumentsTab {
this.selectedDocumentId(null); this.selectedDocumentId(null);
this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected);
} }
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceSuccess( TelemetryProcessor.traceSuccess(
Action.Tab, Action.Tab,
{ {
@@ -243,8 +244,8 @@ export default class MongoDocumentsTab extends DocumentsTab {
this.onLoadStartKey = null; this.onLoadStartKey = null;
} }
}, },
(error: any) => { (error: Error) => {
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceFailure( TelemetryProcessor.traceFailure(
Action.Tab, Action.Tab,
{ {
@@ -265,13 +266,13 @@ export default class MongoDocumentsTab extends DocumentsTab {
.finally(() => this.isExecuting(false)); .finally(() => this.isExecuting(false));
} }
protected _onEditorContentChange(newContent: string) { protected _onEditorContentChange(newContent: string): void {
try { try {
if ( if (
this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid || this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid ||
this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid 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 // Mongo uses BSON format for _id, trying to parse it as JSON blocks normal flow in an edit