From 477055ddef7762fe808e58fd89d970d084483ac0 Mon Sep 17 00:00:00 2001 From: vaidankarswapnil Date: Mon, 23 Aug 2021 12:47:24 +0530 Subject: [PATCH] Fix typescript strict issues for getCollectionDataUsageSize and few more --- src/Common/ErrorHandlingUtils.ts | 4 +-- .../dataAccess/getCollectionDataUsageSize.ts | 7 +++-- .../dataAccess/readMongoDBCollection.tsx | 18 +++++++++---- .../AccessibleElement/AccessibleElement.tsx | 26 ++++++++++++------- .../LeftPaneComponent.tsx | 2 +- tsconfig.strict.json | 6 ++++- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/Common/ErrorHandlingUtils.ts b/src/Common/ErrorHandlingUtils.ts index 8a86bdf32..e3e642d78 100644 --- a/src/Common/ErrorHandlingUtils.ts +++ b/src/Common/ErrorHandlingUtils.ts @@ -28,10 +28,10 @@ export const getErrorMessage = (error: string | Error = ""): string => { }; export const getErrorStack = (error: string | Error): string => { - return typeof error === "string" ? undefined : error.stack; + return typeof error === "string" ? "" : error.stack === undefined ? "" : error.stack; }; -const sendNotificationForError = (errorMessage: string, errorCode: number | string): void => { +const sendNotificationForError = (errorMessage: string, errorCode: number | string | undefined): void => { if (errorCode === HttpStatusCodes.Forbidden) { if (errorMessage?.toLowerCase().indexOf("sharedoffer is disabled for your account") > 0) { return; diff --git a/src/Common/dataAccess/getCollectionDataUsageSize.ts b/src/Common/dataAccess/getCollectionDataUsageSize.ts index bb53bc6ac..99eca705a 100644 --- a/src/Common/dataAccess/getCollectionDataUsageSize.ts +++ b/src/Common/dataAccess/getCollectionDataUsageSize.ts @@ -40,13 +40,16 @@ interface MetricsResponse { value: MetricsData[]; } -export const getCollectionUsageSizeInKB = async (databaseName: string, containerName: string): Promise => { +export const getCollectionUsageSizeInKB = async ( + databaseName: string, + containerName: string +): Promise => { if (userContext.authType !== AuthType.AAD) { return undefined; } const { subscriptionId, resourceGroup, databaseAccount } = userContext; - const accountName = databaseAccount.name; + const accountName = databaseAccount !== undefined ? databaseAccount.name : ""; const filter = `DatabaseName eq '${databaseName}' and CollectionName eq '${containerName}'`; const metricNames = "DataUsage,IndexUsage"; diff --git a/src/Common/dataAccess/readMongoDBCollection.tsx b/src/Common/dataAccess/readMongoDBCollection.tsx index cdc4a0845..b1759a787 100644 --- a/src/Common/dataAccess/readMongoDBCollection.tsx +++ b/src/Common/dataAccess/readMongoDBCollection.tsx @@ -8,19 +8,27 @@ import { handleError } from "../ErrorHandlingUtils"; export async function readMongoDBCollectionThroughRP( databaseId: string, collectionId: string -): Promise { +): Promise { if (userContext.authType !== AuthType.AAD) { return undefined; } - let collection: MongoDBCollectionResource; + let collection: MongoDBCollectionResource | undefined; const { subscriptionId, resourceGroup, databaseAccount } = userContext; - const accountName = databaseAccount.name; + const accountName = databaseAccount !== undefined ? databaseAccount.name : ""; const clearMessage = logConsoleProgress(`Reading container ${collectionId}`); try { - const response = await getMongoDBCollection(subscriptionId, resourceGroup, accountName, databaseId, collectionId); - collection = response.properties.resource; + const response = await getMongoDBCollection( + subscriptionId !== undefined ? subscriptionId : "", + resourceGroup !== undefined ? resourceGroup : "", + accountName, + databaseId, + collectionId + ); + if (response.properties !== undefined) { + collection = response.properties.resource; + } } catch (error) { handleError(error, "ReadMongoDBCollection", `Error while reading container ${collectionId}`); throw error; diff --git a/src/Explorer/Controls/AccessibleElement/AccessibleElement.tsx b/src/Explorer/Controls/AccessibleElement/AccessibleElement.tsx index f46290bff..03b03e23c 100644 --- a/src/Explorer/Controls/AccessibleElement/AccessibleElement.tsx +++ b/src/Explorer/Controls/AccessibleElement/AccessibleElement.tsx @@ -2,9 +2,9 @@ import * as React from "react"; import * as Constants from "../../../Common/Constants"; interface AccessibleElementProps extends React.HtmlHTMLAttributes { - as: string; // tag element name - onActivated: (event: React.SyntheticEvent) => void; - "aria-label": string; + as?: string; // tag element name + onActivated?: (event: React.SyntheticEvent) => void; + "aria-label"?: string; tabIndex?: number; } @@ -16,7 +16,9 @@ export class AccessibleElement extends React.Component { if (event.charCode === Constants.KeyCodes.Space || event.charCode === Constants.KeyCodes.Enter) { event.stopPropagation(); event.preventDefault(); - this.props.onActivated(event); + if (this.props.onActivated !== undefined) { + this.props.onActivated(event); + } } }; @@ -27,11 +29,15 @@ export class AccessibleElement extends React.Component { const tabIndex = this.props.tabIndex === undefined ? 0 : this.props.tabIndex; - return React.createElement(this.props.as, { - ...elementProps, - onKeyPress: this.onKeyPress, - onClick: this.props.onActivated, - tabIndex, - }); + return this.props.as !== undefined ? ( + React.createElement(this.props.as, { + ...elementProps, + onKeyPress: this.onKeyPress, + onClick: this.props.onActivated, + tabIndex, + }) + ) : ( + <> + ); } } diff --git a/src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx b/src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx index f6525e54d..6e3963f06 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx +++ b/src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx @@ -58,7 +58,7 @@ export class LeftPaneComponent extends React.Component { className={className} as="tr" aria-label={node.caption} - onActivated={(e) => this.props.onRootNodeSelected(node.id)} + onActivated={() => this.props.onRootNodeSelected(node.id)} key={node.id} > diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ee037db87..086e2f59e 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -139,7 +139,11 @@ "./src/userContext.test.ts", "src/Common/EntityValue.tsx", "./src/Platform/Hosted/Components/SwitchAccount.tsx", - "./src/Platform/Hosted/Components/SwitchSubscription.tsx" + "./src/Platform/Hosted/Components/SwitchSubscription.tsx", + "./src/Common/dataAccess/getCollectionDataUsageSize.ts", + "./src/Common/dataAccess/readMongoDBCollection.tsx", + "./src/Explorer/Controls/CollapsiblePanel/CollapsiblePanel.tsx", + "./src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx" ], "include": [ "src/CellOutputViewer/transforms/**/*",