Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.6`:
- [[ML] Fix Data Visualizer time picker showing even if data view has
been configured not to use a time filter
(#146080)](#146080)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Quynh Nguyen
(Quinn)","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-23T18:55:42Z","message":"[ML]
Fix Data Visualizer time picker showing even if data view has been
configured not to use a time filter (#146080)\n\nfixes
https://github.com/elastic/kibana/issues/139480","sha":"14437dffcc110a8665444e6dd0e32ac6bc8fefe5","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:File
Data
Viz","v8.6.0","v8.7.0"],"number":146080,"url":"https://github.com/elastic/kibana/pull/146080","mergeCommit":{"message":"[ML]
Fix Data Visualizer time picker showing even if data view has been
configured not to use a time filter (#146080)\n\nfixes
https://github.com/elastic/kibana/issues/139480","sha":"14437dffcc110a8665444e6dd0e32ac6bc8fefe5"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146080","number":146080,"mergeCommit":{"message":"[ML]
Fix Data Visualizer time picker showing even if data view has been
configured not to use a time filter (#146080)\n\nfixes
https://github.com/elastic/kibana/issues/139480","sha":"14437dffcc110a8665444e6dd0e32ac6bc8fefe5"}}]}]
BACKPORT-->

Co-authored-by: Quynh Nguyen (Quinn) <[email protected]>
  • Loading branch information
kibanamachine and qn895 authored Nov 23, 2022
1 parent 60108b3 commit 22e9eac
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 22e9eac

Please sign in to comment.