diff options
Diffstat (limited to 'app/assets/javascripts/pages/projects/merge_requests')
4 files changed, 130 insertions, 0 deletions
diff --git a/app/assets/javascripts/pages/projects/merge_requests/edit/index.js b/app/assets/javascripts/pages/projects/merge_requests/edit/index.js index ec21d8c84e0..5179d1b31ab 100644 --- a/app/assets/javascripts/pages/projects/merge_requests/edit/index.js +++ b/app/assets/javascripts/pages/projects/merge_requests/edit/index.js @@ -1,5 +1,74 @@ +import createFlash from '~/flash'; +import axios from '~/lib/utils/axios_utils'; +import { __ } from '~/locale'; + +import { GitLabDropdown } from '~/deprecated_jquery_dropdown/gl_dropdown'; + import initMergeRequest from '~/pages/projects/merge_requests/init_merge_request'; import initCheckFormState from './check_form_state'; +import initFormUpdate from './update_form'; + +function initTargetBranchSelector() { + const targetBranch = document.querySelector('.js-target-branch'); + const { selected, fieldName, refsUrl } = targetBranch?.dataset ?? {}; + const formField = document.querySelector(`input[name="${fieldName}"]`); + + if (targetBranch && refsUrl && formField) { + /* eslint-disable-next-line no-new */ + new GitLabDropdown(targetBranch, { + selectable: true, + filterable: true, + filterRemote: Boolean(refsUrl), + filterInput: 'input[type="search"]', + data(term, callback) { + const params = { + search: term, + }; + + axios + .get(refsUrl, { + params, + }) + .then(({ data }) => { + callback(data); + }) + .catch(() => + createFlash({ + message: __('Error fetching branches'), + }), + ); + }, + renderRow(branch) { + const item = document.createElement('li'); + const link = document.createElement('a'); + + link.setAttribute('href', '#'); + link.dataset.branch = branch; + link.classList.toggle('is-active', branch === selected); + link.textContent = branch; + + item.appendChild(link); + + return item; + }, + id(obj, $el) { + return $el.data('id'); + }, + toggleLabel(obj, $el) { + return $el.text().trim(); + }, + clicked({ $el, e }) { + e.preventDefault(); + + const branchName = $el[0].dataset.branch; + + formField.setAttribute('value', branchName); + }, + }); + } +} initMergeRequest(); +initFormUpdate(); initCheckFormState(); +initTargetBranchSelector(); diff --git a/app/assets/javascripts/pages/projects/merge_requests/edit/update_form.js b/app/assets/javascripts/pages/projects/merge_requests/edit/update_form.js new file mode 100644 index 00000000000..3bb64f741e7 --- /dev/null +++ b/app/assets/javascripts/pages/projects/merge_requests/edit/update_form.js @@ -0,0 +1,23 @@ +const findForm = () => document.querySelector('.merge-request-form'); + +const removeHiddenCheckbox = (node) => { + const checkboxWrapper = node.closest('.form-check'); + const hiddenCheckbox = checkboxWrapper.querySelector('input[type="hidden"]'); + hiddenCheckbox.remove(); +}; + +export default () => { + const updateCheckboxes = () => { + const checkboxes = document.querySelectorAll('.js-form-update'); + + if (!checkboxes.length) return; + + checkboxes.forEach((checkbox) => { + if (checkbox.checked) { + removeHiddenCheckbox(checkbox); + } + }); + }; + + findForm().addEventListener('submit', () => updateCheckboxes()); +}; diff --git a/app/assets/javascripts/pages/projects/merge_requests/init_merge_request_show.js b/app/assets/javascripts/pages/projects/merge_requests/init_merge_request_show.js index 2db804e1ad8..30734f0b698 100644 --- a/app/assets/javascripts/pages/projects/merge_requests/init_merge_request_show.js +++ b/app/assets/javascripts/pages/projects/merge_requests/init_merge_request_show.js @@ -1,5 +1,6 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; +import { s__ } from '~/locale'; import ShortcutsIssuable from '~/behaviors/shortcuts/shortcuts_issuable'; import { initPipelineCountListener } from '~/commit/pipelines/utils'; import { initIssuableSidebar } from '~/issuable'; @@ -10,6 +11,7 @@ import ZenMode from '~/zen_mode'; import initAwardsApp from '~/emoji/awards_app'; import MrWidgetHowToMergeModal from '~/vue_merge_request_widget/components/mr_widget_how_to_merge_modal.vue'; import { initMrExperienceSurvey } from '~/surveys/merge_request_experience'; +import toast from '~/vue_shared/plugins/global_toast'; import getStateQuery from './queries/get_state.query.graphql'; export default function initMergeRequestShow() { @@ -65,4 +67,10 @@ export default function initMergeRequestShow() { }); }, }); + + const copyReferenceButton = document.querySelector('.js-copy-reference'); + + copyReferenceButton?.addEventListener('click', () => { + toast(s__('MergeRequests|Reference copied')); + }); } diff --git a/app/assets/javascripts/pages/projects/merge_requests/show/index.js b/app/assets/javascripts/pages/projects/merge_requests/show/index.js index 7f49eb60c5c..cc5c393ff8c 100644 --- a/app/assets/javascripts/pages/projects/merge_requests/show/index.js +++ b/app/assets/javascripts/pages/projects/merge_requests/show/index.js @@ -1,9 +1,14 @@ +import Vue from 'vue'; +import StickyHeader from '~/merge_requests/components/sticky_header.vue'; import { initReviewBar } from '~/batch_comments'; import { initIssuableHeaderWarnings } from '~/issuable'; import initMrNotes from '~/mr_notes'; import store from '~/mr_notes/stores'; import initSidebarBundle from '~/sidebar/sidebar_bundle'; +import { apolloProvider } from '~/graphql_shared/issuable_client'; +import { parseBoolean } from '~/lib/utils/common_utils'; import initShow from '../init_merge_request_show'; +import getStateQuery from '../queries/get_state.query.graphql'; initMrNotes(); initShow(); @@ -12,4 +17,29 @@ requestIdleCallback(() => { initSidebarBundle(store); initReviewBar(); initIssuableHeaderWarnings(store); + + const el = document.getElementById('js-merge-sticky-header'); + + if (el) { + const { data } = el.dataset; + const { iid, projectPath, title, tabs, isFluidLayout } = JSON.parse(data); + + // eslint-disable-next-line no-new + new Vue({ + el, + store, + apolloProvider, + provide: { + query: getStateQuery, + iid, + projectPath, + title, + tabs, + isFluidLayout: parseBoolean(isFluidLayout), + }, + render(h) { + return h(StickyHeader); + }, + }); + } }); |