Skip to content

Commit

Permalink
Fixes #37280 - remove typeAheadSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga authored and ekohl committed Apr 5, 2024
1 parent b6bae77 commit 1b215f6
Show file tree
Hide file tree
Showing 21 changed files with 0 additions and 537 deletions.
2 changes: 0 additions & 2 deletions webpack/assets/javascripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import * as advancedFields from './foreman_advanced_fields';
import * as configReportsModalDiff from './foreman_config_reports_modal_diff';
import * as dashboard from './dashboard';
import * as spice from './spice';
import * as typeAheadSelect from './foreman_type_ahead_select';
import * as lookupKeys from './foreman_lookup_keys';
import './react_app/common/MountingService';
import './foreman_overrides';
Expand Down Expand Up @@ -56,6 +55,5 @@ window.tfm = Object.assign(window.tfm || {}, {
document,
componentRegistry,
store,
typeAheadSelect,
lookupKeys,
});
33 changes: 0 additions & 33 deletions webpack/assets/javascripts/foreman_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,39 +103,6 @@ export function activateTooltips(elParam = 'body') {
});
}

export function initTypeAheadSelect(input) {
input.select2({
formatNoMatches: __('No matches found'),
ajax: {
url: input.data('url'),
dataType: 'json',
quietMillis: 250,
data: (term, page) => ({
q: term,
scope: input.data('scope'),
}),
results: data => ({
results: data.map(({ id, name }) => ({ id, text: name })),
}),
cache: true,
},
initSelection(element, callback) {
$.ajax(input.data('url'), {
data: {
scope: input.data('scope'),
},
dataType: 'json',
}).done(data => {
if (data.length > 0) {
// eslint-disable-next-line standard/no-callback-literal
callback({ id: data[0].id, text: data[0].name });
}
});
},
width: '400px',
});
}

// generates an absolute, needed in case of running Foreman from a subpath
export { foremanUrl } from './react_app/common/helpers';

Expand Down
26 changes: 0 additions & 26 deletions webpack/assets/javascripts/foreman_tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,3 @@ describe('deprecate', () => {
);
});
});

/* eslint-disable max-statements */
describe('initTypeAheadSelect', () => {
it('initializes select2 on given input field', () => {
document.body.innerHTML =
'<input type="text" id="typeahead" data-url="testurl" data-scope="testscope">';

const field = $('#typeahead');

$.ajax = jest.fn(url => {
const ajaxMock = $.Deferred();

ajaxMock.resolve([
{ id: 1, name: 'testoption' },
{ id: 2, name: 'anotheroption' },
]);
return ajaxMock.promise();
});

tools.initTypeAheadSelect(field);
$('.select2-choice').trigger('mousedown');
$('.select2-choice').trigger('mouseup');
expect(document.body.innerHTML).toContain('select2-container');
expect($('.select2-chosen').text()).toEqual('testoption');
});
});
13 changes: 0 additions & 13 deletions webpack/assets/javascripts/foreman_type_ahead_select.js

This file was deleted.

1 change: 0 additions & 1 deletion webpack/assets/javascripts/react_app/common/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export const initMockStore = {
factChart: {
modalToDisplay: {},
},
typeAheadSelect: {},
settingRecords: {
settings: {},
editing: null,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 1b215f6

Please sign in to comment.