mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-06 11:11:23 +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 => {
|
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 (errorCode === HttpStatusCodes.Forbidden) {
|
||||||
if (errorMessage?.toLowerCase().indexOf("sharedoffer is disabled for your account") > 0) {
|
if (errorMessage?.toLowerCase().indexOf("sharedoffer is disabled for your account") > 0) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export const SettingsPane: FunctionComponent = () => {
|
|||||||
? LocalStorageUtility.getEntryString(StorageKey.IsCrossPartitionQueryEnabled) === "true"
|
? LocalStorageUtility.getEntryString(StorageKey.IsCrossPartitionQueryEnabled) === "true"
|
||||||
: true
|
: true
|
||||||
);
|
);
|
||||||
const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState<string>(
|
//eslint-disable-next-line
|
||||||
|
const [graphAutoVizDisabled, setGraphAutoVizDisabled] = useState<string | null>(
|
||||||
LocalStorageUtility.hasItem(StorageKey.IsGraphAutoVizDisabled)
|
LocalStorageUtility.hasItem(StorageKey.IsGraphAutoVizDisabled)
|
||||||
? LocalStorageUtility.getEntryString(StorageKey.IsGraphAutoVizDisabled)
|
? LocalStorageUtility.getEntryString(StorageKey.IsGraphAutoVizDisabled)
|
||||||
: "false"
|
: "false"
|
||||||
@@ -42,7 +43,7 @@ export const SettingsPane: FunctionComponent = () => {
|
|||||||
const shouldShowCrossPartitionOption = userContext.apiType !== "Gremlin";
|
const shouldShowCrossPartitionOption = userContext.apiType !== "Gremlin";
|
||||||
const shouldShowParallelismOption = userContext.apiType !== "Gremlin";
|
const shouldShowParallelismOption = userContext.apiType !== "Gremlin";
|
||||||
|
|
||||||
const handlerOnSubmit = (e: MouseEvent<HTMLButtonElement>) => {
|
const handlerOnSubmit = (e: MouseEvent<HTMLButtonElement> | undefined) => {
|
||||||
setIsExecuting(true);
|
setIsExecuting(true);
|
||||||
|
|
||||||
LocalStorageUtility.setEntryNumber(
|
LocalStorageUtility.setEntryNumber(
|
||||||
@@ -83,22 +84,27 @@ export const SettingsPane: FunctionComponent = () => {
|
|||||||
`Updated query setting to ${LocalStorageUtility.getEntryString(StorageKey.SetPartitionKeyUndefined)}`
|
`Updated query setting to ${LocalStorageUtility.getEntryString(StorageKey.SetPartitionKeyUndefined)}`
|
||||||
);
|
);
|
||||||
closeSidePanel();
|
closeSidePanel();
|
||||||
e.preventDefault();
|
if (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isCustomPageOptionSelected = () => {
|
const isCustomPageOptionSelected = () => {
|
||||||
return pageOption === Constants.Queries.CustomPageOption;
|
return pageOption === Constants.Queries.CustomPageOption;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnGremlinChange = (ev: React.FormEvent<HTMLInputElement>, option: IChoiceGroupOption): void => {
|
const handleOnGremlinChange = (
|
||||||
setGraphAutoVizDisabled(option.key);
|
_: React.FormEvent<HTMLElement | HTMLInputElement> | undefined,
|
||||||
|
option: IChoiceGroupOption | undefined
|
||||||
|
): void => {
|
||||||
|
setGraphAutoVizDisabled(option ? option.key : "");
|
||||||
};
|
};
|
||||||
|
|
||||||
const genericPaneProps: RightPaneFormProps = {
|
const genericPaneProps: RightPaneFormProps = {
|
||||||
formError: "",
|
formError: "",
|
||||||
isExecuting,
|
isExecuting,
|
||||||
submitButtonText: "Apply",
|
submitButtonText: "Apply",
|
||||||
onSubmit: () => handlerOnSubmit(undefined),
|
onSubmit: (e?: MouseEvent<HTMLButtonElement> | undefined) => handlerOnSubmit(e),
|
||||||
};
|
};
|
||||||
const pageOptionList: IChoiceGroupOption[] = [
|
const pageOptionList: IChoiceGroupOption[] = [
|
||||||
{ key: Constants.Queries.CustomPageOption, text: "Custom" },
|
{ key: Constants.Queries.CustomPageOption, text: "Custom" },
|
||||||
@@ -110,8 +116,11 @@ export const SettingsPane: FunctionComponent = () => {
|
|||||||
{ key: "true", text: "JSON" },
|
{ key: "true", text: "JSON" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleOnPageOptionChange = (ev: React.FormEvent<HTMLInputElement>, option: IChoiceGroupOption): void => {
|
const handleOnPageOptionChange = (
|
||||||
setPageOption(option.key);
|
_: React.FormEvent<HTMLElement | HTMLInputElement> | undefined,
|
||||||
|
option: IChoiceGroupOption | undefined
|
||||||
|
): void => {
|
||||||
|
setPageOption(option ? option.key : "");
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<RightPaneForm {...genericPaneProps}>
|
<RightPaneForm {...genericPaneProps}>
|
||||||
@@ -218,7 +227,7 @@ export const SettingsPane: FunctionComponent = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ChoiceGroup
|
<ChoiceGroup
|
||||||
selectedKey={graphAutoVizDisabled}
|
selectedKey={graphAutoVizDisabled ? graphAutoVizDisabled : undefined}
|
||||||
options={graphAutoOptionList}
|
options={graphAutoOptionList}
|
||||||
onChange={handleOnGremlinChange}
|
onChange={handleOnGremlinChange}
|
||||||
aria-label="Graph Auto-visualization"
|
aria-label="Graph Auto-visualization"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as Constants from "../../../Common/Constants";
|
import * as Constants from "../../../Common/Constants";
|
||||||
import { AccessInputMetadata, ApiKind } from "../../../Contracts/DataModels";
|
import { AccessInputMetadata, ApiKind } from "../../../Contracts/DataModels";
|
||||||
|
|
||||||
export function parseConnectionString(connectionString: string): AccessInputMetadata {
|
export function parseConnectionString(connectionString: string): AccessInputMetadata | undefined {
|
||||||
if (connectionString) {
|
if (connectionString) {
|
||||||
try {
|
try {
|
||||||
const accessInput = {} as AccessInputMetadata;
|
const accessInput = {} as AccessInputMetadata;
|
||||||
@@ -9,25 +9,28 @@ export function parseConnectionString(connectionString: string): AccessInputMeta
|
|||||||
|
|
||||||
connectionStringParts.forEach((connectionStringPart: string) => {
|
connectionStringParts.forEach((connectionStringPart: string) => {
|
||||||
if (RegExp(Constants.EndpointsRegex.sql).test(connectionStringPart)) {
|
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;
|
accessInput.apiKind = ApiKind.SQL;
|
||||||
} else if (RegExp(Constants.EndpointsRegex.mongo).test(connectionStringPart)) {
|
} else if (RegExp(Constants.EndpointsRegex.mongo).test(connectionStringPart)) {
|
||||||
const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongo);
|
const matches = connectionStringPart.match(Constants.EndpointsRegex.mongo);
|
||||||
accessInput.accountName = matches && matches.length > 1 && matches[2];
|
accessInput.accountName = matches && matches.length > 1 ? matches[2] : "";
|
||||||
accessInput.apiKind = ApiKind.MongoDB;
|
accessInput.apiKind = ApiKind.MongoDB;
|
||||||
} else if (RegExp(Constants.EndpointsRegex.mongoCompute).test(connectionStringPart)) {
|
} else if (RegExp(Constants.EndpointsRegex.mongoCompute).test(connectionStringPart)) {
|
||||||
const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongoCompute);
|
const matches = connectionStringPart.match(Constants.EndpointsRegex.mongoCompute);
|
||||||
accessInput.accountName = matches && matches.length > 1 && matches[2];
|
accessInput.accountName = matches && matches.length > 1 ? matches[2] : "";
|
||||||
accessInput.apiKind = ApiKind.MongoDBCompute;
|
accessInput.apiKind = ApiKind.MongoDBCompute;
|
||||||
} else if (Constants.EndpointsRegex.cassandra.some((regex) => RegExp(regex).test(connectionStringPart))) {
|
} else if (Constants.EndpointsRegex.cassandra.some((regex) => RegExp(regex).test(connectionStringPart))) {
|
||||||
Constants.EndpointsRegex.cassandra.forEach((regex) => {
|
Constants.EndpointsRegex.cassandra.forEach((regex) => {
|
||||||
if (RegExp(regex).test(connectionStringPart)) {
|
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;
|
accessInput.apiKind = ApiKind.Cassandra;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (RegExp(Constants.EndpointsRegex.table).test(connectionStringPart)) {
|
} 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;
|
accessInput.apiKind = ApiKind.Table;
|
||||||
} else if (connectionStringPart.indexOf("ApiKind=Gremlin") >= 0) {
|
} else if (connectionStringPart.indexOf("ApiKind=Gremlin") >= 0) {
|
||||||
accessInput.apiKind = ApiKind.Graph;
|
accessInput.apiKind = ApiKind.Graph;
|
||||||
|
|||||||
@@ -139,7 +139,11 @@
|
|||||||
"./src/userContext.test.ts",
|
"./src/userContext.test.ts",
|
||||||
"src/Common/EntityValue.tsx",
|
"src/Common/EntityValue.tsx",
|
||||||
"./src/Platform/Hosted/Components/SwitchAccount.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": [
|
"include": [
|
||||||
"src/CellOutputViewer/transforms/**/*",
|
"src/CellOutputViewer/transforms/**/*",
|
||||||
|
|||||||
Reference in New Issue
Block a user