Commit 3be38384 authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Alex Kalderimis

Prevent epic_tree_sorting concern knowing about its implementations

This moves class specific logic out from the shared concern to the
individual implementations.

Re-organise epic tree methods

This makes sure the methods have consistent prefixes, and are grouped
togehter in source code.
parent 78852307
...@@ -5,27 +5,18 @@ module EpicTreeSorting ...@@ -5,27 +5,18 @@ module EpicTreeSorting
include FromUnion include FromUnion
include RelativePositioning include RelativePositioning
def self.implementations
@impls ||= [].to_set
end
class_methods do class_methods do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
def relative_positioning_query_base(object) def relative_positioning_query_base(object)
# Only non-root nodes are sortable. # Only non-root nodes are sortable.
return none if object.root_epic_tree_node? return none if object.epic_tree_root?
issue_type = EpicIssue.underscore from_union(EpicTreeSorting.implementations.map { |model| model.epic_tree_node_query(object) })
epic_type = Epic.underscore
issue_selection = <<~SELECT_LIST
id, relative_position, epic_id as parent_id, epic_id, '#{issue_type}' as object_type
SELECT_LIST
epic_selection = <<~SELECT_LIST
id, relative_position, parent_id, parent_id as epic_id, '#{epic_type}' as object_type
SELECT_LIST
from_union([
EpicIssue.select(issue_selection).in_epic(object.parent_ids),
Epic.select(epic_selection).in_parents(object.parent_ids)
])
end end
def relative_positioning_parent_column def relative_positioning_parent_column
...@@ -34,36 +25,38 @@ module EpicTreeSorting ...@@ -34,36 +25,38 @@ module EpicTreeSorting
override :move_nulls override :move_nulls
def move_nulls(objects, **args) def move_nulls(objects, **args)
super(objects&.reject(&:root_epic_tree_node?), **args) super(objects&.reject(&:epic_tree_root?), **args)
end end
end end
included do included do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
EpicTreeSorting.implementations << self
override :move_between override :move_between
def move_between(*) def move_between(*)
super unless root_epic_tree_node? super unless epic_tree_root?
end end
override :move_after override :move_after
def move_after(*) def move_after(*)
super unless root_epic_tree_node? super unless epic_tree_root?
end end
override :move_before override :move_before
def move_before(*) def move_before(*)
super unless root_epic_tree_node? super unless epic_tree_root?
end end
override :move_to_end override :move_to_end
def move_to_end def move_to_end
super unless root_epic_tree_node? super unless epic_tree_root?
end end
override :move_to_start override :move_to_start
def move_to_start def move_to_start
super unless root_epic_tree_node? super unless epic_tree_root?
end end
override :update_relative_siblings override :update_relative_siblings
......
...@@ -126,10 +126,18 @@ module EE ...@@ -126,10 +126,18 @@ module EE
before_save :set_fixed_start_date, if: :start_date_is_fixed? before_save :set_fixed_start_date, if: :start_date_is_fixed?
before_save :set_fixed_due_date, if: :due_date_is_fixed? before_save :set_fixed_due_date, if: :due_date_is_fixed?
def root_epic_tree_node? def epic_tree_root?
parent_id.nil? parent_id.nil?
end end
def self.epic_tree_node_query(node)
selection = <<~SELECT_LIST
id, relative_position, parent_id, parent_id as epic_id, '#{underscore}' as object_type
SELECT_LIST
select(selection).in_parents(node.parent_ids)
end
private private
def set_fixed_start_date def set_fixed_start_date
......
...@@ -18,10 +18,18 @@ class EpicIssue < ApplicationRecord ...@@ -18,10 +18,18 @@ class EpicIssue < ApplicationRecord
validate :validate_confidential_epic validate :validate_confidential_epic
def root_epic_tree_node? def epic_tree_root?
false false
end end
def self.epic_tree_node_query(node)
selection = <<~SELECT_LIST
id, relative_position, epic_id as parent_id, epic_id, '#{underscore}' as object_type
SELECT_LIST
select(selection).in_epic(node.parent_ids)
end
private private
def validate_confidential_epic def validate_confidential_epic
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment