Commit 1f0b369b authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'tz-ee-reduce-js-bundle-select2' into 'master'

EE Port for lazy loading select2

See merge request gitlab-org/gitlab-ee!9353
parents 9682f6a9 14a934ef
...@@ -7,4 +7,3 @@ import 'vendor/jquery.caret'; ...@@ -7,4 +7,3 @@ import 'vendor/jquery.caret';
import 'vendor/jquery.atwho'; import 'vendor/jquery.atwho';
import 'vendor/jquery.scrollTo'; import 'vendor/jquery.scrollTo';
import 'jquery.waitforimages'; import 'jquery.waitforimages';
import 'select2/select2';
...@@ -4,6 +4,8 @@ import Api from './api'; ...@@ -4,6 +4,8 @@ import Api from './api';
import { normalizeHeaders } from './lib/utils/common_utils'; import { normalizeHeaders } from './lib/utils/common_utils';
export default function groupsSelect() { export default function groupsSelect() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
// Needs to be accessible in rspec // Needs to be accessible in rspec
window.GROUP_SELECT_PER_PAGE = 20; window.GROUP_SELECT_PER_PAGE = 20;
$('.ajax-groups-select').each(function setAjaxGroupsSelect2() { $('.ajax-groups-select').each(function setAjaxGroupsSelect2() {
...@@ -93,4 +95,6 @@ export default function groupsSelect() { ...@@ -93,4 +95,6 @@ export default function groupsSelect() {
dropdown.style.height = `${Math.floor(dropdown.scrollHeight)}px`; dropdown.style.height = `${Math.floor(dropdown.scrollHeight)}px`;
}); });
}); });
})
.catch(() => {});
} }
...@@ -11,10 +11,14 @@ class AutoWidthDropdownSelect { ...@@ -11,10 +11,14 @@ class AutoWidthDropdownSelect {
init() { init() {
const { dropdownClass } = this; const { dropdownClass } = this;
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
this.$selectElement.select2({ this.$selectElement.select2({
dropdownCssClass: dropdownClass, dropdownCssClass: dropdownClass,
...AutoWidthDropdownSelect.selectOptions(this.dropdownClass), ...AutoWidthDropdownSelect.selectOptions(this.dropdownClass),
}); });
})
.catch(() => {});
return this; return this;
} }
......
...@@ -7,10 +7,14 @@ export default class IssuableContext { ...@@ -7,10 +7,14 @@ export default class IssuableContext {
constructor(currentUser) { constructor(currentUser) {
this.userSelect = new UsersSelect(currentUser); this.userSelect = new UsersSelect(currentUser);
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('select.select2').select2({ $('select.select2').select2({
width: 'resolve', width: 'resolve',
dropdownAutoWidth: true, dropdownAutoWidth: true,
}); });
})
.catch(() => {});
$('.issuable-sidebar .inline-update').on('change', 'select', function onClickSelect() { $('.issuable-sidebar .inline-update').on('change', 'select', function onClickSelect() {
return $(this).submit(); return $(this).submit();
......
...@@ -122,6 +122,8 @@ export default class IssuableForm { ...@@ -122,6 +122,8 @@ export default class IssuableForm {
} }
initTargetBranchDropdown() { initTargetBranchDropdown() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
this.$targetBranchSelect.select2({ this.$targetBranchSelect.select2({
...AutoWidthDropdownSelect.selectOptions('js-target-branch-select'), ...AutoWidthDropdownSelect.selectOptions('js-target-branch-select'),
ajax: { ajax: {
...@@ -152,5 +154,7 @@ export default class IssuableForm { ...@@ -152,5 +154,7 @@ export default class IssuableForm {
}); });
}, },
}); });
})
.catch(() => {});
} }
} }
...@@ -103,6 +103,9 @@ function deferredInitialisation() { ...@@ -103,6 +103,9 @@ function deferredInitialisation() {
}); });
// Initialize select2 selects // Initialize select2 selects
if ($('select.select2').length) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('select.select2').select2({ $('select.select2').select2({
width: 'resolve', width: 'resolve',
dropdownAutoWidth: true, dropdownAutoWidth: true,
...@@ -115,6 +118,9 @@ function deferredInitialisation() { ...@@ -115,6 +118,9 @@ function deferredInitialisation() {
$(':focus').blur(); $(':focus').blur();
}, 1); }, 1);
}); });
})
.catch(() => {});
}
// Initialize tooltips // Initialize tooltips
$body.tooltip({ $body.tooltip({
......
...@@ -5,6 +5,8 @@ import Api from './api'; ...@@ -5,6 +5,8 @@ import Api from './api';
import ProjectSelectComboButton from './project_select_combo_button'; import ProjectSelectComboButton from './project_select_combo_button';
export default function projectSelect() { export default function projectSelect() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-project-select').each(function(i, select) { $('.ajax-project-select').each(function(i, select) {
var placeholder; var placeholder;
const simpleFilter = $(select).data('simpleFilter') || false; const simpleFilter = $(select).data('simpleFilter') || false;
...@@ -98,4 +100,6 @@ export default function projectSelect() { ...@@ -98,4 +100,6 @@ export default function projectSelect() {
if (simpleFilter) return select; if (simpleFilter) return select;
return new ProjectSelectComboButton(select); return new ProjectSelectComboButton(select);
}); });
})
.catch(() => {});
} }
...@@ -44,9 +44,13 @@ export default class ProjectSelectComboButton { ...@@ -44,9 +44,13 @@ export default class ProjectSelectComboButton {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
openDropdown(event) { openDropdown(event) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$(event.currentTarget) $(event.currentTarget)
.siblings('.project-item-select') .siblings('.project-item-select')
.select2('open'); .select2('open');
})
.catch(() => {});
} }
selectProject() { selectProject() {
......
...@@ -579,6 +579,8 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -579,6 +579,8 @@ function UsersSelect(currentUser, els, options = {}) {
}; };
})(this), })(this),
); );
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-users-select').each( $('.ajax-users-select').each(
(function(_this) { (function(_this) {
return function(i, select) { return function(i, select) {
...@@ -637,7 +639,11 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -637,7 +639,11 @@ function UsersSelect(currentUser, els, options = {}) {
data.results.unshift(anyUser); data.results.unshift(anyUser);
} }
} }
if (showEmailUser && data.results.length === 0 && query.term.match(/^[^@]+@[^@]+$/)) { if (
showEmailUser &&
data.results.length === 0 &&
query.term.match(/^[^@]+@[^@]+$/)
) {
var trimmed = query.term.trim(); var trimmed = query.term.trim();
emailUser = { emailUser = {
name: 'Invite "' + trimmed + '" by email', name: 'Invite "' + trimmed + '" by email',
...@@ -674,6 +680,8 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -674,6 +680,8 @@ function UsersSelect(currentUser, els, options = {}) {
}; };
})(this), })(this),
); );
})
.catch(() => {});
} }
UsersSelect.prototype.initSelection = function(element, callback) { UsersSelect.prototype.initSelection = function(element, callback) {
......
...@@ -76,6 +76,8 @@ export default class ApproversSelect { ...@@ -76,6 +76,8 @@ export default class ApproversSelect {
} }
initSelect2() { initSelect2() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
this.$approverSelect this.$approverSelect
.select2({ .select2({
placeholder: 'Search for users or groups', placeholder: 'Search for users or groups',
...@@ -111,6 +113,8 @@ export default class ApproversSelect { ...@@ -111,6 +113,8 @@ export default class ApproversSelect {
}, },
}) })
.on('change', this.handleSelectChange); .on('change', this.handleSelectChange);
})
.catch(() => {});
} }
static formatSelection(group) { static formatSelection(group) {
......
...@@ -11,6 +11,8 @@ export default function initLDAPGroupsSelect() { ...@@ -11,6 +11,8 @@ export default function initLDAPGroupsSelect() {
groupFormatSelection = function(group) { groupFormatSelection = function(group) {
return group.cn; return group.cn;
}; };
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-ldap-groups-select').each(function(i, select) { $('.ajax-ldap-groups-select').each(function(i, select) {
return $(select).select2({ return $(select).select2({
id: function(group) { id: function(group) {
...@@ -46,6 +48,9 @@ export default function initLDAPGroupsSelect() { ...@@ -46,6 +48,9 @@ export default function initLDAPGroupsSelect() {
}, },
}); });
}); });
})
.catch(() => {});
return $('#ldap_group_link_provider').on('change', function() { return $('#ldap_group_link_provider').on('change', function() {
return $('.ajax-ldap-groups-select').select2('data', null); return $('.ajax-ldap-groups-select').select2('data', null);
}); });
......
...@@ -4,6 +4,8 @@ import $ from 'jquery'; ...@@ -4,6 +4,8 @@ import $ from 'jquery';
import Api from '~/api'; import Api from '~/api';
function AdminEmailSelect() { function AdminEmailSelect() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-admin-email-select').each( $('.ajax-admin-email-select').each(
(function(_this) { (function(_this) {
return function(i, select) { return function(i, select) {
...@@ -53,6 +55,8 @@ function AdminEmailSelect() { ...@@ -53,6 +55,8 @@ function AdminEmailSelect() {
}; };
})(this), })(this),
); );
})
.catch(() => {});
} }
AdminEmailSelect.prototype.formatResult = function(object) { AdminEmailSelect.prototype.formatResult = function(object) {
......
...@@ -32,6 +32,8 @@ export default function geoNodeForm() { ...@@ -32,6 +32,8 @@ export default function geoNodeForm() {
onSelectiveSyncTypeChange(e, $syncByNamespaces, $syncByShards), onSelectiveSyncTypeChange(e, $syncByNamespaces, $syncByShards),
); );
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$select2Dropdown.select2({ $select2Dropdown.select2({
placeholder: s__('Geo|Select groups to replicate.'), placeholder: s__('Geo|Select groups to replicate.'),
multiple: true, multiple: true,
...@@ -57,4 +59,6 @@ export default function geoNodeForm() { ...@@ -57,4 +59,6 @@ export default function geoNodeForm() {
}, },
}, },
}); });
})
.catch(() => {});
} }
...@@ -76,10 +76,14 @@ export default class EEMirrorRepos extends MirrorRepos { ...@@ -76,10 +76,14 @@ export default class EEMirrorRepos extends MirrorRepos {
} }
initSelect2() { initSelect2() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.js-mirror-user', this.$form).select2({ $('.js-mirror-user', this.$form).select2({
width: 'resolve', width: 'resolve',
dropdownAutoWidth: true, dropdownAutoWidth: true,
}); });
})
.catch(() => {});
} }
registerUpdateListeners() { registerUpdateListeners() {
......
<script> <script>
/* eslint-disable no-unused-vars */
import $ from 'jquery'; import $ from 'jquery';
import select2 from 'select2/select2';
import { KNOWN_LICENSES } from '../constants'; import { KNOWN_LICENSES } from '../constants';
export default { export default {
......
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