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

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

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

Signed-off-by: ananzh <[email protected]>
  • Loading branch information
ananzh committed Sep 29, 2023
1 parent 3bf1357 commit a99aea0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
});

const { status } = fetchState;
const onUpdateQuery = useCallback((payload, isUpdate) => {
if(isUpdate == false){
refetch$.next();
}
},[refetch$])
const onQuerySubmit = useCallback(
(payload, isUpdate) => {
if (isUpdate === false) {
refetch$.next();
}
},
[refetch$]
);

useEffect(() => {
const subscription = data$.subscribe((next) => {
Expand Down Expand Up @@ -79,7 +82,7 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
<TopNav
opts={{
setHeaderActionMenu,
onUpdateQuery,
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 @@ -12,13 +13,12 @@ import { IndexPattern } from '../../../opensearch_dashboards_services';
import { getTopNavLinks } from '../../components/top_nav/get_top_nav_links';
import { useDiscoverContext } from '../context';
import { getRootBreadcrumbs } from '../../helpers/breadcrumbs';
import { TimeRange, Query } from 'src/plugins/data/common';

export interface TopNavProps {
opts: {
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
onUpdateQuery: (payload: {dateRange: TimeRange; query?: Query}, isUpdate?: boolean) => void
},
onQuerySubmit: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void;
};
}

export const TopNav = ({ opts }: TopNavProps) => {
Expand Down Expand Up @@ -85,7 +85,7 @@ export const TopNav = ({ opts }: TopNavProps) => {
useDefaultBehaviors
setMenuMountPoint={opts.setHeaderActionMenu}
indexPatterns={indexPattern ? [indexPattern] : indexPatterns}
onQuerySubmit={opts.onUpdateQuery}
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
2 changes: 1 addition & 1 deletion test/functional/apps/dashboard/dashboard_query_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function ({ getService, getPageObjects }) {
});

// 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 a99aea0

Please sign in to comment.