Skip to content

Commit 803d80c

Browse files
authored
Revert "[CCI] Replace jquery usage in console plugin with native methods (#3733)"
This reverts commit ffe4556.
1 parent e74ab2d commit 803d80c

File tree

9 files changed

+52
-33
lines changed

9 files changed

+52
-33
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
191191
- [Console] Replace jQuery.ajax with core.http when calling OSD APIs in console ([#3080](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3080))
192192
- [I18n] Fix Listr type errors and error handlers ([#3629](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3629))
193193
- [Multiple DataSource] Present the authentication type choices in a drop-down ([#3693](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3693))
194-
- [Console] Replace jQuery usage in console plugin with native methods ([#3733](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3733))
195194

196195
### 🔩 Tests
197196

src/plugins/console/public/application/models/legacy_core_editor/__tests__/input.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import '../legacy_core_editor.test.mocks';
3232
import RowParser from '../../../../lib/row_parser';
3333
import { createTokenIterator } from '../../../factories';
34+
import $ from 'jquery';
3435
import { create } from '../create';
3536

3637
describe('Input', () => {
@@ -45,10 +46,10 @@ describe('Input', () => {
4546

4647
coreEditor = create(document.querySelector('#ConAppEditor'));
4748

48-
coreEditor.getContainer().style.display = '';
49+
$(coreEditor.getContainer()).show();
4950
});
5051
afterEach(() => {
51-
coreEditor.getContainer().style.display = 'none';
52+
$(coreEditor.getContainer()).hide();
5253
});
5354

5455
describe('.getLineCount', () => {

src/plugins/console/public/application/models/legacy_core_editor/__tests__/output_tokenization.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030

3131
import '../legacy_core_editor.test.mocks';
32+
import $ from 'jquery';
3233
import RowParser from '../../../../lib/row_parser';
3334
import ace from 'brace';
3435
import { createReadOnlyAceEditor } from '../create_readonly';
@@ -38,11 +39,11 @@ const tokenIterator = ace.acequire('ace/token_iterator');
3839
describe('Output Tokenization', () => {
3940
beforeEach(() => {
4041
output = createReadOnlyAceEditor(document.querySelector('#ConAppOutput'));
41-
output.container.style.display = '';
42+
$(output.container).show();
4243
});
4344

4445
afterEach(() => {
45-
output.container.style.display = 'none';
46+
$(output.container).hide();
4647
});
4748

4849
function tokensAsList() {

src/plugins/console/public/application/models/legacy_core_editor/legacy_core_editor.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import ace from 'brace';
3232
import { Editor as IAceEditor, IEditSession as IAceEditSession } from 'brace';
33+
import $ from 'jquery';
3334
import {
3435
CoreEditor,
3536
Position,
@@ -53,11 +54,11 @@ const rangeToAceRange = ({ start, end }: Range) =>
5354

5455
export class LegacyCoreEditor implements CoreEditor {
5556
private _aceOnPaste: any;
56-
actions: any;
57+
$actions: any;
5758
resize: () => void;
5859

5960
constructor(private readonly editor: IAceEditor, actions: HTMLElement) {
60-
this.actions = actions;
61+
this.$actions = $(actions);
6162
this.editor.setShowPrintMargin(false);
6263

6364
const session = this.editor.getSession();
@@ -273,16 +274,20 @@ export class LegacyCoreEditor implements CoreEditor {
273274

274275
private setActionsBar = (value?: any, topOrBottom: 'top' | 'bottom' = 'top') => {
275276
if (value === null) {
276-
this.actions.style.visibility = 'hidden';
277+
this.$actions.css('visibility', 'hidden');
277278
} else {
278279
if (topOrBottom === 'top') {
279-
this.actions.style.bottom = 'auto';
280-
this.actions.style.top = value;
281-
this.actions.style.visibility = 'visible';
280+
this.$actions.css({
281+
bottom: 'auto',
282+
top: value,
283+
visibility: 'visible',
284+
});
282285
} else {
283-
this.actions.style.top = 'auto';
284-
this.actions.style.bottom = value;
285-
this.actions.style.visibility = 'visible';
286+
this.$actions.css({
287+
top: 'auto',
288+
bottom: value,
289+
visibility: 'visible',
290+
});
286291
}
287292
}
288293
};
@@ -313,14 +318,14 @@ export class LegacyCoreEditor implements CoreEditor {
313318
}
314319

315320
legacyUpdateUI(range: any) {
316-
if (!this.actions) {
321+
if (!this.$actions) {
317322
return;
318323
}
319324
if (range) {
320325
// elements are positioned relative to the editor's container
321326
// pageY is relative to page, so subtract the offset
322327
// from pageY to get the new top value
323-
const offsetFromPage = this.editor.container.offsetTop;
328+
const offsetFromPage = $(this.editor.container).offset()!.top;
324329
const startLine = range.start.lineNumber;
325330
const startColumn = range.start.column;
326331
const firstLine = this.getLineValue(startLine);
@@ -340,11 +345,11 @@ export class LegacyCoreEditor implements CoreEditor {
340345
let offset = 0;
341346
if (isWrapping) {
342347
// Try get the line height of the text area in pixels.
343-
const textArea = this.editor.container.querySelector('textArea');
348+
const textArea = $(this.editor.container.querySelector('textArea')!);
344349
const hasRoomOnNextLine = this.getLineValue(startLine).length < maxLineLength;
345350
if (textArea && hasRoomOnNextLine) {
346351
// Line height + the number of wraps we have on a line.
347-
offset += this.getLineValue(startLine).length * textArea.getBoundingClientRect().height;
352+
offset += this.getLineValue(startLine).length * textArea.height()!;
348353
} else {
349354
if (startLine > 1) {
350355
this.setActionsBar(getScreenCoords(startLine - 1));

src/plugins/console/public/application/models/sense_editor/__tests__/integration.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ describe('Integration', () => {
4444
'<div><div id="ConAppEditor" /><div id="ConAppEditorActions" /><div id="ConCopyAsCurl" /></div>';
4545

4646
senseEditor = create(document.querySelector('#ConAppEditor'));
47-
senseEditor.getCoreEditor().getContainer().style.display = '';
47+
$(senseEditor.getCoreEditor().getContainer()).show();
4848
senseEditor.autocomplete._test.removeChangeListener();
4949
});
5050
afterEach(() => {
51-
senseEditor.getCoreEditor().getContainer().style.display = 'none';
51+
$(senseEditor.getCoreEditor().getContainer()).hide();
5252
senseEditor.autocomplete._test.addChangeListener();
5353
});
5454

src/plugins/console/public/application/models/sense_editor/__tests__/sense_editor.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import '../sense_editor.test.mocks';
3232

33+
import $ from 'jquery';
3334
import _ from 'lodash';
3435

3536
import { create } from '../create';
@@ -50,11 +51,11 @@ describe('Editor', () => {
5051
</div>`;
5152

5253
input = create(document.querySelector('#ConAppEditor'));
53-
input.getCoreEditor().getContainer().style.display = '';
54+
$(input.getCoreEditor().getContainer()).show();
5455
input.autocomplete._test.removeChangeListener();
5556
});
5657
afterEach(function () {
57-
input.getCoreEditor().getContainer().style.display = 'none';
58+
$(input.getCoreEditor().getContainer()).hide();
5859
input.autocomplete._test.addChangeListener();
5960
});
6061

src/plugins/console/public/application/models/sense_editor/sense_editor.test.mocks.ts

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@
3131
/* eslint no-undef: 0 */
3232

3333
import '../legacy_core_editor/legacy_core_editor.test.mocks';
34+
35+
import jQuery from 'jquery';
36+
jest.spyOn(jQuery, 'ajax').mockImplementation(
37+
() =>
38+
new Promise(() => {
39+
// never resolve
40+
}) as any
41+
);

src/plugins/console/public/lib/ace_token_provider/token_provider.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import '../../application/models/sense_editor/sense_editor.test.mocks';
3232

33+
import $ from 'jquery';
34+
3335
// TODO:
3436
// We import from application models as a convenient way to bootstrap loading up of an editor using
3537
// this lib. We also need to import application specific mocks which is not ideal.
@@ -57,14 +59,14 @@ describe('Ace (legacy) token provider', () => {
5759

5860
senseEditor = create(document.querySelector<HTMLElement>('#ConAppEditor')!);
5961

60-
senseEditor.getCoreEditor().getContainer().style.display = '';
62+
$(senseEditor.getCoreEditor().getContainer())!.show();
6163

6264
(senseEditor as any).autocomplete._test.removeChangeListener();
6365
tokenProvider = senseEditor.getCoreEditor().getTokenProvider();
6466
});
6567

6668
afterEach(async () => {
67-
senseEditor.getCoreEditor().getContainer().style.display = 'none';
69+
$(senseEditor.getCoreEditor().getContainer())!.hide();
6870
(senseEditor as any).autocomplete._test.addChangeListener();
6971
await senseEditor.update('', true);
7072
});

src/plugins/console/public/lib/osd/osd.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
UsernameAutocompleteComponent,
3939
} from '../autocomplete/components';
4040

41+
import $ from 'jquery';
4142
import _ from 'lodash';
4243

4344
import Api from './api';
@@ -173,19 +174,20 @@ function loadApisFromJson(
173174
// like this, it looks like a minor security issue.
174175
export function setActiveApi(api) {
175176
if (!api) {
176-
fetch('../api/console/api_server', {
177-
method: 'GET',
177+
$.ajax({
178+
url: '../api/console/api_server',
179+
dataType: 'json', // disable automatic guessing
178180
headers: {
179181
'osd-xsrf': 'opensearch-dashboards',
180182
},
181-
})
182-
.then(function (response) {
183-
response.json();
184-
})
185-
.then(function (data) {
183+
}).then(
184+
function (data) {
186185
setActiveApi(loadApisFromJson(data));
187-
})
188-
.catch((error) => console.log(`failed to load API '${api}': ${error}`));
186+
},
187+
function (jqXHR) {
188+
console.log("failed to load API '" + api + "': " + jqXHR.responseText);
189+
}
190+
);
189191
return;
190192
}
191193

0 commit comments

Comments
 (0)