Commit b2e31786 authored by charlieablett's avatar charlieablett Committed by Jan Provaznik

Expose epic groupings in boards

Added a new epic field to the board type.
parent d57379f8
......@@ -30,6 +30,7 @@ class EpicsFinder < IssuableFinder
def self.scalar_params
@scalar_params ||= %i[
board
parent_id
author_id
author_username
......@@ -108,6 +109,7 @@ class EpicsFinder < IssuableFinder
end
def filter_items(items)
items = in_board(items)
items = by_created_at(items)
items = by_updated_at(items)
items = by_author(items)
......@@ -154,6 +156,16 @@ class EpicsFinder < IssuableFinder
items.iid_starts_with(query)
end
def in_board(items)
board = params[:board]
return items unless board.present?
list_service = Boards::Issues::ListService.new(board.resource_parent, current_user, { board_id: board.id })
issues = list_service.execute.except(:order).pluck_primary_key
epics_in_boards = EpicIssue.where(issue: issues)
items.id_in(epics_in_boards.select("epic_id as id"))
end
def related_groups
include_ancestors = params.fetch(:include_ancestor_groups, false)
include_descendants = params.fetch(:include_descendant_groups, true)
......
......@@ -20,6 +20,10 @@ module EE
field :weight, type: GraphQL::INT_TYPE, null: true,
description: 'Weight of the board.'
field :epic_groups, ::Types::EpicType.connection_type, null: true,
description: 'Epics associated with board issues.',
resolver: ::Resolvers::BoardGroupings::EpicsResolver
end
end
end
......
# frozen_string_literal: true
module Resolvers
module BoardGroupings
class EpicsResolver < BaseResolver
type Types::EpicType, null: true
def resolve(**args)
board = object.respond_to?(:sync) ? object.sync : object
return [] unless resolver_object.present?
return [] unless epic_feature_enabled?
EpicsFinder.new(context[:current_user], args.merge(board: board)).execute
end
private
attr_reader :resolver_object
def epic_feature_enabled?
group.feature_available?(:epics)
end
end
end
end
......@@ -459,6 +459,26 @@ RSpec.describe EpicsFinder do
end
end
context 'by issue board' do
let_it_be(:epic1) { create(:epic, group: group, title: "first epic") }
let_it_be(:epic2) { create(:epic, group: group, title: "second epic") }
let_it_be(:label) { create(:group_label, group: group, name: 'some label') }
let_it_be(:project) { create(:project, namespace: group) }
let_it_be(:board) { create(:board, group: group) }
let_it_be(:label_list) { create(:list, board: board, label: label) }
let_it_be(:backlog_list) { create(:backlog_list, board: board) }
let_it_be(:issue) { create(:labeled_issue, project: project, labels: [label]) }
let_it_be(:epic_issue) { create(:epic_issue, epic: epic1, issue: issue) }
it 'returns epics that are in the board' do
params = {
board_id: board.id
}
expect(epics(params)).to contain_exactly(epic1)
end
end
context 'when using group cte for search' do
context 'and two labels more search string are present' do
let_it_be(:label1) { create(:label) }
......
......@@ -4,6 +4,6 @@ require 'spec_helper'
RSpec.describe GitlabSchema.types['Board'] do
it 'includes the ee specific fields' do
expect(described_class).to have_graphql_field('weight')
expect(described_class).to have_graphql_fields(:weight, :epic_groups)
end
end
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