Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Show icon to add/remove favorite on index

Oliver Günthere5413aa88fc9
diff --git a/app/components/_index.sass b/app/components/_index.sass
index eca561ec0d4..df5d51df72f 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -4,3 +4,4 @@
@import "open_project/common/attribute_component"
@import "filters_component"
@import "projects/settings/project_custom_field_sections/index_component"
+@import "projects/row_component"
diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb
index 5f598cd13f4..a7c6482ac74 100644
--- a/app/components/projects/row_component.rb
+++ b/app/components/projects/row_component.rb
@@ -45,9 +45,23 @@ module Projects
end
def favored
- if favored_project_ids.include?(project.id)
- render(Primer::Beta::Octicon.new(icon: "star-fill", classes: "op-primer--star-icon", "aria-label": I18n.t(:label_favoured)))
- end
+ render(Primer::Beta::IconButton.new(
+ icon: currently_favored? ? "star-fill" : "star",
+ scheme: :invisible,
+ mobile_icon: currently_favored? ? "star-fill" : "star",
+ size: :medium,
+ tag: :a,
+ href: helpers.build_favorite_path(project, format: :html),
+ data: { method: currently_favored? ? :delete : :post },
+ classes: currently_favored? ? "op-primer--star-icon " : "op-project-row-component--favorite",
+ label: currently_favored? ? I18n.t(:button_unfavorite) : I18n.t(:button_favorite),
+ aria: { label: currently_favored? ? I18n.t(:button_unfavorite) : I18n.t(:button_favorite) },
+ test_selector: 'project-list-favorite-button'
+ ))
+ end
+
+ def currently_favored?
+ @currently_favored ||= favored_project_ids.include?(project.id)
end
def column_value(column)
@@ -146,7 +160,7 @@ module Projects
end
def row_css_class
- classes = %w[basics context-menu--reveal]
+ classes = %w[basics context-menu--reveal op-project-row-component]
classes << project_css_classes
classes << row_css_level_classes
diff --git a/app/components/projects/row_component.sass b/app/components/projects/row_component.sass
new file mode 100644
index 00000000000..aec8e467e33
--- /dev/null
+++ b/app/components/projects/row_component.sass
@@ -0,0 +1,6 @@
+.op-project-row-component
+ &--favorite
+ opacity: 0
+
+ &:hover &--favorite
+ opacity: 1
diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erb
index 0948e687bba..7e0378d0424 100644
--- a/app/components/projects/table_component.html.erb
+++ b/app/components/projects/table_component.html.erb
@@ -65,7 +65,7 @@ See COPYRIGHT and LICENSE files for more details.
<div class="generic-table--sort-header">
<span>
<% if column.attribute == :favored %>
- <%= render(Primer::Beta::Octicon.new(icon: "star-fill", color: :subtle, "aria-label": I18n.t(:label_favoured))) %>
+ <%= render(Primer::Beta::Octicon.new(icon: "star-fill", color: :subtle, ml: 2, "aria-label": I18n.t(:label_favoured))) %>
<% else %>
<%= column.caption %>
<% end %>
diff --git a/frontend/src/global_styles/primer/_icons.sass b/frontend/src/global_styles/primer/_icons.sass
index 1ff09da718e..78048aee542 100644
--- a/frontend/src/global_styles/primer/_icons.sass
+++ b/frontend/src/global_styles/primer/_icons.sass
@@ -28,5 +28,6 @@
// Adjustments for icons
-.op-primer--star-icon
+.op-primer--star-icon,
+.Button--invisible.Button--iconOnly.op-primer--star-icon svg
color: var(--color-scale-yellow-2) !important