diff --git a/src/plugins/discover/public/application/components/chart/chart.tsx b/src/plugins/discover/public/application/components/chart/chart.tsx
index 30b7b3894f71..dc3d0b0eaccb 100644
--- a/src/plugins/discover/public/application/components/chart/chart.tsx
+++ b/src/plugins/discover/public/application/components/chart/chart.tsx
@@ -26,7 +26,7 @@ interface DiscoverChartProps {
hits: number;
resetQuery: () => void;
showResetButton?: boolean;
- timeField?: string;
+ isTimeBased?: boolean;
services: DiscoverServices;
}
@@ -37,7 +37,7 @@ export const DiscoverChart = ({
data,
hits,
resetQuery,
- timeField,
+ isTimeBased,
services,
showResetButton = false,
}: DiscoverChartProps) => {
@@ -73,7 +73,7 @@ export const DiscoverChart = ({
onResetQuery={resetQuery}
/>
- {timeField && (
+ {isTimeBased && (
)}
- {timeField && chartData && (
+ {isTimeBased && chartData && (
!uiSettings.get(DOC_HIDE_TIME_COLUMN_SETTING, false) && indexPattern?.isTimeBased(),
+ [indexPattern, uiSettings]
+ );
+
return (
{}}
sort={sort}
rows={rows}
- displayTimeColumn={true}
+ displayTimeColumn={displayTimeColumn || true}
services={services}
isToolbarVisible={false}
isContextView={true}
diff --git a/src/plugins/discover/public/application/view_components/canvas/discover_chart_container.tsx b/src/plugins/discover/public/application/view_components/canvas/discover_chart_container.tsx
index db3ad027c9c2..cae81b6604c0 100644
--- a/src/plugins/discover/public/application/view_components/canvas/discover_chart_container.tsx
+++ b/src/plugins/discover/public/application/view_components/canvas/discover_chart_container.tsx
@@ -4,7 +4,7 @@
*/
import './discover_chart_container.scss';
-import React from 'react';
+import React, { useMemo } from 'react';
import { DiscoverViewServices } from '../../../build_services';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
import { useDiscoverContext } from '../context';
@@ -16,27 +16,26 @@ export const DiscoverChartContainer = ({ hits, bucketInterval, chartData }: Sear
const { uiSettings, data } = services;
const { indexPattern, savedSearch } = useDiscoverContext();
- const timeField = indexPattern?.timeFieldName;
-
- if (!hits || !bucketInterval || !chartData) {
- // TODO: handle better
- return null;
- }
+ const isTimeBased = useMemo(() => (indexPattern ? indexPattern.isTimeBased() : false), [
+ indexPattern,
+ ]);
return (
- {
- window.location.href = `#/view/${savedSearch?.id}`;
- window.location.reload();
- }}
- services={services}
- showResetButton={!!savedSearch && !!savedSearch.id}
- />
+ hits && (
+ {
+ window.location.href = `#/view/${savedSearch?.id}`;
+ window.location.reload();
+ }}
+ services={services}
+ showResetButton={!!savedSearch && !!savedSearch.id}
+ isTimeBased={isTimeBased}
+ />
+ )
);
};
diff --git a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx
index b228110ec9fc..13b2b7d9d66d 100644
--- a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx
+++ b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import React, { useState, useEffect, useCallback } from 'react';
+import React, { useState, useEffect, useCallback, useMemo } from 'react';
import { History } from 'history';
import { DiscoverViewServices } from '../../../build_services';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
@@ -21,6 +21,7 @@ import { ResultStatus, SearchData } from '../utils/use_search';
import { IndexPatternField, opensearchFilters } from '../../../../../data/public';
import { DocViewFilterFn } from '../../doc_views/doc_views_types';
import { SortOrder } from '../../../saved_searches/types';
+import { DOC_HIDE_TIME_COLUMN_SETTING } from '../../../../common';
interface Props {
history: History;
@@ -28,7 +29,12 @@ interface Props {
export const DiscoverTable = ({ history }: Props) => {
const { services } = useOpenSearchDashboards();
- const { filterManager } = services.data.query;
+ const {
+ uiSettings,
+ data: {
+ query: { filterManager },
+ },
+ } = services;
const { data$, refetch$, indexPattern } = useDiscoverContext();
const [fetchState, setFetchState] = useState({
status: data$.getValue().status,
@@ -57,6 +63,10 @@ export const DiscoverTable = ({ history }: Props) => {
},
[filterManager, indexPattern]
);
+ const displayTimeColumn = useMemo(
+ () => !uiSettings.get(DOC_HIDE_TIME_COLUMN_SETTING, false) && indexPattern?.isTimeBased(),
+ [indexPattern, uiSettings]
+ );
const { rows } = fetchState || {};
@@ -93,7 +103,7 @@ export const DiscoverTable = ({ history }: Props) => {
onSort={onSetSort}
sort={sort}
rows={rows}
- displayTimeColumn={true}
+ displayTimeColumn={displayTimeColumn || true}
services={services}
/>
);
diff --git a/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx b/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx
index d45e9909b322..d8befd7d9f74 100644
--- a/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx
+++ b/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import React, { useEffect, useState } from 'react';
+import React, { useEffect, useMemo, useState } from 'react';
import { AppMountParameters } from '../../../../../../core/public';
import { NEW_DISCOVER_APP, PLUGIN_ID } from '../../../../common';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
@@ -20,7 +20,7 @@ export interface TopNavProps {
export const TopNav = ({ opts }: TopNavProps) => {
const { services } = useOpenSearchDashboards();
- const { inspectorAdapters, savedSearch } = useDiscoverContext();
+ const { inspectorAdapters, savedSearch, indexPattern } = useDiscoverContext();
const [indexPatterns, setIndexPatterns] = useState(undefined);
const {
@@ -52,11 +52,11 @@ export const TopNav = ({ opts }: TopNavProps) => {
let isMounted = true;
const getDefaultIndexPattern = async () => {
await data.indexPatterns.ensureDefaultIndexPattern();
- const indexPattern = await data.indexPatterns.getDefault();
+ const defaultIndexPattern = await data.indexPatterns.getDefault();
if (!isMounted) return;
- setIndexPatterns(indexPattern ? [indexPattern] : undefined);
+ setIndexPatterns(defaultIndexPattern ? [defaultIndexPattern] : undefined);
};
getDefaultIndexPattern();
@@ -66,12 +66,16 @@ export const TopNav = ({ opts }: TopNavProps) => {
};
}, [data.indexPatterns]);
+ const showDatePicker = useMemo(() => (indexPattern ? indexPattern.isTimeBased() : false), [
+ indexPattern,
+ ]);
+
return (