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

[Backport 2.x] [Bug] Updated notebooks reporting button render #2287

Merged
merged 1 commit into from
Dec 7, 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
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
52 changes: 27 additions & 25 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({

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

View check run for this annotation

Codecov / codecov/patch

public/components/notebooks/components/notebook.tsx#L985

Added line #L985 was not covered by tests
isReportingActionsPopoverOpen: !this.state.isReportingActionsPopoverOpen,
})
}
>
Reporting
</EuiSmallButton>
}
isOpen={this.state.isReportingActionsPopoverOpen}
closePopover={() => this.setState({ isReportingActionsPopoverOpen: false })}

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

View check run for this annotation

Codecov / codecov/patch

public/components/notebooks/components/notebook.tsx#L994

Added line #L994 was not covered by tests
>
<EuiContextMenu initialPanelId={0} panels={reportingActionPanels} size="s" />
</EuiPopover>
</div>
) : null;

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