Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] [BUG] Allow Save in Top Nav Menu to capture filter and query #6687

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { TopNavMenuData } from '../../../../navigation/public';
import { opensearchFilters, connectStorageToQueryState } from '../../../../data/public';

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

Check warning on line 24 in src/plugins/vis_builder/public/application/components/top_nav.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_builder/public/application/components/top_nav.tsx#L24

Added line #L24 was not covered by tests

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

Check warning on line 28 in src/plugins/vis_builder/public/application/components/top_nav.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_builder/public/application/components/top_nav.tsx#L27-L28

Added lines #L27 - L28 were not covered by tests
}
}

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 @@
const rootState = useTypedSelector((state) => state);
const dispatch = useTypedDispatch();

useDeepEffect(() => {
dispatch(setEditorState({ state: 'dirty' }));

Check warning on line 48 in src/plugins/vis_builder/public/application/components/top_nav.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_builder/public/application/components/top_nav.tsx#L47-L48

Added lines #L47 - L48 were not covered by tests
}, [data.query.queryString.getQuery(), data.query.filterManager.getFilters()]);

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