2020-05-13 15:08:23 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Types
|
|
|
|
module DesignManagement
|
|
|
|
module DesignFields
|
|
|
|
include BaseInterface
|
|
|
|
|
|
|
|
field_class Types::BaseField
|
|
|
|
|
2021-08-25 15:11:14 +00:00
|
|
|
field :id, GraphQL::Types::ID, description: 'ID of this design.', null: false
|
|
|
|
field :project, Types::ProjectType, null: false, description: 'Project the design belongs to.'
|
|
|
|
field :issue, Types::IssueType, null: false, description: 'Issue the design belongs to.'
|
|
|
|
field :filename, GraphQL::Types::String, null: false, description: 'Filename of the design.'
|
|
|
|
field :full_path, GraphQL::Types::String, null: false, description: 'Full path to the design file.'
|
|
|
|
field :image, GraphQL::Types::String, null: false, extras: [:parent], description: 'URL of the full-sized image.'
|
2021-07-22 09:08:22 +00:00
|
|
|
field :image_v432x230, GraphQL::Types::String, null: true, extras: [:parent],
|
2020-05-13 15:08:23 +00:00
|
|
|
description: 'The URL of the design resized to fit within the bounds of 432x230. ' \
|
|
|
|
'This will be `null` if the image has not been generated'
|
|
|
|
field :diff_refs, Types::DiffRefsType,
|
|
|
|
null: false,
|
|
|
|
calls_gitaly: true,
|
|
|
|
extras: [:parent],
|
2021-08-25 15:11:14 +00:00
|
|
|
description: 'Diff refs for this design.'
|
2020-05-13 15:08:23 +00:00
|
|
|
field :event, Types::DesignManagement::DesignVersionEventEnum,
|
|
|
|
null: false,
|
|
|
|
extras: [:parent],
|
2021-01-22 21:09:10 +00:00
|
|
|
description: 'How this design was changed in the current version.'
|
2020-05-13 15:08:23 +00:00
|
|
|
field :notes_count,
|
2021-07-22 09:08:22 +00:00
|
|
|
GraphQL::Types::Int,
|
2020-05-13 15:08:23 +00:00
|
|
|
null: false,
|
|
|
|
method: :user_notes_count,
|
2021-08-25 15:11:14 +00:00
|
|
|
description: 'Total count of user-created notes for this design.'
|
2020-05-13 15:08:23 +00:00
|
|
|
|
|
|
|
def diff_refs(parent:)
|
|
|
|
version = cached_stateful_version(parent)
|
|
|
|
version.diff_refs
|
|
|
|
end
|
|
|
|
|
|
|
|
def image(parent:)
|
|
|
|
sha = cached_stateful_version(parent).sha
|
|
|
|
|
|
|
|
Gitlab::UrlBuilder.build(design, ref: sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
def image_v432x230(parent:)
|
|
|
|
version = cached_stateful_version(parent)
|
|
|
|
action = design.actions.up_to_version(version).most_recent.first
|
|
|
|
|
|
|
|
# A `nil` return value indicates that the image has not been processed
|
|
|
|
return unless action.image_v432x230.file
|
|
|
|
|
|
|
|
Gitlab::UrlBuilder.build(design, ref: version.sha, size: :v432x230)
|
|
|
|
end
|
|
|
|
|
|
|
|
def event(parent:)
|
|
|
|
version = cached_stateful_version(parent)
|
|
|
|
|
|
|
|
action = cached_actions_for_version(version)[design.id]
|
|
|
|
|
|
|
|
action&.event || ::Types::DesignManagement::DesignVersionEventEnum::NONE
|
|
|
|
end
|
|
|
|
|
|
|
|
def cached_actions_for_version(version)
|
|
|
|
Gitlab::SafeRequestStore.fetch(['DesignFields', 'actions_for_version', version.id]) do
|
2022-02-28 15:13:55 +00:00
|
|
|
version.actions.index_by(&:design_id)
|
2020-05-13 15:08:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
|
|
|
::Gitlab::Graphql::Loaders::BatchModelLoader.new(::Project, design.project_id).find
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue
|
|
|
|
::Gitlab::Graphql::Loaders::BatchModelLoader.new(::Issue, design.issue_id).find
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|