forked from elastic/kibana
-
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.
[Discover] Adds an Options menu for switching between the two table m…
…odes (elastic#97120) * [Discover] Adds an Options menu for enabling the Legacy table * Add unit test * Layout and copy tweaks * Update UI and fix unit test * Change description text * Revert legacy text mode functionality Co-authored-by: Ryan Keairns <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
a796024
commit af07b52
Showing
6 changed files
with
183 additions
and
0 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
5 changes: 5 additions & 0 deletions
5
src/plugins/discover/public/application/components/top_nav/open_options_popover.scss
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,5 @@ | ||
$dscOptionsPopoverWidth: $euiSizeL * 12; | ||
|
||
.dscOptionsPopover { | ||
width: $dscOptionsPopoverWidth; | ||
} |
49 changes: 49 additions & 0 deletions
49
src/plugins/discover/public/application/components/top_nav/open_options_popover.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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl } from '@kbn/test/jest'; | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
import { getServices } from '../../../kibana_services'; | ||
|
||
jest.mock('../../../kibana_services', () => { | ||
const mockUiSettings = new Map(); | ||
return { | ||
getServices: () => ({ | ||
core: { | ||
uiSettings: { | ||
get: (key: string) => { | ||
return mockUiSettings.get(key); | ||
}, | ||
set: (key: string, value: boolean) => { | ||
mockUiSettings.set(key, value); | ||
}, | ||
}, | ||
}, | ||
addBasePath: (path: string) => path, | ||
}), | ||
}; | ||
}); | ||
|
||
import { OptionsPopover } from './open_options_popover'; | ||
|
||
test('should display the correct text if datagrid is selected', () => { | ||
const element = document.createElement('div'); | ||
const component = mountWithIntl(<OptionsPopover onClose={jest.fn()} anchorElement={element} />); | ||
expect(findTestSubject(component, 'docTableMode').text()).toBe('Data grid'); | ||
}); | ||
|
||
test('should display the correct text if legacy table is selected', () => { | ||
const { | ||
core: { uiSettings }, | ||
} = getServices(); | ||
uiSettings.set('doc_table:legacy', true); | ||
const element = document.createElement('div'); | ||
const component = mountWithIntl(<OptionsPopover onClose={jest.fn()} anchorElement={element} />); | ||
expect(findTestSubject(component, 'docTableMode').text()).toBe('Legacy table'); | ||
}); |
98 changes: 98 additions & 0 deletions
98
src/plugins/discover/public/application/components/top_nav/open_options_popover.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,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { I18nStart } from 'kibana/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { EuiSpacer, EuiButton, EuiText, EuiWrappingPopover, EuiCode } from '@elastic/eui'; | ||
import { getServices } from '../../../kibana_services'; | ||
import './open_options_popover.scss'; | ||
|
||
let isOpen = false; | ||
|
||
interface OptionsPopoverProps { | ||
onClose: () => void; | ||
anchorElement: HTMLElement; | ||
} | ||
|
||
export function OptionsPopover(props: OptionsPopoverProps) { | ||
const { | ||
core: { uiSettings }, | ||
addBasePath, | ||
} = getServices(); | ||
const isLegacy = uiSettings.get('doc_table:legacy'); | ||
|
||
const mode = isLegacy | ||
? i18n.translate('discover.openOptionsPopover.legacyTableText', { | ||
defaultMessage: 'Legacy table', | ||
}) | ||
: i18n.translate('discover.openOptionsPopover.dataGridText', { | ||
defaultMessage: 'Data grid', | ||
}); | ||
|
||
return ( | ||
<EuiWrappingPopover ownFocus button={props.anchorElement} closePopover={props.onClose} isOpen> | ||
<div className="dscOptionsPopover"> | ||
<EuiText color="subdued" size="s"> | ||
<p> | ||
<strong>Current view mode:</strong>{' '} | ||
<EuiCode data-test-subj="docTableMode">{mode}</EuiCode> | ||
</p> | ||
</EuiText> | ||
<EuiSpacer size="s" /> | ||
<EuiText color="subdued" size="s"> | ||
<FormattedMessage | ||
id="discover.topNav.openOptionsPopover.description" | ||
defaultMessage="The new data grid layout includes enhanced data sorting, drag-and-drop columns, multi-document selection, and a full screen view. Toggle 'Use legacy table' in Advanced Settings to switch modes." | ||
/> | ||
</EuiText> | ||
<EuiSpacer /> | ||
<EuiButton | ||
iconType="tableDensityNormal" | ||
fullWidth | ||
href={addBasePath('/app/management/kibana/settings?query=Use legacy table')} | ||
> | ||
{i18n.translate('discover.openOptionsPopover.goToAdvancedSettings', { | ||
defaultMessage: 'Go to Advanced Settings', | ||
})} | ||
</EuiButton> | ||
</div> | ||
</EuiWrappingPopover> | ||
); | ||
} | ||
|
||
export function openOptionsPopover({ | ||
I18nContext, | ||
anchorElement, | ||
}: { | ||
I18nContext: I18nStart['Context']; | ||
anchorElement: HTMLElement; | ||
}) { | ||
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 = ( | ||
<I18nContext> | ||
<OptionsPopover onClose={onClose} anchorElement={anchorElement} /> | ||
</I18nContext> | ||
); | ||
ReactDOM.render(element, container); | ||
} |