Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move initSelects() from utils.js to selects.js
dominik-zeglenb651ed1d0bcc
diff --git a/saleor/static/dashboard/js/components/index.js b/saleor/static/dashboard/js/components/index.jsindex 28ecb7884c..ecfcde3453 100644--- a/saleor/static/dashboard/js/components/index.js+++ b/saleor/static/dashboard/js/components/index.js@@ -7,6 +7,7 @@ import './messages';import './misc';import './modal';import './search';-import './styleguide';+import './selects';+import './side-menu';import './tab';import './vouchers';diff --git a/saleor/static/dashboard/js/components/misc.js b/saleor/static/dashboard/js/components/misc.jsindex 2d8344ead6..b3b62d3145 100644--- a/saleor/static/dashboard/js/components/misc.js+++ b/saleor/static/dashboard/js/components/misc.js@@ -1,6 +1,7 @@import SVGInjector from 'svg-injector-2';-import { initSelects, onScroll } from './utils';+import { initSelects } from './selects';+import { onScroll } from './utils';const screenSizes = {sm: 600,diff --git a/saleor/static/dashboard/js/components/modal.js b/saleor/static/dashboard/js/components/modal.jsindex 4f72f55d69..6b20726f9f 100644--- a/saleor/static/dashboard/js/components/modal.js+++ b/saleor/static/dashboard/js/components/modal.js@@ -1,5 +1,5 @@-import { initSelects } from './utils';import { svgInjector } from './misc';+import { initSelects } from './selects';// List of input types that can be autofocused after opening modalconst focusInputs = [diff --git a/saleor/static/dashboard/js/components/selects.js b/saleor/static/dashboard/js/components/selects.jsnew file mode 100644index 0000000000..1f69b75fb4--- /dev/null+++ b/saleor/static/dashboard/js/components/selects.js@@ -0,0 +1,38 @@+import 'select2';++function appendOption ($select, option) {+ $select.append($('<option></option>')+ .attr('value', option.id).text(option.text));+}++function initSelects() {+ $('select:not(.browser-default):not(.enable-ajax-select2):not([multiple])').material_select();+ $('select[multiple]:not(.browser-default):not(.enable-ajax-select2)').select2({width: '100%'});++ $('select.enable-ajax-select2').each((i, select) => {+ const $select = $(select);+ const initial = $select.data('initial');++ if (initial) {+ const initialData = initial instanceof Array ? initial : [initial];+ const selected = initialData.map((item) => {+ appendOption($select, item);+ return (item.id);+ });+ $select.val(selected);+ }++ $select.select2({+ ajax: {+ url: $select.data('url'),+ delay: 250+ },+ width: '100%',+ minimumInputLength: 2+ });+ });+}++export {+ initSelects+}diff --git a/saleor/static/dashboard/js/components/utils.js b/saleor/static/dashboard/js/components/utils.jsindex d862fd90be..c977d0c4f0 100644--- a/saleor/static/dashboard/js/components/utils.js+++ b/saleor/static/dashboard/js/components/utils.js@@ -1,4 +1,3 @@-import 'select2';import detectPassiveEvents from 'detect-passive-events';function onScroll(func) {@@ -7,40 +6,6 @@ function onScroll(func) {} : false);}-function appendOption ($select, option) {- $select.append($('<option></option>')- .attr('value', option.id).text(option.text));-}--function initSelects() {- $('select:not(.browser-default):not(.enable-ajax-select2):not([multiple])').material_select();- $('select[multiple]:not(.browser-default):not(.enable-ajax-select2)').select2({width: '100%'});-- $('select.enable-ajax-select2').each((i, select) => {- const $select = $(select);- const initial = $select.data('initial');-- if (initial) {- const initialData = initial instanceof Array ? initial : [initial];- const selected = initialData.map((item) => {- appendOption($select, item);- return (item.id);- });- $select.val(selected);- }-- $select.select2({- ajax: {- url: $select.data('url'),- delay: 250- },- width: '100%',- minimumInputLength: 2- });- });-}-export {- onScroll,- initSelects,+ onScroll};