Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Implement results from no timestamp in Explorer #1573

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions public/components/common/query_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,23 @@ export const composeFinalQuery = (
});
};

export const composeFinalQueryWithoutTimestamp = (
curQuery: string,
appBaseQuery: string,
selectedPatternField?: string,
patternRegex?: string,
filteredPattern?: string
) => {
let fullQuery = curQuery.includes(appBaseQuery) ? curQuery : buildQuery(appBaseQuery, curQuery);
if (isEmpty(fullQuery)) return '';

// if a pattern is selected as filter, build it into finalQuery
if (selectedPatternField && filteredPattern)
fullQuery = buildPatternsQuery(fullQuery, selectedPatternField, patternRegex, filteredPattern);

return fullQuery;
};

export const removeBacktick = (stringContainsBacktick: string) => {
if (!stringContainsBacktick) return '';
return stringContainsBacktick.replace(/`/g, '');
Expand Down
37 changes: 25 additions & 12 deletions public/components/common/search/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { EuiSuperDatePicker, EuiToolTip } from '@elastic/eui';
import React from 'react';
import { i18n } from '@osd/i18n';
import { uiSettingsService } from '../../../../common/utils';
import { coreRefs } from '../../../framework/core_refs';
import { IDatePickerProps } from './search';
Expand All @@ -22,29 +23,41 @@
isAppAnalytics,
} = props;

const handleTimeChange = (e: any) => handleTimePickerChange([e.start, e.end]);

Check warning on line 26 in public/components/common/search/date_picker.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const allowTimeChanging = !coreRefs.queryAssistEnabled || isAppAnalytics;

let finalizedStartTime;
let finalizedEndTime;
let setDisabled;
let toolTipMessage;

if (coreRefs.queryAssistEnabled && !isAppAnalytics) {
// is query assistant inside log explorer
finalizedStartTime = QUERY_ASSIST_START_TIME;
finalizedEndTime = QUERY_ASSIST_END_TIME;
setDisabled = true;
toolTipMessage = i18n.translate('discover.queryAssistant.timePickerDisabledMessage', {
defaultMessage: 'Date range has been disabled to accomodate timerange of all datasets',
});
} else {
finalizedStartTime = startTime;
finalizedEndTime = endTime;
setDisabled = false;
toolTipMessage = false;
}

return (
<>
<EuiToolTip
position="bottom"
content={
allowTimeChanging
? false
: 'Date range has been disabled to accomodate timerange of all datasets'
}
>
<EuiToolTip position="bottom" content={toolTipMessage}>
<EuiSuperDatePicker
data-test-subj="pplSearchDatePicker"
start={allowTimeChanging ? startTime : QUERY_ASSIST_START_TIME}
end={allowTimeChanging ? endTime : QUERY_ASSIST_END_TIME}
start={finalizedStartTime}
end={finalizedEndTime}
dateFormat={uiSettingsService.get('dateFormat')}
onTimeChange={handleTimeChange}
onRefresh={handleTimeRangePickerRefresh}
className="osdQueryBar__datePicker"
showUpdateButton={false}
isDisabled={!allowTimeChanging}
isDisabled={setDisabled}
/>
</EuiToolTip>
</>
Expand Down
59 changes: 31 additions & 28 deletions public/components/common/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
resetSummary,
selectQueryAssistantSummarization,
} from '../../event_analytics/redux/slices/query_assistant_summarization_slice';
import { reset } from '../../event_analytics/redux/slices/query_result_slice';
import { reset, selectQueryResult } from '../../event_analytics/redux/slices/query_result_slice';
import {
changeData,
changeQuery,
Expand All @@ -65,7 +65,7 @@
tempQuery: string;
handleQueryChange: (query: string) => void;
handleQuerySearch: () => void;
dslService: any;

Check warning on line 68 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface IDatePickerProps {
Expand All @@ -75,12 +75,12 @@
setEndTime: (end: string) => void;
setTimeRange: () => void;
setIsOutputStale: () => void;
handleTimePickerChange: (timeRange: string[]) => any;

Check warning on line 78 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
handleTimeRangePickerRefresh: () => any;

Check warning on line 79 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
isAppAnalytics: boolean;
}

export const Search = (props: any) => {

Check warning on line 83 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const {
query,
tempQuery,
Expand Down Expand Up @@ -123,6 +123,7 @@
} = props;

const queryRedux = useSelector(selectQueries)[tabId];
const queryResults = useSelector(selectQueryResult)[tabId];
const queryAssistantSummarization = useSelector(selectQueryAssistantSummarization)[tabId];
const dispatch = useDispatch();
const appLogEvents = tabId.match(APP_ANALYTICS_TAB_ID_REGEX);
Expand All @@ -143,7 +144,7 @@
error: pollingError,
startPolling: _startPolling,
stopPolling,
} = usePolling<any, any>((params) => {

Check warning on line 147 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 147 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return sqlService.fetchWithJobId(params);
}, 5000);

Expand Down Expand Up @@ -241,7 +242,7 @@
stopPolling();
setIsQueryRunning(false);
}
}, [pollingResult, pollingError]);

Check warning on line 245 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'dispatchOnGettingHis', 'setIsQueryRunning', and 'stopPolling'. Either include them or remove the dependency array

useEffect(() => {
// set index and olly query assistant question if changed elsewhere
Expand All @@ -267,7 +268,7 @@
})
);
}
}, [queryRedux.index, queryRedux.ollyQueryAssistant]);

Check warning on line 271 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'dispatch', 'getAvailableFields', 'handleQueryChange', and 'props.tabId'. Either include them or remove the dependency array

const runChanges = () => {
batch(() => {
Expand Down Expand Up @@ -409,33 +410,35 @@
</EuiFlexItem>
)}
<EuiFlexItem grow={false} />
<EuiFlexItem className="euiFlexItem--flexGrowZero event-date-picker" grow={false}>
{!isLiveTailOn && (
<DatePicker
startTime={startTime}
endTime={endTime}
setStartTime={setStartTime}
setEndTime={setEndTime}
setIsOutputStale={setIsOutputStale}
liveStreamChecked={props.liveStreamChecked}
onLiveStreamChange={props.onLiveStreamChange}
handleTimePickerChange={(tRange: string[]) => {
// modifies run button to look like the update button, if there is a time change, disables timepicker setting update if timepicker is disabled
setNeedsUpdate(
!showQueryArea && // keeps statement false if using query assistant ui, timepicker shouldn't change run button
!(tRange[0] === startTime && tRange[1] === endTime) // checks to see if the time given is different from prev
);
// keeps the time range change local, to be used when update pressed
setStartTime(tRange[0]);
setEndTime(tRange[1]);
}}
handleTimeRangePickerRefresh={() => {
onQuerySearch(queryLang);
}}
isAppAnalytics={isAppAnalytics}
/>
)}
</EuiFlexItem>
{!(queryRedux.selectedTimestamp === '' && queryResults?.datarows) && ( // index with no timestamp, dont show timepicker
<EuiFlexItem className="euiFlexItem--flexGrowZero event-date-picker" grow={false}>
{!isLiveTailOn && (
<DatePicker
startTime={startTime}
endTime={endTime}
setStartTime={setStartTime}
setEndTime={setEndTime}
setIsOutputStale={setIsOutputStale}
liveStreamChecked={props.liveStreamChecked}
onLiveStreamChange={props.onLiveStreamChange}
handleTimePickerChange={(tRange: string[]) => {
// modifies run button to look like the update button, if there is a time change, disables timepicker setting update if timepicker is disabled
setNeedsUpdate(
!showQueryArea && // keeps statement false if using query assistant ui, timepicker shouldn't change run button
!(tRange[0] === startTime && tRange[1] === endTime) // checks to see if the time given is different from prev
);
// keeps the time range change local, to be used when update pressed
setStartTime(tRange[0]);
setEndTime(tRange[1]);
}}
handleTimeRangePickerRefresh={() => {
onQuerySearch(queryLang);
}}
isAppAnalytics={isAppAnalytics}
/>
)}
</EuiFlexItem>
)}
{!showQueryArea && (
<EuiFlexItem grow={false}>
<EuiToolTip position="bottom" content={needsUpdate ? 'Click to apply' : false}>
Expand Down
Loading
Loading