From a46c4a72eb2ada5d5a4c80bf272abd521c624a26 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Tue, 3 Oct 2023 06:41:34 -0700 Subject: [PATCH] [BUG][Discover] Add onQuerySubmit to top nav and allow force update to embeddable (#5160) * all reload to force update embeddable * add onQuerySubmit to top nav Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5116 https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5159 Signed-off-by: ananzh Co-authored-by: Miki Co-authored-by: Ashwin P Chandran Signed-off-by: Willie Hung --- CHANGELOG.md | 1 + package.json | 2 +- .../application/view_components/canvas/index.tsx | 11 ++++++++++- .../application/view_components/canvas/top_nav.tsx | 3 +++ .../discover/public/embeddable/search_embeddable.tsx | 5 +++-- test/functional/apps/dashboard/dashboard_query_bar.js | 3 +-- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcbb3d110d09..5301f78512e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Correct the generated path for downloading plugins by their names on Windows ([#4953](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4953)) - [BUG] Fix buildPointSeriesData unit test fails due to local timezone ([#4992](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4992)) - [BUG][Data Explorer][Discover] Fix total hits issue for no time based data ([#5087](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5087)) +- [BUG][Data Explorer][Discover] Add onQuerySubmit to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160)) ### 🚞 Infrastructure diff --git a/package.json b/package.json index 74ad208e3f8f..b34f0c9ffec0 100644 --- a/package.json +++ b/package.json @@ -468,4 +468,4 @@ "node": ">=14.20.1 <19", "yarn": "^1.22.10" } -} \ No newline at end of file +} diff --git a/src/plugins/discover/public/application/view_components/canvas/index.tsx b/src/plugins/discover/public/application/view_components/canvas/index.tsx index 3c25e5a221dc..d5a5e6444eb0 100644 --- a/src/plugins/discover/public/application/view_components/canvas/index.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/index.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect, useState, useRef } from 'react'; +import React, { useEffect, useState, useRef, useCallback } from 'react'; import { EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui'; import { TopNav } from './top_nav'; import { ViewProps } from '../../../../../data_explorer/public'; @@ -42,6 +42,14 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro }); const { status } = fetchState; + const onQuerySubmit = useCallback( + (payload, isUpdate) => { + if (isUpdate === false) { + refetch$.next(); + } + }, + [refetch$] + ); useEffect(() => { const subscription = data$.subscribe((next) => { @@ -74,6 +82,7 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro 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 4a8ebfb1bf29..3d1795c1f155 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 @@ -4,6 +4,7 @@ */ import React, { useEffect, useMemo, useState } from 'react'; +import { TimeRange, Query } from 'src/plugins/data/common'; import { AppMountParameters } from '../../../../../../core/public'; import { PLUGIN_ID } from '../../../../common'; import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; @@ -16,6 +17,7 @@ import { getRootBreadcrumbs } from '../../helpers/breadcrumbs'; export interface TopNavProps { opts: { setHeaderActionMenu: AppMountParameters['setHeaderActionMenu']; + onQuerySubmit: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void; }; } @@ -83,6 +85,7 @@ export const TopNav = ({ opts }: TopNavProps) => { useDefaultBehaviors setMenuMountPoint={opts.setHeaderActionMenu} indexPatterns={indexPattern ? [indexPattern] : indexPatterns} + onQuerySubmit={opts.onQuerySubmit} /> ); }; diff --git a/src/plugins/discover/public/embeddable/search_embeddable.tsx b/src/plugins/discover/public/embeddable/search_embeddable.tsx index 6a0fd097aeef..8b8db9079ba6 100644 --- a/src/plugins/discover/public/embeddable/search_embeddable.tsx +++ b/src/plugins/discover/public/embeddable/search_embeddable.tsx @@ -309,7 +309,7 @@ export class SearchEmbeddable public reload() { if (this.searchProps) { - this.pushContainerStateParamsToProps(this.searchProps); + this.pushContainerStateParamsToProps(this.searchProps, true); } } @@ -377,8 +377,9 @@ export class SearchEmbeddable ReactDOM.render(, node); } - private async pushContainerStateParamsToProps(searchProps: SearchProps) { + private async pushContainerStateParamsToProps(searchProps: SearchProps, force: boolean = false) { const isFetchRequired = + force || !opensearchFilters.onlyDisabledFiltersChanged(this.input.filters, this.prevFilters) || !isEqual(this.prevQuery, this.input.query) || !isEqual(this.prevTimeRange, this.input.timeRange) || diff --git a/test/functional/apps/dashboard/dashboard_query_bar.js b/test/functional/apps/dashboard/dashboard_query_bar.js index 91885a282b15..f1c2893268a9 100644 --- a/test/functional/apps/dashboard/dashboard_query_bar.js +++ b/test/functional/apps/dashboard/dashboard_query_bar.js @@ -49,8 +49,7 @@ export default function ({ getService, getPageObjects }) { await PageObjects.dashboard.loadSavedDashboard('dashboard with filter'); }); - // https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5116 - it.skip('causes panels to reload when refresh is clicked', async () => { + it('causes panels to reload when refresh is clicked', async () => { await opensearchArchiver.unload('dashboard/current/data'); await queryBar.clickQuerySubmitButton();