mirror of
https://github.com/we-promise/sure.git
synced 2026-09-03 13:51:29 +00:00
chore: drop dead transactions-section preferences (#3021)
`transactions_section_controller.js` was added by #454 for the upcoming recurring-transactions section. #771 moved recurring transactions to a dedicated tab and removed the only mount, so the controller and its whole persistence chain have been dead since then: `data-controller="transactions-section"` appears nowhere in app/views or app/components, and `transactions_section_collapsed?` had no callers outside its own definition. Removed: - app/javascript/controllers/transactions_section_controller.js - User#update_transactions_preferences - User#transactions_section_collapsed? - TransactionsController#update_preferences + #preferences_params - the `patch :update_preferences` route on the transactions collection The only caller of /transactions/update_preferences was the dead controller itself. No tests referenced any of it — the `update_preferences` cases in pages_controller_test cover the dashboard's route — which is how it stayed dead unnoticed. No migration: users who collapsed a section before #771 keep a stale `transactions_collapsed_sections` key in `users.preferences`, and nothing reads it after this. The dashboard and reports section-layout preferences are untouched.
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
import { Controller } from "@hotwired/stimulus";
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["content", "chevron", "button"];
|
||||
static values = {
|
||||
sectionKey: String,
|
||||
collapsed: Boolean,
|
||||
};
|
||||
|
||||
connect() {
|
||||
if (this.collapsedValue) {
|
||||
this.collapse(false);
|
||||
}
|
||||
}
|
||||
|
||||
toggle(event) {
|
||||
event.preventDefault();
|
||||
if (this.collapsedValue) {
|
||||
this.expand();
|
||||
} else {
|
||||
this.collapse();
|
||||
}
|
||||
}
|
||||
|
||||
handleToggleKeydown(event) {
|
||||
// Handle Enter and Space keys for keyboard accessibility
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.toggle(event);
|
||||
}
|
||||
}
|
||||
|
||||
collapse(persist = true) {
|
||||
this.contentTarget.classList.add("hidden");
|
||||
this.chevronTarget.classList.add("-rotate-90");
|
||||
this.collapsedValue = true;
|
||||
if (this.hasButtonTarget) {
|
||||
this.buttonTarget.setAttribute("aria-expanded", "false");
|
||||
}
|
||||
if (persist) {
|
||||
this.savePreference(true);
|
||||
}
|
||||
}
|
||||
|
||||
expand() {
|
||||
this.contentTarget.classList.remove("hidden");
|
||||
this.chevronTarget.classList.remove("-rotate-90");
|
||||
this.collapsedValue = false;
|
||||
if (this.hasButtonTarget) {
|
||||
this.buttonTarget.setAttribute("aria-expanded", "true");
|
||||
}
|
||||
this.savePreference(false);
|
||||
}
|
||||
|
||||
async savePreference(collapsed) {
|
||||
const preferences = {
|
||||
collapsed_sections: {
|
||||
[this.sectionKeyValue]: collapsed,
|
||||
},
|
||||
};
|
||||
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]');
|
||||
if (!csrfToken) {
|
||||
console.error(
|
||||
"[Transactions Section] CSRF token not found. Cannot save preferences.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("/transactions/update_preferences", {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-CSRF-Token": csrfToken.content,
|
||||
},
|
||||
body: JSON.stringify({ preferences }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
console.error(
|
||||
"[Transactions Section] Failed to save preferences:",
|
||||
response.status,
|
||||
errorData,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"[Transactions Section] Network error saving preferences:",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user