bot-url: Reset to blank state when integration type is changed.

If the integration type is changed in the modal, resets the values
for the stream, topic and events parameters to a blank state.
This commit is contained in:
sujal 2024-03-22 16:31:39 +05:30 committed by Tim Abbott
parent fbcf31c9e0
commit 6ee354ddd6
1 changed files with 21 additions and 5 deletions

View File

@ -35,6 +35,7 @@ export function show_generate_integration_url_modal(api_key: string): void {
let selected_integration = ""; let selected_integration = "";
let stream_input_dropdown_widget: DropdownWidget; let stream_input_dropdown_widget: DropdownWidget;
let integration_input_dropdown_widget: DropdownWidget; let integration_input_dropdown_widget: DropdownWidget;
let previous_selected_integration = "";
const $override_topic = $("#integration-url-override-topic"); const $override_topic = $("#integration-url-override-topic");
const $topic_input = $<HTMLInputElement>("input#integration-url-topic-input"); const $topic_input = $<HTMLInputElement>("input#integration-url-topic-input");
@ -87,6 +88,9 @@ export function show_generate_integration_url_modal(api_key: string): void {
function update_url(render_events = false): void { function update_url(render_events = false): void {
selected_integration = integration_input_dropdown_widget.value()!.toString(); selected_integration = integration_input_dropdown_widget.value()!.toString();
if (previous_selected_integration !== selected_integration) {
reset_to_blank_state();
}
if (selected_integration === default_integration_option.unique_id) { if (selected_integration === default_integration_option.unique_id) {
$("#integration-url-stream_widget").prop("disabled", true); $("#integration-url-stream_widget").prop("disabled", true);
$integration_url.text(default_url_message); $integration_url.text(default_url_message);
@ -94,6 +98,8 @@ export function show_generate_integration_url_modal(api_key: string): void {
return; return;
} }
$("#integration-url-stream_widget").prop("disabled", false); $("#integration-url-stream_widget").prop("disabled", false);
previous_selected_integration = selected_integration;
const stream_id = stream_input_dropdown_widget.value(); const stream_id = stream_input_dropdown_widget.value();
const topic_name = $topic_input.val()!; const topic_name = $topic_input.val()!;
@ -104,11 +110,6 @@ export function show_generate_integration_url_modal(api_key: string): void {
if (all_event_types !== null) { if (all_event_types !== null) {
$("#integration-events-parameter").removeClass("hide"); $("#integration-events-parameter").removeClass("hide");
} else {
$("#integration-events-parameter").addClass("hide");
$("#integrations-event-container").addClass("hide");
$("#integrations-event-options").empty();
$show_integration_events.prop("checked", false);
} }
if ($show_integration_events.prop("checked") && render_events) { if ($show_integration_events.prop("checked") && render_events) {
@ -251,6 +252,21 @@ export function show_generate_integration_url_modal(api_key: string): void {
} }
return false; return false;
} }
function reset_to_blank_state(): void {
$("#integration-events-parameter").addClass("hide");
$("#integrations-event-container").addClass("hide");
$("#integrations-event-options").empty();
$("#integrations-event-container .integration-event").prop("checked", false);
$show_integration_events.prop("checked", false);
$override_topic.prop("checked", false).prop("disabled", true);
$override_topic.closest(".input-group").addClass("control-label-disabled");
$topic_input.val("");
$topic_input.parent().addClass("hide");
stream_input_dropdown_widget.render(direct_messages_option.unique_id);
}
} }
dialog_widget.launch({ dialog_widget.launch({