From 55b117d83b0be493e9c668a925c4bbeb5f5447a4 Mon Sep 17 00:00:00 2001 From: vaidankarswapnil Date: Fri, 20 Aug 2021 15:35:08 +0530 Subject: [PATCH] Fixed typescript issues for DatabaseAccountUtility and InMemoryContentProvider --- src/Common/DatabaseAccountUtility.ts | 8 ++++-- src/Common/ErrorHandlingUtils.ts | 4 +-- .../AccessibleElement/AccessibleElement.tsx | 26 ++++++++++++------- .../InMemoryContentProvider.ts | 2 +- tsconfig.strict.json | 7 +++-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/Common/DatabaseAccountUtility.ts b/src/Common/DatabaseAccountUtility.ts index 693f581f8..558ce926f 100644 --- a/src/Common/DatabaseAccountUtility.ts +++ b/src/Common/DatabaseAccountUtility.ts @@ -5,11 +5,15 @@ function isVirtualNetworkFilterEnabled() { } function isIpRulesEnabled() { - return userContext.databaseAccount?.properties?.ipRules?.length > 0; + return userContext?.databaseAccount?.properties?.ipRules !== undefined + ? userContext?.databaseAccount?.properties?.ipRules?.length > 0 + : false; } function isPrivateEndpointConnectionsEnabled() { - return userContext.databaseAccount?.properties?.privateEndpointConnections?.length > 0; + return userContext.databaseAccount?.properties?.privateEndpointConnections !== undefined + ? userContext.databaseAccount?.properties?.privateEndpointConnections?.length > 0 + : false; } export function isPublicInternetAccessAllowed(): boolean { 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/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/Notebook/NotebookComponent/ContentProviders/InMemoryContentProvider.ts b/src/Explorer/Notebook/NotebookComponent/ContentProviders/InMemoryContentProvider.ts index 9d979324d..75400d67e 100644 --- a/src/Explorer/Notebook/NotebookComponent/ContentProviders/InMemoryContentProvider.ts +++ b/src/Explorer/Notebook/NotebookComponent/ContentProviders/InMemoryContentProvider.ts @@ -89,7 +89,7 @@ export class InMemoryContentProvider implements IContentProvider { request: {}, status, response: content ? content : undefined, - responseText: content ? JSON.stringify(content) : undefined, + responseText: content ? JSON.stringify(content) : "", responseType: "json", }; } diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ee037db87..697cedd69 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -137,9 +137,12 @@ "./src/quickstart.ts", "./src/setupTests.ts", "./src/userContext.test.ts", - "src/Common/EntityValue.tsx", + "./src/Common/EntityValue.tsx", "./src/Platform/Hosted/Components/SwitchAccount.tsx", - "./src/Platform/Hosted/Components/SwitchSubscription.tsx" + "./src/Platform/Hosted/Components/SwitchSubscription.tsx", + "./src/Common/DatabaseAccountUtility.ts", + "./src/Explorer/Controls/Tabs/TabComponent.tsx", + "./src/Explorer/Notebook/NotebookComponent/ContentProviders/InMemoryContentProvider.ts" ], "include": [ "src/CellOutputViewer/transforms/**/*",