summaryrefslogtreecommitdiff
path: root/app/components
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-14 12:09:31 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-14 12:09:31 +0000
commit9769ccf613ec45634ee32efaf1c39763a759a917 (patch)
treea48a3a73458978a2e9cfe0a0e1b4ace4c7c9da53 /app/components
parent66f492cea7772633bfb6e0cb1352d90d10a67008 (diff)
downloadgitlab-ce-9769ccf613ec45634ee32efaf1c39763a759a917.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/components')
-rw-r--r--app/components/diffs/overflow_warning_component.html.haml9
-rw-r--r--app/components/diffs/overflow_warning_component.rb73
2 files changed, 82 insertions, 0 deletions
diff --git a/app/components/diffs/overflow_warning_component.html.haml b/app/components/diffs/overflow_warning_component.html.haml
new file mode 100644
index 00000000000..907d066e73d
--- /dev/null
+++ b/app/components/diffs/overflow_warning_component.html.haml
@@ -0,0 +1,9 @@
+= render Pajamas::AlertComponent.new(title: _('Too many changes to show.'),
+ variant: :warning,
+ alert_class: 'gl-mb-5') do
+ .gl-alert-body
+ = message
+
+ .gl-alert-actions
+ = diff_link
+ = patch_link
diff --git a/app/components/diffs/overflow_warning_component.rb b/app/components/diffs/overflow_warning_component.rb
new file mode 100644
index 00000000000..0d0e225beb4
--- /dev/null
+++ b/app/components/diffs/overflow_warning_component.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+module Diffs
+ class OverflowWarningComponent < BaseComponent
+ # Skipping coverage because of https://gitlab.com/gitlab-org/gitlab/-/issues/357381
+ #
+ # This is fully tested by the output in the view part of this component,
+ # but undercoverage doesn't understand the relationship between the two parts.
+ #
+ # :nocov:
+ def initialize(diffs:, diff_files:, project:, commit: nil, merge_request: nil)
+ @diffs = diffs
+ @diff_files = diff_files
+ @project = project
+ @commit = commit
+ @merge_request = merge_request
+ end
+
+ def message
+ html_escape(message_text) % {
+ display_size: @diff_files.size,
+ real_size: @diffs.real_size,
+ strong_open: '<strong>'.html_safe,
+ strong_close: '</strong>'.html_safe
+ }
+ end
+
+ def diff_link
+ text = _("Plain diff")
+
+ if commit?
+ link_to text, project_commit_path(@project, @commit, format: :diff), class: button_classes
+ elsif merge_request?
+ link_to text, merge_request_path(@merge_request, format: :diff), class: button_classes
+ end
+ end
+
+ def patch_link
+ text = _("Email patch")
+
+ if commit?
+ link_to text, project_commit_path(@project, @commit, format: :patch), class: button_classes
+ elsif merge_request?
+ link_to text, merge_request_path(@merge_request, format: :patch), class: button_classes
+ end
+ end
+
+ private
+
+ def commit?
+ current_controller?(:commit) &&
+ @commit.present?
+ end
+
+ def merge_request?
+ current_controller?("projects/merge_requests/diffs") &&
+ @merge_request.present? &&
+ @merge_request.persisted?
+ end
+
+ def message_text
+ _(
+ "To preserve performance only %{strong_open}%{display_size} " \
+ "of %{real_size}%{strong_close} files are displayed."
+ )
+ end
+
+ def button_classes
+ "btn gl-alert-action btn-default gl-button btn-default-secondary"
+ end
+ # :nocov:
+ end
+end