2021-05-06 04:56:03 +05:30
|
|
|
import { Text, TextField } from "@fluentui/react";
|
2021-05-19 08:27:31 +05:30
|
|
|
import { useBoolean } from "@fluentui/react-hooks";
|
2021-10-12 20:08:34 +05:30
|
|
|
import { Areas } from "Common/Constants";
|
|
|
|
import DeleteFeedback from "Common/DeleteFeedback";
|
|
|
|
import { getErrorMessage, getErrorStack } from "Common/ErrorHandlingUtils";
|
2023-06-21 15:04:36 -07:00
|
|
|
import { deleteDatabase } from "Common/dataAccess/deleteDatabase";
|
2021-10-12 20:08:34 +05:30
|
|
|
import { Collection, Database } from "Contracts/ViewModels";
|
|
|
|
import { DefaultExperienceUtility } from "Shared/DefaultExperienceUtility";
|
|
|
|
import { Action, ActionModifiers } from "Shared/Telemetry/TelemetryConstants";
|
|
|
|
import * as TelemetryProcessor from "Shared/Telemetry/TelemetryProcessor";
|
|
|
|
import { userContext } from "UserContext";
|
|
|
|
import { logConsoleError } from "Utils/NotificationConsoleUtils";
|
2023-06-21 15:04:36 -07:00
|
|
|
import { useSidePanel } from "hooks/useSidePanel";
|
|
|
|
import { useTabs } from "hooks/useTabs";
|
|
|
|
import React, { FunctionComponent, useState } from "react";
|
2021-06-18 11:25:08 -07:00
|
|
|
import { useDatabases } from "../useDatabases";
|
2021-06-24 11:56:33 -07:00
|
|
|
import { useSelectedNode } from "../useSelectedNode";
|
2021-04-01 04:14:07 +05:30
|
|
|
import { PanelInfoErrorComponent, PanelInfoErrorProps } from "./PanelInfoErrorComponent";
|
2021-05-19 08:27:31 +05:30
|
|
|
import { RightPaneForm, RightPaneFormProps } from "./RightPaneForm/RightPaneForm";
|
2021-04-01 04:14:07 +05:30
|
|
|
|
|
|
|
interface DeleteDatabaseConfirmationPanelProps {
|
2021-07-08 21:32:22 -07:00
|
|
|
refreshDatabases: () => Promise<void>;
|
2021-04-01 04:14:07 +05:30
|
|
|
}
|
|
|
|
|
2021-05-19 08:27:31 +05:30
|
|
|
export const DeleteDatabaseConfirmationPanel: FunctionComponent<DeleteDatabaseConfirmationPanelProps> = ({
|
2021-07-08 21:32:22 -07:00
|
|
|
refreshDatabases,
|
2021-05-19 08:27:31 +05:30
|
|
|
}: DeleteDatabaseConfirmationPanelProps): JSX.Element => {
|
2021-05-27 16:07:07 -05:00
|
|
|
const closeSidePanel = useSidePanel((state) => state.closeSidePanel);
|
2021-06-18 11:25:08 -07:00
|
|
|
const isLastNonEmptyDatabase = useDatabases((state) => state.isLastNonEmptyDatabase);
|
2021-04-01 04:14:07 +05:30
|
|
|
const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false);
|
|
|
|
|
|
|
|
const [formError, setFormError] = useState<string>("");
|
|
|
|
const [databaseInput, setDatabaseInput] = useState<string>("");
|
|
|
|
const [databaseFeedbackInput, setDatabaseFeedbackInput] = useState<string>("");
|
2021-07-08 21:32:22 -07:00
|
|
|
const selectedDatabase: Database = useDatabases.getState().findSelectedDatabase();
|
2021-04-01 04:14:07 +05:30
|
|
|
|
2021-05-19 08:27:31 +05:30
|
|
|
const submit = async (): Promise<void> => {
|
2021-04-01 04:14:07 +05:30
|
|
|
if (selectedDatabase?.id() && databaseInput !== selectedDatabase.id()) {
|
2023-06-21 15:04:36 -07:00
|
|
|
setFormError(
|
|
|
|
`Input database name "${databaseInput}" does not match the selected database "${selectedDatabase.id()}"`
|
|
|
|
);
|
2021-04-01 04:14:07 +05:30
|
|
|
logConsoleError(`Error while deleting collection ${selectedDatabase && selectedDatabase.id()}`);
|
2023-06-21 15:04:36 -07:00
|
|
|
logConsoleError(
|
|
|
|
`Input database name "${databaseInput}" does not match the selected database "${selectedDatabase.id()}"`
|
|
|
|
);
|
2021-04-01 04:14:07 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
setFormError("");
|
|
|
|
setLoadingTrue();
|
|
|
|
|
|
|
|
const startKey: number = TelemetryProcessor.traceStart(Action.DeleteDatabase, {
|
|
|
|
databaseId: selectedDatabase.id(),
|
|
|
|
dataExplorerArea: Areas.ContextualPane,
|
|
|
|
paneTitle: "Delete Database",
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
await deleteDatabase(selectedDatabase.id());
|
2021-05-27 16:07:07 -05:00
|
|
|
closeSidePanel();
|
2021-07-08 21:32:22 -07:00
|
|
|
refreshDatabases();
|
|
|
|
useTabs.getState().closeTabsByComparator((tab) => tab.node?.id() === selectedDatabase.id());
|
2021-06-24 11:56:33 -07:00
|
|
|
useSelectedNode.getState().setSelectedNode(undefined);
|
2021-04-01 04:14:07 +05:30
|
|
|
selectedDatabase
|
|
|
|
.collections()
|
|
|
|
.forEach((collection: Collection) =>
|
2021-07-08 21:32:22 -07:00
|
|
|
useTabs
|
|
|
|
.getState()
|
|
|
|
.closeTabsByComparator(
|
|
|
|
(tab) =>
|
|
|
|
tab.node?.id() === collection.id() && (tab.node as Collection).databaseId === collection.databaseId
|
|
|
|
)
|
2021-04-01 04:14:07 +05:30
|
|
|
);
|
|
|
|
TelemetryProcessor.traceSuccess(
|
|
|
|
Action.DeleteDatabase,
|
|
|
|
{
|
|
|
|
databaseId: selectedDatabase.id(),
|
|
|
|
dataExplorerArea: Areas.ContextualPane,
|
|
|
|
paneTitle: "Delete Database",
|
|
|
|
},
|
|
|
|
startKey
|
|
|
|
);
|
|
|
|
|
2021-06-18 11:25:08 -07:00
|
|
|
if (isLastNonEmptyDatabase()) {
|
2021-04-01 04:14:07 +05:30
|
|
|
const deleteFeedback = new DeleteFeedback(
|
|
|
|
userContext?.databaseAccount.id,
|
|
|
|
userContext?.databaseAccount.name,
|
2021-04-29 00:55:04 +05:30
|
|
|
DefaultExperienceUtility.getApiKindFromDefaultExperience(userContext.apiType),
|
2021-04-01 04:14:07 +05:30
|
|
|
databaseFeedbackInput
|
|
|
|
);
|
|
|
|
|
|
|
|
TelemetryProcessor.trace(Action.DeleteDatabase, ActionModifiers.Mark, {
|
|
|
|
message: JSON.stringify(deleteFeedback, Object.getOwnPropertyNames(deleteFeedback)),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
setLoadingFalse();
|
|
|
|
const errorMessage = getErrorMessage(error);
|
2023-01-13 14:06:24 -05:00
|
|
|
setFormError(errorMessage);
|
2021-04-01 04:14:07 +05:30
|
|
|
TelemetryProcessor.traceFailure(
|
|
|
|
Action.DeleteDatabase,
|
|
|
|
{
|
|
|
|
databaseId: selectedDatabase.id(),
|
|
|
|
dataExplorerArea: Areas.ContextualPane,
|
|
|
|
paneTitle: "Delete Database",
|
|
|
|
error: errorMessage,
|
|
|
|
errorStack: getErrorStack(error),
|
|
|
|
},
|
|
|
|
startKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-19 08:27:31 +05:30
|
|
|
const props: RightPaneFormProps = {
|
|
|
|
formError,
|
|
|
|
isExecuting: isLoading,
|
|
|
|
submitButtonText: "OK",
|
|
|
|
onSubmit: () => submit(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const errorProps: PanelInfoErrorProps = {
|
|
|
|
messageType: "warning",
|
|
|
|
showErrorDetails: false,
|
|
|
|
message:
|
|
|
|
"Warning! The action you are about to take cannot be undone. Continuing will permanently delete this resource and all of its children resources.",
|
|
|
|
};
|
2021-09-17 02:53:29 +05:30
|
|
|
const confirmDatabase = "Confirm by typing the database id";
|
|
|
|
const reasonInfo = "Help us improve Azure Cosmos DB! What is the reason why you are deleting this database?";
|
2021-04-01 04:14:07 +05:30
|
|
|
return (
|
2021-05-19 08:27:31 +05:30
|
|
|
<RightPaneForm {...props}>
|
|
|
|
{!formError && <PanelInfoErrorComponent {...errorProps} />}
|
2021-04-01 04:14:07 +05:30
|
|
|
<div className="panelMainContent">
|
|
|
|
<div className="confirmDeleteInput">
|
|
|
|
<span className="mandatoryStar">* </span>
|
|
|
|
<Text variant="small">Confirm by typing the database id</Text>
|
|
|
|
<TextField
|
|
|
|
id="confirmDatabaseId"
|
|
|
|
autoFocus
|
|
|
|
styles={{ fieldGroup: { width: 300 } }}
|
|
|
|
onChange={(event, newInput?: string) => {
|
|
|
|
setDatabaseInput(newInput);
|
|
|
|
}}
|
2021-09-17 02:53:29 +05:30
|
|
|
ariaLabel={confirmDatabase}
|
2021-04-01 04:14:07 +05:30
|
|
|
/>
|
|
|
|
</div>
|
2021-06-18 11:25:08 -07:00
|
|
|
{isLastNonEmptyDatabase() && (
|
2021-04-01 04:14:07 +05:30
|
|
|
<div className="deleteDatabaseFeedback">
|
|
|
|
<Text variant="small" block>
|
|
|
|
Help us improve Azure Cosmos DB!
|
|
|
|
</Text>
|
|
|
|
<Text variant="small" block>
|
|
|
|
What is the reason why you are deleting this database?
|
|
|
|
</Text>
|
|
|
|
<TextField
|
|
|
|
id="deleteDatabaseFeedbackInput"
|
|
|
|
styles={{ fieldGroup: { width: 300 } }}
|
|
|
|
multiline
|
|
|
|
rows={3}
|
|
|
|
onChange={(event, newInput?: string) => {
|
|
|
|
setDatabaseFeedbackInput(newInput);
|
|
|
|
}}
|
2021-09-17 02:53:29 +05:30
|
|
|
ariaLabel={reasonInfo}
|
2021-04-01 04:14:07 +05:30
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-05-19 08:27:31 +05:30
|
|
|
</RightPaneForm>
|
2021-04-01 04:14:07 +05:30
|
|
|
);
|
|
|
|
};
|