Skip to content
代码片段 群组 项目
未验证 提交 a1d0f65f 编辑于 作者: Thomas Randolph's avatar Thomas Randolph 提交者: GitLab
浏览文件

Add button for the diff file header options menu

[Rapid Diffs]
上级 1b0a935a
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
import { ExpandLinesAdapter } from '~/rapid_diffs/expand_lines/adapter'; import { ExpandLinesAdapter } from '~/rapid_diffs/expand_lines/adapter';
import { OptionsMenuAdapter } from '~/rapid_diffs/options_menu/adapter';
import { ToggleFileAdapter } from '~/rapid_diffs/toggle_file/adapter'; import { ToggleFileAdapter } from '~/rapid_diffs/toggle_file/adapter';
const RAPID_DIFFS_VIEWERS = { const RAPID_DIFFS_VIEWERS = {
...@@ -6,7 +7,7 @@ const RAPID_DIFFS_VIEWERS = { ...@@ -6,7 +7,7 @@ const RAPID_DIFFS_VIEWERS = {
text_parallel: 'text_parallel', text_parallel: 'text_parallel',
}; };
const COMMON_ADAPTERS = [ExpandLinesAdapter, ToggleFileAdapter]; const COMMON_ADAPTERS = [ExpandLinesAdapter, OptionsMenuAdapter, ToggleFileAdapter];
export const VIEWER_ADAPTERS = { export const VIEWER_ADAPTERS = {
[RAPID_DIFFS_VIEWERS.text_inline]: COMMON_ADAPTERS, [RAPID_DIFFS_VIEWERS.text_inline]: COMMON_ADAPTERS,
......
import Vue from 'vue';
import { GlDisclosureDropdown } from '@gitlab/ui';
export const OptionsMenuAdapter = {
clicks: {
toggleOptionsMenu(event) {
const button = event.target.closest('.js-options-button');
if (!this.sink.optionsMenu) {
this.sink.optionsMenu = new Vue({
el: Vue.version.startsWith('2') ? button : button.parentElement,
name: 'GlDisclosureDropdown',
render: (createElement = Vue.h) =>
createElement(GlDisclosureDropdown, {
props: {
icon: 'ellipsis_v',
startOpened: true,
noCaret: true,
category: 'tertiary',
size: 'small',
},
}),
});
}
},
},
};
...@@ -48,3 +48,6 @@ ...@@ -48,3 +48,6 @@
%span.rd-lines-removed %span.rd-lines-removed
%span>= "−".html_safe %span>= "−".html_safe
%span{ "data-testid" => "js-file-deletion-line" }= @diff_file.removed_lines %span{ "data-testid" => "js-file-deletion-line" }= @diff_file.removed_lines
.rd-diff-file-options-menu.gl-ml-2
.js-options-menu
= render Pajamas::ButtonComponent.new(category: :tertiary, size: :small, icon: 'ellipsis_v', button_options: { class: 'js-options-button', data: { click: 'toggleOptionsMenu' }, aria: { label: _('Options') } })
import { DiffFile } from '~/rapid_diffs/diff_file';
import { OptionsMenuAdapter } from '~/rapid_diffs/options_menu/adapter';
describe('Diff File Options Menu', () => {
const html = `
<diff-file data-viewer="any">
<div class="rd-diff-file">
<div class="rd-diff-file-header" data-testid="rd-diff-file-header">
<div class="rd-diff-file-options-menu gl-ml-2">
<div class="js-options-menu">
<button class="js-options-button" data-click="toggleOptionsMenu" type="button"></button>
</div>
</div>
</div>
<div data-file-body=""><!-- body content --></div>
<diff-file-mounted></diff-file-mounted>
</diff-file>
`;
function get(element) {
const elements = {
file: () => document.querySelector('diff-file'),
container: () => get('file').querySelector('.js-options-menu'),
serverButton: () => get('container').querySelector('.js-options-button'),
vueButton: () => get('container').querySelector('[data-testid="base-dropdown-toggle"]'),
};
return elements[element]?.();
}
function assignAdapter(customAdapter) {
get('file').adapterConfig = { any: [customAdapter] };
}
beforeAll(() => {
customElements.define('diff-file', DiffFile);
});
beforeEach(() => {
document.body.innerHTML = html;
assignAdapter(OptionsMenuAdapter);
get('file').mount();
});
it('starts with the server-rendered button', () => {
expect(get('serverButton')).not.toBeNull();
});
it('replaces the server-rendered button with a Vue GlDisclosureDropdown when the button is clicked', () => {
const button = get('serverButton');
expect(get('vueButton')).toBeNull();
expect(button).not.toBeNull();
button.click();
expect(get('vueButton')).not.toBeNull();
/*
* This button being replaced also means this replacement can only
* happen once (desireable!), so testing that it's no longer present is good
*/
expect(get('serverButton')).toBeNull();
});
});
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册