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/Panes/SettingsPane/SettingsPane.tsx b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx index bec1200f7..d028e3543 100644 --- a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx +++ b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx @@ -26,7 +26,8 @@ export const SettingsPane: FunctionComponent = () => { ? LocalStorageUtility.getEntryString(StorageKey.IsCrossPartitionQueryEnabled) === "true" : true ); - const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState( + //eslint-disable-next-line + const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState( LocalStorageUtility.hasItem(StorageKey.IsGraphAutoVizDisabled) ? LocalStorageUtility.getEntryString(StorageKey.IsGraphAutoVizDisabled) : "false" @@ -42,7 +43,7 @@ export const SettingsPane: FunctionComponent = () => { const shouldShowCrossPartitionOption = userContext.apiType !== "Gremlin"; const shouldShowParallelismOption = userContext.apiType !== "Gremlin"; - const handlerOnSubmit = (e: MouseEvent) => { + const handlerOnSubmit = (e: MouseEvent | undefined) => { setIsExecuting(true); LocalStorageUtility.setEntryNumber( @@ -83,22 +84,27 @@ export const SettingsPane: FunctionComponent = () => { `Updated query setting to ${LocalStorageUtility.getEntryString(StorageKey.SetPartitionKeyUndefined)}` ); closeSidePanel(); - e.preventDefault(); + if (e) { + e.preventDefault(); + } }; const isCustomPageOptionSelected = () => { return pageOption === Constants.Queries.CustomPageOption; }; - const handleOnGremlinChange = (ev: React.FormEvent, option: IChoiceGroupOption): void => { - setGraphAutoVizDisabled(option.key); + const handleOnGremlinChange = ( + _: React.FormEvent | undefined, + option: IChoiceGroupOption | undefined + ): void => { + setGraphAutoVizDisabled(option ? option.key : ""); }; const genericPaneProps: RightPaneFormProps = { formError: "", isExecuting, submitButtonText: "Apply", - onSubmit: () => handlerOnSubmit(undefined), + onSubmit: (e?: MouseEvent | undefined) => handlerOnSubmit(e), }; const pageOptionList: IChoiceGroupOption[] = [ { key: Constants.Queries.CustomPageOption, text: "Custom" }, @@ -110,8 +116,11 @@ export const SettingsPane: FunctionComponent = () => { { key: "true", text: "JSON" }, ]; - const handleOnPageOptionChange = (ev: React.FormEvent, option: IChoiceGroupOption): void => { - setPageOption(option.key); + const handleOnPageOptionChange = ( + _: React.FormEvent | undefined, + option: IChoiceGroupOption | undefined + ): void => { + setPageOption(option ? option.key : ""); }; return ( @@ -218,7 +227,7 @@ export const SettingsPane: FunctionComponent = () => { { if (RegExp(Constants.EndpointsRegex.sql).test(connectionStringPart)) { - accessInput.accountName = connectionStringPart.match(Constants.EndpointsRegex.sql)[1]; + const matchArray = connectionStringPart.match(Constants.EndpointsRegex.sql); + accessInput.accountName = matchArray && matchArray.length > 0 ? matchArray[1] : ""; accessInput.apiKind = ApiKind.SQL; } else if (RegExp(Constants.EndpointsRegex.mongo).test(connectionStringPart)) { - const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongo); - accessInput.accountName = matches && matches.length > 1 && matches[2]; + const matches = connectionStringPart.match(Constants.EndpointsRegex.mongo); + accessInput.accountName = matches && matches.length > 1 ? matches[2] : ""; accessInput.apiKind = ApiKind.MongoDB; } else if (RegExp(Constants.EndpointsRegex.mongoCompute).test(connectionStringPart)) { - const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongoCompute); - accessInput.accountName = matches && matches.length > 1 && matches[2]; + const matches = connectionStringPart.match(Constants.EndpointsRegex.mongoCompute); + accessInput.accountName = matches && matches.length > 1 ? matches[2] : ""; accessInput.apiKind = ApiKind.MongoDBCompute; } else if (Constants.EndpointsRegex.cassandra.some((regex) => RegExp(regex).test(connectionStringPart))) { Constants.EndpointsRegex.cassandra.forEach((regex) => { if (RegExp(regex).test(connectionStringPart)) { - accessInput.accountName = connectionStringPart.match(regex)[1]; + const matchArray = connectionStringPart.match(regex); + accessInput.accountName = matchArray && matchArray.length > 0 ? matchArray[1] : ""; accessInput.apiKind = ApiKind.Cassandra; } }); } else if (RegExp(Constants.EndpointsRegex.table).test(connectionStringPart)) { - accessInput.accountName = connectionStringPart.match(Constants.EndpointsRegex.table)[1]; + const matchArray = connectionStringPart.match(Constants.EndpointsRegex.table); + accessInput.accountName = matchArray && matchArray.length > 0 ? matchArray[1] : ""; accessInput.apiKind = ApiKind.Table; } else if (connectionStringPart.indexOf("ApiKind=Gremlin") >= 0) { accessInput.apiKind = ApiKind.Graph; diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ee037db87..ca2151ff8 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/Utils/NotebookConfigurationUtils.ts", + "./src/Index.tsx", + "./src/Platform/Hosted/Helpers/ConnectionStringParser.ts", + "./src/Explorer/Panes/SettingsPane/SettingsPane.tsx" ], "include": [ "src/CellOutputViewer/transforms/**/*",