Commit cd40c625 authored by Savas Vedova's avatar Savas Vedova

Merge branch 'fix-disabled-buttons-tooltips' into 'master'

Fix disabled copy to clipboard and view comments buttons tooltips

See merge request gitlab-org/gitlab!55080
parents e9048ecc abd2da17
...@@ -62,6 +62,7 @@ export default class BlobViewer { ...@@ -62,6 +62,7 @@ export default class BlobViewer {
this.switcher = document.querySelector('.js-blob-viewer-switcher'); this.switcher = document.querySelector('.js-blob-viewer-switcher');
this.switcherBtns = document.querySelectorAll('.js-blob-viewer-switch-btn'); this.switcherBtns = document.querySelectorAll('.js-blob-viewer-switch-btn');
this.copySourceBtn = document.querySelector('.js-copy-blob-source-btn'); this.copySourceBtn = document.querySelector('.js-copy-blob-source-btn');
this.copySourceBtnTooltip = document.querySelector('.js-copy-blob-source-btn-tooltip');
this.simpleViewer = this.$fileHolder[0].querySelector('.blob-viewer[data-type="simple"]'); this.simpleViewer = this.$fileHolder[0].querySelector('.blob-viewer[data-type="simple"]');
this.richViewer = this.$fileHolder[0].querySelector('.blob-viewer[data-type="rich"]'); this.richViewer = this.$fileHolder[0].querySelector('.blob-viewer[data-type="rich"]');
...@@ -109,23 +110,23 @@ export default class BlobViewer { ...@@ -109,23 +110,23 @@ export default class BlobViewer {
toggleCopyButtonState() { toggleCopyButtonState() {
if (!this.copySourceBtn) return; if (!this.copySourceBtn) return;
if (this.simpleViewer.getAttribute('data-loaded')) { if (this.simpleViewer.getAttribute('data-loaded')) {
this.copySourceBtn.setAttribute('title', __('Copy file contents')); this.copySourceBtnTooltip.setAttribute('title', __('Copy file contents'));
this.copySourceBtn.classList.remove('disabled'); this.copySourceBtn.classList.remove('disabled');
} else if (this.activeViewer === this.simpleViewer) { } else if (this.activeViewer === this.simpleViewer) {
this.copySourceBtn.setAttribute( this.copySourceBtnTooltip.setAttribute(
'title', 'title',
__('Wait for the file to load to copy its contents'), __('Wait for the file to load to copy its contents'),
); );
this.copySourceBtn.classList.add('disabled'); this.copySourceBtn.classList.add('disabled');
} else { } else {
this.copySourceBtn.setAttribute( this.copySourceBtnTooltip.setAttribute(
'title', 'title',
__('Switch to the source to copy the file contents'), __('Switch to the source to copy the file contents'),
); );
this.copySourceBtn.classList.add('disabled'); this.copySourceBtn.classList.add('disabled');
} }
fixTitle($(this.copySourceBtn)); fixTitle($(this.copySourceBtnTooltip));
} }
switchToViewer(name) { switchToViewer(name) {
......
...@@ -235,7 +235,9 @@ module BlobHelper ...@@ -235,7 +235,9 @@ module BlobHelper
def copy_blob_source_button(blob) def copy_blob_source_button(blob)
return unless blob.rendered_as_text?(ignore_errors: false) return unless blob.rendered_as_text?(ignore_errors: false)
clipboard_button(target: ".blob-content[data-blob-id='#{blob.id}'] > pre", class: "btn gl-button btn-default btn-icon js-copy-blob-source-btn", title: _("Copy file contents")) content_tag(:span, class: 'btn-group has-tooltip js-copy-blob-source-btn-tooltip') do
clipboard_button(target: ".blob-content[data-blob-id='#{blob.id}'] > pre", class: "btn gl-button btn-default btn-icon js-copy-blob-source-btn", hide_tooltip: true)
end
end end
def open_raw_blob_button(blob) def open_raw_blob_button(blob)
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
- unless diff_file.submodule? - unless diff_file.submodule?
.file-actions.d-none.d-sm-block .file-actions.d-none.d-sm-block
- if diff_file.blob&.readable_text? - if diff_file.blob&.readable_text?
= link_to '#', class: 'js-toggle-diff-comments btn gl-button active has-tooltip', title: _("Toggle comments for this file"), disabled: @diff_notes_disabled do %span.has-tooltip{ title: _("Toggle comments for this file") }
= link_to '#', class: 'js-toggle-diff-comments btn gl-button active', disabled: @diff_notes_disabled do
= sprite_icon('comment') = sprite_icon('comment')
\ \
- if editable_diff?(diff_file) - if editable_diff?(diff_file)
......
...@@ -85,9 +85,11 @@ describe('Blob viewer', () => { ...@@ -85,9 +85,11 @@ describe('Blob viewer', () => {
describe('copy blob button', () => { describe('copy blob button', () => {
let copyButton; let copyButton;
let copyButtonTooltip;
beforeEach(() => { beforeEach(() => {
copyButton = document.querySelector('.js-copy-blob-source-btn'); copyButton = document.querySelector('.js-copy-blob-source-btn');
copyButtonTooltip = document.querySelector('.js-copy-blob-source-btn-tooltip');
}); });
it('disabled on load', () => { it('disabled on load', () => {
...@@ -95,7 +97,7 @@ describe('Blob viewer', () => { ...@@ -95,7 +97,7 @@ describe('Blob viewer', () => {
}); });
it('has tooltip when disabled', () => { it('has tooltip when disabled', () => {
expect(copyButton.getAttribute('title')).toBe( expect(copyButtonTooltip.getAttribute('title')).toBe(
'Switch to the source to copy the file contents', 'Switch to the source to copy the file contents',
); );
}); });
...@@ -131,7 +133,7 @@ describe('Blob viewer', () => { ...@@ -131,7 +133,7 @@ describe('Blob viewer', () => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click(); document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
setImmediate(() => { setImmediate(() => {
expect(copyButton.getAttribute('title')).toBe('Copy file contents'); expect(copyButtonTooltip.getAttribute('title')).toBe('Copy file contents');
done(); done();
}); });
......
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