forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggling between legacy and new table
According to opensearch-project#5739, add toggle using storage. Signed-off-by: abbyhu2000 <[email protected]>
- Loading branch information
1 parent
3bc11d5
commit 3cabfa5
Showing
10 changed files
with
235 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/plugins/discover/public/application/components/top_nav/show_table_feedbacks_panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 = ( | ||
<OpenSearchDashboardsContextProvider services={services}> | ||
<I18nContext> | ||
<TableFeedbacksPanel onClose={onClose} onTurnOff={onTurnOff} /> | ||
</I18nContext> | ||
</OpenSearchDashboardsContextProvider> | ||
); | ||
ReactDOM.render(element, container); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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(<TableFeedbacksPanel onClose={onCloseMock} onTurnOff={onTurnOffMock} />); | ||
}); | ||
|
||
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(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
src/plugins/discover/public/application/components/top_nav/table_feedbacks_panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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<void>; | ||
} | ||
|
||
export const TableFeedbacksPanel = ({ onClose, onTurnOff }: TableFeedbacksPanelProps) => ( | ||
<EuiModal onClose={onClose} maxWidth={600}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle> | ||
<h4>Share your thoughts on the latest Discover features</h4> | ||
</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
|
||
<EuiModalBody> | ||
<EuiText> | ||
<p> | ||
Event tables: Documents are now expanded through a flyout. Density, column order, and | ||
sorting controls have been improved.{' '} | ||
<a href="https://survey.opensearch.org">Provide feedbacks</a>. | ||
</p> | ||
</EuiText> | ||
</EuiModalBody> | ||
|
||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={onClose}>Cancel</EuiButtonEmpty> | ||
<EuiButton onClick={onTurnOff} fill> | ||
Turn off new features | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
); |
17 changes: 17 additions & 0 deletions
17
src/plugins/discover/public/application/components/utils/local_storage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Storage } from '../../../../../opensearch_dashboards_utils/public'; | ||
|
||
export const DATA_GRID_TABLE_KEY = 'discover:dataGridTable'; | ||
|
||
export const getDataGridTableSetting = (storage: Storage): boolean => { | ||
const storedValue = storage.get(DATA_GRID_TABLE_KEY); | ||
return storedValue !== null ? JSON.parse(storedValue) : false; | ||
}; | ||
|
||
export const setDataGridTableSetting = (value: boolean, storage: Storage) => { | ||
storage.set(DATA_GRID_TABLE_KEY, JSON.stringify(value)); | ||
}; |
Oops, something went wrong.