Skip to content

Commit a1cb5b9

Browse files
committed
use component for global and project definition administration
1 parent d6ae767 commit a1cb5b9

File tree

10 files changed

+62
-105
lines changed

10 files changed

+62
-105
lines changed

app/components/projects/life_cycle_component.html.erb

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%= flex_layout(align_items: :center) do |type_container|
2+
type_container.with_column(classes: icon_color_class, mr: 1) do
3+
render Primer::Beta::Octicon.new(icon: icon)
4+
end
5+
type_container.with_column(test_selector: "project-life-cycle-step-definition-name", classes: "ellipsis") do
6+
if edit_link?
7+
render(Primer::Beta::Link.new(href: phase_href, **phase_text_options)) { phase_text }
8+
else
9+
render(Primer::Beta::Text.new(**phase_text_options)) { phase_text }
10+
end
11+
end
12+
type_container.with_column(ml: 2, classes: "no-wrap") do
13+
render(Primer::Beta::Text.new(**gates_text_options)) { gates_text }
14+
end
15+
end %>

app/components/projects/life_cycle_component.rb renamed to app/components/projects/phase_definition_component.rb

+21-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@
2828
# See COPYRIGHT and LICENSE files for more details.
2929
# ++
3030
module Projects
31-
class LifeCycleComponent < ApplicationComponent
31+
class PhaseDefinitionComponent < ApplicationComponent
3232
include OpPrimer::ComponentHelpers
3333

3434
# TODO: This component is currently not in use! It should be a shared component
3535
# between the Projects::Settings::LifeCycleSteps::StepComponent and the
3636
# Settings::ProjectLifeCycleStepDefinitions::RowComponent.
3737
# It should hold the icon, definition name and gate text information.
38-
def text
38+
def phase_text
39+
model.name
40+
end
41+
42+
def phase_href
43+
edit_admin_settings_project_phase_definition_path(model)
44+
end
45+
46+
def gates_text
3947
if model.start_gate? && model.finish_gate?
4048
I18n.t("settings.project_phase_definitions.both_gate")
4149
elsif model.start_gate?
@@ -52,14 +60,22 @@ def icon
5260
end
5361

5462
def icon_color_class
55-
helpers.hl_inline_class("project_phase_definition", model)
63+
helpers.hl_inline_class("project_phase_definition", model.id)
5664
end
5765

58-
def text_options
66+
def gates_text_options
5967
# The tag: :div is is a hack to fix the line height difference
6068
# caused by font_size: :small. That line height difference
6169
# would otherwise lead to the text being not on the same height as the icon
62-
{ color: :muted, font_size: :small, tag: :div }.merge(options)
70+
{ color: :muted, font_size: :small, tag: :div }.merge(options[:gates_text_options] || {})
71+
end
72+
73+
def phase_text_options
74+
{ font_weight: :bold }.merge(options[:phase_text_options] || {})
75+
end
76+
77+
def edit_link?
78+
options[:edit_link]
6379
end
6480
end
6581
end

app/components/projects/settings/life_cycle_steps/step_component.html.erb

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
align_items: :center,
44
justify_content: :space_between
55
) do |step_container|
6-
step_container.with_column(flex_layout: true, mr: 2, classes: "min-width-0") do |title_container|
7-
title_container.with_column(pt: 1, mr: 1, classes: icon_color_class) do
8-
render Primer::Beta::Octicon.new(icon: icon)
9-
end
10-
title_container.with_column(pt: 1, mr: 2, classes: "ellipsis") do
11-
render(Primer::Beta::Text.new(classes: "filter-target-visible-text")) { definition.name }
12-
end
13-
title_container.with_column(pt: 1, classes: "no-wrap") do
14-
render(Primer::Beta::Text.new(**gate_text_options)) { gate_info }
15-
end
6+
step_container.with_column(mr: 2, classes: "min-width-0") do
7+
render(
8+
Projects::PhaseDefinitionComponent.new(
9+
definition,
10+
edit_link: User.current.admin?,
11+
phase_text_options: { classes: "filter-target-visible-text" }
12+
)
13+
)
1614
end
1715
# py: 1 quick fix: prevents the row from bouncing as the toggle switch currently changes height while toggling
1816
step_container.with_column(py: 1, mr: 2) do

app/components/projects/settings/life_cycle_steps/step_component.rb

-26
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,6 @@ class StepComponent < ApplicationComponent
3737
options :definition,
3838
:active?
3939

