From fae4e3c79b104ebe871593df3f261493cf5a73a1 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 10:24:25 -0700 Subject: [PATCH] [Data Explorer] Fixes save search glitch + misc (#4870) (#4880) * Hide view toggle * misc fixes * fixes save behavior --------- (cherry picked from commit 51c536095da39dbb7e5147f6640fa381579d25e6) Signed-off-by: Ashwin P Chandran Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../public/components/sidebar/index.tsx | 5 +- .../components/skip_bottom_button/index.ts | 31 --------- .../skip_bottom_button.test.tsx | 51 -------------- .../skip_bottom_button/skip_bottom_button.tsx | 66 ------------------- .../components/top_nav/get_top_nav_links.tsx | 14 ++-- .../view_components/canvas/top_nav.tsx | 22 ++----- 6 files changed, 14 insertions(+), 175 deletions(-) delete mode 100644 src/plugins/discover/public/application/components/skip_bottom_button/index.ts delete mode 100644 src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx delete mode 100644 src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.tsx diff --git a/src/plugins/data_explorer/public/components/sidebar/index.tsx b/src/plugins/data_explorer/public/components/sidebar/index.tsx index 579c024acbc7..4133ef1f09b0 100644 --- a/src/plugins/data_explorer/public/components/sidebar/index.tsx +++ b/src/plugins/data_explorer/public/components/sidebar/index.tsx @@ -101,7 +101,8 @@ export const Sidebar: FC = ({ children }) => { dispatch(setIndexPattern(value)); }} /> - + {/* Hidden for the 2.10 release of Data Explorer. Uncomment when Data explorer is released */} + {/* { dispatch(setView(e.target.value)); }} fullWidth - /> + /> */} {children} diff --git a/src/plugins/discover/public/application/components/skip_bottom_button/index.ts b/src/plugins/discover/public/application/components/skip_bottom_button/index.ts deleted file mode 100644 index 094d8e286875..000000000000 --- a/src/plugins/discover/public/application/components/skip_bottom_button/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -export { SkipBottomButton } from './skip_bottom_button'; diff --git a/src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx b/src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx deleted file mode 100644 index 28ffef9dae86..000000000000 --- a/src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React from 'react'; -import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { ReactWrapper } from 'enzyme'; -import { SkipBottomButton, SkipBottomButtonProps } from './skip_bottom_button'; - -describe('Skip to Bottom Button', function () { - let props: SkipBottomButtonProps; - let component: ReactWrapper; - - beforeAll(() => { - props = { - onClick: jest.fn(), - }; - }); - - it('should be clickable', function () { - component = mountWithIntl(); - component.simulate('click'); - expect(props.onClick).toHaveBeenCalled(); - }); -}); diff --git a/src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.tsx b/src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.tsx deleted file mode 100644 index a780752fc54c..000000000000 --- a/src/plugins/discover/public/application/components/skip_bottom_button/skip_bottom_button.tsx +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React from 'react'; -import { EuiSkipLink } from '@elastic/eui'; -import { FormattedMessage, I18nProvider } from '@osd/i18n/react'; - -export interface SkipBottomButtonProps { - /** - * Action to perform on click - */ - onClick: () => void; -} - -export function SkipBottomButton({ onClick }: SkipBottomButtonProps) { - return ( - - { - // prevent the anchor to reload the page on click - event.preventDefault(); - // The destinationId prop cannot be leveraged here as the table needs - // to be updated first - onClick(); - }} - className="dscSkipButton" - destinationId="" - data-test-subj="discoverSkipTableButton" - > - - - - ); -} diff --git a/src/plugins/discover/public/application/components/top_nav/get_top_nav_links.tsx b/src/plugins/discover/public/application/components/top_nav/get_top_nav_links.tsx index e893f9ee73c9..8c19d38eb20d 100644 --- a/src/plugins/discover/public/application/components/top_nav/get_top_nav_links.tsx +++ b/src/plugins/discover/public/application/components/top_nav/get_top_nav_links.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { DiscoverViewServices } from '../../../build_services'; import { showOpenSearchPanel } from './show_open_search_panel'; import { SavedSearch } from '../../../saved_searches'; -import { NEW_DISCOVER_APP } from '../../..'; +import { NEW_DISCOVER_APP } from '../../../../common'; import { Adapters } from '../../../../../inspector/public'; import { TopNavMenuData } from '../../../../../navigation/public'; import { ISearchSource, unhashUrl } from '../../../opensearch_dashboards_services'; @@ -102,11 +102,7 @@ export const getTopNavLinks = ( }); if (id !== state.savedSearch) { - setTimeout(() => { - history().push(`/view/${encodeURIComponent(id)}`); - // TODO: figure out why a history push doesn't update the app state. The page reload is a hack around it - window.location.reload(); - }, 0); + history().push(`/view/${encodeURIComponent(id)}`); } else { chrome.docTitle.change(savedSearch.lastSavedTitle); chrome.setBreadcrumbs([ @@ -122,6 +118,8 @@ export const getTopNavLinks = ( // set App state to clean store!.dispatch({ type: setSavedSearchId.type, payload: id }); + + return { id }; } } catch (error) { toastNotifications.addDanger({ @@ -136,9 +134,9 @@ export const getTopNavLinks = ( // Reset the original title savedSearch.title = currentTitle; - } - return { test: true }; + return { error }; + } }; const saveModal = ( 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 41fea855b3e7..a7c7c5ef473d 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 @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { i18n } from '@osd/i18n'; import React, { useEffect, useState } from 'react'; import { AppMountParameters } from '../../../../../../core/public'; import { NEW_DISCOVER_APP, PLUGIN_ID } from '../../../../common'; @@ -12,6 +11,7 @@ import { DiscoverViewServices } from '../../../build_services'; 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'; export interface TopNavProps { opts: { @@ -30,7 +30,7 @@ export const TopNav = ({ opts }: TopNavProps) => { ui: { TopNavMenu }, }, core: { - application: { navigateToApp }, + application: { navigateToApp, getUrlForApp }, }, data, chrome, @@ -74,25 +74,13 @@ export const TopNav = ({ opts }: TopNavProps) => { if (savedSearch?.id) { chrome.setBreadcrumbs([ - { - text: i18n.translate('discover.discoverBreadcrumbTitle', { - defaultMessage: 'Discover', - }), - href: '#/', - }, + ...getRootBreadcrumbs(getUrlForApp(PLUGIN_ID)), { text: savedSearch.title }, ]); } else { - chrome.setBreadcrumbs([ - { - text: i18n.translate('discover.discoverBreadcrumbTitle', { - defaultMessage: 'Discover', - }), - href: '#/', - }, - ]); + chrome.setBreadcrumbs([...getRootBreadcrumbs(getUrlForApp(PLUGIN_ID))]); } - }, [chrome, savedSearch?.id, savedSearch?.title]); + }, [chrome, getUrlForApp, savedSearch?.id, savedSearch?.title]); return (