Skip to content

Commit

Permalink
Merge branch 'main' into panelCypressFixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ritvibhatt authored Dec 6, 2024
2 parents 9e89788 + 207004a commit 93e7719
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .cypress/integration/notebooks_test/notebooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ describe('Testing paragraphs', () => {
cy.get('h3[data-test-subj="notebookTitle"]').contains(TEST_NOTEBOOK).should('exist');
cy.get('[data-test-subj="notebook-duplicate-icon"]').click();
cy.get('.euiButton__text').contains('Duplicate').click();
cy.get('h3[data-test-subj="notebookTitle"]').contains(TEST_NOTEBOOK + ' (copy)').should('exist');

cy.get('[data-test-subj="notebook-edit-icon"]').click();
cy.get('input.euiFieldText[data-autofocus="true"]').focus().type(' (rename)');
cy.get('input.euiFieldText[data-autofocus="true"]').clear().type(TEST_NOTEBOOK + ' (rename)');
cy.get('.euiButton__text').last().contains('Rename').click();
cy.reload();

cy.get('h3[data-test-subj="notebookTitle"]')
.contains(TEST_NOTEBOOK + ' (rename)')
Expand Down
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
8 changes: 5 additions & 3 deletions public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ export class Main extends React.Component<MainProps, MainState> {
if (this.props.dataSourceEnabled) {
// If `MDS` is enabled, only fetch from the first endpoint.
return this.props.http
.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook/`)
.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook`)
.then((savedNotebooksResponse) => {
this.setState({ data: savedNotebooksResponse.data });
})
.catch((err) => {
console.error('Issue in fetching the notebooks', err.body.message);
});
}
// If `MDS` is not enabled /savedNotebook/ API returns notebooks stored as saved objects, and the other one returns notebooks stored as observability objects.
// If `MDS` is not enabled /savedNotebook API returns notebooks stored as saved objects, and the other one returns notebooks stored as observability objects.
// ${NOTEBOOKS_API_PREFIX}/savedNotebook: this point to new notebooks saved in saved objects
// ${NOTEBOOKS_API_PREFIX}/: this point to old notebooks saved in observability index
return Promise.all([
this.props.http.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook/`),
this.props.http.get(`${NOTEBOOKS_API_PREFIX}/savedNotebook`),
this.props.http.get(`${NOTEBOOKS_API_PREFIX}/`),
])
.then(([savedNotebooksResponse, secondResponse]) => {
Expand Down
70 changes: 36 additions & 34 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 @@ -416,7 +416,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
};

return this.props.http
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`, {
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`, {
body: JSON.stringify(addParaObj),
})
.then((res) => {
Expand Down Expand Up @@ -468,7 +468,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
};

return this.props.http
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs/`, {
.post(`${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs`, {
body: JSON.stringify(moveParaObj),
})
.then((_res) => this.setState({ paragraphs, parsedPara }))
Expand Down Expand Up @@ -499,7 +499,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
noteId: this.props.openedNoteId,
};
this.props.http
.put(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall/`, {
.put(`${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall`, {
body: JSON.stringify(clearParaObj),
})
.then((res) => {
Expand Down Expand Up @@ -537,7 +537,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
};
const isValid = isValidUUID(this.props.openedNoteId);
const route = isValid
? `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run/`
? `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run`
: `${NOTEBOOKS_API_PREFIX}/paragraph/update/run/`;
return this.props.http
.post(route, {
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
10 changes: 5 additions & 5 deletions server/routes/notebooks/paraRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export function registerParaRoute(router: IRouter) {

router.post(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -314,7 +314,7 @@ export function registerParaRoute(router: IRouter) {
);
router.put(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/clearall`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -377,7 +377,7 @@ export function registerParaRoute(router: IRouter) {

router.post(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/update/run`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -413,7 +413,7 @@ export function registerParaRoute(router: IRouter) {

router.put(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/paragraph`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down Expand Up @@ -445,7 +445,7 @@ export function registerParaRoute(router: IRouter) {
);
router.post(
{
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs/`,
path: `${NOTEBOOKS_API_PREFIX}/savedNotebook/set_paragraphs`,
validate: {
body: schema.object({
noteId: schema.string(),
Expand Down

0 comments on commit 93e7719

Please sign in to comment.