Skip to content

Commit

Permalink
updated notebooks reporting button render (#2278) (#2287)
Browse files Browse the repository at this point in the history
(cherry picked from commit 207004a)

Signed-off-by: Shenoy Pratik <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 90bc9ce commit 64e98ce
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ exports[`<Notebook /> spec Renders the empty component 1`] = `
>
<button
class="euiButton euiButton--primary euiButton--small"
data-test-subj="reporting-actions-button"
id="reportingActionsButton"
type="button"
>
Expand Down
55 changes: 55 additions & 0 deletions public/components/notebooks/components/__tests__/notebook.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,61 @@ describe('<Notebook /> spec', () => {
expect(deleteNotebook).toHaveBeenCalledTimes(1);
});

it('Checks notebook reporting action presence', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));

const utils = render(
<Notebook
pplService={pplService}
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
renameNotebook={jest.fn()}
cloneNotebook={jest.fn()}
deleteNotebook={deleteNotebook}
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});

const button = utils.queryByTestId('reporting-actions-button');
expect(button).toBeInTheDocument();
});

it('Checks notebook reporting action absence', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));

const utils = render(
<Notebook
pplService={pplService}
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
renameNotebook={jest.fn()}
cloneNotebook={jest.fn()}
deleteNotebook={deleteNotebook}
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={true}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});
const button = utils.queryByTestId('reporting-actions-button');
expect(button).not.toBeInTheDocument();
});

it('Renders the visualization component', async () => {
SavedObjectsActions.getBulk = jest.fn().mockResolvedValue({
observabilityObjectList: [{ savedVisualization: sampleSavedVisualization }],
Expand Down
52 changes: 27 additions & 25 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -970,31 +970,33 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
},
];

const showReportingContextMenu = this.state.isReportingPluginInstalled ? (
<div>
<EuiPopover
panelPaddingSize="none"
button={
<EuiSmallButton
id="reportingActionsButton"
iconType="arrowDown"
iconSide="right"
onClick={() =>
this.setState({
isReportingActionsPopoverOpen: !this.state.isReportingActionsPopoverOpen,
})
}
>
Reporting
</EuiSmallButton>
}
isOpen={this.state.isReportingActionsPopoverOpen}
closePopover={() => this.setState({ isReportingActionsPopoverOpen: false })}
>
<EuiContextMenu initialPanelId={0} panels={reportingActionPanels} size="s" />
</EuiPopover>
</div>
) : null;
const showReportingContextMenu =
this.state.isReportingPluginInstalled && !this.state.dataSourceMDSEnabled ? (
<div>
<EuiPopover
panelPaddingSize="none"
button={
<EuiSmallButton
data-test-subj="reporting-actions-button"
id="reportingActionsButton"
iconType="arrowDown"
iconSide="right"
onClick={() =>
this.setState({
isReportingActionsPopoverOpen: !this.state.isReportingActionsPopoverOpen,
})
}
>
Reporting
</EuiSmallButton>
}
isOpen={this.state.isReportingActionsPopoverOpen}
closePopover={() => this.setState({ isReportingActionsPopoverOpen: false })}
>
<EuiContextMenu initialPanelId={0} panels={reportingActionPanels} size="s" />
</EuiPopover>
</div>
) : null;

const showLoadingModal = this.state.isReportingLoadingModalOpen ? (
<GenerateReportLoadingModal setShowLoading={this.toggleReportingLoadingModal} />
Expand Down

0 comments on commit 64e98ce

Please sign in to comment.