Skip to content
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

[Bug] Updated notebooks reporting button render #2278

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -54,9 +54,9 @@
const cloneNotebook = jest.fn();
const deleteNotebook = jest.fn();
const setToast = jest.fn();
const location = jest.fn() as any;

Check warning on line 57 in public/components/notebooks/components/__tests__/notebook.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
location.search = '';
const history = jest.fn() as any;

Check warning on line 59 in public/components/notebooks/components/__tests__/notebook.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
history.replace = jest.fn();
history.push = jest.fn();

Expand Down Expand Up @@ -518,6 +518,61 @@
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 @@
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 { 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 @@
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 All @@ -78,7 +78,7 @@
http: CoreStart['http'];
parentBreadcrumb: ChromeBreadcrumb;
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
renameNotebook: (newNoteName: string, noteId: string) => Promise<any>;

Check warning on line 81 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
cloneNotebook: (newNoteName: string, noteId: string) => Promise<string>;
deleteNotebook: (noteList: string[], toastMessage?: string) => void;
setToast: (title: string, color?: string, text?: string) => void;
Expand All @@ -97,7 +97,7 @@
path: string;
dateCreated: string;
dateModified: string;
paragraphs: any; // notebook paragraphs fetched from API

Check warning on line 100 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
parsedPara: ParaType[]; // paragraphs parsed to a common format
vizPrefix: string; // prefix for visualizations in Zeppelin Adaptor
isAddParaPopoverOpen: boolean;
Expand Down Expand Up @@ -153,7 +153,7 @@
};

// parse paragraphs based on backend
parseParagraphs = (paragraphs: any[]): ParaType[] => {

Check warning on line 156 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
try {
const parsedPara = defaultParagraphParser(paragraphs);
parsedPara.forEach((para: ParaType) => {
Expand Down Expand Up @@ -587,7 +587,7 @@
}
};

runForAllParagraphs = (reducer: (para: ParaType, _index: number) => Promise<any>) => {

Check warning on line 590 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return this.state.parsedPara
.map((para: ParaType, _index: number) => () => reducer(para, _index))
.reduce((chain, func) => chain.then(func), Promise.resolve());
Expand Down Expand Up @@ -685,7 +685,7 @@
this.setState({ dataSourceMDSId: id, dataSourceMDSLabel: label });
};

loadQueryResultsFromInput = async (paragraph: any, dataSourceMDSId?: any) => {

Check warning on line 688 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 688 in public/components/notebooks/components/notebook.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const queryType =
paragraph.input.inputText.substring(0, 4) === '%sql' ? 'sqlquery' : 'pplquery';
const query = {
Expand Down Expand Up @@ -970,31 +970,33 @@
},
];

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
Loading