From 14437dffcc110a8665444e6dd0e32ac6bc8fefe5 Mon Sep 17 00:00:00 2001
From: "Quynh Nguyen (Quinn)" <43350163+qn895@users.noreply.github.com>
Date: Wed, 23 Nov 2022 12:55:42 -0600
Subject: [PATCH] [ML] Fix Data Visualizer time picker showing even if data
view has been configured not to use a time filter (#146080)
fixes https://github.com/elastic/kibana/issues/139480
---
.../date_picker_wrapper/date_picker_wrapper.tsx | 11 +++++++----
.../index_data_visualizer_view.tsx | 14 +++++++++++---
.../search_strategy/requests/get_document_stats.ts | 8 ++++++--
3 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/date_picker_wrapper/date_picker_wrapper.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/date_picker_wrapper/date_picker_wrapper.tsx
index 12d6b257ec292..a3f5dbfffe517 100644
--- a/x-pack/plugins/data_visualizer/public/application/common/components/date_picker_wrapper/date_picker_wrapper.tsx
+++ b/x-pack/plugins/data_visualizer/public/application/common/components/date_picker_wrapper/date_picker_wrapper.tsx
@@ -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 },
@@ -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}
@@ -257,7 +260,7 @@ export const DatePickerWrapper: FC = () => {
/>
- {isTimeRangeSelectorEnabled ? null : (
+ {showRefresh === true || !isTimeRangeSelectorEnabled ? (
{
/>
- )}
+ ) : null}
) : null;
};
diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx
index 30ff09f9c492e..bb9095bc6f269 100644
--- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx
+++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx
@@ -449,6 +449,11 @@ export const IndexDataVisualizerView: FC = (dataVi
language: searchQueryLanguage,
});
}, [data, searchQueryLanguage, searchString]);
+
+ const hasValidTimeField = useMemo(
+ () => currentDataView.timeFieldName !== undefined && currentDataView.timeFieldName !== '',
+ [currentDataView.timeFieldName]
+ );
const helpLink = docLinks.links.ml.guide;
return (
@@ -475,7 +480,7 @@ export const IndexDataVisualizerView: FC = (dataVi
gutterSize="s"
data-test-subj="dataVisualizerTimeRangeSelectorSection"
>
- {currentDataView.timeFieldName !== undefined && (
+ {hasValidTimeField ? (
= (dataVi
timefilter={timefilter}
/>
- )}
+ ) : null}
-
+
diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_document_stats.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_document_stats.ts
index 4b6f5bf937b07..7607dc30c8130 100644
--- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_document_stats.ts
+++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_document_stats.ts
@@ -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,
@@ -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