From 7efc231cd75eeaafb9c61a4106d0596a4ce77cac Mon Sep 17 00:00:00 2001 From: Josh Romero Date: Mon, 27 Mar 2023 10:19:52 -0700 Subject: [PATCH] [Chore] Update timeline default expression (#2720) * [Chore] Update other timeline `es()` examples and test usage to make sure we continue supporting the old format. * [Chore] Update BWC data generation to use es(*) * [Test] Add better programmatic text clearing for monaco editor * [Test] Wait for loader to finish after clicking update Update default expression from `.es(*)` to `opensearch(*)`. Both work, but we'd prefer the latter Signed-off-by: Josh Romero --------- Signed-off-by: Josh Romero --- CHANGELOG.md | 1 + .../with-security/check_timeline.js | 45 ++++++++++--------- .../with-security/helpers/generate_data.js | 8 ++++ .../without-security/check_timeline.js | 45 ++++++++++--------- .../without-security/helpers/generate_data.js | 8 ++++ src/plugins/timeline/public/app.js | 2 +- .../directives/timeline_expression_input.html | 4 +- .../timeline_help/timeline_help.html | 32 ++++++------- .../timeline/public/services/_saved_sheet.ts | 2 +- .../public/__snapshots__/to_ast.test.ts.snap | 4 +- .../public/timeline_vis_fn.ts | 2 +- .../public/timeline_vis_type.tsx | 2 +- .../vis_type_timeline/public/to_ast.test.ts | 4 +- .../server/handlers/lib/parse_sheet.test.js | 6 +-- .../vis_type_timeline/server/plugin.ts | 4 +- .../management/exports/_import_too_big.ndjson | 4 +- .../apps/timeline/_expression_typeahead.js | 10 ++--- 17 files changed, 103 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8599b46b811f..0873a250d749 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### 🛠 Maintenance - Adding @zhongnansu as maintainer. ([#2590](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2590)) +- [Timeline] Update default expressions from `.es(*)` to `.opensearch(*)`. ([2720](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2720)) - Removes `minimatch` manual resolution ([#3019](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3019)) - Remove `github-checks-reporter`, an unused dependency ([#3126](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3126)) - Upgrade `vega-lite` dependency to ^5.6.0 ([#3076](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3076)) diff --git a/cypress/integration/with-security/check_timeline.js b/cypress/integration/with-security/check_timeline.js index 2cd6401edc13..dc6c06f536b4 100644 --- a/cypress/integration/with-security/check_timeline.js +++ b/cypress/integration/with-security/check_timeline.js @@ -44,87 +44,90 @@ describe('check timeline visualization', () => { .find('[data-test-subj="newItemButton"]') .click(); cy.get('[data-test-subj="visType-timelion"]').click(); + // Because monaco editor doesn't use a contenteditable, input, or textarea, .clear() or .type('{selectall}') won't work. To clear, we just backspace for each character instead. + cy.get('[class="view-line"]') + .invoke('text') + .then((expressionText) => { + cy.get('[class="view-line"]').type('{backspace}'.repeat(expressionText.length)); + }); }); it('.es(*, kibana1=true) should report search error', () => { - cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana1=true)'); + cy.get('[class="view-line"]').type('.es(*, kibana1=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); }); it('.es(*, kibana=true) should not report search error', () => { - cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana=true)'); + cy.get('[class="view-line"]').type('.es(*, kibana=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.es(*, opensearchDashboards=true) should not report search error', () => { - cy.get('[class="view-line"]').type('{selectall}{backspace}, opensearchDashboards=true)'); + cy.get('[class="view-line"]').type('.es(*, opensearchDashboards=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.elasticsearch(*, kibana1=true) should report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana1=true)' - ); + cy.get('[class="view-line"]').type('.elasticsearch(*, kibana1=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); }); it('.elasticsearch(*, kibana=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana=true)' - ); + cy.get('[class="view-line"]').type('.elasticsearch(*, kibana=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.elasticsearch(*, opensearchDashboards=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, opensearchDashboards=true)' - ); + cy.get('[class="view-line"]').type('.elasticsearch(*, opensearchDashboards=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.opensearch(*, kibana1=true) should report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana1=true)' - ); + cy.get('[class="view-line"]').type('.opensearch(*, kibana1=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); }); it('.opensearch(*, kibana=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana=true)' - ); + cy.get('[class="view-line"]').type('.opensearch(*, kibana=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.opensearch(*, opensearchDashboards=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, opensearchDashboards=true)' - ); + cy.get('[class="view-line"]').type('.opensearch(*, opensearchDashboards=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); diff --git a/cypress/integration/with-security/helpers/generate_data.js b/cypress/integration/with-security/helpers/generate_data.js index 0790c8c771b5..1509dca7b012 100755 --- a/cypress/integration/with-security/helpers/generate_data.js +++ b/cypress/integration/with-security/helpers/generate_data.js @@ -79,6 +79,14 @@ describe('Generating BWC test data with security', () => { .find('[data-test-subj="newItemButton"]') .click(); cy.get('[data-test-subj="visType-timelion"]').click(); + // Because monaco editor doesn't use a contenteditable, input, or textarea, .clear() or .type('{selectall}') won't work. To clear, we just backspace for each character instead. + cy.get('[class="view-line"]') + .invoke('text') + .then((expressionText) => { + cy.get('[class="view-line"]').type('{backspace}'.repeat(expressionText.length)); + }); + // update default expression to use `.es(*)` instead of `.opensearch(*)` for bwc + cy.get('[class="view-line"]').type('.es(*)'); cy.get('[data-test-subj="visualizeSaveButton"]').click(); cy.get('[data-test-subj="savedObjectTitle"]').type('test-timeline'); cy.get('[data-test-subj="confirmSaveSavedObjectButton"]').click(); diff --git a/cypress/integration/without-security/check_timeline.js b/cypress/integration/without-security/check_timeline.js index fe97f6c01c1d..cd35ee744482 100644 --- a/cypress/integration/without-security/check_timeline.js +++ b/cypress/integration/without-security/check_timeline.js @@ -28,87 +28,90 @@ describe('check timeline visualization', () => { .find('[data-test-subj="newItemButton"]') .click(); cy.get('[data-test-subj="visType-timelion"]').click(); + // Because monaco editor doesn't use a contenteditable, input, or textarea, .clear() or .type('{selectall}') won't work. To clear, we just backspace for each character instead. + cy.get('[class="view-line"]') + .invoke('text') + .then((expressionText) => { + cy.get('[class="view-line"]').type('{backspace}'.repeat(expressionText.length)); + }); }); it('.es(*, kibana1=true) should report search error', () => { - cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana1=true)'); + cy.get('[class="view-line"]').type('.es(*, kibana1=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); }); it('.es(*, kibana=true) should not report search error', () => { - cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana=true)'); + cy.get('[class="view-line"]').type('.es(*, kibana=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.es(*, opensearchDashboards=true) should not report search error', () => { - cy.get('[class="view-line"]').type('{selectall}{backspace}, opensearchDashboards=true)'); + cy.get('[class="view-line"]').type('.es(*, opensearchDashboards=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.elasticsearch(*, kibana1=true) should report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana1=true)' - ); + cy.get('[class="view-line"]').type('.elasticsearch(*, kibana1=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); }); it('.elasticsearch(*, kibana=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana=true)' - ); + cy.get('[class="view-line"]').type('.elasticsearch(*, kibana=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.elasticsearch(*, opensearchDashboards=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, opensearchDashboards=true)' - ); + cy.get('[class="view-line"]').type('.elasticsearch(*, opensearchDashboards=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.opensearch(*, kibana1=true) should report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana1=true)' - ); + cy.get('[class="view-line"]').type('.opensearch(*, kibana1=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); }); it('.opensearch(*, kibana=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana=true)' - ); + cy.get('[class="view-line"]').type('.opensearch(*, kibana=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); }); it('.opensearch(*, opensearchDashboards=true) should not report search error', () => { - cy.get('[class="view-line"]').type( - '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, opensearchDashboards=true)' - ); + cy.get('[class="view-line"]').type('.opensearch(*, opensearchDashboards=true)'); cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.waitForLoader(); cy.get('[data-test-subj="globalToastList"]') .find('[data-test-subj="errorToastMessage"]') .should('not.exist'); diff --git a/cypress/integration/without-security/helpers/generate_data.js b/cypress/integration/without-security/helpers/generate_data.js index 1dee48f1aab9..f792a9b304a1 100755 --- a/cypress/integration/without-security/helpers/generate_data.js +++ b/cypress/integration/without-security/helpers/generate_data.js @@ -62,6 +62,14 @@ describe('Generating BWC test data without security', () => { .find('[data-test-subj="newItemButton"]') .click(); cy.get('[data-test-subj="visType-timelion"]').click(); + // Because monaco editor doesn't use a contenteditable, input, or textarea, .clear() or .type('{selectall}') won't work. To clear, we just backspace for each character instead. + cy.get('[class="view-line"]') + .invoke('text') + .then((expressionText) => { + cy.get('[class="view-line"]').type('{backspace}'.repeat(expressionText.length)); + }); + // update default expression to use `.es(*)` instead of `.opensearch(*)` for bwc + cy.get('[class="view-line"]').type('.es(*)'); cy.get('[data-test-subj="visualizeSaveButton"]').click(); cy.get('[data-test-subj="savedObjectTitle"]').type('test-timeline'); cy.get('[data-test-subj="confirmSaveSavedObjectButton"]').click(); diff --git a/src/plugins/timeline/public/app.js b/src/plugins/timeline/public/app.js index 6680e5518dcd..d0e940b9dded 100644 --- a/src/plugins/timeline/public/app.js +++ b/src/plugins/timeline/public/app.js @@ -169,7 +169,7 @@ export function initTimelineApp(app, deps) { const savedVisualizations = deps.plugins.visualizations.savedVisualizationsLoader; const timezone = getTimezone(deps.core.uiSettings); - const defaultExpression = '.es(*)'; + const defaultExpression = '.opensearch(*)'; $scope.topNavMenu = getTopNavMenu(); diff --git a/src/plugins/timeline/public/directives/timeline_expression_input.html b/src/plugins/timeline/public/directives/timeline_expression_input.html index e2e73706621f..b565e6643fc6 100644 --- a/src/plugins/timeline/public/directives/timeline_expression_input.html +++ b/src/plugins/timeline/public/directives/timeline_expression_input.html @@ -4,7 +4,7 @@ For some reasons it doesn't work without it (even though the default role of the element is textbox anyway). -->