Skip to content

Commit

Permalink
[ML] Fix Data Visualizer time picker showing even if data view has be…
Browse files Browse the repository at this point in the history
…en configured not to use a time filter (elastic#146080)

fixes elastic#139480
  • Loading branch information
qn895 authored Nov 23, 2022
1 parent 78a6764 commit 14437df
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ function updateLastRefresh(timeRange?: OnRefreshProps) {
}

// FIXME: Consolidate this component with ML and AIOps's component
export const DatePickerWrapper: FC = () => {
export const DatePickerWrapper: FC<{ isAutoRefreshOnly?: boolean; showRefresh?: boolean }> = ({
isAutoRefreshOnly,
showRefresh,
}) => {
const {
services,
notifications: { toasts },
Expand Down Expand Up @@ -246,7 +249,7 @@ export const DatePickerWrapper: FC = () => {
start={time.from}
end={time.to}
isPaused={refreshInterval.pause}
isAutoRefreshOnly={!isTimeRangeSelectorEnabled}
isAutoRefreshOnly={!isTimeRangeSelectorEnabled || isAutoRefreshOnly}
refreshInterval={refreshInterval.value || DEFAULT_REFRESH_INTERVAL_MS}
onTimeChange={updateTimeFilter}
onRefresh={updateLastRefresh}
Expand All @@ -257,7 +260,7 @@ export const DatePickerWrapper: FC = () => {
/>
</EuiFlexItem>

{isTimeRangeSelectorEnabled ? null : (
{showRefresh === true || !isTimeRangeSelectorEnabled ? (
<EuiFlexItem grow={false}>
<EuiButton
fill
Expand All @@ -272,7 +275,7 @@ export const DatePickerWrapper: FC = () => {
/>
</EuiButton>
</EuiFlexItem>
)}
) : null}
</EuiFlexGroup>
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
language: searchQueryLanguage,
});
}, [data, searchQueryLanguage, searchString]);

const hasValidTimeField = useMemo(
() => currentDataView.timeFieldName !== undefined && currentDataView.timeFieldName !== '',
[currentDataView.timeFieldName]
);
const helpLink = docLinks.links.ml.guide;

return (
Expand All @@ -475,7 +480,7 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
gutterSize="s"
data-test-subj="dataVisualizerTimeRangeSelectorSection"
>
{currentDataView.timeFieldName !== undefined && (
{hasValidTimeField ? (
<EuiFlexItem grow={false}>
<FullTimeRangeSelector
dataView={currentDataView}
Expand All @@ -484,9 +489,12 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
timefilter={timefilter}
/>
</EuiFlexItem>
)}
) : null}
<EuiFlexItem grow={false}>
<DatePickerWrapper />
<DatePickerWrapper
isAutoRefreshOnly={!hasValidTimeField}
showRefresh={!hasValidTimeField}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPageContentHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ export const getDocumentCountStats = async (
},
});

const hasTimeField = timeFieldName !== undefined && intervalMs !== undefined && intervalMs > 0;
const hasTimeField =
timeFieldName !== undefined &&
timeFieldName !== '' &&
intervalMs !== undefined &&
intervalMs > 0;

const getSearchParams = (aggregations: unknown, trackTotalHits = false) => ({
index,
Expand Down Expand Up @@ -159,7 +163,7 @@ export const getDocumentCountStats = async (

// If time field is not defined, no need to show the document count chart
// Just need to return the tracked total hits
if (timeFieldName === undefined) {
if (!hasTimeField) {
const trackedTotalHits =
typeof firstResp.rawResponse.hits.total === 'number'
? firstResp.rawResponse.hits.total
Expand Down

0 comments on commit 14437df

Please sign in to comment.