settings: Use url_template for internal names.

This replaces any "url_format_string" or "url_format" with
"url_template" for the linkifier settings, including HTML ids, template
variables, and etc.

This is not affected by any external API changes.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li 2022-10-05 16:52:26 -04:00 committed by Tim Abbott
parent 6f42542320
commit 05a3456581
6 changed files with 31 additions and 40 deletions

View File

@ -26,10 +26,7 @@ async function test_add_linkifier(page: Page): Promise<void> {
"#(?P<id>[0-9]+)",
);
assert.strictEqual(
await common.get_text_from_selector(
page,
".linkifier_row span.linkifier_url_format_string",
),
await common.get_text_from_selector(page, ".linkifier_row span.linkifier_url_template"),
"https://trac.example.com/ticket/{id}",
);
}
@ -74,10 +71,7 @@ async function test_edit_linkifier(page: Page): Promise<void> {
() => document.querySelector(".linkifier_pattern")?.textContent === "(?P<num>[0-9a-f]{40})",
);
assert.strictEqual(
await common.get_text_from_selector(
page,
".linkifier_row span.linkifier_url_format_string",
),
await common.get_text_from_selector(page, ".linkifier_row span.linkifier_url_template"),
"https://trac.example.com/commit/{num}",
);
}
@ -102,13 +96,13 @@ async function test_edit_invalid_linkifier(page: Page): Promise<void> {
"Failed: Bad regular expression: bad repetition operator: ????",
);
const edit_linkifier_format_status_selector = "div#edit-linkifier-format-status";
await page.waitForSelector(edit_linkifier_format_status_selector, {visible: true});
const edit_linkifier_format_status = await common.get_text_from_selector(
const edit_linkifier_template_status_selector = "div#edit-linkifier-template-status";
await page.waitForSelector(edit_linkifier_template_status_selector, {visible: true});
const edit_linkifier_template_status = await common.get_text_from_selector(
page,
edit_linkifier_format_status_selector,
edit_linkifier_template_status_selector,
);
assert.strictEqual(edit_linkifier_format_status, "Failed: Invalid URL template.");
assert.strictEqual(edit_linkifier_template_status, "Failed: Invalid URL template.");
await page.click(".dialog_cancel_button");
await page.waitForSelector("#dialog_widget_modal", {hidden: true});
@ -119,10 +113,7 @@ async function test_edit_invalid_linkifier(page: Page): Promise<void> {
"(?P<num>[0-9a-f]{40})",
);
assert.strictEqual(
await common.get_text_from_selector(
page,
".linkifier_row span.linkifier_url_format_string",
),
await common.get_text_from_selector(page, ".linkifier_row span.linkifier_url_template"),
"https://trac.example.com/commit/{num}",
);
}

View File

