1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 13:35:21 +02:00

Nested Categories (#1561)
Some checks failed
Publish Docker image / ci (push) Has been cancelled
Publish Docker image / Build docker image (push) Has been cancelled

* Prepare entry search for nested categories

* Subcategory implementation

* Remove caching for test stability
This commit is contained in:
Zach Gollwitzer 2024-12-20 11:37:26 -05:00 committed by GitHub
parent a4d10097d5
commit 77def1db40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 297 additions and 234 deletions

View file

@ -2,7 +2,7 @@
<% category ||= null_category %>
<div>
<span class="flex items-center gap-1 text-sm font-medium rounded-full px-1.5 py-1 border"
<span class="flex items-center gap-1 text-sm font-medium rounded-full px-1.5 py-1 border truncate"
style="
background-color: color-mix(in srgb, <%= category.color %> 5%, white);
border-color: color-mix(in srgb, <%= category.color %> 30%, white);

View file

@ -1,7 +1,11 @@
<%# locals: (category:) %>
<div id="<%= dom_id(category) %>" class="flex justify-between items-center p-4 bg-white">
<div id="<%= dom_id(category) %>" class="flex justify-between items-center px-4 pb-4 <%= "pt-4" unless category.subcategory? %> <%= "pb-4" unless category.subcategories.any? %> bg-white">
<div class="flex w-full items-center gap-2.5">
<% if category.subcategory? %>
<%= lucide_icon "corner-down-right", class: "shrink-0 w-5 h-5 text-gray-400 ml-2" %>
<% end %>
<%= render partial: "categories/badge", locals: { category: category } %>
</div>
<div class="justify-self-end">

View file

@ -1,9 +1,12 @@
<%# locals: (category:, categories:) %>
<div data-controller="color-avatar">
<%= styled_form_with model: category, class: "space-y-4", data: { turbo_frame: :_top } do |f| %>
<section class="space-y-4">
<div class="w-fit m-auto">
<%= render partial: "shared/color_avatar", locals: { name: category.name, color: category.color } %>
</div>
<div class="flex gap-2 items-center justify-center">
<% Category::COLORS.each do |color| %>
<label class="relative">
@ -12,8 +15,14 @@
</label>
<% end %>
</div>
<div class="relative flex items-center border border-gray-200 rounded-lg">
<%= f.text_field :name, placeholder: t(".placeholder"), required: true, autofocus: true, data: { color_avatar_target: "name" } %>
<% if category.errors.any? %>
<%= render "shared/form_errors", model: category %>
<% end %>
<div class="space-y-2">
<%= f.text_field :name, placeholder: t(".placeholder"), required: true, autofocus: true, label: "Name", data: { color_avatar_target: "name" } %>
<%= f.select :parent_id, categories.pluck(:name, :id), { include_blank: "(unassigned)", label: "Parent category (optional)" } %>
</div>
</section>

View file

@ -5,7 +5,7 @@
<%= render partial: "categories/badge", locals: { category: transaction.category } %>
</button>
<div data-menu-target="content" class="absolute z-10 hidden w-screen mt-2 max-w-min cursor-default">
<div class="w-64 text-sm font-semibold leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<div class="w-80 text-sm font-semibold leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<%= turbo_frame_tag "category_dropdown", src: category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id), loading: :lazy do %>
<div class="p-6 flex items-center justify-center">
<p class="text-sm text-gray-500 animate-pulse"><%= t(".loading") %></p>

View file

@ -1,3 +1,3 @@
<%= modal_form_wrapper title: t(".edit") do %>
<%= render "form", category: @category %>
<%= render "form", category: @category, categories: @categories %>
<% end %>

View file

@ -23,18 +23,32 @@
<div class="border border-alpha-black-25 rounded-md bg-white shadow-xs">
<div class="overflow-hidden rounded-md">
<%= render partial: @categories, spacer_template: "categories/ruler" %>
<% Category::Group.for(@categories).each_with_index do |group, idx| %>
<%= render group.category %>
<% group.subcategories.each do |subcategory| %>
<%= render subcategory %>
<% end %>
<% unless idx == Category::Group.for(@categories).count - 1 %>
<%= render "categories/ruler" %>
<% end %>
<% end %>
</div>
</div>
</div>
<% else %>
<div class="flex justify-center items-center py-20">
<div class="text-center flex flex-col items-center max-w-[300px]">
<p class="text-gray-900 mb-1 font-medium text-sm"><%= t(".empty") %></p>
<%= link_to new_category_path, class: "w-fit flex text-white text-sm font-medium items-center gap-1 bg-gray-900 rounded-lg p-2 pr-3", data: { turbo_frame: "modal" } do %>
<%= lucide_icon("plus", class: "w-5 h-5") %>
<span><%= t(".new") %></span>
<% end %>
<div class="text-center flex flex-col items-center max-w-[500px]">
<p class="text-sm text-gray-500 mb-4"><%= t(".empty") %></p>
<div class="flex items-center gap-2">
<%= button_to t(".bootstrap"), bootstrap_categories_path, class: "btn btn--primary" %>
<%= link_to new_category_path, class: "btn btn--outline flex items-center gap-1", data: { turbo_frame: "modal" } do %>
<%= lucide_icon("plus", class: "w-5 h-5") %>
<span><%= t(".new") %></span>
<% end %>
</div>
</div>
</div>
<% end %>

View file

@ -1,3 +1,3 @@
<%= modal_form_wrapper title: t(".new_category") do %>
<%= render "form", category: @category %>
<%= render "form", category: @category, categories: @categories %>
<% end %>