Skip to content

Commit

Permalink
[BUG] Allow Save in Top Nav Menu to capture filter and query (#6636) (#…
Browse files Browse the repository at this point in the history
…6687)

Before this PR, can't save when filter or query change.
After this PR, if the canvas is not empty, can save filter and query updates.

Issue Resolve
#5645


(cherry picked from commit 7aa7a74)

Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 73c76d1 commit 6e21d5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/6636.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [BUG] Allow Save in Top Nav Menu to capture filter and query ([#6636](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6636))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import { isEqual } from 'lodash';
import { useParams } from 'react-router-dom';
import { useUnmount } from 'react-use';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
Expand All @@ -19,11 +20,21 @@ import { saveStateToSavedObject } from '../../saved_visualizations/transforms';
import { TopNavMenuData } from '../../../../navigation/public';
import { opensearchFilters, connectStorageToQueryState } from '../../../../data/public';

function useDeepEffect(callback, dependencies) {
const currentDepsRef = useRef(dependencies);

if (!isEqual(currentDepsRef.current, dependencies)) {
callback();
currentDepsRef.current = dependencies;
}
}

export const TopNav = () => {
// id will only be set for the edit route
const { id: visualizationIdFromUrl } = useParams<{ id: string }>();
const { services } = useOpenSearchDashboards<VisBuilderServices>();
const {
data,
setHeaderActionMenu,
navigation: {
ui: { TopNavMenu },
Expand All @@ -33,6 +44,10 @@ export const TopNav = () => {
const rootState = useTypedSelector((state) => state);
const dispatch = useTypedDispatch();

useDeepEffect(() => {
dispatch(setEditorState({ state: 'dirty' }));
}, [data.query.queryString.getQuery(), data.query.filterManager.getFilters()]);

const saveDisabledReason = useCanSave();
const savedVisBuilderVis = useSavedVisBuilderVis(visualizationIdFromUrl);
connectStorageToQueryState(services.data.query, services.osdUrlStateStorage, {
Expand Down

0 comments on commit 6e21d5e

Please sign in to comment.