From 37eb71d9d159eadea907a3dcf63e8886b776ae6d Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Wed, 13 Apr 2022 12:51:16 -0700 Subject: [PATCH] format livetail file, optional args and specific cypress name Signed-off-by: Kavitha Conjeevaram Mohan --- .../integration/event_analytics.spec.js | 4 +- .../common/live_tail/live_tail_button.tsx | 79 +++++++++---------- .../public/components/explorer/explorer.tsx | 16 ++-- 3 files changed, 48 insertions(+), 51 deletions(-) diff --git a/dashboards-observability/.cypress/integration/event_analytics.spec.js b/dashboards-observability/.cypress/integration/event_analytics.spec.js index 3f40da076..981b10b53 100644 --- a/dashboards-observability/.cypress/integration/event_analytics.spec.js +++ b/dashboards-observability/.cypress/integration/event_analytics.spec.js @@ -394,7 +394,7 @@ describe('Switch on and off livetail', () => { cy.get('[data-test-subj="searchAutocompleteTextArea"]').type(TEST_QUERIES[1].query); cy.get('[data-test-subj=eventLiveTail]').click(); - cy.get('[data-test-subj=10s]').click(); + cy.get('[data-test-subj=eventLiveTail__delay10s]').click(); cy.wait(delay * 2); cy.get('.euiToastHeader__title').contains('On').should('exist'); @@ -412,7 +412,7 @@ describe('Live tail stop automatically', () => { cy.get('[data-test-subj="searchAutocompleteTextArea"]').type(TEST_QUERIES[1].query); cy.get('[data-test-subj=eventLiveTail]').click(); - cy.get('[data-test-subj=10s]').click(); + cy.get('[data-test-subj=eventLiveTail__delay10s]').click(); cy.wait(delay * 2); cy.get('.euiToastHeader__title').contains('On').should('exist'); }); diff --git a/dashboards-observability/public/components/common/live_tail/live_tail_button.tsx b/dashboards-observability/public/components/common/live_tail/live_tail_button.tsx index 1384e9e7a..d6d4dff7c 100644 --- a/dashboards-observability/public/components/common/live_tail/live_tail_button.tsx +++ b/dashboards-observability/public/components/common/live_tail/live_tail_button.tsx @@ -5,54 +5,51 @@ //Define pop over interval options for live tail button in your plugin -import { EuiButton } from '@elastic/eui'; -import React, { useMemo } from 'react'; -import { LiveTailProps } from 'common/types/explorer'; +import { EuiButton } from "@elastic/eui"; +import React, { useMemo } from "react"; +import { LiveTailProps } from "common/types/explorer"; //Live Tail Button export const LiveTailButton = ({ - isLiveTailOn, - isLiveTailPopoverOpen, - setIsLiveTailPopoverOpen, - liveTailName, - dataTestSubj, + isLiveTailOn, + isLiveTailPopoverOpen, + setIsLiveTailPopoverOpen, + liveTailName, + dataTestSubj }: LiveTailProps) => { - - const liveButton = useMemo(() => { - return ( - setIsLiveTailPopoverOpen(!isLiveTailPopoverOpen)} - data-test-subj={dataTestSubj} - > - {liveTailName} - - )}, [isLiveTailPopoverOpen, isLiveTailOn]); - return liveButton; + const liveButton = useMemo(() => { + return ( + setIsLiveTailPopoverOpen(!isLiveTailPopoverOpen)} + data-test-subj={dataTestSubj} + > + {liveTailName} + + ); + }, [isLiveTailPopoverOpen, isLiveTailOn]); + return liveButton; }; export const StopLiveButton = (props: any) => { - const { - StopLive, - dataTestSubj, -} = props; - - const stopButton = () => { - return ( - StopLive()} - color="danger" - data-test-subj={dataTestSubj} - > - Stop - - ) - }; - return stopButton(); + const { StopLive, dataTestSubj } = props; + + const stopButton = () => { + return ( + StopLive()} + color="danger" + data-test-subj={dataTestSubj} + > + Stop + + ); + }; + return stopButton(); }; export const sleep = (milliseconds: number | undefined) => { - return new Promise((resolve) => setTimeout(resolve, milliseconds)); - }; \ No newline at end of file + return new Promise(resolve => setTimeout(resolve, milliseconds)); +}; diff --git a/dashboards-observability/public/components/explorer/explorer.tsx b/dashboards-observability/public/components/explorer/explorer.tsx index 156158d36..33ad3fa6e 100644 --- a/dashboards-observability/public/components/explorer/explorer.tsx +++ b/dashboards-observability/public/components/explorer/explorer.tsx @@ -285,7 +285,7 @@ export const Explorer = ({ ? TYPE_TAB_MAPPING[SAVED_QUERY] : TYPE_TAB_MAPPING[SAVED_VISUALIZATION]; setSelectedContentTab(tabToBeFocused); - await fetchData('', ''); + await fetchData(); }) .catch((error) => { notifications.toasts.addError(error, { @@ -298,7 +298,7 @@ export const Explorer = ({ indexPattern: string ): Promise => await timestampUtils.getTimestamp(indexPattern); - const fetchData = async (startTime: string, endTime: string) => { + const fetchData = async (startTime?: string, endTime?: string) => { const curQuery = queryRef.current; const rawQueryStr = buildQuery(appBaseQuery, curQuery![RAW_QUERY]); const curIndex = getIndexPatternFromRawQuery(rawQueryStr); @@ -323,7 +323,7 @@ export const Explorer = ({ } } - if (!isLiveTailOnRef.current) { + if ((isEqual(typeof startTime, 'undefined')) && (isEqual(typeof endTime, 'undefined'))) { startTime = curQuery![SELECTED_DATE_RANGE][0]; endTime = curQuery![SELECTED_DATE_RANGE][1]; } @@ -405,7 +405,7 @@ export const Explorer = ({ if (objectId) { updateTabData(objectId); } else { - fetchData('', ''); + fetchData(); } }, []); @@ -433,7 +433,7 @@ export const Explorer = ({ }, }) ); - await fetchData('', ''); + await fetchData(); }; const handleAddField = (field: IField) => toggleFields(field, AVAILABLE_FIELDS, SELECTED_FIELDS); @@ -796,7 +796,7 @@ export const Explorer = ({ await updateCurrentTimeStamp(''); } await updateQueryInStore(tempQuery); - fetchData('', ''); + fetchData(); }, [tempQuery, query[RAW_QUERY]]); const handleQueryChange = async (newQuery: string) => { @@ -1059,7 +1059,7 @@ export const Explorer = ({ }, [selectedContentTabId, browserTabFocus]); //stop live tail if the page is moved using breadcrumbs - var lastUrl = location.href; + let lastUrl = location.href; new MutationObserver(() => { const url = location.href; if (url !== lastUrl) { @@ -1075,7 +1075,7 @@ export const Explorer = ({ onClick={async () => { liveTailLoop(e.label, e.startTime, LIVE_END_TIME, e.delayTime); }} - data-test-subj={e.label} + data-test-subj={'eventLiveTail__delay'+e.label} > {e.label}