mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 14:19:39 +02:00
Preserve transaction filters and transaction focus across page visits (#1733)
* Preserve transaction filters across page visits * Preserve params when per_page is updated * Autofocus selected transactions * Lint fixes * Fix syntax error * Fix filter clearing * Update e2e tests for new UI * Consolidate focus behavior into concern * Lint fixes
This commit is contained in:
parent
0b17976256
commit
282c05345d
34 changed files with 310 additions and 243 deletions
21
app/javascript/controllers/focus_record_controller.js
Normal file
21
app/javascript/controllers/focus_record_controller.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Controller } from "@hotwired/stimulus";
|
||||
|
||||
// Connects to data-controller="focus-record"
|
||||
export default class extends Controller {
|
||||
static values = {
|
||||
id: String,
|
||||
};
|
||||
|
||||
connect() {
|
||||
const element = document.getElementById(this.idValue);
|
||||
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: "smooth" });
|
||||
|
||||
// Remove the focused_record_id parameter from URL
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.delete("focused_record_id");
|
||||
window.history.replaceState({}, "", url);
|
||||
}
|
||||
}
|
||||
}
|
20
app/javascript/controllers/selectable_link_controller.js
Normal file
20
app/javascript/controllers/selectable_link_controller.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { Controller } from "@hotwired/stimulus";
|
||||
|
||||
// Connects to data-controller="selectable-link"
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.element.addEventListener("change", this.handleChange.bind(this));
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.element.removeEventListener("change", this.handleChange.bind(this));
|
||||
}
|
||||
|
||||
handleChange(event) {
|
||||
const paramName = this.element.name;
|
||||
const currentUrl = new URL(window.location.href);
|
||||
currentUrl.searchParams.set(paramName, event.target.value);
|
||||
|
||||
Turbo.visit(currentUrl.toString());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue