-
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
[Lens] Add toolbar api #69263
Merged
Merged
[Lens] Add toolbar api #69263
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bebac29
add toolbar api
flash1293 e983014
fix teests
flash1293 3fbff62
fix types
flash1293 426f2ce
fix functional test
flash1293 44a17c3
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 8c7381e
add back title
flash1293 64ee8ef
remove separator line
flash1293 9bb7843
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 c1ddaaa
fix i18n
flash1293 e51ff5e
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/_…
flash1293 e3c6f94
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 a278772
Merge branch 'lens/toolbar' of github.com:flash1293/kibana into lens/…
flash1293 bfb6898
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 b3fb6e8
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 2434486
do not show unsaved when there is no cahrt
flash1293 85c128e
revert unnecessary changes
flash1293 1ece895
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 34cff58
always show title if available
flash1293 7a20163
Merge remote-tracking branch 'upstream/master' into lens/toolbar
flash1293 0246d64
Merge branch 'master' into lens/toolbar
elasticmachine 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
65 changes: 65 additions & 0 deletions
65
...ck/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel_wrapper.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,65 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Visualization } from '../../types'; | ||
import { createMockVisualization, createMockFramePublicAPI, FrameMock } from '../mocks'; | ||
import { mountWithIntl as mount } from 'test_utils/enzyme_helpers'; | ||
import { ReactWrapper } from 'enzyme'; | ||
import { WorkspacePanelWrapper, WorkspacePanelWrapperProps } from './workspace_panel_wrapper'; | ||
|
||
describe('workspace_panel_wrapper', () => { | ||
let mockVisualization: jest.Mocked<Visualization>; | ||
let mockFrameAPI: FrameMock; | ||
let instance: ReactWrapper<WorkspacePanelWrapperProps>; | ||
|
||
beforeEach(() => { | ||
mockVisualization = createMockVisualization(); | ||
mockFrameAPI = createMockFramePublicAPI(); | ||
}); | ||
|
||
afterEach(() => { | ||
instance.unmount(); | ||
}); | ||
|
||
it('should render its children', () => { | ||
const MyChild = () => <span>The child elements</span>; | ||
instance = mount( | ||
<WorkspacePanelWrapper | ||
dispatch={jest.fn()} | ||
framePublicAPI={mockFrameAPI} | ||
visualizationState={{}} | ||
activeVisualization={mockVisualization} | ||
emptyExpression={false} | ||
> | ||
<MyChild /> | ||
</WorkspacePanelWrapper> | ||
); | ||
|
||
expect(instance.find(MyChild)).toHaveLength(1); | ||
}); | ||
|
||
it('should call the toolbar renderer if provided', () => { | ||
const renderToolbarMock = jest.fn(); | ||
const visState = { internalState: 123 }; | ||
instance = mount( | ||
<WorkspacePanelWrapper | ||
dispatch={jest.fn()} | ||
framePublicAPI={mockFrameAPI} | ||
visualizationState={visState} | ||
children={<span />} | ||
activeVisualization={{ ...mockVisualization, renderToolbar: renderToolbarMock }} | ||
emptyExpression={false} | ||
/> | ||
); | ||
|
||
expect(renderToolbarMock).toHaveBeenCalledWith(expect.any(Element), { | ||
state: visState, | ||
frame: mockFrameAPI, | ||
setState: expect.anything(), | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -4,25 +4,86 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiPageContent, EuiPageContentHeader, EuiPageContentBody } from '@elastic/eui'; | ||
import React, { useCallback } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import classNames from 'classnames'; | ||
import { | ||
EuiPageContent, | ||
EuiPageContentBody, | ||
EuiPageContentHeader, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
} from '@elastic/eui'; | ||
import { FramePublicAPI, Visualization } from '../../types'; | ||
import { NativeRenderer } from '../../native_renderer'; | ||
import { Action } from './state_management'; | ||
|
||
interface Props { | ||
title: string; | ||
export interface WorkspacePanelWrapperProps { | ||
children: React.ReactNode | React.ReactNode[]; | ||
framePublicAPI: FramePublicAPI; | ||
visualizationState: unknown; | ||
activeVisualization: Visualization | null; | ||
dispatch: (action: Action) => void; | ||
emptyExpression: boolean; | ||
title?: string; | ||
} | ||
|
||
export function WorkspacePanelWrapper({ children, title }: Props) { | ||
export function WorkspacePanelWrapper({ | ||
children, | ||
framePublicAPI, | ||
visualizationState, | ||
activeVisualization, | ||
dispatch, | ||
title, | ||
emptyExpression, | ||
}: WorkspacePanelWrapperProps) { | ||
const setVisualizationState = useCallback( | ||
(newState: unknown) => { | ||
if (!activeVisualization) { | ||
return; | ||
} | ||
dispatch({ | ||
type: 'UPDATE_VISUALIZATION_STATE', | ||
visualizationId: activeVisualization.id, | ||
newState, | ||
clearStagedPreview: false, | ||
}); | ||
}, | ||
[dispatch] | ||
); | ||
return ( | ||
<EuiPageContent className="lnsWorkspacePanelWrapper"> | ||
{title && ( | ||
<EuiPageContentHeader className="lnsWorkspacePanelWrapper__pageContentHeader"> | ||
<span data-test-subj="lns_ChartTitle">{title}</span> | ||
</EuiPageContentHeader> | ||
cchaos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<EuiFlexGroup gutterSize="s" direction="column" alignItems="stretch"> | ||
{activeVisualization && activeVisualization.renderToolbar && ( | ||
<EuiFlexItem grow={false}> | ||
<NativeRenderer | ||
render={activeVisualization.renderToolbar} | ||
nativeProps={{ | ||
frame: framePublicAPI, | ||
state: visualizationState, | ||
setState: setVisualizationState, | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
)} | ||
<EuiPageContentBody className="lnsWorkspacePanelWrapper__pageContentBody"> | ||
{children} | ||
</EuiPageContentBody> | ||
</EuiPageContent> | ||
<EuiFlexItem> | ||
<EuiPageContent className="lnsWorkspacePanelWrapper"> | ||
{(!emptyExpression || title) && ( | ||
<EuiPageContentHeader | ||
className={classNames('lnsWorkspacePanelWrapper__pageContentHeader', { | ||
'lnsWorkspacePanelWrapper__pageContentHeader--unsaved': !title, | ||
})} | ||
> | ||
<span data-test-subj="lns_ChartTitle"> | ||
{title || | ||
i18n.translate('xpack.lens.chartTitle.unsaved', { defaultMessage: 'Unsaved' })} | ||
</span> | ||
</EuiPageContentHeader> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic doesn't look right to me: it hides the title for a saved visualization in the following case:
|
||
<EuiPageContentBody className="lnsWorkspacePanelWrapper__pageContentBody"> | ||
{children} | ||
</EuiPageContentBody> | ||
</EuiPageContent> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
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
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.
Can you add
activeVisualization
to dependency array ofuseCallback
?