Skip to content

Commit

Permalink
Merge pull request opensearch-project#538 from TackAdam/filterFix
Browse files Browse the repository at this point in the history
Bugfix: Event Analytics Filters
(cherry picked from commit 220ee69)
Signed-off-by: TackAdam <[email protected]>
(cherry picked from commit da0d264)
  • Loading branch information
TackAdam authored and A9 Swift Project User committed Aug 9, 2023
1 parent 95b42a7 commit b175f07
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions auto_sync_commit_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"last_github_commit": "449860fde94bef5a7efd869753205c7c4ed53054",
"last_gitfarm_commit": "35ce20daf2ffe9b975d7aa05a04bb09bad147bd7"
"last_github_commit": "da0d264e43d8ad77f67715e8ce739ed4032729fa",
"last_gitfarm_commit": "6440ea8a7a8746a17c2ef5521c49668e3fc39ec0"
}
3 changes: 1 addition & 2 deletions public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ export const Explorer = ({
<EuiHorizontalRule margin="xs" />
<LogPatterns
selectedIntervalUnit={selectedIntervalRef.current}
setTempQuery={setTempQuery}
handleTimeRangePickerRefresh={handleTimeRangePickerRefresh}
/>
</>
Expand Down Expand Up @@ -727,7 +726,7 @@ export const Explorer = ({
if (availability !== true) {
await updateQueryInStore(tempQuery);
}
await fetchData();
await fetchData(startTime, endTime);
},
[tempQuery, query]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiLink, EuiText } from '@elastic/eui';
import React, { useContext, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { connect, useDispatch } from 'react-redux';
import {
FILTERED_PATTERN,
Expand All @@ -25,15 +25,13 @@ export interface LogPatternProps {
text: string;
value: string;
};
setTempQuery: () => string;
handleTimeRangePickerRefresh: (flag: boolean) => {};
patterns: PatternTableData[];
query: IQuery;
}

const EventPatterns = ({
selectedIntervalUnit,
setTempQuery,
handleTimeRangePickerRefresh,
patterns,
query,
Expand All @@ -49,21 +47,35 @@ const EventPatterns = ({
requestParams: { tabId },
});

// refresh patterns on opening page
useEffect(() => {
getPatterns(selectedIntervalUnit?.value?.replace(/^auto_/, '') || 'y');
}, []);

const onPatternSelection = async (pattern: string) => {
if (query[FILTERED_PATTERN] === pattern) {
return;
}
dispatch(
// await here allows react to render update properly and display it.
// it forces the query to be changed before running it, without await the visual wont update.
await dispatch(
changeQuery({
tabId,
query: {
[FILTERED_PATTERN]: pattern,
},
})
);
// workaround to refresh callback and trigger fetch data
await setTempQuery(query[RAW_QUERY]);
await handleTimeRangePickerRefresh(true);
handleTimeRangePickerRefresh(true);
// after rendering the patterns visual, we want the pattern to be reset for future searches
await dispatch(
changeQuery({
tabId,
query: {
[FILTERED_PATTERN]: '',
},
})
);
};

const showToastError = (errorMsg: string) => {
Expand Down
17 changes: 6 additions & 11 deletions public/services/data_fetchers/ppl/ppl_data_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
} = this.searchContext;
const { dispatch, changeQuery } = this.storeContext;

await this.processTimestamp(query, appBaseQuery);
await this.processTimestamp(query);
if (isEmpty(this.timestamp)) return;

const curStartTime = startingTime || this.query[SELECTED_DATE_RANGE][0];
Expand All @@ -103,7 +103,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
);

// update UI with new query state
await this.updateQueryState(this.query[RAW_QUERY], finalQuery, this.timestamp, appBaseQuery);
await this.updateQueryState(this.query[RAW_QUERY], finalQuery, this.timestamp);
// calculate proper time interval for count distribution
if (!selectedInterval.current || selectedInterval.current.text === 'Auto') {
findAutoInterval(curStartTime, curEndTime);
Expand Down Expand Up @@ -158,8 +158,8 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
}
}

async processTimestamp(query: IQuery, appBaseQuery: string) {
if (query[SELECTED_TIMESTAMP] && appBaseQuery === '') {
async processTimestamp(query: IQuery) {
if (query[SELECTED_TIMESTAMP]) {
this.timestamp = query[SELECTED_TIMESTAMP];
} else {
await this.setTimestamp(this.queryIndex);
Expand All @@ -175,12 +175,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
return await timestampUtils.getTimestamp(indexPattern);
}

async updateQueryState(
rawQuery: string,
finalQuery: string,
curTimestamp: string,
appBaseQuery: string
) {
async updateQueryState(rawQuery: string, finalQuery: string, curTimestamp: string) {
const { batch, dispatch, changeQuery, changeVizConfig } = this.storeContext;
const { query } = this.searchParams;
const {
Expand All @@ -197,7 +192,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
tabId,
query: {
finalQuery,
[RAW_QUERY]: buildRawQuery(query, appBaseQuery),
[RAW_QUERY]: query.rawQuery,
[SELECTED_TIMESTAMP]: curTimestamp,
},
})
Expand Down

0 comments on commit b175f07

Please sign in to comment.