Skip to content

Commit ab06960

Browse files
committed
extract shared component methods to Projects::Phases::Shared
1 parent 391a218 commit ab06960

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

app/components/projects/phase_component.rb

+1-15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
module Projects
3131
class PhaseComponent < ApplicationComponent
3232
include OpPrimer::ComponentHelpers
33+
include Projects::Phases::Shared
3334

3435
def initialize(phase:, **)
3536
@phase = phase
@@ -61,21 +62,6 @@ def display_finish_gate?
6162
phase.finish_gate? && phase.finish_date.present?
6263
end
6364

64-
def self.gate_icon
65-
:"op-gate"
66-
end
67-
delegate :gate_icon, to: :class
68-
69-
def self.icon_color_class(definition_id)
70-
# FIXME: this is a workaround so that this class method can be called from another component
71-
helper = Object.new.extend(ColorsHelper)
72-
helper.hl_inline_class("project_phase_definition", definition_id)
73-
end
74-
75-
def icon_color_class
76-
self.class.icon_color_class(phase.definition_id)
77-
end
78-
7965
def hover_card_data_args(gate:)
8066
raise ArgumentError, "gate must be either :start or :finish" unless %i[start finish].include?(gate)
8167

app/components/projects/phases/hover_card_component.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details.
3535
f.with_column(classes: "op-phase-gate-hover-card--name flex-self-start") do
3636
flex_layout do |fl|
3737
fl.with_column(classes: icon_color_class, mr: 1) do
38-
render Primer::Beta::Octicon.new(icon: Projects::PhaseComponent.gate_icon)
38+
render Primer::Beta::Octicon.new(icon: gate_icon)
3939
end
4040
fl.with_column do
4141
render(Primer::Beta::Text.new(data: { test_selector: "phase-gate-hover-card-name" })) { phase_gate_name }

app/components/projects/phases/hover_card_component.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Projects
3232
module Phases
3333
class HoverCardComponent < ApplicationComponent
3434
include OpPrimer::ComponentHelpers
35+
include Projects::Phases::Shared
3536

3637
attr_reader :phase
3738

@@ -63,10 +64,6 @@ def phase_gate_date
6364

6465
helpers.format_date(date)
6566
end
66-
67-
def icon_color_class
68-
Projects::PhaseComponent.icon_color_class(@phase.definition.id)
69-
end
7067
end
7168
end
7269
end
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Projects
32+
module Phases
33+
module Shared
34+
def gate_icon = :"op-gate"
35+
36+
def icon_color_class
37+
helpers.hl_inline_class("project_phase_definition", phase.definition_id)
38+
end
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)