Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node-select): Display order and seperator style #2877

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/assets/stylesheets/alchemy/node-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@
align-items: center;
height: 21px;

.icon {
> alchemy-icon {
margin: 0 8px 0 4px;
}

.icon {
.select2-highlighted & {
fill: $white;
}
}
}

.node-select--node-display_name,
.node-select--node-ancestors {
display: inline-flex;
align-items: center;
}

.node-select--node-name {
font-weight: bold;
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/api/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
@nodes = Node.all
@nodes = @nodes.includes(:parent)
@nodes = @nodes.where(language_id: params[:language_id]) if params[:language_id]
@nodes = @nodes.ransack(params[:filter]).result
@nodes = @nodes.ransack(params[:filter]).result.order(:lft)

if params[:page]
@nodes = @nodes.page(params[:page]).per(params[:per_page])
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/alchemy_admin/components/node_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class NodeSelect extends RemoteSelect {
*/
_renderListEntry(node) {
const ancestors = node.ancestors.map((a) => a.name)
const seperator = `<alchemy-icon name="arrow-right-s"></alchemy-icon>`

return `
<div class="node-select--node">
<alchemy-icon name="menu-2"></alchemy-icon>
<div class="node-select--node-display_name">
<span class="node-select--node-ancestors">
${ancestors.join(" /&nbsp;")}
${ancestors.length > 0 ? ancestors.join(seperator) + seperator : ""}
</span>
<span class="node-select--node-name">
${node.name}
Expand Down
3 changes: 2 additions & 1 deletion app/views/alchemy/admin/nodes/_page_nodes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<th class="tools"></th>
</tr>
<% nodes = @page.nodes.select(&:persisted?) %>
<% seperator = '<alchemy-icon name="arrow-right-s" style="vertical-align: text-bottom"></alchemy-icon>' %>
<% if nodes.length > 0 %>
<% nodes.each do |node| %>
<tr class="even">
<td><%= "#{node.ancestors.map(&:name).join(" / ")} / #{node.name}" %></td>
<td><%== "#{node.ancestors.map(&:name).join(seperator)}#{seperator}<strong>#{node.name}</strong>" %></td>
<td class="tools">
<sl-tooltip content="<%= Alchemy.t("delete_node") %>">
<%= link_to render_icon(:minus),
Expand Down
4 changes: 2 additions & 2 deletions spec/features/admin/nodes_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_menu_item
add_menu_item

within "#page_nodes table" do
expect(page).to have_content("Menu node Menu / A Page 1")
expect(page).to have_content("Menu node MenuA Page 1")
end
within "[panel='nodes']" do
expect(page).to have_content("(1) Menu node")
Expand Down Expand Up @@ -59,7 +59,7 @@ def add_menu_item
end

within "#page_nodes table" do
expect(page).to_not have_content("Menu node Menu / A Page 1")
expect(page).to_not have_content("Menu node MenuA Page 1")
expect(page).to have_content(Alchemy.t("No menu node for this page found"))
end
within "[panel='nodes']" do
Expand Down
18 changes: 11 additions & 7 deletions spec/requests/alchemy/api/nodes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Alchemy
context "with nodes present" do
let!(:node) { create(:alchemy_node, name: "lol") }
let!(:node2) { create(:alchemy_node, name: "yup") }
let!(:node3) { create(:alchemy_node, name: "foo", parent: node) }

let(:result) { JSON.parse(response.body) }

it "returns JSON" do
Expand All @@ -26,19 +28,21 @@ module Alchemy
expect(result).to have_key("data")
end

it "returns all nodes" do
it "returns all nodes ordered by nesting" do
get alchemy.api_nodes_path(params: {format: :json})

expect(result["data"].size).to eq(2)
expect(result["data"].size).to eq(3)
expect(result["data"][0]).to match(hash_including("id" => node.id))
expect(result["data"][1]).to match(hash_including("id" => node3.id))
expect(result["data"][2]).to match(hash_including("id" => node2.id))
end

it "includes meta data" do
get alchemy.api_nodes_path(params: {format: :json})

expect(result["data"].size).to eq(2)
expect(result["data"].size).to eq(3)
expect(result["meta"]["page"]).to eq(1)
expect(result["meta"]["per_page"]).to eq(2)
expect(result["meta"]["total_count"]).to eq(2)
expect(result["meta"]["per_page"]).to eq(3)
expect(result["meta"]["total_count"]).to eq(3)
end

context "with page param given" do
Expand All @@ -52,7 +56,7 @@ module Alchemy
expect(result["data"].size).to eq(1)
expect(result["meta"]["page"]).to eq(2)
expect(result["meta"]["per_page"]).to eq(1)
expect(result["meta"]["total_count"]).to eq(2)
expect(result["meta"]["total_count"]).to eq(3)
end
end

Expand Down