Skip to content

Commit

Permalink
Revert "[Explorer] Fixes for cancel button and saved object loading (o…
Browse files Browse the repository at this point in the history
…pensearch-project#1197) (opensearch-project#1201)"

This reverts commit f0e7a9d.

Signed-off-by: Eric <[email protected]>
  • Loading branch information
mengweieric committed Nov 8, 2023
1 parent 4146047 commit 06bbd29
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 55 deletions.
1 change: 0 additions & 1 deletion common/constants/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ export enum DATA_SOURCE_TYPES {
SPARK = 'spark',
S3Glue = 's3glue',
}
export const ASYNC_POLLING_INTERVAL = 2000;
4 changes: 2 additions & 2 deletions public/components/common/search/sql_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { isEqual } from 'lodash';
import React, { useEffect, useState } from 'react';
import { batch, useDispatch, useSelector } from 'react-redux';
import { ASYNC_POLLING_INTERVAL, QUERY_LANGUAGE } from '../../../../common/constants/data_sources';
import { QUERY_LANGUAGE } from '../../../../common/constants/data_sources';
import { APP_ANALYTICS_TAB_ID_REGEX, RAW_QUERY } from '../../../../common/constants/explorer';
import { PPL_NEWLINE_REGEX, PPL_SPAN_REGEX } from '../../../../common/constants/shared';
import { DirectQueryLoadingStatus, DirectQueryRequest } from '../../../../common/types/explorer';
Expand Down Expand Up @@ -103,7 +103,7 @@ export const DirectSearch = (props: any) => {
stopPolling,
} = usePolling<any, any>((params) => {
return sqlService.fetchWithJobId(params);
}, ASYNC_POLLING_INTERVAL);
}, 2000);

const requestParams = { tabId };
const { dispatchOnGettingHis } = useFetchEvents({
Expand Down
31 changes: 16 additions & 15 deletions public/components/event_analytics/explorer/direct_query_running.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ export const DirectQueryRunning = ({ tabId }: { tabId: string }) => {
const sqlService = new SQLService(coreRefs.http);

const cancelQuery = () => {
if (explorerSearchMeta.queryId) {
sqlService.deleteWithJobId({ queryId: explorerSearchMeta.queryId }).catch((e) => {
console.error(e);
});
if (explorerSearchMeta.queryId !== '') {
sqlService
.deleteWithJobId({ queryId: explorerSearchMeta.queryId })
.catch((e) => {
console.error(e);
})
.finally(() => {
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
},
})
);
});
}

// reset isPolling flag to remove loading page and queryId to empty
dispatch(
updateSearchMetaData({
tabId,
data: {
isPolling: false,
queryId: '',
},
})
);
};

return (
Expand Down
23 changes: 10 additions & 13 deletions public/components/event_analytics/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ const EventAnalyticsHome = (props: IHomeProps) => {
>
Delete
</EuiContextMenuItem>,
<EuiContextMenuItem
key="redirect"
onClick={() => {
setIsActionsPopoverOpen(false);
history.push(`/explorer`);
}}
data-test-subj="eventHomeAction__explorer"
>
Event Explorer
</EuiContextMenuItem>,
<EuiContextMenuItem
key="addSample"
onClick={() => {
Expand Down Expand Up @@ -284,19 +294,6 @@ const EventAnalyticsHome = (props: IHomeProps) => {
<EuiContextMenuPanel items={popoverItems} />
</EuiPopover>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
key="redirect"
onClick={() => {
setIsActionsPopoverOpen(false);
history.push(`/explorer`);
}}
data-test-subj="eventHomeAction__explorer"
fill
>
Event Explorer
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import { QueryManager } from '../../../../common/query_manager';
import { statsChunk } from '../../../../common/query_manager/ast/types/stats';
import {
DirectQueryRequest,
IField,
SavedQuery,
SavedVisualization,
Expand All @@ -44,9 +43,6 @@ import { PollingConfigurations } from '../../../components/hooks';
import { SQLService } from '../../requests/sql';
import { coreRefs } from '../../../framework/core_refs';
import { UsePolling } from '../../../components/hooks/use_polling';
import { getAsyncSessionId, setAsyncSessionId } from '../../../../common/utils/query_session_utils';
import { get as getObjValue } from '../../../../common/utils/shared';
import { ASYNC_POLLING_INTERVAL } from '../../../../common/constants/data_sources';

enum DIRECT_DATA_SOURCE_TYPES {
DEFAULT_INDEX_PATTERNS = 'DEFAULT_INDEX_PATTERNS',
Expand Down Expand Up @@ -304,12 +300,6 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
dispatchOnGettingHis(pollingResult, '');
return true;
}
dispatch(
updateSearchMetaData({
tabId,
data: { status: pollingResult.status },
})
);
return false;
};

Expand All @@ -326,23 +316,13 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
loadSparkGlue = ({ objectData, dataSources, tabId }) => {
const { dispatch } = this.dispatchers;
const sqlService = new SQLService(coreRefs.http);
const sessionId = getAsyncSessionId();
const requestPayload = {
lang: objectData.query_lang.toLowerCase(),
query: objectData.query,
datasource: dataSources[0].label,
} as DirectQueryRequest;

if (sessionId) {
requestPayload.sessionId = sessionId;
}

// Create an instance of UsePolling
const polling = new UsePolling<any, any>(
(params) => {
return sqlService.fetchWithJobId(params);
},
ASYNC_POLLING_INTERVAL,
5000,
this.handleDirectQuerySuccess,
this.handleDirectQueryError,
{ tabId }
Expand All @@ -363,11 +343,13 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
);

sqlService
.fetch(requestPayload)
.fetch({
lang: objectData.query_lang.toLowerCase(),
query: objectData.query,
datasource: dataSources[0].label,
})
.then((result) => {
setAsyncSessionId(getObjValue(result, 'sessionId', null));
if (result.queryId) {
dispatch(updateSearchMetaData({ tabId, data: { queryId: result.queryId } }));
startPolling({ queryId: result.queryId });
} else {
console.log('no query id found in response');
Expand Down

0 comments on commit 06bbd29

Please sign in to comment.