mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-30 22:31:56 +00:00
Fix typescript strict issues for ConnectionStringParser and other files
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -26,7 +26,8 @@ export const SettingsPane: FunctionComponent = () => {
|
||||
? LocalStorageUtility.getEntryString(StorageKey.IsCrossPartitionQueryEnabled) === "true"
|
||||
: true
|
||||
);
|
||||
const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState<string>(
|
||||
//eslint-disable-next-line
|
||||
const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState<string | null>(
|
||||
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<HTMLButtonElement>) => {
|
||||
const handlerOnSubmit = (e: MouseEvent<HTMLButtonElement> | 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<HTMLInputElement>, option: IChoiceGroupOption): void => {
|
||||
setGraphAutoVizDisabled(option.key);
|
||||
const handleOnGremlinChange = (
|
||||
_: React.FormEvent<HTMLElement | HTMLInputElement> | undefined,
|
||||
option: IChoiceGroupOption | undefined
|
||||
): void => {
|
||||
setGraphAutoVizDisabled(option ? option.key : "");
|
||||
};
|
||||
|
||||
const genericPaneProps: RightPaneFormProps = {
|
||||
formError: "",
|
||||
isExecuting,
|
||||
submitButtonText: "Apply",
|
||||
onSubmit: () => handlerOnSubmit(undefined),
|
||||
onSubmit: (e?: MouseEvent<HTMLButtonElement> | 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<HTMLInputElement>, option: IChoiceGroupOption): void => {
|
||||
setPageOption(option.key);
|
||||
const handleOnPageOptionChange = (
|
||||
_: React.FormEvent<HTMLElement | HTMLInputElement> | undefined,
|
||||
option: IChoiceGroupOption | undefined
|
||||
): void => {
|
||||
setPageOption(option ? option.key : "");
|
||||
};
|
||||
return (
|
||||
<RightPaneForm {...genericPaneProps}>
|
||||
@@ -218,7 +227,7 @@ export const SettingsPane: FunctionComponent = () => {
|
||||
</div>
|
||||
|
||||
<ChoiceGroup
|
||||
selectedKey={graphAutoVizDisabled}
|
||||
selectedKey={graphAutoVizDisabled ? graphAutoVizDisabled : undefined}
|
||||
options={graphAutoOptionList}
|
||||
onChange={handleOnGremlinChange}
|
||||
aria-label="Graph Auto-visualization"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Constants from "../../../Common/Constants";
|
||||
import { AccessInputMetadata, ApiKind } from "../../../Contracts/DataModels";
|
||||
|
||||
export function parseConnectionString(connectionString: string): AccessInputMetadata {
|
||||
export function parseConnectionString(connectionString: string): AccessInputMetadata | undefined {
|
||||
if (connectionString) {
|
||||
try {
|
||||
const accessInput = {} as AccessInputMetadata;
|
||||
@@ -9,25 +9,28 @@ export function parseConnectionString(connectionString: string): AccessInputMeta
|
||||
|
||||
connectionStringParts.forEach((connectionStringPart: string) => {
|
||||
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;
|
||||
|
||||
@@ -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/**/*",
|
||||
|
||||
Reference in New Issue
Block a user