forked from maybe-finance/maybe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve transaction filters and transaction focus across page visits (…
…maybe-finance#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
- Loading branch information
Showing
34 changed files
with
310 additions
and
243 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module ScrollFocusable | ||
extend ActiveSupport::Concern | ||
|
||
def set_focused_record(record_scope, record_id, default_per_page: 10) | ||
return unless record_id.present? | ||
|
||
@focused_record = record_scope.find_by(id: record_id) | ||
|
||
record_index = record_scope.pluck(:id).index(record_id) | ||
|
||
return unless record_index | ||
|
||
page_of_focused_record = (record_index / (params[:per_page]&.to_i || default_per_page)) + 1 | ||
|
||
if params[:page]&.to_i != page_of_focused_record | ||
( | ||
redirect_to(url_for(page: page_of_focused_record, focused_record_id: record_id)) | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.