Skip to content

Commit

Permalink
format livetail file, optional args and specific cypress name
Browse files Browse the repository at this point in the history
Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>
  • Loading branch information
kavithacm committed Apr 13, 2022
1 parent 67685f1 commit 37eb71d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EuiButton
iconType={isLiveTailOn ? 'stop' : 'play'}
iconSide="left"
onClick={() => setIsLiveTailPopoverOpen(!isLiveTailPopoverOpen)}
data-test-subj={dataTestSubj}
>
{liveTailName}
</EuiButton>
)}, [isLiveTailPopoverOpen, isLiveTailOn]);
return liveButton;
const liveButton = useMemo(() => {
return (
<EuiButton
iconType={isLiveTailOn ? "stop" : "play"}
iconSide="left"
onClick={() => setIsLiveTailPopoverOpen(!isLiveTailPopoverOpen)}
data-test-subj={dataTestSubj}
>
{liveTailName}
</EuiButton>
);
}, [isLiveTailPopoverOpen, isLiveTailOn]);
return liveButton;
};

export const StopLiveButton = (props: any) => {
const {
StopLive,
dataTestSubj,
} = props;

const stopButton = () => {
return (
<EuiButton
iconType="stop"
onClick={() => StopLive()}
color="danger"
data-test-subj={dataTestSubj}
>
Stop
</EuiButton>
)
};
return stopButton();
const { StopLive, dataTestSubj } = props;

const stopButton = () => {
return (
<EuiButton
iconType="stop"
onClick={() => StopLive()}
color="danger"
data-test-subj={dataTestSubj}
>
Stop
</EuiButton>
);
};
return stopButton();
};

export const sleep = (milliseconds: number | undefined) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};
return new Promise(resolve => setTimeout(resolve, milliseconds));
};
16 changes: 8 additions & 8 deletions dashboards-observability/public/components/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -298,7 +298,7 @@ export const Explorer = ({
indexPattern: string
): Promise<IDefaultTimestampState> => 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);
Expand All @@ -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];
}
Expand Down Expand Up @@ -405,7 +405,7 @@ export const Explorer = ({
if (objectId) {
updateTabData(objectId);
} else {
fetchData('', '');
fetchData();
}
}, []);

Expand Down Expand Up @@ -433,7 +433,7 @@ export const Explorer = ({
},
})
);
await fetchData('', '');
await fetchData();
};

const handleAddField = (field: IField) => toggleFields(field, AVAILABLE_FIELDS, SELECTED_FIELDS);
Expand Down Expand Up @@ -796,7 +796,7 @@ export const Explorer = ({
await updateCurrentTimeStamp('');
}
await updateQueryInStore(tempQuery);
fetchData('', '');
fetchData();
}, [tempQuery, query[RAW_QUERY]]);

const handleQueryChange = async (newQuery: string) => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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}
</EuiContextMenuItem>
Expand Down

0 comments on commit 37eb71d

Please sign in to comment.