Skip to content

Commit

Permalink
[BUG][Discover] Add onQuerySubmit to top nav and allow force update t…
Browse files Browse the repository at this point in the history
…o embeddable (opensearch-project#5160)

* all reload to force update embeddable
* add onQuerySubmit to top nav

Issue Resolve
opensearch-project#5116
opensearch-project#5159

Signed-off-by: ananzh <ananzh@amazon.com>
Co-authored-by: Miki <miki@amazon.com>
Co-authored-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: Leo Deng <leo7deng@gmail.com>
  • Loading branch information
3 people authored and Leo7Deng committed Oct 4, 2023
1 parent ee7730b commit 1e93ed4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,4 @@
"node": ">=14.20.1 <19",
"yarn": "^1.22.10"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -74,6 +82,7 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
<TopNav
opts={{
setHeaderActionMenu,
onQuerySubmit,
}}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
};
}

Expand Down Expand Up @@ -83,6 +85,7 @@ export const TopNav = ({ opts }: TopNavProps) => {
useDefaultBehaviors
setMenuMountPoint={opts.setHeaderActionMenu}
indexPatterns={indexPattern ? [indexPattern] : indexPatterns}
onQuerySubmit={opts.onQuerySubmit}
/>
);
};
5 changes: 3 additions & 2 deletions src/plugins/discover/public/embeddable/search_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class SearchEmbeddable

public reload() {
if (this.searchProps) {
this.pushContainerStateParamsToProps(this.searchProps);
this.pushContainerStateParamsToProps(this.searchProps, true);
}
}

Expand Down Expand Up @@ -377,8 +377,9 @@ export class SearchEmbeddable
ReactDOM.render(<SearchEmbeddableComponent {...props} />, 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) ||
Expand Down
3 changes: 1 addition & 2 deletions test/functional/apps/dashboard/dashboard_query_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1e93ed4

Please sign in to comment.