Skip to content

Commit

Permalink
[Console Monaco migration] Fixes (#186479)
Browse files Browse the repository at this point in the history
## Summary

Fixes #184927
Fixes #184584
Fixes #184447


This PR fixes various issues in the migrated Console: 
- The url params with whitespaces are now parsed correctly and the whole
values is sent in the request
(#184927)
- The autocomplete for fields only shows the fields of the current index
(#184584)
- The popup with autocomplete suggestion is not covered by the resizer
bar (#184447)

#### How to test
1. Send a request with a url param that contains a whitespace, for
example `GET _search?q="test test"`. The request should be executed
correctly.
2. Create an index with only 1 field 
```
PUT field_test/_doc/1
{
  "test": 1
}
```
Try a search query with the fields autocomplete and check that only 1
field is suggested
```
GET field_test/_search
{
  "query": {
    "match": {
      "
```
3. Check that the popup with autocomplete suggestions is not covered by
the resizer bar


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
yuliacech committed Jun 25, 2024
1 parent 131ade8 commit f8589f8
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 10 deletions.
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'),
],
},
{
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'],
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 @@ -371,5 +371,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

0 comments on commit f8589f8

Please sign in to comment.