diff --git a/src/plugins/discover/public/application/components/top_nav/__snapshots__/table_feedbacks_panel.test.tsx.snap b/src/plugins/discover/public/application/components/top_nav/__snapshots__/table_feedbacks_panel.test.tsx.snap deleted file mode 100644 index 65ba4921c22..00000000000 --- a/src/plugins/discover/public/application/components/top_nav/__snapshots__/table_feedbacks_panel.test.tsx.snap +++ /dev/null @@ -1,46 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`TableFeedbacksPanel renders correctly 1`] = ` - - - -

- Share your thoughts on the latest Discover features -

-
-
- - -

- Help drive future improvements by - - - providing feedback - - - about your experience. -

-
-
- - - Cancel - - - Turn off new features - - -
-`; 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 a4e1a7ca51a..dc35f6c0a1b 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 @@ -5,8 +5,8 @@ import { i18n } from '@osd/i18n'; import React from 'react'; +import { EuiText } from '@elastic/eui'; import { DiscoverViewServices } from '../../../build_services'; -import { showOpenSearchPanel } from './show_open_search_panel'; import { SavedSearch } from '../../../saved_searches'; import { Adapters } from '../../../../../inspector/public'; import { TopNavMenuData } from '../../../../../navigation/public'; @@ -16,14 +16,17 @@ import { SavedObjectSaveModal, showSaveModal, } from '../../../../../saved_objects/public'; +import { + OpenSearchDashboardsContextProvider, + toMountPoint, +} from '../../../../../opensearch_dashboards_react/public'; import { DiscoverState, setSavedSearchId } from '../../utils/state_management'; import { DOC_HIDE_TIME_COLUMN_SETTING, SORT_DEFAULT_ORDER_SETTING } from '../../../../common'; import { getSortForSearchSource } from '../../view_components/utils/get_sort_for_search_source'; import { getRootBreadcrumbs } from '../../helpers/breadcrumbs'; import { syncQueryStateWithUrl } from '../../../../../data/public'; - -import { showTableFeedbacksPanel } from './show_table_feedbacks_panel'; import { getDataGridTableSetting, setDataGridTableSetting } from '../utils/local_storage'; +import { OpenSearchPanel } from './open_search_panel'; export const getTopNavLinks = ( services: DiscoverViewServices, @@ -166,11 +169,20 @@ export const getTopNavLinks = ( }), testId: 'discoverOpenButton', run: () => { - showOpenSearchPanel({ - makeUrl: (searchId) => `#/view/${encodeURIComponent(searchId)}`, - I18nContext: core.i18n.Context, - services, - }); + const flyoutSession = services.overlays.openFlyout( + toMountPoint( + + { + if (flyoutSession) { + flyoutSession.close(); + } + }} + makeUrl={(searchId) => `#/view/${encodeURIComponent(searchId)}`} + /> + + ) + ); }, }; @@ -201,7 +213,7 @@ export const getTopNavLinks = ( ...sharingData, title: savedSearch.title, }, - isDirty: !savedSearch.id || state.isDirty, + isDirty: !savedSearch.id || state.isDirty || false, }); }, }; @@ -238,12 +250,34 @@ export const getTopNavLinks = ( testId: 'datagridTableButton', run: async () => { // Read the current state from localStorage - const useDatagridTable = getDataGridTableSetting(storage); - if (useDatagridTable) { - showTableFeedbacksPanel({ - I18nContext: core.i18n.Context, - services, - }); + const newDiscoverEnabled = getDataGridTableSetting(storage); + if (newDiscoverEnabled) { + const confirmed = await services.overlays.openConfirm( + toMountPoint( + +

+ Help drive future improvements by{' '} + + providing feedback + {' '} + about your experience. +

+
+ ), + { + title: i18n.translate('discover.localMenu.newTableConfirmModalTitle', { + defaultMessage: 'Share your thoughts on the latest Discover features', + }), + cancelButtonText: 'Cancel', + confirmButtonText: 'Turn off new features', + defaultFocusedButton: 'confirm', + } + ); + + if (confirmed) { + setDataGridTableSetting(false, storage); + window.location.reload(); + } } else { // Save the new setting to localStorage setDataGridTableSetting(true, storage); diff --git a/src/plugins/discover/public/application/components/top_nav/show_open_search_panel.tsx b/src/plugins/discover/public/application/components/top_nav/show_open_search_panel.tsx deleted file mode 100644 index 5bc95b1b9cf..00000000000 --- a/src/plugins/discover/public/application/components/top_nav/show_open_search_panel.tsx +++ /dev/null @@ -1,70 +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 ReactDOM from 'react-dom'; -import { OpenSearchPanel } from './open_search_panel'; -import { I18nStart } from '../../../../../../core/public'; -import { OpenSearchDashboardsContextProvider } from '../../../../../opensearch_dashboards_react/public'; -import { DiscoverViewServices } from '../../../build_services'; - -let isOpen = false; - -export function showOpenSearchPanel({ - makeUrl, - I18nContext, - services, -}: { - makeUrl: (id: string) => string; - I18nContext: I18nStart['Context']; - services: DiscoverViewServices; -}) { - if (isOpen) { - return; - } - - isOpen = true; - const container = document.createElement('div'); - const onClose = () => { - ReactDOM.unmountComponentAtNode(container); - document.body.removeChild(container); - isOpen = false; - }; - - document.body.appendChild(container); - const element = ( - - - - - - ); - ReactDOM.render(element, container); -} diff --git a/src/plugins/discover/public/application/components/top_nav/show_table_feedbacks_panel.tsx b/src/plugins/discover/public/application/components/top_nav/show_table_feedbacks_panel.tsx deleted file mode 100644 index 50db0cf5b6f..00000000000 --- a/src/plugins/discover/public/application/components/top_nav/show_table_feedbacks_panel.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import ReactDOM from 'react-dom'; - -import { I18nStart } from '../../../../../../core/public'; -import { OpenSearchDashboardsContextProvider } from '../../../../../opensearch_dashboards_react/public'; -import { DiscoverViewServices } from '../../../build_services'; -import { setDataGridTableSetting } from '../utils/local_storage'; -import { TableFeedbacksPanel } from './table_feedbacks_panel'; -let isFeedbackPanelOpen = false; - -export function showTableFeedbacksPanel({ - I18nContext, - services, -}: { - I18nContext: I18nStart['Context']; - services: DiscoverViewServices; -}) { - if (isFeedbackPanelOpen) { - return; - } - - isFeedbackPanelOpen = true; - const container = document.createElement('div'); - const onClose = () => { - ReactDOM.unmountComponentAtNode(container); - document.body.removeChild(container); - isFeedbackPanelOpen = false; - }; - - const onTurnOff = async () => { - // Save the new setting to localStorage - setDataGridTableSetting(false, services.storage); - onClose(); - window.location.reload(); - }; - - document.body.appendChild(container); - const element = ( - - - - - - ); - ReactDOM.render(element, container); -} diff --git a/src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.test.tsx b/src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.test.tsx deleted file mode 100644 index 72e08dc6167..00000000000 --- a/src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.test.tsx +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import { shallow, ShallowWrapper } from 'enzyme'; -import { TableFeedbacksPanel } from './table_feedbacks_panel'; - -describe('TableFeedbacksPanel', () => { - let onCloseMock: jest.Mock; - let onTurnOffMock: jest.Mock; - let wrapper: ShallowWrapper; - - beforeEach(() => { - onCloseMock = jest.fn(); - onTurnOffMock = jest.fn(); - wrapper = shallow(); - }); - - it('renders correctly', () => { - expect(wrapper).toMatchSnapshot(); - }); - - it('calls onClose when the Cancel button is clicked', () => { - wrapper.find('EuiButtonEmpty').simulate('click'); - expect(onCloseMock).toHaveBeenCalled(); - }); - - it('calls onTurnOff when the Turn off new features button is clicked', () => { - wrapper.find('EuiButton').simulate('click'); - expect(onTurnOffMock).toHaveBeenCalled(); - }); -}); diff --git a/src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.tsx b/src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.tsx deleted file mode 100644 index 212f1c99ca2..00000000000 --- a/src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import { - EuiModal, - EuiModalHeader, - EuiModalHeaderTitle, - EuiModalBody, - EuiModalFooter, - EuiButton, - EuiText, - EuiButtonEmpty, -} from '@elastic/eui'; - -interface TableFeedbacksPanelProps { - onClose: () => void; - onTurnOff: () => Promise; -} - -export const TableFeedbacksPanel = ({ onClose, onTurnOff }: TableFeedbacksPanelProps) => ( - - - -

Share your thoughts on the latest Discover features

-
-
- - - -

- Help drive future improvements by{' '} - - providing feedback - {' '} - about your experience. -

-
-
- - - Cancel - - Turn off new features - - -
-);