-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Discover] Adds an Options menu for switching between the two table modes #97120
Merged
stratoula
merged 8 commits into
elastic:master
from
stratoula:discover-datagrid-popover
Apr 20, 2021
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad39f75
[Discover] Adds an Options menu for enabling the Legacy table
stratoula 1d5ecc7
Add unit test
stratoula d7516aa
Layout and copy tweaks
ryankeairns b5242bf
Merge branch 'master' into discover-datagrid-popover
kibanamachine 32bdf60
Merge pull request #3 from ryankeairns/discover-datagrid-popover
stratoula 9db48b6
Update UI and fix unit test
stratoula 7e0e83e
Change description text
stratoula 53488ab
Revert legacy text mode functionality
stratoula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} |
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
/* | ||
* 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 { shallow } from 'enzyme'; | ||
import { EuiLink } from '@elastic/eui'; | ||
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 contain a link with the correct text if datagrid is selected', () => { | ||
const element = document.createElement('div'); | ||
const component = shallow(<OptionsPopover onClose={jest.fn()} anchorElement={element} />); | ||
expect(component.find(EuiLink).length).toBe(1); | ||
expect(component.find(EuiLink).text()).toBe('Switch to legacy table'); | ||
}); | ||
|
||
test('should contain a link with 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 = shallow(<OptionsPopover onClose={jest.fn()} anchorElement={element} />); | ||
expect(component.find(EuiLink).text()).toBe('Switch to data grid'); | ||
}); |
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
/* | ||
* 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, EuiLink, EuiText, EuiWrappingPopover } 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 linkText = isLegacy | ||
? i18n.translate('discover.openOptionsPopover.switchToDataGridText', { | ||
defaultMessage: 'Switch to data grid', | ||
}) | ||
: i18n.translate('discover.openOptionsPopover.switchToLegacyText', { | ||
defaultMessage: 'Switch to legacy table', | ||
}); | ||
|
||
return ( | ||
<EuiWrappingPopover ownFocus button={props.anchorElement} closePopover={props.onClose} isOpen> | ||
<div className="dscOptionsPopover"> | ||
<EuiLink href={addBasePath('/app/management/kibana/settings?query=Use legacy table')}> | ||
{linkText} | ||
</EuiLink> | ||
<EuiSpacer size="s" /> | ||
<EuiText color="subdued" size="s"> | ||
<FormattedMessage | ||
id="discover.topNav.openOptionsPopover.description" | ||
defaultMessage="The new data grid layout includes better data sorting, drag-and-drop columns, and a full | ||
screen view. Enable this option if you prefer to fall back to the legacy table." | ||
/> | ||
</EuiText> | ||
</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); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx a lot for taking care of this 🙇 , so here's my first thought while playing with this: I think also the link description should be different depending on which state is selected, FYI @gchaps & @shaunmcgough for finding the right words here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps: "The new data grid features faster loading, better comparison, a flyout window, enhanced options, and is going to replace the legacy table soon. Enable this option if you prefer to fall back to the legacy table."
@gchaps what say you?