mirror of
https://github.com/sissbruecker/linkding.git
synced 2026-02-28 06:53:12 +08:00
Disable bulk execute button when no bookmarks selected (#1241)
* feat: disable execute button when no bookmarks selected in bulk edit * format --------- Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
@@ -82,6 +82,7 @@ class BookmarkPage extends HeadlessElement {
|
||||
this.querySelectorAll(".bulk-edit-checkbox:not(.all) input"),
|
||||
);
|
||||
this.selectAcross = this.querySelector("label.select-across");
|
||||
this.executeButton = this.querySelector("button[name='bulk_execute']");
|
||||
|
||||
// Add listeners
|
||||
this.activeToggle.addEventListener("click", this.onToggleBulkEdit);
|
||||
@@ -97,6 +98,7 @@ class BookmarkPage extends HeadlessElement {
|
||||
checkbox.checked = false;
|
||||
});
|
||||
this.updateSelectAcross(false);
|
||||
this.updateExecuteButton();
|
||||
|
||||
// Update total number of bookmarks
|
||||
const totalHolder = this.querySelector("[data-bookmarks-total]");
|
||||
@@ -119,6 +121,7 @@ class BookmarkPage extends HeadlessElement {
|
||||
checkbox.checked = allChecked;
|
||||
});
|
||||
this.updateSelectAcross(allChecked);
|
||||
this.updateExecuteButton();
|
||||
}
|
||||
|
||||
onToggleBookmark() {
|
||||
@@ -127,6 +130,7 @@ class BookmarkPage extends HeadlessElement {
|
||||
});
|
||||
this.allCheckbox.checked = allChecked;
|
||||
this.updateSelectAcross(allChecked);
|
||||
this.updateExecuteButton();
|
||||
}
|
||||
|
||||
updateSelectAcross(allChecked) {
|
||||
@@ -137,6 +141,13 @@ class BookmarkPage extends HeadlessElement {
|
||||
this.selectAcross.querySelector("input").checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
updateExecuteButton() {
|
||||
const anyChecked = this.bookmarkCheckboxes.some((checkbox) => {
|
||||
return checkbox.checked;
|
||||
});
|
||||
this.executeButton.disabled = !anyChecked;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("ld-bookmark-page", BookmarkPage);
|
||||
|
||||
@@ -319,3 +319,32 @@ class BookmarkPageBulkEditE2ETestCase(LinkdingE2ETestCase):
|
||||
expect(
|
||||
self.locate_bulk_edit_bar().get_by_text("All 70 bookmarks")
|
||||
).to_be_visible()
|
||||
|
||||
def test_execute_button_is_disabled_when_no_bookmarks_selected(self):
|
||||
self.setup_numbered_bookmarks(5)
|
||||
|
||||
url = reverse("linkding:bookmarks.index")
|
||||
self.open(url)
|
||||
|
||||
self.locate_bulk_edit_toggle().click()
|
||||
|
||||
execute_button = self.locate_bulk_edit_bar().get_by_text("Execute")
|
||||
|
||||
# Execute button should be disabled by default
|
||||
expect(execute_button).to_be_disabled()
|
||||
|
||||
# Check a single bookmark - execute button should be enabled
|
||||
self.locate_bookmark("Bookmark 1").locator("label.bulk-edit-checkbox").click()
|
||||
expect(execute_button).to_be_enabled()
|
||||
|
||||
# Uncheck the bookmark - execute button should be disabled again
|
||||
self.locate_bookmark("Bookmark 1").locator("label.bulk-edit-checkbox").click()
|
||||
expect(execute_button).to_be_disabled()
|
||||
|
||||
# Check all bookmarks - execute button should be enabled
|
||||
self.locate_bulk_edit_select_all().click()
|
||||
expect(execute_button).to_be_enabled()
|
||||
|
||||
# Uncheck all bookmarks - execute button should be disabled again
|
||||
self.locate_bulk_edit_select_all().click()
|
||||
expect(execute_button).to_be_disabled()
|
||||
|
||||
Reference in New Issue
Block a user