settings: Use HTML table for "Alert Words" for better icon alignment.

"Alert Words" is one of Zulip's oldest settings UI elements, and as a
result is buggy.  This commit converts it to use our standard
progressive-table-wrapper system used for settings tables, which has
the side effect of fixing a bug that mad ethe tables look pretty bad
if one adds a very long word.

Fixes #17172.
This commit is contained in:
Josh Gilley 2021-02-01 19:35:51 -05:00 committed by Tim Abbott
parent 28d437672f
commit de74d2fd7c
5 changed files with 23 additions and 24 deletions

View File

@ -136,11 +136,11 @@ run_test("remove_alert_word", (override) => {
const remove_func = word_list.get_on_handler("click", ".remove-alert-word"); const remove_func = word_list.get_on_handler("click", ".remove-alert-word");
const remove_alert_word = $(".remove-alert-word"); const remove_alert_word = $(".remove-alert-word");
const list_item = $("li.alert-word-item"); const list_item = $("tr.alert-word-item");
const val_item = $("span.value"); const val_item = $("span.value");
val_item.text(i18n.t("zot")); val_item.text(i18n.t("zot"));
remove_alert_word.set_parents_result("li", list_item); remove_alert_word.set_parents_result("tr", list_item);
list_item.set_find_results(".value", val_item); list_item.set_find_results(".value", val_item);
const event = { const event = {

View File

@ -62,7 +62,6 @@ function add_alert_word(alert_word) {
function remove_alert_word(alert_word) { function remove_alert_word(alert_word) {
const words_to_be_removed = [alert_word]; const words_to_be_removed = [alert_word];
channel.del({ channel.del({
url: "/json/users/me/alert_words", url: "/json/users/me/alert_words",
data: {alert_words: JSON.stringify(words_to_be_removed)}, data: {alert_words: JSON.stringify(words_to_be_removed)},
@ -86,7 +85,7 @@ export function set_up_alert_words() {
}); });
$("#alert_words_list").on("click", ".remove-alert-word", (event) => { $("#alert_words_list").on("click", ".remove-alert-word", (event) => {
const word = $(event.currentTarget).parents("li").find(".value").text(); const word = $(event.currentTarget).parents("tr").find(".value").text().trim();
remove_alert_word(word); remove_alert_word(word);
}); });
@ -95,7 +94,6 @@ export function set_up_alert_words() {
// Handle Enter (13) as "add". // Handle Enter (13) as "add".
if (key === 13) { if (key === 13) {
event.preventDefault(); event.preventDefault();
const word = $(event.target).val(); const word = $(event.target).val();
add_alert_word(word); add_alert_word(word);
} }

View File

@ -486,13 +486,6 @@ input[type="checkbox"] {
border-left: 0; border-left: 0;
} }
.alert-word-information-box {
position: relative;
padding: 7px;
margin: 2px;
width: 50%;
}
.green-bg { .green-bg {
background-color: hsl(120, 29%, 84%); background-color: hsl(120, 29%, 84%);
} }
@ -910,7 +903,6 @@ input[type="checkbox"] {
li { li {
list-style-type: none; list-style-type: none;
&.alert-word-item:first-child { &.alert-word-item:first-child {
background: none; background: none;
margin-top: 8px; margin-top: 8px;
@ -918,7 +910,6 @@ input[type="checkbox"] {
} }
.alert_word_listing .value { .alert_word_listing .value {
display: block;
word-wrap: break-word; word-wrap: break-word;
word-break: break-all; word-break: break-all;
white-space: normal; white-space: normal;

View File

@ -27,5 +27,14 @@
</div> </div>
</div> </div>
</form> </form>
<ul id="alert_words_list"></ul> <div class="progressive-table-wrapper" data-simplebar>
<table class="table table-condensed table-striped wrapped-table">
<thead>
<th class="active">{{t "Word" }}</th>
<th>{{t "Delete" }}</th>
</thead>
<tbody id="alert_words_list" class="alert_words_list required-text thick"
data-empty="{{t 'There are no current alert words.' }}"></tbody>
</table>
</div>
</div> </div>

View File

@ -1,13 +1,14 @@
{{! Alert word in the settings page that can be removed }} {{! Alert word in the settings page that can be removed }}
<li class="alert-word-item" data-word='{{word}}'>
<div class="alert-word-information-box grey-box"> <tr class="alert-word-item" data-word='{{word}}'>
<td>
<div class="alert_word_listing"> <div class="alert_word_listing">
<span class="value">{{word}}</span> <span class="value">{{word}}</span>
</div> </div>
<div class="edit-alert-word-buttons"> </td>
<button type="submit" class="button small btn-danger remove-alert-word" title="{{t 'Delete alert word' }}" data-word="{{word}}"> <td>
<i class="fa fa-trash-o" aria-hidden="true"></i> <button type="submit" class="button rounded small delete btn-danger remove-alert-word" title="{{t 'Delete alert word' }}" data-word="{{word}}">
</button> <i class="fa fa-trash-o" aria-hidden="true"></i>
</div> </button>
</div> </td>
</li> </tr>