Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Add confirmation dialog to delete code playgrounds.

Ganesh Pawar92b4bb7ffc04
diff --git a/frontend_tests/puppeteer_tests/realm-playground.ts b/frontend_tests/puppeteer_tests/realm-playground.ts
index 1dd84b10e74..ec5b31a571c 100644
--- a/frontend_tests/puppeteer_tests/realm-playground.ts
+++ b/frontend_tests/puppeteer_tests/realm-playground.ts
@@ -74,6 +74,11 @@ async function test_invalid_playground_parameters(page: Page): Promise<void> {
async function test_successful_playground_deletion(page: Page): Promise<void> {
await page.click(".playground_row button.delete");
+
+ await common.wait_for_micromodal_to_open(page);
+ await page.click("#confirm_delete_code_playgrounds_modal .dialog_submit_button");
+ await common.wait_for_micromodal_to_close(page);
+
await page.waitForSelector(".playground_row", {hidden: true});
}
diff --git a/static/js/settings_playgrounds.js b/static/js/settings_playgrounds.js
index c4f3bd6f805..5f8453d415a 100644
--- a/static/js/settings_playgrounds.js
+++ b/static/js/settings_playgrounds.js
@@ -1,8 +1,11 @@
import $ from "jquery";
+import render_confirm_delete_playground from "../templates/confirm_dialog/confirm_delete_playground.hbs";
import render_admin_playground_list from "../templates/settings/admin_playground_list.hbs";
import * as channel from "./channel";
+import * as confirm_dialog from "./confirm_dialog";
+import * as dialog_widget from "./dialog_widget";
import {$t_html} from "./i18n";
import * as ListWidget from "./list_widget";
import {page_params} from "./page_params";
@@ -95,14 +98,16 @@ function build_page() {
e.preventDefault();
e.stopPropagation();
const $btn = $(this);
-
- channel.del({
- url: "/json/realm/playgrounds/" + encodeURIComponent($btn.attr("data-playground-id")),
- error(xhr) {
- ui_report.generic_row_button_error(xhr, $btn);
- },
- // There is no need for an on-success action here since the row is removed by the
- // `realm_playgrounds` events handler which builds the playground list again.
+ const url =
+ "/json/realm/playgrounds/" + encodeURIComponent($btn.attr("data-playground-id"));
+ const html_body = render_confirm_delete_playground();
+
+ confirm_dialog.launch({
+ html_heading: $t_html({defaultMessage: "Delete code playground?"}),
+ html_body,
+ id: "confirm_delete_code_playgrounds_modal",
+ on_click: () => dialog_widget.submit_api_request(channel.del, url),
+ loading_spinner: true,
});
});
diff --git a/static/templates/confirm_dialog/confirm_delete_playground.hbs b/static/templates/confirm_dialog/confirm_delete_playground.hbs
new file mode 100644
index 00000000000..890b3b29168
--- /dev/null
+++ b/static/templates/confirm_dialog/confirm_delete_playground.hbs
@@ -0,0 +1,2 @@
+<p>{{t "This action cannot be undone."}}</p>
+