40-
# TODO: Remove these helper methods once the Projects::LifeCycleComponent
41-
# has been refactored.
42-
def icon
43-
:"op-phase"
44-
end
45-
46-
def icon_color_class
47-
helpers.hl_inline_class("project_phase_definition", definition)
48-
end
49-
50-
def gate_info
51-
if definition.start_gate? && definition.finish_gate?
52-
I18n.t("settings.project_phase_definitions.both_gate")
53-
elsif definition.start_gate?
54-
I18n.t("settings.project_phase_definitions.start_gate")
55-
elsif definition.finish_gate?
56-
I18n.t("settings.project_phase_definitions.finish_gate")
57-
else
58-
I18n.t("settings.project_phase_definitions.no_gate")
59-
end
60-
end
61-
62-
def gate_text_options
63-
{ color: :muted, font_size: :small }.merge(options)
64-
end
65-
6640
def toggle_aria_label
6741
I18n.t("projects.settings.life_cycle.step.use_in_project", step: definition.name)
6842
end

app/components/settings/project_life_cycle_step_definitions/row_component.html.erb

+7-21
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,14 @@ See COPYRIGHT and LICENSE files for more details.
3939
)
4040
end
4141
end
42-
title_container.with_column(classes: icon_color_class) do
43-
render Primer::Beta::Octicon.new(icon: icon)
44-
end
45-
title_container.with_column(classes: "ellipsis", test_selector: "project-life-cycle-step-definition-name") do
46-
render(
47-
if allowed_to_customize_life_cycle?
48-
Primer::Beta::Link.new(
49-
classes: "filter-target-visible-text",
50-
href: edit_admin_settings_project_phase_definition_path(definition),
51-
font_weight: :bold
52-
)
53-
else
54-
Primer::Beta::Text.new(
55-
font_weight: :bold
56-
)
57-
end
58-
) do
59-
definition.name
60-
end
61-
end
6242
title_container.with_column do
63-
render(Primer::Beta::Text.new(**gate_text_options)) { gate_info }
43+
render(
44+
Projects::PhaseDefinitionComponent.new(
45+
definition,
46+
edit_link: allowed_to_customize_life_cycle?,
47+
phase_text_options: { classes: "filter-target-visible-text" }
48+
)
49+
)
6450
end
6551
title_container.with_column(classes: "no-wrap") do
6652
render(Primer::Beta::Text.new) { t("project.count", count: definition.project_count) }

app/components/settings/project_life_cycle_step_definitions/row_component.rb

-26
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,6 @@ class RowComponent < ApplicationComponent
3939
options :first?,
4040
:last?
4141

42-
# TODO: Remove these helper classes once the Projects::LifeCycleComponent
43-
# has been refactored.
44-
def icon
45-
:"op-phase"
46-
end
47-
48-
def icon_color_class
49-
helpers.hl_inline_class("project_phase_definition", definition)
50-
end
51-
52-
def gate_info
53-
if definition.start_gate? && definition.finish_gate?
54-
I18n.t("settings.project_phase_definitions.both_gate")
55-
elsif definition.start_gate?
56-
I18n.t("settings.project_phase_definitions.start_gate")
57-
elsif definition.finish_gate?
58-
I18n.t("settings.project_phase_definitions.finish_gate")
59-
else
60-
I18n.t("settings.project_phase_definitions.no_gate")
61-
end
62-
end
63-
64-
def gate_text_options
65-
{ color: :muted, font_size: :small }.merge(options)
66-
end
67-
6842
private
6943

7044
def move_action(menu:, move_to:, label:, icon:)

lookbook/previews/open_project/projects/life_cycle_component_preview/phase.html.erb

-6
This file was deleted.

lookbook/previews/open_project/projects/life_cycle_component_preview.rb renamed to lookbook/previews/open_project/projects/phase_definition_component_preview.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
module OpenProject
3232
module Projects
3333
# @logical_path OpenProject/Projects
34-
class LifeCycleComponentPreview < Lookbook::Preview
34+
class PhaseDefinitionComponentPreview < Lookbook::Preview
35+
# @param edit_link [boolean]
3536
# @param start_gate [boolean]
3637
# @param finish_gate [boolean]
37-
def phase(start_gate: false, finish_gate: false)
38+
def phase(edit_link: false, start_gate: false, finish_gate: false)
3839
model = Project::PhaseDefinition.new(id: 1, name: "The first phase", start_gate:, finish_gate:)
39-
render_with_template(locals: { model: })
40+
41+
render_with_template(locals: { model:, edit_link: })
4042
end
4143
end
4244
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- Depends on having the color defined in the highlighting/styles.css.erb file. -->
2+
<style>
3+
.__hl_inline_project_phase_definition_1 { color: red; }
4+
</style>
5+
6+
<%= render(::Projects::PhaseDefinitionComponent.new(model, edit_link:)) %>

0 commit comments

Comments
 (0)