Skip to content

Commit 4e9d006

Browse files
authored
Merge pull request #23792 from opf/bug/dream-726-add-blankslate-for-favorited-projects-when-there-are-none
[DREAM-726] Add blankslate for favorited projects when there are none
2 parents 291cedb + 7768d20 commit 4e9d006

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

app/views/header/projects/index.html.erb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ See COPYRIGHT and LICENSE files for more details.
3434
test_selector: "op-header-project-select--list" }
3535
)
3636
) do |tree| %>
37-
<% @tree.each do |node| %>
38-
<%= render Header::Projects::NodeComponent.new(
39-
component: tree,
40-
node:,
41-
current_project_id: @current_project_id,
42-
favorited_ids: @favorited_ids,
43-
jump: @jump
44-
) %>
37+
<% if @tree.empty? && params[:filter_mode] == "favorited" && params[:query].blank? %>
38+
<% tree.with_leaf(
39+
label: t("header.project_select_component.no_favorite_projects"),
40+
disabled: true,
41+
data: { test_selector: "op-header-project-select--no-favourites" }
42+
) %>
43+
<% else %>
44+
<% @tree.each do |node| %>
45+
<%= render Header::Projects::NodeComponent.new(
46+
component: tree,
47+
node:,
48+
current_project_id: @current_project_id,
49+
favorited_ids: @favorited_ids,
50+
jump: @jump
51+
) %>
52+
<% end %>
4553
<% end %>
4654
<% end %>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,6 +3608,7 @@ en:
36083608
all_projects: "All projects"
36093609
favorites: "Favorites"
36103610
leave_project: "Leave project"
3611+
no_favorite_projects: "You have no favorite projects."
36113612
title: "Projects"
36123613

36133614
toggle_switch:

spec/controllers/header/projects_controller_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
end
3939

4040
describe "#index" do
41+
render_views
4142
shared_let(:parent_project) { create(:project, name: "Alpha Parent") }
4243
shared_let(:child_project) { create(:project, name: "Beta Child", parent: parent_project) }
4344
shared_let(:other_project) { create(:project, name: "Gamma Other") }
@@ -117,6 +118,20 @@
117118
make_request
118119
expect(assigns(:projects)).to be_empty
119120
end
121+
122+
it "renders the no-favourites placeholder" do
123+
make_request
124+
expect(response.body).to include("op-header-project-select--no-favourites")
125+
end
126+
127+
context "when a query is present" do
128+
subject(:make_request) { get :index, params: { filter_mode: "favorited", query: "Alpha" } }
129+
130+
it "does not render the no-favourites placeholder" do
131+
make_request
132+
expect(response.body).not_to include("op-header-project-select--no-favourites")
133+
end
134+
end
120135
end
121136

122137
context "when the user is anonymous" do

0 commit comments

Comments
 (0)