Skip to content

Commit

Permalink
modify timepicker logic to disappear instead of disable
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Sebastian <paulstn@amazon.com>
  • Loading branch information
paulstn committed Mar 18, 2024
1 parent fe634d0 commit 0b1aaeb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
35 changes: 13 additions & 22 deletions public/components/common/search/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function DatePicker(props: IDatePickerProps) {
handleTimePickerChange,
handleTimeRangePickerRefresh,
isAppAnalytics,
includesTimestamp,
} = props;

const handleTimeChange = (e: any) => handleTimePickerChange([e.start, e.end]);
Expand All @@ -31,27 +30,19 @@ export function DatePicker(props: IDatePickerProps) {
let setDisabled;
let toolTipMessage;

switch (true) {
case coreRefs.queryAssistEnabled && !isAppAnalytics: // is query assistant inside log explorer
setStartTime = QUERY_ASSIST_START_TIME;
setEndTime = QUERY_ASSIST_END_TIME;
setDisabled = true;
toolTipMessage = i18n.translate('discover.queryAssistant.timePickerDisabledMessage', {
defaultMessage: 'Date range has been disabled to accomodate timerange of all datasets',
});
break;
case !includesTimestamp: // there is no timestamp
setStartTime = 'now';
setDisabled = true;
toolTipMessage = i18n.translate('discover.events.timePickerNotFoundMessage', {
defaultMessage: 'There is no timestamp found in the index',
});
break;
default:
setStartTime = startTime;
setEndTime = endTime;
setDisabled = false;
toolTipMessage = false;
if (coreRefs.queryAssistEnabled && !isAppAnalytics) {
// is query assistant inside log explorer
setStartTime = QUERY_ASSIST_START_TIME;
setEndTime = 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 {
setStartTime = startTime;
setEndTime = endTime;
setDisabled = false;
toolTipMessage = false;
}

return (
Expand Down
61 changes: 31 additions & 30 deletions public/components/common/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
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 Down Expand Up @@ -78,7 +78,6 @@ export interface IDatePickerProps {
handleTimePickerChange: (timeRange: string[]) => any;
handleTimeRangePickerRefresh: () => any;
isAppAnalytics: boolean;
includesTimestamp: boolean;
}

export const Search = (props: any) => {
Expand Down Expand Up @@ -124,6 +123,7 @@ export const Search = (props: any) => {
} = 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 Down Expand Up @@ -410,34 +410,35 @@ export const Search = (props: any) => {
</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}
includesTimestamp={queryRedux.selectedTimestamp !== ''}
/>
)}
</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

0 comments on commit 0b1aaeb

Please sign in to comment.