Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console Monaco migration] Fixes #186479

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ describe('tokens_utils', () => {
const result = removeTrailingWhitespaces(url);
expect(result).toBe('_search');
});
it(`doesn't split a query parameter with whitespaces`, () => {
const url = '_search?q="with whitespace"';
const result = removeTrailingWhitespaces(url);
expect(result).toBe(url);
});
});

describe('parseBody', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,24 @@ export const parseBody = (value: string): string[] => {
* Ideally the parser would do that, but currently they are included in url.
*/
export const removeTrailingWhitespaces = (url: string): string => {
return url.trim().split(whitespacesRegex)[0];
let index = 0;
let whitespaceIndex = -1;
let isQueryParam = false;
let char = url[index];
while (char) {
if (char === '"') {
isQueryParam = !isQueryParam;
} else if (char === ' ' && !isQueryParam) {
whitespaceIndex = index;
break;
}
index++;
char = url[index];
}
if (whitespaceIndex > 0) {
return url.slice(0, whitespaceIndex);
}
return url;
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,6 @@ describe('Integration', () => {
autoCompleteSet: [
tt('field1.1.1', { f: 1 }, 'string'),
tt('field1.1.2', { f: 1 }, 'string'),
tt('field2.1.1', { f: 1 }, 'string'),
tt('field2.1.2', { f: 1 }, 'string'),
],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in this test files is the reverse of changes in this PR #162917

},
{
Expand All @@ -958,8 +956,6 @@ describe('Integration', () => {
autoCompleteSet: [
{ name: 'field1.1.1', meta: 'string' },
{ name: 'field1.1.2', meta: 'string' },
{ name: 'field2.1.1', meta: 'string' },
{ name: 'field2.1.2', meta: 'string' },
],
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ export class IndexAutocompleteComponent extends ListComponent {
}
return !_.find(tokens, nonValidIndexType);
}

getDefaultTermMeta() {
return 'index';
}

getContextKey() {
return 'indices';
}
}
4 changes: 2 additions & 2 deletions src/plugins/console/public/lib/kb/kb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ describe('Knowledge base', () => {
);

indexTest('Index integration 2', ['index1'], [], {
index: ['index1'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in this test files is the reverse of changes in this PR #162917

indices: ['index1'],
autoCompleteSet: ['_multi_indices', '_single_index'],
});

indexTest('Index integration 2', [['index1', 'index2']], [], {
index: ['index1', 'index2'],
indices: ['index1', 'index2'],
autoCompleteSet: ['_multi_indices', '_single_index'],
});
});
8 changes: 8 additions & 0 deletions src/plugins/console/public/styles/_app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@
.console__monaco_editor__selectedRequests {
background: transparentize($euiColorLightShade, .3);
}
/*
* The z-index for the autocomplete suggestions popup
*/

.kibanaCodeEditor .monaco-editor .suggest-widget {
// the value needs to be above the z-index of the resizer bar
z-index: $euiZLevel1 + 2;
}
26 changes: 26 additions & 0 deletions test/functional/apps/console/monaco/_autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,31 @@ GET _search
});
});
});

describe('index fields autocomplete', () => {
const indexName = `index_field_test-${Date.now()}-${Math.random()}`;

before(async () => {
await PageObjects.console.monaco.clearEditorText();
// create an index with only 1 field
await PageObjects.console.monaco.enterText(`PUT ${indexName}/_doc/1\n{\n"test":1\n}`);
await PageObjects.console.clickPlay();
});

after(async () => {
await PageObjects.console.monaco.clearEditorText();
// delete the test index
await PageObjects.console.monaco.enterText(`DELETE ${indexName}`);
await PageObjects.console.clickPlay();
});

it('fields autocomplete only shows fields of the index', async () => {
await PageObjects.console.monaco.clearEditorText();
await PageObjects.console.monaco.enterText('GET _search\n{\n"fields": ["');

expect(await PageObjects.console.monaco.getAutocompleteSuggestion(0)).to.be.eql('test');
expect(await PageObjects.console.monaco.getAutocompleteSuggestion(1)).to.be.eql(undefined);
});
});
});
}
3 changes: 1 addition & 2 deletions test/functional/apps/console/monaco/_console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
});

// issue with the url params with whitespaces https://github.com/elastic/kibana/issues/184927
it.skip('default request response should include `"timed_out" : false`', async () => {
it('default request response should include `"timed_out" : false`', async () => {
const expectedResponseContains = `"timed_out": false`;
await PageObjects.console.monaco.selectAllRequests();
await PageObjects.console.clickPlay();
Expand Down
6 changes: 5 additions & 1 deletion test/functional/page_objects/console_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export class ConsolePageObject extends FtrService {
getAutocompleteSuggestion: async (index: number) => {
const suggestionsWidget = await this.find.byClassName('suggest-widget');
const suggestions = await suggestionsWidget.findAllByClassName('monaco-list-row');
const label = await suggestions[index].findByClassName('label-name');
const suggestion = suggestions[index];
if (!suggestion) {
return undefined;
}
const label = await suggestion.findByClassName('label-name');
return label.getVisibleText();
},
pressUp: async (shift: boolean = false) => {
Expand Down