app/components/solidus_admin/ui/table/component.js in solidus_admin-0.2.0 vs app/components/solidus_admin/ui/table/component.js in solidus_admin-0.3.0

- old
+ new

@@ -102,11 +102,19 @@ if (event.target.closest("td").contains(event.target.closest("a,select,textarea,button,input,summary"))) return if (this.modeValue === "batch") { this.toggleCheckbox(event.currentTarget) } else { - window.Turbo.visit(event.params.url) + const url = new URL(event.params.url, "http://dummy.com") + const params = new URLSearchParams(url.search) + const frameId = params.get('_turbo_frame') + const frame = frameId ? { frame: frameId } : {} + // remove the custom _turbo_frame param from url search: + params.delete('_turbo_frame') + url.search = params.toString() + + window.Turbo.visit(url.pathname + url.search, frame) } } toggleCheckbox(row) { const checkbox = this.checkboxTargets.find(selection => row.contains(selection)) @@ -115,11 +123,32 @@ checkbox.checked = !checkbox.checked this.selectRow() } } + selectedRows() { + return this.checkboxTargets.filter((checkbox) => checkbox.checked) + } + + confirmAction(event) { + const message = event.params.message + .replace( + "${count}", + this.selectedRows().length + ).replace( + "${resource}", + this.selectedRows().length > 1 ? + event.params.resourcePlural : + event.params.resourceSingular + ) + + if (!confirm(message)) { + event.preventDefault() + } + } + render() { - const selectedRows = this.checkboxTargets.filter((checkbox) => checkbox.checked) + const selectedRows = this.selectedRows() if (this.hasSearchFieldTarget) { this.searchToolbarTarget.toggleAttribute("hidden", this.modeValue !== "search") }