@ -51,7 +51,7 @@ function open_linkifier_edit_form(linkifier_id) {
const html_body = render_admin_linkifier_edit_form({
linkifier_id,
pattern: linkifier.pattern,
url_format_string: linkifier.url_template,
url_template: linkifier.url_template,
});
function submit_linkifier_form() {
@ -61,10 +61,10 @@ function open_linkifier_edit_form(linkifier_id) {
const $modal = $("#dialog_widget_modal");
const url = "/json/realm/filters/" + encodeURIComponent(linkifier_id);
const pattern = $modal.find("#edit-linkifier-pattern").val().trim();
const url_format_string = $modal.find("#edit-linkifier-url-format-string").val().trim();
const data = {pattern, url_format_string};
const url_template = $modal.find("#edit-linkifier-url-template").val().trim();
const data = {pattern, url_template};
const $pattern_status = $modal.find("#edit-linkifier-pattern-status").expectOne();
const $format_status = $modal.find("#edit-linkifier-format-status").expectOne();
const $template_status = $modal.find("#edit-linkifier-template-status").expectOne();
const $dialog_error_element = $modal.find("#dialog_error").expectOne();
const opts = {
success_continuation() {
@ -78,7 +78,7 @@ function open_linkifier_edit_form(linkifier_id) {
handle_linkifier_api_error(
xhr,
$pattern_status,
$format_status,
$template_status,
$dialog_error_element,
);
} else {
@ -109,7 +109,7 @@ function open_linkifier_edit_form(linkifier_id) {
});
}
function handle_linkifier_api_error(xhr, pattern_status, format_status, linkifier_status) {
function handle_linkifier_api_error(xhr, pattern_status, template_status, linkifier_status) {
// The endpoint uses the Django ValidationError system for error
// handling, which returns somewhat complicated error
// dictionaries. This logic parses them.
@ -120,7 +120,7 @@ function handle_linkifier_api_error(xhr, pattern_status, format_status, linkifie
}
if (errors.url_template !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.url_template});
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, format_status);
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, template_status);
}
if (errors.__all__ !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.__all__});
@ -140,7 +140,7 @@ export function populate_linkifiers(linkifiers_data) {
return render_admin_linkifier_list({
linkifier: {
pattern: linkifier.pattern,
url_format_string: linkifier.url_template,
url_template: linkifier.url_template,
id: linkifier.id,
},
can_modify: page_params.is_admin,
@ -211,12 +211,12 @@ export function build_page() {
e.stopPropagation();
const $linkifier_status = $("#admin-linkifier-status");
const $pattern_status = $("#admin-linkifier-pattern-status");
const $format_status = $("#admin-linkifier-format-status");
const $template_status = $("#admin-linkifier-template-status");
const $add_linkifier_button = $(".new-linkifier-form button");
$add_linkifier_button.prop("disabled", true);
$linkifier_status.hide();
$pattern_status.hide();
$format_status.hide();
$template_status.hide();
const linkifier = {};
for (const obj of $(this).serializeArray()) {
@ -228,7 +228,7 @@ export function build_page() {
data: $(this).serialize(),
success(data) {
$("#linkifier_pattern").val("");
$("#linkifier_format_string").val("");
$("#linkifier_template").val("");
$add_linkifier_button.prop("disabled", false);
linkifier.id = data.id;
ui_report.success(
@ -241,7 +241,7 @@ export function build_page() {
handle_linkifier_api_error(
xhr,
$pattern_status,
$format_status,
$template_status,
$linkifier_status,
);
},

View File

@ -246,7 +246,7 @@ h3,
#linkifier-settings {
#linkifier_pattern,
#linkifier_format_string {
#linkifier_template {
width: calc(100% - 10em - 6em);
}
}
@ -726,7 +726,7 @@ input[type="checkbox"] {
}
#admin-linkifier-pattern-status,
#admin-linkifier-format-status {
#admin-linkifier-template-status {
margin: 20px 0 0;
}
@ -1899,7 +1899,7 @@ $option_title_width: 180px;
#edit-linkifier-form {
#edit-linkifier-pattern,
#edit-linkifier-url-format-string {
#edit-linkifier-url-template {
width: 400px;
}
@ -1908,7 +1908,7 @@ $option_title_width: 180px;
}
#edit-linkifier-pattern-status,
#edit-linkifier-format-status {
#edit-linkifier-template-status {
margin-top: 10px;
}

View File

@ -6,9 +6,9 @@
<div class="alert" id="edit-linkifier-pattern-status"></div>
</div>
<div class="input-group name_change_container">
<label for="edit-linkifier-url-format-string" >{{t "URL template" }}</label>
<input type="text" autocomplete="off" id="edit-linkifier-url-format-string" name="url_template" placeholder="https://github.com/zulip/zulip/issues/{id}" value="{{ url_format_string }}" />
<div class="alert" id="edit-linkifier-format-status"></div>
<label for="edit-linkifier-url-template" >{{t "URL template" }}</label>
<input type="text" autocomplete="off" id="edit-linkifier-url-template" name="url_template" placeholder="https://github.com/zulip/zulip/issues/{id}" value="{{ url_template }}" />
<div class="alert" id="edit-linkifier-template-status"></div>
</div>
</form>
</div>

View File

@ -4,7 +4,7 @@
<span class="linkifier_pattern">{{pattern}}</span>
</td>
<td>
<span class="linkifier_url_format_string">{{url_format_string}}</span>
<span class="linkifier_url_template">{{url_template}}</span>
</td>
{{#if ../can_modify}}
<td class="no-select actions">

View File

@ -44,9 +44,9 @@
<div class="alert" id="admin-linkifier-pattern-status"></div>
</div>
<div class="input-group">
<label for="linkifier_format_string">{{t "URL template" }}</label>
<input type="text" id="linkifier_format_string" name="url_template" placeholder="https://github.com/zulip/zulip/issues/{id}" />
<div class="alert" id="admin-linkifier-format-status"></div>
<label for="linkifier_template">{{t "URL template" }}</label>
<input type="text" id="linkifier_template" name="url_template" placeholder="https://github.com/zulip/zulip/issues/{id}" />
<div class="alert" id="admin-linkifier-template-status"></div>
</div>
<button type="submit" class="button rounded sea-green">
{{t 'Add linkifier' }}