Skip to content

Commit

Permalink
updated notebooks reporting button render
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <[email protected]>
  • Loading branch information
ps48 committed Dec 5, 2024
1 parent ab396b9 commit d207a53
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 30 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
62 changes: 32 additions & 30 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

import {
EuiSmallButton,
EuiButtonGroup,
EuiButtonGroupOptionProps,
EuiButtonIcon,
EuiCallOut,
EuiCard,
EuiContextMenu,
Expand All @@ -19,18 +19,18 @@ import {
EuiPageBody,
EuiPanel,
EuiPopover,
EuiSmallButton,
EuiSpacer,
EuiText,
EuiButtonIcon,
EuiTitle,
EuiToolTip,
} from '@elastic/eui';
import { FormattedMessage } from '@osd/i18n/react';
import CSS from 'csstype';
import moment from 'moment';
import queryString from 'query-string';
import React, { Component } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { FormattedMessage } from '@osd/i18n/react';
import {
ChromeBreadcrumb,
CoreStart,
Expand All @@ -43,6 +43,8 @@ import { CREATE_NOTE_MESSAGE, NOTEBOOKS_API_PREFIX } from '../../../../common/co
import { UI_DATE_FORMAT } from '../../../../common/constants/shared';
import { ParaType } from '../../../../common/types/notebooks';
import { setNavBreadCrumbs } from '../../../../common/utils/set_nav_bread_crumbs';
import { HeaderControlledComponentsWrapper } from '../../../../public/plugin_helpers/plugin_headerControl';
import { coreRefs } from '../../../framework/core_refs';
import PPLService from '../../../services/requests/ppl';
import { GenerateReportLoadingModal } from './helpers/custom_modals/reporting_loading_modal';
import { defaultParagraphParser } from './helpers/default_parser';
Expand All @@ -54,8 +56,6 @@ import {
generateInContextReport,
} from './helpers/reporting_context_menu_helper';
import { Paragraphs } from './paragraph_components/paragraphs';
import { HeaderControlledComponentsWrapper } from '../../../../public/plugin_helpers/plugin_headerControl';
import { coreRefs } from '../../../framework/core_refs';

const newNavigation = coreRefs.chrome?.navGroup.getNavGroupEnabled();

Expand Down 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 d207a53

Please sign in to comment.