1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

New Design System + Codebase Refresh (#1823)

Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization.

Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to:

- Establish the brand new and simplified dashboard view (pictured above)
- Establish and move towards the conventions introduced in Cursor rules and project design overview #1788
- Consolidate layouts and improve the performance of layout queries
- Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability
- Remove stale / dead code from codebase
- Remove overly complex code paths in favor of simpler ones
This commit is contained in:
Zach Gollwitzer 2025-02-21 11:57:59 -05:00 committed by GitHub
parent 8539ac7dec
commit d75be2282b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
278 changed files with 3428 additions and 4354 deletions

View file

@ -1,46 +1,167 @@
class Period
attr_reader :name, :date_range
include ActiveModel::Validations, Comparable
attr_reader :start_date, :end_date
validates :start_date, :end_date, presence: true
validate :must_be_valid_date_range
PERIODS = {
"last_day" => {
date_range: [ 1.day.ago.to_date, Date.current ],
label_short: "1D",
label: "Last Day",
comparison_label: "vs. yesterday"
},
"current_week" => {
date_range: [ Date.current.beginning_of_week, Date.current ],
label_short: "WTD",
label: "Current Week",
comparison_label: "vs. start of week"
},
"last_7_days" => {
date_range: [ 7.days.ago.to_date, Date.current ],
label_short: "7D",
label: "Last 7 Days",
comparison_label: "vs. last week"
},
"current_month" => {
date_range: [ Date.current.beginning_of_month, Date.current ],
label_short: "MTD",
label: "Current Month",
comparison_label: "vs. start of month"
},
"last_30_days" => {
date_range: [ 30.days.ago.to_date, Date.current ],
label_short: "30D",
label: "Last 30 Days",
comparison_label: "vs. last month"
},
"last_90_days" => {
date_range: [ 90.days.ago.to_date, Date.current ],
label_short: "90D",
label: "Last 90 Days",
comparison_label: "vs. last quarter"
},
"current_year" => {
date_range: [ Date.current.beginning_of_year, Date.current ],
label_short: "YTD",
label: "Current Year",
comparison_label: "vs. start of year"
},
"last_365_days" => {
date_range: [ 365.days.ago.to_date, Date.current ],
label_short: "365D",
label: "Last 365 Days",
comparison_label: "vs. 1 year ago"
},
"last_5_years" => {
date_range: [ 5.years.ago.to_date, Date.current ],
label_short: "5Y",
label: "Last 5 Years",
comparison_label: "vs. 5 years ago"
}
}
class << self
def from_param(param)
find_by_name(param) || self.last_30_days
def default
from_key("last_30_days")
end
def find_by_name(name)
INDEX[name]
def from_key(key, fallback: false)
if PERIODS[key].present?
start_date, end_date = PERIODS[key].fetch(:date_range)
new(start_date: start_date, end_date: end_date)
else
return default if fallback
raise ArgumentError, "Invalid period key: #{key}"
end
end
def names
INDEX.keys.sort
def all
PERIODS.map { |key, period| from_key(key) }
end
end
def initialize(name: "custom", date_range:)
@name = name
@date_range = date_range
end
def extend_backward(duration)
Period.new(name: name + "_extended", date_range: (date_range.first - duration)..date_range.last)
end
BUILTIN = [
new(name: "all", date_range: nil..Date.current),
new(name: "current_week", date_range: Date.current.beginning_of_week..Date.current),
new(name: "last_7_days", date_range: 7.days.ago.to_date..Date.current),
new(name: "current_month", date_range: Date.current.beginning_of_month..Date.current),
new(name: "last_30_days", date_range: 30.days.ago.to_date..Date.current),
new(name: "current_quarter", date_range: Date.current.beginning_of_quarter..Date.current),
new(name: "last_90_days", date_range: 90.days.ago.to_date..Date.current),
new(name: "current_year", date_range: Date.current.beginning_of_year..Date.current),
new(name: "last_365_days", date_range: 365.days.ago.to_date..Date.current)
]
INDEX = BUILTIN.index_by(&:name)
BUILTIN.each do |period|
define_singleton_method(period.name) do
period
PERIODS.each do |key, period|
define_singleton_method(key) do
start_date, end_date = period.fetch(:date_range)
new(start_date: start_date, end_date: end_date)
end
end
def initialize(start_date:, end_date:, date_format: "%b %d, %Y")
@start_date = start_date
@end_date = end_date
@date_format = date_format
validate!
end
def <=>(other)
[ start_date, end_date ] <=> [ other.start_date, other.end_date ]
end
def date_range
start_date..end_date
end
def days
(end_date - start_date).to_i + 1
end
def within?(other)
start_date >= other.start_date && end_date <= other.end_date
end
def interval
if days > 90
"1 month"
else
"1 day"
end
end
def key
PERIODS.find { |_, period| period.fetch(:date_range) == [ start_date, end_date ] }&.first
end
def label
if known?
PERIODS[key].fetch(:label)
else
"Custom Period"
end
end
def label_short
if known?
PERIODS[key].fetch(:label_short)
else
"CP"
end
end
def comparison_label
if known?
PERIODS[key].fetch(:comparison_label)
else
"#{start_date.strftime(@date_format)} to #{end_date.strftime(@date_format)}"
end
end
private
def known?
key.present?
end
def must_be_valid_date_range
return if start_date.nil? || end_date.nil?
unless start_date.is_a?(Date) && end_date.is_a?(Date)
errors.add(:start_date, "must be a valid date")
errors.add(:end_date, "must be a valid date")
return
end
errors.add(:start_date, "must be before end date") if start_date > end_date
end
end