Commit 316d85c8 authored by Lukas Eipert's avatar Lukas Eipert

Migrate away from gl.utils

This moves most remaining usages from gl.utils over to direct imports
parent 1e00a38d
import $ from 'jquery'; import $ from 'jquery';
import { getSelectedFragment } from '~/lib/utils/common_utils'; import { getSelectedFragment, insertText } from '~/lib/utils/common_utils';
export class CopyAsGFM { export class CopyAsGFM {
constructor() { constructor() {
...@@ -79,7 +79,7 @@ export class CopyAsGFM { ...@@ -79,7 +79,7 @@ export class CopyAsGFM {
} }
static insertPastedText(target, text, gfm) { static insertPastedText(target, text, gfm) {
window.gl.utils.insertText(target, textBefore => { insertText(target, textBefore => {
// If the text before the cursor contains an odd number of backticks, // If the text before the cursor contains an odd number of backticks,
// we are either inside an inline code span that starts with 1 backtick // we are either inside an inline code span that starts with 1 backtick
// or a code block that starts with 3 backticks. // or a code block that starts with 3 backticks.
......
...@@ -5,7 +5,7 @@ import NewCommitForm from '../new_commit_form'; ...@@ -5,7 +5,7 @@ import NewCommitForm from '../new_commit_form';
import EditBlob from './edit_blob'; import EditBlob from './edit_blob';
import BlobFileDropzone from '../blob/blob_file_dropzone'; import BlobFileDropzone from '../blob/blob_file_dropzone';
import initPopover from '~/blob/suggest_gitlab_ci_yml'; import initPopover from '~/blob/suggest_gitlab_ci_yml';
import { setCookie } from '~/lib/utils/common_utils'; import { disableButtonIfEmptyField, setCookie } from '~/lib/utils/common_utils';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
export default () => { export default () => {
...@@ -51,10 +51,7 @@ export default () => { ...@@ -51,10 +51,7 @@ export default () => {
new BlobFileDropzone(uploadBlobForm, method); new BlobFileDropzone(uploadBlobForm, method);
new NewCommitForm(uploadBlobForm); new NewCommitForm(uploadBlobForm);
window.gl.utils.disableButtonIfEmptyField( disableButtonIfEmptyField(uploadBlobForm.find('.js-commit-message'), '.btn-upload-file');
uploadBlobForm.find('.js-commit-message'),
'.btn-upload-file',
);
} }
if (deleteBlobForm.length) { if (deleteBlobForm.length) {
......
...@@ -3,6 +3,7 @@ import autosize from 'autosize'; ...@@ -3,6 +3,7 @@ import autosize from 'autosize';
import GfmAutoComplete, { defaultAutocompleteConfig } from 'ee_else_ce/gfm_auto_complete'; import GfmAutoComplete, { defaultAutocompleteConfig } from 'ee_else_ce/gfm_auto_complete';
import dropzoneInput from './dropzone_input'; import dropzoneInput from './dropzone_input';
import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_markdown'; import { addMarkdownListeners, removeMarkdownListeners } from './lib/utils/text_markdown';
import { disableButtonIfEmptyField } from '~/lib/utils/common_utils';
export default class GLForm { export default class GLForm {
constructor(form, enableGFM = {}) { constructor(form, enableGFM = {}) {
...@@ -45,7 +46,7 @@ export default class GLForm { ...@@ -45,7 +46,7 @@ export default class GLForm {
this.form.find('.div-dropzone').remove(); this.form.find('.div-dropzone').remove();
this.form.addClass('gfm-form'); this.form.addClass('gfm-form');
// remove notify commit author checkbox for non-commit notes // remove notify commit author checkbox for non-commit notes
gl.utils.disableButtonIfEmptyField( disableButtonIfEmptyField(
this.form.find('.js-note-text'), this.form.find('.js-note-text'),
this.form.find('.js-comment-button, .js-note-new-discussion'), this.form.find('.js-comment-button, .js-note-new-discussion'),
); );
......
...@@ -888,35 +888,6 @@ export const searchBy = (query = '', searchSpace = {}) => { ...@@ -888,35 +888,6 @@ export const searchBy = (query = '', searchSpace = {}) => {
*/ */
export const isScopedLabel = ({ title = '' }) => title.indexOf('::') !== -1; export const isScopedLabel = ({ title = '' }) => title.indexOf('::') !== -1;
window.gl = window.gl || {};
window.gl.utils = {
...(window.gl.utils || {}),
getPagePath,
isInGroupsPage,
isInProjectPage,
getProjectSlug,
getGroupSlug,
isInIssuePage,
ajaxGet,
rstrip,
updateTooltipTitle,
disableButtonIfEmptyField,
handleLocationHash,
isInViewport,
parseUrl,
parseUrlPathname,
getUrlParamsArray,
isMetaKey,
isMetaClick,
scrollToElement,
getParameterByName,
getSelectedFragment,
insertText,
nodeMatchesSelector,
spriteIcon,
imagePath,
};
// Methods to set and get Cookie // Methods to set and get Cookie
export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 }); export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 });
......
...@@ -427,7 +427,6 @@ export const dayInQuarter = (date, quarter) => { ...@@ -427,7 +427,6 @@ export const dayInQuarter = (date, quarter) => {
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.utils = { window.gl.utils = {
...(window.gl.utils || {}), ...(window.gl.utils || {}),
getTimeago,
localTimeAgo, localTimeAgo,
}; };
......
import $ from 'jquery'; import $ from 'jquery';
import { disableButtonIfEmptyField } from '~/lib/utils/common_utils';
export default class Members { export default class Members {
constructor() { constructor() {
...@@ -13,7 +14,7 @@ export default class Members { ...@@ -13,7 +14,7 @@ export default class Members {
$('.js-edit-member-form') $('.js-edit-member-form')
.off('ajax:success') .off('ajax:success')
.on('ajax:success', this.formSuccess.bind(this)); .on('ajax:success', this.formSuccess.bind(this));
gl.utils.disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change'); disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change');
} }
dropdownClicked(options) { dropdownClicked(options) {
......
...@@ -11,6 +11,7 @@ import sidebarSubscriptions from './components/subscriptions/sidebar_subscriptio ...@@ -11,6 +11,7 @@ import sidebarSubscriptions from './components/subscriptions/sidebar_subscriptio
import Translate from '../vue_shared/translate'; import Translate from '../vue_shared/translate';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { store } from '~/notes/stores'; import { store } from '~/notes/stores';
import { isInIssuePage } from '~/lib/utils/common_utils';
Vue.use(Translate); Vue.use(Translate);
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -43,7 +44,7 @@ function mountAssigneesComponent(mediator) { ...@@ -43,7 +44,7 @@ function mountAssigneesComponent(mediator) {
projectPath: fullPath, projectPath: fullPath,
field: el.dataset.field, field: el.dataset.field,
signedIn: el.hasAttribute('data-signed-in'), signedIn: el.hasAttribute('data-signed-in'),
issuableType: gl.utils.isInIssuePage() ? 'issue' : 'merge_request', issuableType: isInIssuePage() ? 'issue' : 'merge_request',
}, },
}), }),
}); });
...@@ -93,7 +94,7 @@ function mountLockComponent(mediator) { ...@@ -93,7 +94,7 @@ function mountLockComponent(mediator) {
isLocked: initialData.is_locked, isLocked: initialData.is_locked,
isEditable: initialData.is_editable, isEditable: initialData.is_editable,
mediator, mediator,
issuableType: gl.utils.isInIssuePage() ? 'issue' : 'merge_request', issuableType: isInIssuePage() ? 'issue' : 'merge_request',
}, },
}).$mount(el); }).$mount(el);
} }
......
...@@ -20,7 +20,7 @@ export default { ...@@ -20,7 +20,7 @@ export default {
Here is an example `change` method: Here is an example `change` method:
change(pagenum) { change(pagenum) {
gl.utils.visitUrl(`?page=${pagenum}`); visitUrl(`?page=${pagenum}`);
}, },
*/ */
change: { change: {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import { __ } from '~/locale'; import { __ } from '~/locale';
import Flash from '~/flash'; import Flash from '~/flash';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
import { spriteIcon } from '~/lib/utils/common_utils';
import GitlabSlackService from '../services/gitlab_slack_service'; import GitlabSlackService from '../services/gitlab_slack_service';
...@@ -59,11 +60,11 @@ export default { ...@@ -59,11 +60,11 @@ export default {
computed: { computed: {
doubleHeadedArrowSvg() { doubleHeadedArrowSvg() {
return gl.utils.spriteIcon('double-headed-arrow'); return spriteIcon('double-headed-arrow');
}, },
arrowRightSvg() { arrowRightSvg() {
return gl.utils.spriteIcon('arrow-right'); return spriteIcon('arrow-right');
}, },
hasProjects() { hasProjects() {
......
import * as commonUtils from '~/lib/utils/common_utils';
import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm'; import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm';
describe('CopyAsGFM', () => { describe('CopyAsGFM', () => {
...@@ -27,7 +28,7 @@ describe('CopyAsGFM', () => { ...@@ -27,7 +28,7 @@ describe('CopyAsGFM', () => {
} }
it('wraps pasted code when not already in code tags', () => { it('wraps pasted code when not already in code tags', () => {
jest.spyOn(window.gl.utils, 'insertText').mockImplementation((el, textFunc) => { jest.spyOn(commonUtils, 'insertText').mockImplementation((el, textFunc) => {
const insertedText = textFunc('This is code: ', ''); const insertedText = textFunc('This is code: ', '');
expect(insertedText).toEqual('`code`'); expect(insertedText).toEqual('`code`');
...@@ -37,7 +38,7 @@ describe('CopyAsGFM', () => { ...@@ -37,7 +38,7 @@ describe('CopyAsGFM', () => {
}); });
it('does not wrap pasted code when already in code tags', () => { it('does not wrap pasted code when already in code tags', () => {
jest.spyOn(window.gl.utils, 'insertText').mockImplementation((el, textFunc) => { jest.spyOn(commonUtils, 'insertText').mockImplementation((el, textFunc) => {
const insertedText = textFunc('This is code: `', '`'); const insertedText = textFunc('This is code: `', '`');
expect(insertedText).toEqual('code'); expect(insertedText).toEqual('code');
......
...@@ -46,7 +46,7 @@ describe('ShortcutsIssuable', () => { ...@@ -46,7 +46,7 @@ describe('ShortcutsIssuable', () => {
}); });
describe('replyWithSelectedText', () => { describe('replyWithSelectedText', () => {
// Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML. // Stub getSelectedFragment to return a node with the provided HTML.
const stubSelection = (html, invalidNode) => { const stubSelection = (html, invalidNode) => {
getSelectedFragment.mockImplementation(() => { getSelectedFragment.mockImplementation(() => {
const documentFragment = document.createDocumentFragment(); const documentFragment = document.createDocumentFragment();
......
...@@ -2,7 +2,6 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_se ...@@ -2,7 +2,6 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_se
import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error'; import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error';
import RecentSearchesRoot from '~/filtered_search/recent_searches_root'; import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys';
import '~/lib/utils/common_utils';
import DropdownUtils from '~/filtered_search/dropdown_utils'; import DropdownUtils from '~/filtered_search/dropdown_utils';
import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens'; import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens';
import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager'; import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager';
...@@ -10,6 +9,7 @@ import FilteredSearchManager from '~/filtered_search/filtered_search_manager'; ...@@ -10,6 +9,7 @@ import FilteredSearchManager from '~/filtered_search/filtered_search_manager';
import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper';
import { BACKSPACE_KEY_CODE, DELETE_KEY_CODE } from '~/lib/utils/keycodes'; import { BACKSPACE_KEY_CODE, DELETE_KEY_CODE } from '~/lib/utils/keycodes';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import * as commonUtils from '~/lib/utils/common_utils';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'), ...jest.requireActual('~/lib/utils/url_utility'),
...@@ -83,7 +83,7 @@ describe('Filtered Search Manager', () => { ...@@ -83,7 +83,7 @@ describe('Filtered Search Manager', () => {
jest jest
.spyOn(FilteredSearchDropdownManager.prototype, 'updateDropdownOffset') .spyOn(FilteredSearchDropdownManager.prototype, 'updateDropdownOffset')
.mockImplementation(); .mockImplementation();
jest.spyOn(gl.utils, 'getParameterByName').mockReturnValue(null); jest.spyOn(commonUtils, 'getParameterByName').mockReturnValue(null);
jest.spyOn(FilteredSearchVisualTokens, 'unselectTokens'); jest.spyOn(FilteredSearchVisualTokens, 'unselectTokens');
input = document.querySelector('.filtered-search'); input = document.querySelector('.filtered-search');
......
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